コード例 #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
            }
        }
コード例 #2
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 Macro 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);
        }
コード例 #3
0
 /// <summary>
 /// Register the usage of the application with a Macro 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 Macro 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);
         }
     }
 }