Changeset 3578 for trunk/sources/HeuristicLab.Hive.Client.Communication
- Timestamp:
- 05/01/10 13:58:24 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Hive.Client.Communication/3.2
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Hive.Client.Communication/3.2/CommunicationsPlugin.cs
r2591 r3578 35 35 [PluginDependency("HeuristicLab.Hive.Client.Common-3.2")] 36 36 [PluginDependency("HeuristicLab.Hive.Contracts-3.2")] 37 [PluginDependency("HeuristicLab.Tracing")] 37 38 public class CommunicationsPlugin : PluginBase { 38 39 } -
trunk/sources/HeuristicLab.Hive.Client.Communication/3.2/HeuristicLab.Hive.Client.Communication-3.2.csproj
r3203 r3578 120 120 <Name>HeuristicLab.PluginInfrastructure</Name> 121 121 </ProjectReference> 122 <ProjectReference Include="..\..\HeuristicLab.Tracing\3.2\HeuristicLab.Tracing-3.2.csproj"> 123 <Project>{EE2034D9-6E27-48A1-B855-42D45F69A4FC}</Project> 124 <Name>HeuristicLab.Tracing-3.2</Name> 125 </ProjectReference> 122 126 </ItemGroup> 123 127 <ItemGroup> -
trunk/sources/HeuristicLab.Hive.Client.Communication/3.2/WcfService.cs
r3203 r3578 33 33 using System.IO; 34 34 using System.Runtime.Serialization.Formatters.Binary; 35 using HeuristicLab.Tracing; 35 36 36 37 namespace HeuristicLab.Hive.Client.Communication { … … 45 46 /// <returns>the Instance of the WcfService class</returns> 46 47 public static WcfService Instance { 47 get { 48 get { 48 49 if (instance == null) { 50 Logger.Debug("New WcfService Instance created"); 49 51 instance = new WcfService(); 50 52 } … … 76 78 public void Connect() { 77 79 try { 80 Logger.Debug("Starting the Connection Process"); 78 81 if (String.Empty.Equals(ServerIP) || ServerPort == 0) { 79 Logg ing.Instance.Info(this.ToString(),"No Server IP or Port set!");82 Logger.Info("No Server IP or Port set!"); 80 83 return; 81 84 } 85 86 Logger.Debug("Creating the new connection proxy"); 82 87 proxy = new ClientFacadeClient( 83 88 WcfSettings.GetStreamedBinding(), 84 89 new EndpointAddress("net.tcp://" + ServerIP + ":" + ServerPort + "/HiveServer/ClientCommunicator") 85 90 ); 86 91 Logger.Debug("Created the new connection proxy"); 92 93 Logger.Debug("Registring new Events"); 87 94 proxy.LoginCompleted += new EventHandler<LoginCompletedEventArgs>(proxy_LoginCompleted); 88 95 proxy.SendStreamedJobCompleted += new EventHandler<SendStreamedJobCompletedEventArgs>(proxy_SendStreamedJobCompleted); … … 90 97 proxy.ProcessSnapshotStreamedCompleted += new EventHandler<ProcessSnapshotStreamedCompletedEventArgs>(proxy_ProcessSnapshotStreamedCompleted); 91 98 proxy.ProcessHeartBeatCompleted += new EventHandler<ProcessHeartBeatCompletedEventArgs>(proxy_ProcessHeartBeatCompleted); 99 Logger.Debug("Registered new Events"); 100 Logger.Debug("Opening the Connection"); 92 101 proxy.Open(); 102 Logger.Debug("Opened the Connection"); 93 103 94 104 ConnState = NetworkEnum.WcfConnState.Connected; 95 105 ConnectedSince = DateTime.Now; 96 97 if (Connected != null) 98 Connected(this, new EventArgs()); 99 //Todo: This won't be hit. EVER 106 107 if (Connected != null) { 108 Logger.Debug("Calling the connected Event"); 109 Connected(this, new EventArgs()); 110 //Todo: This won't be hit. EVER 111 } 100 112 if (ConnState == NetworkEnum.WcfConnState.Failed) 101 113 ConnectionRestored(this, new EventArgs()); … … 113 125 /// <param name="serverPort">current Server Port</param> 114 126 public void Connect(String serverIP, int serverPort) { 127 Logger.Debug("Called Connected with " + serverIP + ":" + serverPort); 115 128 String oldIp = this.ServerIP; 116 129 int oldPort = this.ServerPort; … … 124 137 125 138 public void SetIPAndPort(String serverIP, int serverPort) { 139 Logger.Debug("Called with " + serverIP + ":" + serverPort); 126 140 this.ServerIP = serverIP; 127 141 this.ServerPort = serverPort; … … 141 155 private void HandleNetworkError(Exception e) { 142 156 ConnState = NetworkEnum.WcfConnState.Failed; 143 Logg ing.Instance.Error(this.ToString(), "exception: ",e);157 Logger.Error("Network exception occurred: " + e); 144 158 } 145 159 … … 152 166 public event System.EventHandler<LoginCompletedEventArgs> LoginCompleted; 153 167 public void LoginAsync(ClientDto clientInfo) { 154 if (ConnState == NetworkEnum.WcfConnState.Connected) 168 if (ConnState == NetworkEnum.WcfConnState.Connected) { 169 Logger.Debug("STARTED: Login Async"); 155 170 proxy.LoginAsync(clientInfo); 171 } 156 172 } 157 173 private void proxy_LoginCompleted(object sender, LoginCompletedEventArgs e) { 158 if (e.Error == null) 174 if (e.Error == null) { 175 Logger.Debug("ENDED: Login Async"); 159 176 LoginCompleted(sender, e); 160 else177 } else 161 178 HandleNetworkError(e.Error.InnerException); 162 179 } … … 165 182 try { 166 183 if (ConnState == NetworkEnum.WcfConnState.Connected) { 184 Logger.Debug("STARTED: Login Sync"); 167 185 Response res = proxy.Login(clientInfo); 168 186 if (!res.Success) { 169 Logg ing.Instance.Error(this.ToString(), "Login Failed! " + res.StatusMessage);170 HandleNetworkError(new Exception(res.StatusMessage));187 Logger.Error("FAILED: Login Failed! " + res.StatusMessage); 188 throw new Exception(res.StatusMessage); 171 189 } else { 172 ConnState = NetworkEnum.WcfConnState.Loggedin;173 Logging.Instance.Info(this.ToString(), res.StatusMessage);190 Logger.Info("ENDED: Login succeeded" + res.StatusMessage); 191 ConnState = NetworkEnum.WcfConnState.Loggedin; 174 192 } 175 193 } … … 188 206 public event System.EventHandler<SendJobCompletedEventArgs> SendJobCompleted; 189 207 public void SendJobAsync(Guid guid) { 190 if (ConnState == NetworkEnum.WcfConnState.Loggedin) 208 if (ConnState == NetworkEnum.WcfConnState.Loggedin) { 209 Logger.Debug("STARTED: Fetching of Jobs from Server for Client"); 191 210 proxy.SendStreamedJobAsync(guid); 211 } 192 212 } 193 213 194 214 void proxy_SendStreamedJobCompleted(object sender, SendStreamedJobCompletedEventArgs e) { 195 215 if (e.Error == null) { 216 Logger.Debug("ENDED: Fetching of Jobs from Server for Client"); 196 217 Stream stream = null; 197 218 MemoryStream memStream = null; … … 220 241 new SendJobCompletedEventArgs(new object[] { response, memStream.GetBuffer() }, e.Error, e.Cancelled, e.UserState); 221 242 SendJobCompleted(sender, completedEventArgs); 222 } 223 finally { 243 } catch (Exception ex) { 244 Logger.Error(ex); 245 } finally { 224 246 if(stream != null) 225 247 stream.Dispose(); … … 241 263 public void StoreFinishedJobResultAsync(Guid clientId, Guid jobId, byte[] result, double percentage, Exception exception, bool finished) { 242 264 if (ConnState == NetworkEnum.WcfConnState.Loggedin) { 265 Logger.Debug("STARTED: Sending back the finished job results"); 266 Logger.Debug("Building stream"); 243 267 Stream stream = 244 268 GetStreamedJobResult(clientId, jobId, result, percentage, exception); 245 269 Logger.Debug("Builded stream"); 270 Logger.Debug("Making the call"); 246 271 proxy.StoreFinishedJobResultStreamedAsync(stream, stream); 247 272 } 248 273 } 249 274 private void proxy_StoreFinishedJobResultStreamedCompleted(object sender, StoreFinishedJobResultStreamedCompletedEventArgs e) { 275 Logger.Debug("Finished storing the job"); 250 276 Stream stream = 251 277 (Stream)e.UserState; 252 if (stream != null) 278 if (stream != null) { 279 Logger.Debug("Stream not null, disposing it"); 253 280 stream.Dispose(); 254 281 } 255 282 if (e.Error == null) { 256 283 StoreFinishedJobResultCompletedEventArgs args = 257 284 new StoreFinishedJobResultCompletedEventArgs( 258 285 new object[] { e.Result }, e.Error, e.Cancelled, e.UserState); 286 Logger.Debug("calling the Finished Job Event"); 259 287 StoreFinishedJobResultCompleted(sender, args); 288 Logger.Debug("ENDED: Sending back the finished job results"); 260 289 } else 261 290 HandleNetworkError(e.Error); … … 300 329 public void SendHeartBeatAsync(HeartBeatData hbd) { 301 330 if (ConnState == NetworkEnum.WcfConnState.Loggedin) 331 Logger.Debug("STARTING: sending heartbeat"); 302 332 proxy.ProcessHeartBeatAsync(hbd); 303 333 } 304 334 305 335 private void proxy_ProcessHeartBeatCompleted(object sender, ProcessHeartBeatCompletedEventArgs e) { 306 if (e.Error == null && e.Result.Success == true) 336 if (e.Error == null && e.Result.Success == true) { 307 337 SendHeartBeatCompleted(sender, e); 308 else { 338 Logger.Debug("ENDED: sending heartbeats"); 339 } else { 309 340 try { 310 Logging.Instance.Error(this.ToString(), "Error: " + e.Result.StatusMessage); 311 } catch (Exception ex) { 312 Logging.Instance.Error(this.ToString(), "Error: ", ex); 341 Logger.Error("Error: " + e.Result.StatusMessage); 342 } 343 catch (Exception ex) { 344 Logger.Error("Error: ", ex); 313 345 } 314 346 HandleNetworkError(e.Error); … … 351 383 public Response IsJobStillNeeded(Guid jobId) { 352 384 try { 353 return proxy.IsJobStillNeeded(jobId); 385 Logger.Debug("STARTING: Sync call: IsJobStillNeeded"); 386 Response res = proxy.IsJobStillNeeded(jobId); 387 Logger.Debug("ENDED: Sync call: IsJobStillNeeded"); 388 return res; 354 389 } 355 390 catch (Exception e) { … … 361 396 362 397 public ResponseResultReceived ProcessSnapshotSync(Guid clientId, Guid jobId, byte[] result, double percentage, Exception exception) { 363 try { 364 Logging.Instance.Info(this.ToString(), "Snapshot for Job " + jobId + " submitted"); 398 try { 365 399 return proxy.ProcessSnapshotStreamed( 366 400 GetStreamedJobResult(clientId, jobId, result, percentage, exception)); … … 374 408 public List<CachedHivePluginInfoDto> RequestPlugins(List<HivePluginInfoDto> requestedPlugins) { 375 409 try { 410 Logger.Debug("STARTED: Requesting Plugins for Job"); 411 Logger.Debug("STARTED: Getting the stream"); 376 412 Stream stream = proxy.SendStreamedPlugins(requestedPlugins.ToArray()); 377 413 Logger.Debug("ENDED: Getting the stream"); 378 414 BinaryFormatter formatter = 379 415 new BinaryFormatter(); 416 Logger.Debug("STARTED: Deserializing the stream"); 380 417 ResponsePlugin response = (ResponsePlugin)formatter.Deserialize(stream); 418 Logger.Debug("ENDED: Deserializing the stream"); 419 if (stream != null) 420 stream.Dispose(); 381 421 return response.Plugins; 382 422 } … … 389 429 public void Logout(Guid guid) { 390 430 try { 431 Logger.Debug("STARTED: Logout"); 391 432 proxy.Logout(guid); 433 Logger.Debug("ENDED: Logout"); 392 434 } 393 435 catch (Exception e) { … … 398 440 public ResponseCalendar GetCalendarSync(Guid clientId) { 399 441 try { 400 return proxy.GetCalendar(clientId); 442 Logger.Debug("STARTED: Syncing Calendars"); 443 ResponseCalendar cal = proxy.GetCalendar(clientId); 444 Logger.Debug("ENDED: Syncing Calendars"); 445 return cal; 401 446 } 402 447 catch (Exception e) { … … 408 453 public Response SetCalendarStatus (Guid clientId, CalendarState state) { 409 454 try { 410 return proxy.SetCalendarStatus(clientId, state); 455 Logger.Debug("STARTED: Setting Calendar status to: " + state); 456 Response resp = proxy.SetCalendarStatus(clientId, state); 457 Logger.Debug("ENDED: Setting Calendar status to: " + state); 458 return resp; 411 459 } catch (Exception e) { 412 460 HandleNetworkError(e);
Note: See TracChangeset
for help on using the changeset viewer.