Example #1
0
        /// <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 4rf,
                        // 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
            }
        }
Example #2
0
        public UsageTrackingForm()
        {
            InitializeComponent();
            UsageUtilities.MessageEvent += DisplayMessage;

            _message = UsageUtilities.GetUsageMessage();

            textBoxVersion.Text = _message.Version;
            textBoxProduct.Text = _message.Product;
            textBoxOS.Text = _message.OS;
            textBoxRegion.Text = _message.Region;
            textBoxLicense.Text = _message.LicenseString;
            textBoxComponent.Text = _message.Component;
            textBoxMachineIdentifier.Text = _message.MachineIdentifier;
            textBoxEdition.Text = _message.Edition;
        }
Example #3
0
        /// <summary>
        /// Get a <see cref="UsageMessage"/> for the application.
        /// </summary>
        /// <returns>
        /// <para>
        /// A new <see cref="UsageMessage"/> object with product, region, timestamp, license, and OS information filled in.
        /// </para>
        /// <para>
        /// The <see cref="UsageMessage"/> instance is used in conjunction with <see cref="Register"/> to send a usage message
        /// to ClearCanvas servers.
        /// </para>
        /// </returns>
        public static UsageMessage GetUsageMessage()
        {
            UsageMessage msg;

            // if license key cannot be retrieved, send an empty string to maintain the existing data on the server
            string   licenseString     = String.Empty;
            string   licenseType       = String.Empty;
            DateTime?licenseExpiryTime = null;

            try
            {
                licenseString     = LicenseInformation.LicenseKey;
                licenseExpiryTime = LicenseInformation.ExpiryTime;
                licenseType       = LicenseInformation.LicenseType;
            }
            catch (Exception ex)
            {
                Platform.Log(LogLevel.Debug, ex, "An error has occurred when trying to get the license string");
            }
            finally
            {
                msg = new UsageMessage
                {
                    Version            = ProductInformation.GetVersion(true, true),
                    Product            = ProductInformation.Product,
                    Component          = ProductInformation.Component,
                    Edition            = ProductInformation.Edition,
                    Release            = ProductInformation.Release,
                    AllowDiagnosticUse = LicenseInformation.DiagnosticUse != LicenseDiagnosticUse.None,
                    Region             = CultureInfo.CurrentCulture.Name,
                    Timestamp          = Platform.Time,
                    OS = Environment.OSVersion.ToString(),
                    MachineIdentifier = EnvironmentUtilities.MachineIdentifier,
                    MessageType       = UsageType.Other,
                    LicenseString     = licenseString,
                    LicenseType       = licenseType
                };

                if (licenseExpiryTime.HasValue)
                {
                    msg.LicenseExpiryTimeUTC = licenseExpiryTime.Value.ToUniversalTime();
                }
            }

            return(msg);
        }
Example #4
0
 /// <summary>
 /// Register the usage of the application with a ClearCanvas server on a background thread.
 /// </summary>
 /// <remarks>
 /// A check is done of the <see cref="UsageTrackingSettings"/>, and if usage tracking is enabled, the
 /// <paramref name="message"/> is sent to the ClearCanvas server.
 /// </remarks>
 /// <param name="message">The usage message to send.</param>
 /// <param name="thread">Flag telling if the usage will be sent on the current thread or a background thread.</param>
 public static void Register(UsageMessage message, UsageTrackingThread thread)
 {
     if (UsageTrackingSettings.Default.Enabled)
     {
         try
         {
             UsageMessage theMessage = message;
             if (thread == UsageTrackingThread.Current)
             {
                 Send(theMessage);
             }
             else if (thread == UsageTrackingThread.Background)
             {
                 ThreadPool.QueueUserWorkItem(Send, theMessage);
             }
         }
         catch (Exception e)
         {
             // Fail silently
             Platform.Log(LogLevel.Debug, e);
         }
     }
 }
        private void AppendUsageData(UsageMessage message)
        {
            message.AppData = new System.Collections.Generic.List<UsageApplicationData>();

            if (_uptime != null)
            {
                message.AppData.Add(new UsageApplicationData()
                {
                    Key = "UPTIME",
                    Value = _uptime.Value.TotalHours.ToString(CultureInfo.InvariantCulture.NumberFormat),
                });
            }

        }
Example #6
0
        private void AppendUsageData(UsageMessage message)
        {
            message.AppData = new System.Collections.Generic.List<UsageApplicationData>();

            if (_uptime!=null)
            {
                message.AppData.Add(new UsageApplicationData()
                {
                    Key = "UPTIME",
                    Value = _uptime.Value.TotalHours.ToString(CultureInfo.InvariantCulture.NumberFormat),
                });
            }

            ImageServerData data = new ImageServerData();
            message.AppData.Add(new UsageApplicationData() {Key = "TOTAL_STUDIES",
                Value = data.TotalStudiesCount.ToString(CultureInfo.InvariantCulture.NumberFormat),
            });

            message.AppData.Add(new UsageApplicationData()
            {
                Key = "ACTIVE_DEVICES",
                Value = data.ActiveDeviceCount.ToString(CultureInfo.InvariantCulture.NumberFormat),
            });
        }
Example #7
0
		/// <summary>
		/// Get a <see cref="UsageMessage"/> for the application.
		/// </summary>
		/// <returns>
		/// <para>
		/// A new <see cref="UsageMessage"/> object with product, region, timestamp, license, and OS information filled in.
		/// </para>
		/// <para>
		/// The <see cref="UsageMessage"/> instance is used in conjunction with <see cref="Register"/> to send a usage message
		/// to ClearCanvas servers.
		/// </para>
		/// </returns>
		public static UsageMessage GetUsageMessage()
		{
			UsageMessage msg;

			// if license key cannot be retrieved, send an empty string to maintain the existing data on the server
			string licenseString = String.Empty;
			string licenseType = String.Empty;
			DateTime? licenseExpiryTime = null;
			try
			{
				licenseString = LicenseInformation.LicenseKey;
				licenseExpiryTime = LicenseInformation.ExpiryTime;
				licenseType = LicenseInformation.LicenseType;
			}
			catch (Exception ex)
			{
				Platform.Log(LogLevel.Debug, ex, "An error has occurred when trying to get the license string");
			}
			finally
			{
				msg = new UsageMessage
				      	{
				      		Version = ProductInformation.GetVersion(true, true),
				      		Product = ProductInformation.Product,
				      		Component = GetComponentName(),
				      		Edition = ProductInformation.Edition,
				      		Release = ProductInformation.Release,
				      		AllowDiagnosticUse = LicenseInformation.DiagnosticUse != LicenseDiagnosticUse.None,
				      		Region = CultureInfo.CurrentCulture.Name,
				      		Timestamp = Platform.Time,
				      		OS = Environment.OSVersion.ToString(),
				      		MachineIdentifier = EnvironmentUtilities.MachineIdentifier,
				      		MessageType = UsageType.Other,
				      		LicenseString = licenseString,
				      		LicenseType = licenseType
				      	};

				if (licenseExpiryTime.HasValue)
					msg.LicenseExpiryTimeUTC = licenseExpiryTime.Value.ToUniversalTime();
			}

			return msg;
		}
Example #8
0
		/// <summary>
		/// Register the usage of the application with a ClearCanvas server on a background thread.
		/// </summary>
		/// <remarks>
		/// A check is done of the <see cref="UsageTrackingSettings"/>, and if usage tracking is enabled, the 
		/// <paramref name="message"/> is sent to the ClearCanvas server.
		/// </remarks>
		/// <param name="message">The usage message to send.</param>
		/// <param name="thread">Flag telling if the usage will be sent on the current thread or a background thread.</param>
		public static void Register(UsageMessage message, UsageTrackingThread thread)
		{
			if (UsageTrackingSettings.Default.Enabled)
				try
				{
					UsageMessage theMessage = message;
					if (thread == UsageTrackingThread.Current)
						Send(theMessage);
					else if (thread == UsageTrackingThread.Background)
						ThreadPool.QueueUserWorkItem(Send, theMessage);
				}
				catch (Exception e)
				{
					// Fail silently
					Platform.Log(LogLevel.Debug, e);
				}
		}
Example #9
0
 /// <summary>
 /// Get a <see cref="UsageMessage"/> for the application.
 /// </summary>
 /// <returns>
 /// <para>
 /// A new <see cref="UsageMessage"/> object with product, region, timestamp, license, and OS information filled in.
 /// </para>
 /// <para>
 /// The <see cref="UsageMessage"/> instance is used in conjunction with <see cref="Register"/> to send a usage message
 /// to ClearCanvas servers.
 /// </para>
 /// </returns>
 public static UsageMessage GetUsageMessage()
 {
     UsageMessage msg = new UsageMessage
                            {
                                Version = ProductInformation.GetVersion(true, true),
                                Product = ProductInformation.Product,
                                Component = ProductInformation.Component,
                                Edition = ProductInformation.Edition,
                                AllowDiagnosticUse = ProductInformation.AllowDiagnosticUse,
                                Region = CultureInfo.CurrentCulture.Name,
                                Timestamp = Platform.Time,
                                OS = Environment.OSVersion.ToString(),
                                MachineIdentifier =  EnvironmentUtilities.MachineIdentifier,
                                MessageType = UsageType.Other,
                                LicenseString = LicenseInformation.LicenseKey
                            };
     return msg;
 }