private static bool TrySend(RegisterRequest message, Binding binding, EndpointAddress endpointAddress) { try { RegisterResponse response; using (UsageTrackingServiceClient client = new UsageTrackingServiceClient(binding, endpointAddress)) { response = client.Register(message); } if (response != null && response.Message != null && UsageTrackingSettings.Default.DisplayMessages) { EventsHelper.Fire(Message, null, new ItemEventArgs<DisplayMessage>(response.Message)); } return true; } catch (Exception) { return false; } }
/// <summary> /// Send the UsageTracking message. /// </summary> /// <param name="theMessage"></param> private static void Send(object theMessage) { try { lock (SyncLock) { if (_first) { //TODO double check to see if this is required on final configuration ServicePointManager.ServerCertificateValidationCallback += ((sender, certificate, chain, sslPolicyErrors) => true); _first = false; } } UsageMessage message = theMessage as UsageMessage; if (message != null) { RegisterRequest req = new RegisterRequest { Message = message }; #if UNIT_TESTS_USAGE_TRACKING WSHttpBinding binding = new WSHttpBinding(); EndpointAddress endpointAddress = new EndpointAddress("http://localhost:8080/UsageTracking"); #elif DEBUG WSHttpBinding binding = new WSHttpBinding(); EndpointAddress endpointAddress = new EndpointAddress("http://localhost/Tracking/Service.svc"); #else //TODO: This should be updated to real address WSHttpBinding binding = new WSHttpBinding(SecurityMode.Transport); binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None; EndpointAddress endpointAddress = new EndpointAddress("https://4rf/Tracking/Service.svc"); #endif RegisterResponse response; using (UsageTrackingServiceClient client = new UsageTrackingServiceClient(binding, endpointAddress)) { response = client.Register(req); } if (response != null && response.Message != null && UsageTrackingSettings.Default.DisplayMessages) { EventsHelper.Fire(Message, null, new ItemEventArgs<DisplayMessage>(response.Message)); } } } catch (Exception e) { Platform.Log(LogLevel.Debug, e); } }