Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/01/10 13:58:24 (14 years ago)
Author:
kgrading
Message:

Removed References to HiveLogging and updated the default logging mechanism (#991)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Client.Communication/3.2/WcfService.cs

    r3203 r3578  
    3333using System.IO;
    3434using System.Runtime.Serialization.Formatters.Binary;
     35using HeuristicLab.Tracing;
    3536
    3637namespace HeuristicLab.Hive.Client.Communication {
     
    4546    /// <returns>the Instance of the WcfService class</returns>
    4647    public static WcfService Instance {
    47       get {
     48      get {       
    4849        if (instance == null) {
     50          Logger.Debug("New WcfService Instance created");
    4951          instance = new WcfService();
    5052        }
     
    7678    public void Connect() {
    7779      try {
     80        Logger.Debug("Starting the Connection Process");
    7881        if (String.Empty.Equals(ServerIP) || ServerPort == 0) {
    79           Logging.Instance.Info(this.ToString(), "No Server IP or Port set!");
     82          Logger.Info("No Server IP or Port set!");
    8083          return;
    8184        }
     85
     86        Logger.Debug("Creating the new connection proxy");
    8287        proxy = new ClientFacadeClient(
    8388          WcfSettings.GetStreamedBinding(),
    8489          new EndpointAddress("net.tcp://" + ServerIP + ":" + ServerPort + "/HiveServer/ClientCommunicator")
    8590        );
    86 
     91        Logger.Debug("Created the new connection proxy");
     92
     93        Logger.Debug("Registring new Events");
    8794        proxy.LoginCompleted += new EventHandler<LoginCompletedEventArgs>(proxy_LoginCompleted);
    8895        proxy.SendStreamedJobCompleted += new EventHandler<SendStreamedJobCompletedEventArgs>(proxy_SendStreamedJobCompleted);
     
    9097        proxy.ProcessSnapshotStreamedCompleted += new EventHandler<ProcessSnapshotStreamedCompletedEventArgs>(proxy_ProcessSnapshotStreamedCompleted);
    9198        proxy.ProcessHeartBeatCompleted += new EventHandler<ProcessHeartBeatCompletedEventArgs>(proxy_ProcessHeartBeatCompleted);
     99        Logger.Debug("Registered new Events");
     100        Logger.Debug("Opening the Connection");
    92101        proxy.Open();
     102        Logger.Debug("Opened the Connection");
    93103
    94104        ConnState = NetworkEnum.WcfConnState.Connected;
    95105        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        }
    100112        if (ConnState == NetworkEnum.WcfConnState.Failed)
    101113          ConnectionRestored(this, new EventArgs());       
     
    113125    /// <param name="serverPort">current Server Port</param>
    114126    public void Connect(String serverIP, int serverPort) {
     127      Logger.Debug("Called Connected with " + serverIP + ":" + serverPort);
    115128      String oldIp = this.ServerIP;
    116129      int oldPort = this.ServerPort;
     
    124137
    125138    public void SetIPAndPort(String serverIP, int serverPort) {
     139      Logger.Debug("Called with " + serverIP + ":" + serverPort);
    126140      this.ServerIP = serverIP;
    127141      this.ServerPort = serverPort;
     
    141155    private void HandleNetworkError(Exception e) {
    142156      ConnState = NetworkEnum.WcfConnState.Failed;
    143       Logging.Instance.Error(this.ToString(), "exception: ", e);
     157      Logger.Error("Network exception occurred: " + e);
    144158    }
    145159
     
    152166    public event System.EventHandler<LoginCompletedEventArgs> LoginCompleted;
    153167    public void LoginAsync(ClientDto clientInfo) {
    154       if (ConnState == NetworkEnum.WcfConnState.Connected)
     168      if (ConnState == NetworkEnum.WcfConnState.Connected) {
     169        Logger.Debug("STARTED: Login Async");
    155170        proxy.LoginAsync(clientInfo);
     171      }
    156172    }
    157173    private void proxy_LoginCompleted(object sender, LoginCompletedEventArgs e) {
    158       if (e.Error == null)
     174      if (e.Error == null) {
     175        Logger.Debug("ENDED: Login Async");
    159176        LoginCompleted(sender, e);
    160       else
     177      } else
    161178        HandleNetworkError(e.Error.InnerException);
    162179    }
     
    165182      try {
    166183        if (ConnState == NetworkEnum.WcfConnState.Connected) {
     184          Logger.Debug("STARTED: Login Sync");
    167185          Response res = proxy.Login(clientInfo);
    168186          if (!res.Success) {
    169             Logging.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);
    171189          } 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;           
    174192          }
    175193        }
     
    188206    public event System.EventHandler<SendJobCompletedEventArgs> SendJobCompleted;
    189207    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");
    191210        proxy.SendStreamedJobAsync(guid);
     211      }
    192212    }
    193213
    194214    void proxy_SendStreamedJobCompleted(object sender, SendStreamedJobCompletedEventArgs e) {
    195215      if (e.Error == null) {
     216        Logger.Debug("ENDED: Fetching of Jobs from Server for Client");
    196217        Stream stream = null;
    197218        MemoryStream memStream = null;
     
    220241            new SendJobCompletedEventArgs(new object[] { response, memStream.GetBuffer() }, e.Error, e.Cancelled, e.UserState);
    221242          SendJobCompleted(sender, completedEventArgs);
    222         }
    223         finally {
     243        } catch (Exception ex) {
     244          Logger.Error(ex);
     245        } finally {
    224246          if(stream != null)
    225247            stream.Dispose();
     
    241263    public void StoreFinishedJobResultAsync(Guid clientId, Guid jobId, byte[] result, double percentage, Exception exception, bool finished) {
    242264      if (ConnState == NetworkEnum.WcfConnState.Loggedin) {
     265        Logger.Debug("STARTED: Sending back the finished job results");
     266        Logger.Debug("Building stream");
    243267        Stream stream =
    244268          GetStreamedJobResult(clientId, jobId, result, percentage, exception);
    245 
     269        Logger.Debug("Builded stream");
     270        Logger.Debug("Making the call");
    246271        proxy.StoreFinishedJobResultStreamedAsync(stream, stream);
    247272      }
    248273     }
    249274    private void proxy_StoreFinishedJobResultStreamedCompleted(object sender, StoreFinishedJobResultStreamedCompletedEventArgs e) {
     275      Logger.Debug("Finished storing the job");
    250276      Stream stream =
    251277        (Stream)e.UserState;
    252       if (stream != null)
     278      if (stream != null) {
     279        Logger.Debug("Stream not null, disposing it");
    253280        stream.Dispose();
    254      
     281      }
    255282      if (e.Error == null) {
    256283        StoreFinishedJobResultCompletedEventArgs args =
    257284          new StoreFinishedJobResultCompletedEventArgs(
    258285            new object[] { e.Result }, e.Error, e.Cancelled, e.UserState);
     286        Logger.Debug("calling the Finished Job Event");
    259287        StoreFinishedJobResultCompleted(sender, args);
     288        Logger.Debug("ENDED: Sending back the finished job results");
    260289      } else
    261290        HandleNetworkError(e.Error);
     
    300329    public void SendHeartBeatAsync(HeartBeatData hbd) {
    301330      if (ConnState == NetworkEnum.WcfConnState.Loggedin)
     331        Logger.Debug("STARTING: sending heartbeat");
    302332        proxy.ProcessHeartBeatAsync(hbd);
    303333    }
    304334
    305335    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) {
    307337        SendHeartBeatCompleted(sender, e);
    308       else {
     338        Logger.Debug("ENDED: sending heartbeats");
     339      } else {
    309340        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);
    313345        }
    314346        HandleNetworkError(e.Error);
     
    351383    public Response IsJobStillNeeded(Guid jobId) {
    352384      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;
    354389      }
    355390      catch (Exception e) {
     
    361396
    362397    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 {       
    365399        return proxy.ProcessSnapshotStreamed(
    366400          GetStreamedJobResult(clientId, jobId, result, percentage, exception));
     
    374408    public List<CachedHivePluginInfoDto> RequestPlugins(List<HivePluginInfoDto> requestedPlugins) {
    375409      try {
     410        Logger.Debug("STARTED: Requesting Plugins for Job");
     411        Logger.Debug("STARTED: Getting the stream");
    376412        Stream stream = proxy.SendStreamedPlugins(requestedPlugins.ToArray());
    377 
     413        Logger.Debug("ENDED: Getting the stream");
    378414        BinaryFormatter formatter =
    379415          new BinaryFormatter();
     416        Logger.Debug("STARTED: Deserializing the stream");
    380417        ResponsePlugin response = (ResponsePlugin)formatter.Deserialize(stream);
     418        Logger.Debug("ENDED: Deserializing the stream");
     419        if (stream != null)
     420          stream.Dispose();       
    381421        return response.Plugins;       
    382422      }
     
    389429    public void Logout(Guid guid) {
    390430      try {
     431        Logger.Debug("STARTED: Logout");
    391432        proxy.Logout(guid);
     433        Logger.Debug("ENDED: Logout");
    392434      }
    393435      catch (Exception e) {
     
    398440    public ResponseCalendar GetCalendarSync(Guid clientId) {
    399441      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;
    401446      }
    402447      catch (Exception e) {
     
    408453    public Response SetCalendarStatus (Guid clientId, CalendarState state) {
    409454      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;
    411459      } catch (Exception e) {
    412460        HandleNetworkError(e);
Note: See TracChangeset for help on using the changeset viewer.