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);
            }
        }
Exemple #2
0
		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;
			}
		}
Exemple #3
0
        public RegisterResponse Register(RegisterRequest request)
        {
            try
            {
                ReceivedMessageCount++;
                if (ThrowError)
                    throw new Exception("Exception on the server");

                if (ThrowCommunicationError)
                    throw new CommunicationException("CommunicationException");

                if (DelayResponse>0)
                {
                    Thread.Sleep(DelayResponse);
                }
                return Response;
            }
            finally
            {
                _sync.Set();
            }
        }
 /// <summary>
 /// Register the application.
 /// </summary>
 /// <param name="request">The register request.</param>
 public RegisterResponse Register(RegisterRequest request)
 {
     return(Channel.Register(request));
 }
		/// <summary>
		/// Send the UsageTracking message.
		/// </summary>
		/// <param name="theMessage"></param>
		private static void Send(object theMessage)
		{
			try
			{
				lock (_syncLock)
				{
					if (_first)
					{
#if DEBUG_SERVER
						// Note, this is required when in debug mode and communicating with the test server,
						// which doesn't have an official cert, it isn't required for communicating with
						// the production server.
						ServicePointManager.ServerCertificateValidationCallback +=
							((sender, certificate, chain, sslPolicyErrors) =>
							 true);
#endif

						_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");
                    TrySend(req, binding, endpointAddress);
#else
					WSHttpBinding binding = new WSHttpBinding(SecurityMode.Transport);
					binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
					binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
					EndpointAddress endpointAddress = new EndpointAddress(string.Format(TrackingServiceEndpoint, TrackingServerHost));
					if (!TrySend(req, binding, endpointAddress))
					{
						endpointAddress = new EndpointAddress(string.Format(TrackingServiceEndpoint, TrackingServerIp));
						TrySend(req, binding, endpointAddress);
					}
#endif
				}
			}
			catch (Exception e)
			{
				// Fail silently
#if	DEBUG
				Platform.Log(LogLevel.Debug, e);
#endif
			}
		}
Exemple #6
0
        /// <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);
            }
        }