Example #1
0
        public static async Task<MBRegistrationRecord> GetRegistrationStatus(IHttpClient httpClient, IJsonSerializer jsonSerializer, string feature, string mb2Equivalent = null, string version = null)
        {
            //check the reg file first to alleviate strain on the MB admin server - must actually check in every 30 days tho
            var reg = new RegRecord {registered = LicenseFile.LastChecked(feature) > DateTime.UtcNow.AddDays(-30)};

            if (!reg.registered)
            {
                var mac = _networkManager.GetMacAddress();
                var data = new Dictionary<string, string> { { "feature", feature }, { "key", SupporterKey }, { "mac", mac }, { "mb2equiv", mb2Equivalent }, { "legacykey", LegacyKey }, { "ver", version }, { "platform", Environment.OSVersion.VersionString } };

                try
                {
                    using (var json = await httpClient.Post(MBValidateUrl, data, CancellationToken.None).ConfigureAwait(false))
                    {
                        reg = jsonSerializer.DeserializeFromStream<RegRecord>(json);
                    }

                    if (reg.registered)
                    {
                        LicenseFile.AddRegCheck(feature);
                    }
                    else
                    {
                        LicenseFile.RemoveRegCheck(feature);
                    }

                }
                catch (Exception e)
                {
                    _logger.ErrorException("Error checking registration status of {0}", e, feature);
                }
            }

            return new MBRegistrationRecord {IsRegistered = reg.registered, ExpirationDate = reg.expDate, RegChecked = true};
        }
        public static async Task<MBRegistrationRecord> GetRegistrationStatus(IHttpClient httpClient, IJsonSerializer jsonSerializer, string feature, string mb2Equivalent = null)
        {
            var mac = _networkManager.GetMacAddress();
            var data = new Dictionary<string, string> {{"feature", feature}, {"key",SupporterKey}, {"mac",mac}, {"mb2equiv",mb2Equivalent}, {"legacykey", LegacyKey} };

            var reg = new RegRecord();
            try
            {
                using (var json = await httpClient.Post(MBValidateUrl, data, CancellationToken.None).ConfigureAwait(false))
                {
                    reg = jsonSerializer.DeserializeFromStream<RegRecord>(json);
                }

                if (reg.registered)
                {
                    LicenseFile.AddRegCheck(feature);
                }

            }
            catch (Exception)
            {
                //if we have trouble obtaining from web - allow it if we've validated in the past 30 days
                reg.registered = LicenseFile.LastChecked(feature) > DateTime.UtcNow.AddDays(-30);
            }

            return new MBRegistrationRecord {IsRegistered = reg.registered, ExpirationDate = reg.expDate, RegChecked = true};
        }
Example #3
0
        public static async Task <MBRegistrationRecord> GetRegistrationStatus(IHttpClient httpClient, IJsonSerializer jsonSerializer, string feature, string mb2Equivalent = null)
        {
            var mac  = _networkManager.GetMacAddress();
            var data = new Dictionary <string, string> {
                { "feature", feature }, { "key", SupporterKey }, { "mac", mac }, { "mb2equiv", mb2Equivalent }, { "legacykey", LegacyKey }
            };

            var reg = new RegRecord();

            try
            {
                using (var json = await httpClient.Post(MBValidateUrl, data, CancellationToken.None).ConfigureAwait(false))
                {
                    reg = jsonSerializer.DeserializeFromStream <RegRecord>(json);
                }

                if (reg.registered)
                {
                    LicenseFile.AddRegCheck(feature);
                }
            }
            catch (Exception)
            {
                //if we have trouble obtaining from web - allow it if we've validated in the past 30 days
                reg.registered = LicenseFile.LastChecked(feature) > DateTime.UtcNow.AddDays(-30);
            }

            return(new MBRegistrationRecord {
                IsRegistered = reg.registered, ExpirationDate = reg.expDate, RegChecked = true
            });
        }
        public static async Task <MBRegistrationRecord> GetRegistrationStatus(IHttpClient httpClient, IJsonSerializer jsonSerializer, string feature, string mb2Equivalent = null, string version = null)
        {
            //check the reg file first to alleviate strain on the MB admin server - must actually check in every 30 days tho
            var reg = new RegRecord {
                registered = LicenseFile.LastChecked(feature) > DateTime.UtcNow.AddDays(-30)
            };
            var success = reg.registered;

            if (!reg.registered)
            {
                var mac  = _networkManager.GetMacAddress();
                var data = new Dictionary <string, string>
                {
                    { "feature", feature },
                    { "key", SupporterKey },
                    { "mac", mac },
                    { "mb2equiv", mb2Equivalent },
                    { "legacykey", LegacyKey },
                    { "ver", version },
                    { "platform", Environment.OSVersion.VersionString },
                    { "isservice", _applicationHost.IsRunningAsService.ToString().ToLower() }
                };

                try
                {
                    using (var json = await httpClient.Post(MBValidateUrl, data, CancellationToken.None).ConfigureAwait(false))
                    {
                        reg     = jsonSerializer.DeserializeFromStream <RegRecord>(json);
                        success = true;
                    }

                    if (reg.registered)
                    {
                        LicenseFile.AddRegCheck(feature);
                    }
                    else
                    {
                        LicenseFile.RemoveRegCheck(feature);
                    }
                }
                catch (Exception e)
                {
                    _logger.ErrorException("Error checking registration status of {0}", e, feature);
                }
            }

            return(new MBRegistrationRecord {
                IsRegistered = reg.registered, ExpirationDate = reg.expDate, RegChecked = true, RegError = !success
            });
        }
        private async Task<MBRegistrationRecord> GetRegistrationStatusInternal(string feature,
            string mb2Equivalent = null,
            string version = null)
        {
            var lastChecked = LicenseFile.LastChecked(feature);

            //check the reg file first to alleviate strain on the MB admin server - must actually check in every 30 days tho
            var reg = new RegRecord
            {
                // Cache the result for up to a week
                registered = lastChecked > DateTime.UtcNow.AddDays(-7)
            };

            var success = reg.registered;

            if (!(lastChecked > DateTime.UtcNow.AddDays(-1)))
            {
                var data = new Dictionary<string, string>
                {
                    { "feature", feature }, 
                    { "key", SupporterKey }, 
                    { "mac", _appHost.SystemId }, 
                    { "systemid", _appHost.SystemId }, 
                    { "mb2equiv", mb2Equivalent }, 
                    { "ver", version }, 
                    { "platform", _appHost.OperatingSystemDisplayName }, 
                    { "isservice", _appHost.IsRunningAsService.ToString().ToLower() }
                };

                try
                {
                    using (var json = await _httpClient.Post(MBValidateUrl, data, CancellationToken.None).ConfigureAwait(false))
                    {
                        reg = _jsonSerializer.DeserializeFromStream<RegRecord>(json);
                        success = true;
                    }

                    if (reg.registered)
                    {
                        LicenseFile.AddRegCheck(feature);
                    }
                    else
                    {
                        LicenseFile.RemoveRegCheck(feature);
                    }

                }
                catch (Exception e)
                {
                    _logger.ErrorException("Error checking registration status of {0}", e, feature);
                }
            }

            var record = new MBRegistrationRecord
            {
                IsRegistered = reg.registered,
                ExpirationDate = reg.expDate,
                RegChecked = true,
                RegError = !success
            };

            record.TrialVersion = IsInTrial(reg.expDate, record.RegChecked, record.IsRegistered);
            record.IsValid = !record.RegChecked || (record.IsRegistered || record.TrialVersion);

            return record;
        }
Example #6
0
        private async Task <MBRegistrationRecord> GetRegistrationStatusInternal(string feature,
                                                                                string mb2Equivalent = null,
                                                                                string version       = null)
        {
            var lastChecked = LicenseFile.LastChecked(feature);

            //check the reg file first to alleviate strain on the MB admin server - must actually check in every 30 days tho
            var reg = new RegRecord
            {
                // Cache the result for up to a week
                registered = lastChecked > DateTime.UtcNow.AddDays(-7)
            };

            var success = reg.registered;

            if (!(lastChecked > DateTime.UtcNow.AddDays(-1)))
            {
                var data = new Dictionary <string, string>
                {
                    { "feature", feature },
                    { "key", SupporterKey },
                    { "mac", _appHost.SystemId },
                    { "systemid", _appHost.SystemId },
                    { "mb2equiv", mb2Equivalent },
                    { "ver", version },
                    { "platform", _appHost.OperatingSystemDisplayName },
                    { "isservice", _appHost.IsRunningAsService.ToString().ToLower() }
                };

                try
                {
                    var options = new HttpRequestOptions
                    {
                        Url = MBValidateUrl,

                        // Seeing block length errors
                        EnableHttpCompression = false
                    };

                    options.SetPostData(data);

                    using (var json = (await _httpClient.Post(options).ConfigureAwait(false)).Content)
                    {
                        reg     = _jsonSerializer.DeserializeFromStream <RegRecord>(json);
                        success = true;
                    }

                    if (reg.registered)
                    {
                        LicenseFile.AddRegCheck(feature);
                    }
                    else
                    {
                        LicenseFile.RemoveRegCheck(feature);
                    }
                }
                catch (Exception e)
                {
                    _logger.ErrorException("Error checking registration status of {0}", e, feature);
                }
            }

            var record = new MBRegistrationRecord
            {
                IsRegistered   = reg.registered,
                ExpirationDate = reg.expDate,
                RegChecked     = true,
                RegError       = !success
            };

            record.TrialVersion = IsInTrial(reg.expDate, record.RegChecked, record.IsRegistered);
            record.IsValid      = !record.RegChecked || record.IsRegistered || record.TrialVersion;

            return(record);
        }