Main Page | Class Hierarchy | Class List | File List | Class Members

SmartClientControl.cs

00001 using System;
00002 using System.Data;
00003 using System.Threading;
00004 
00005 
00006 namespace GPRSWeb.SmartDeviceClient
00007 {
00008 
00009 //      /// <summary>
00010 //      /// Processes Client Requests and manages client components
00011 //      /// </summary>
00012 //      public class SmartClientControl {
00013 //              internal MessageLogger msgLog;
00019 //
00020 //              Thread processingThread;
00021 //
00022 //              
00023 //              public SmartClientControl(MessageLogger log) {
00024 //                      this.msgLog = log;
00025 //                      try {
00026 //                              log.Log("Initialising GRPSWeb Smart Client Library (Version {0}, Build {1})", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(2), System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Build);
00032 //                      } catch (ApplicationException appEx) {
00033 //                              throw new ApplicationException("Unable to create Client Control object\r\n" + appEx.ToString());
00034 //                      }
00035 //              }
00036 //
00037 //              /// <summary>
00038 //              /// Called when protocol stack is reset, in case client needs to react to this information.
00039 //              /// Currently it simply calles the reset connection handler in server stub, 
00040 //              /// which calls the reset handler in the protocol stack
00041 //              /// </summary>
00042 //              public void ResetConnection() {
00043 //                      msgLog.LogError("Connection Rest");
00044 //                      serverStub.ResetConnection();
00045 //              }
00046 //
00047 //              /// <summary>
00048 //              /// Client's main processing loop. Called to run in own thread.
00049 //              /// </summary>
00050 //              protected void Run() {
00051 //                      ClientHTTPRequestQueueObject currentReqQObj; 
00052 //                      Connection client;
00053 //                      try {
00054 //                              while(true) {
00055 //                                      // dequeue request
00056 //                                      currentReqQObj = (ClientHTTPRequestQueueObject)userRequests.DequeueBlocking();
00057 //
00058 //                                      // Assign to client the connection we want to send the results to
00059 //                                      client = currentReqQObj.connection;
00060 //
00061 //                                      // check to see if request can be serviced by cache
00062 //                                      try {
00063 //                                              if (clientCacheManager.CanService(currentReqQObj) && !currentReqQObj.HasPragmaNoCacheSet) { /*DISABLE CACHE*/
00064 //                                                      clientCacheManager.ServiceReq(currentReqQObj, client); /*DISABLE CACHE*/
00065 //                                              } else { // service from upstream /*DISABLE CACHE*/
00066 //                                                      if (currentReqQObj.HasPragmaNoCacheSet) {
00067 //                                                              myConsole.WriteLine("- Pragma: no-cache is set in request for {0}", currentReqQObj.URI);
00068 //                                                      }
00069 //                                                      serverStub.ServiceReq(currentReqQObj, client);
00070 //                                              }/*DISABLE CACHE*/      
00071 //                                      } catch (CacheNotFoundException ex) {
00072 //                                              myConsole.WriteLine("*** "+ ex.ToString() + " ***");
00073 //                                              myConsole.WriteLine("- Issuing regular request");
00074 //                                              serverStub.ServiceReq(currentReqQObj, client);
00075 //                                      }
00076 //                              }
00077 //                      } catch (ThreadAbortException) {
00078 //                              myConsole.WriteLine("[Caught Thread Abort Exception: Shutting down Request Queue processor]");
00079 //                      } catch (Exception ex) {
00080 //                              myConsole.Error.WriteLine("*** Unhandled error in client library. Shutting Down ***\n{0}", ex);
00081 //                              Stop();
00082 //                      }
00083 //              }
00084 // 
00085 //              public void Start() {
00086 //                      this.processingThread = new Thread(new ThreadStart(run));
00087 //                      serverStub.Start();
00088 //                      processingThread.Start();
00089 //                      connectionManager.Start();
00090 //                      CacheIndexMessage ciMsg = clientCacheManager.GetCacheIndexMessage();/*DISABLE CACHE*/                   
00091 //                      ciMsg.Destination = settings.ServerID;/*DISABLE CACHE*/                 
00092 //                      serverStub.SendCacheIndexMessage(ciMsg);/*DISABLE CACHE*/                       
00093 //              }
00094 //
00095 //              public void Stop() {
00096 //                      myConsole.WriteLine("+++ Stopping Client Control library +++");
00097 //                      if (processingThread != null && processingThread.IsAlive) {
00098 //                              processingThread.Abort();
00099 //                      }
00100 //                      // stop child processes
00101 //                      connectionManager.Stop();
00102 //                      clientCacheManager.Stop();
00103 //                      serverStub.Stop();
00104 //                      // wait for termination of client control thread
00105 //                      if (processingThread != null && processingThread.IsAlive) {
00106 //                              processingThread.Join();
00107 //                      }
00108 //                      myConsole.WriteLine("+++ Client Control library Stopped +++");
00109 //              }
00110 //
00111 //              public void Join() {
00112 //                      processingThread.Join();
00113 //              }
00114 //      } 
00115 
00116         /*************************************************************************/
00117 
00118 
00119 //      class ClientHTTPRequestQueueObject : HTTPRequestQueueObject {
00120 //              public Connection connection;
00121 //              public ClientHTTPRequestQueueObject(System.Net.Sockets.NetworkStream s) : base(s) {}
00122 //              public ClientHTTPRequestQueueObject(HTTPRequest req) : base(req) {}
00123 //      }
00124 
00125 //      /*************************************************************************/
00126 //      /// <summary>
00127 //      /// Logs client activity
00128 //      /// </summary>
00129 //      public class Logger {
00130 //              System.IO.StreamWriter textOut;
00131 //              bool started;
00132 //              ClientSettings settings;
00133 //
00134 //              /// <summary>
00135 //              /// Default constructor. If logging enabled, starts logging.
00136 //              /// </summary>
00137 //              /// <param name="settings"></param>
00138 //              public Logger(ClientSettings settings) {
00139 //                      this.settings = settings;
00140 //                      started = false;
00141 //                      if (settings.LogRequests) { 
00142 //                              Start(); 
00143 //                      }
00144 //              }
00145 //
00146 //              /// <summary>
00147 //              /// Logs a given client request
00148 //              /// </summary>
00149 //              /// <param name="requestUri">URI of the client request</param>
00150 //              /// <param name="startTime">time request received</param>
00151 //              /// <param name="endTime">time request was completely serviced</param>
00152 //              public void Log(Uri requestUri, DateTime startTime, DateTime endTime) {
00153 //                      try {
00154 //                              if (started) {
00155 //                                      TimeSpan delta = endTime - startTime;
00156 //                                      textOut.WriteLine("{0}\t{1}\t{2}\t{3}", requestUri.ToString(), delta.ToString(), startTime.ToString(), endTime.ToString()); 
00157 //                                      textOut.Flush();
00158 //                              }
00159 //                      } catch (Exception ex) {
00160 //                              myConsole.Error.WriteLine("*** Error Writing to Client Log: ***\n{0}", ex);
00161 //                      }
00162 //              }
00163 //
00164 //              /// <summary>
00165 //              /// Begins logging of client-processed requests
00166 //              /// </summary>
00167 //              public void Start() {
00168 //                      try {
00169 //                              if (!started) {
00170 //                                      textOut = new StreamWriter("usage.log", true); 
00171 //                                      textOut.WriteLine("Logging started {0}", DateTime.Now.ToString());
00172 //                                      started = true;
00173 //                              } 
00174 //                      } catch (Exception ex) {
00175 //                              myConsole.Error.WriteLine("*** Error Starting Client Log: ***\n{0}", ex);
00176 //                      }
00177 //              }
00178 //
00179 //              /// <summary>
00180 //              /// Ends logging of client-processed requests
00181 //              /// </summary>
00182 //              public void Stop() {
00183 //                      try {
00184 //                              if (started) {
00185 //                                      textOut.WriteLine("Logging stopped {0}", DateTime.Now.ToString());
00186 //                                      textOut.WriteLine();
00187 //                                      textOut.Close();
00188 //                              }
00189 //                      } catch (Exception ex) {
00190 //                              myConsole.Error.WriteLine("*** Error Closing Client Log: ***\n{0}", ex);
00191 //                      }
00192 //              }
00193 //      }
00194 }

Generated on Mon May 8 22:07:27 2006 by  doxygen 1.3.9.1