private void Ping_PingCompleted(object sender, PingCompletedEventArgs e) { string ip = e.UserState as string; if (ip != string.Empty && e.Reply.Status == IPStatus.Success) { if (_networkManager != null) { string hostName = _networkManager.GetHostName(ip); string macAddress = _networkManager.GetMacAddress(ip); var availableHost = new AvailableHost { IP = ip, HostName = hostName, MacAddress = macAddress }; Application.Current.Dispatcher.BeginInvoke(new Action(() => { if (!_cancelRequested) { AvailableHostsModels.Add(availableHost); } })); } } _hostsAmount++; AvailableHosts = _hostsAmount.ToString(); }
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 Task ReportServerUsage(CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var mac = _networkManager.GetMacAddress(); var plugins = string.Join("|", _applicationHost.Plugins.Select(i => i.Name).ToArray()); var data = new Dictionary <string, string> { { "feature", _applicationHost.Name }, { "mac", mac }, { "ver", _applicationHost.ApplicationVersion.ToString() }, { "platform", Environment.OSVersion.VersionString }, { "isservice", _applicationHost.IsRunningAsService.ToString().ToLower() }, { "plugins", plugins } }; return(_httpClient.Post(Constants.Constants.MbAdminUrl + "service/registration/ping", data, cancellationToken)); }
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 }); }
public void Post(CreateReviewRequest request) { var review = new Dictionary <string, string> { { "id", request.Id.ToString(CultureInfo.InvariantCulture) }, { "mac", _netManager.GetMacAddress() }, { "rating", request.Rating.ToString(CultureInfo.InvariantCulture) }, { "recommend", request.Recommend.ToString() }, { "title", request.Title }, { "review", request.Review }, }; Task.WaitAll(_httpClient.Post(Constants.MbAdminUrl + "/service/packageReview/update", review, CancellationToken.None)); }
/// <summary> /// Get all available packages including registration information. /// Use this for the plug-in catalog to provide all information for this installation. /// </summary> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <IEnumerable <PackageInfo> > GetAvailablePackages(CancellationToken cancellationToken) { var data = new Dictionary <string, string> { { "key", _securityManager.SupporterKey }, { "mac", _networkManager.GetMacAddress() } }; using (var json = await _httpClient.Post(Constants.Constants.MbAdminUrl + "service/package/retrieveall", data, cancellationToken).ConfigureAwait(false)) { cancellationToken.ThrowIfCancellationRequested(); var packages = _jsonSerializer.DeserializeFromStream <List <PackageInfo> >(json).ToList(); return(FilterVersions(packages)); } }
public Task ReportServerUsage(CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var mac = _networkManager.GetMacAddress(); var data = new Dictionary <string, string> { { "feature", _applicationHost.Name }, { "mac", mac }, { "serverid", _applicationHost.SystemId }, { "deviceid", _applicationHost.SystemId }, { "ver", _applicationHost.ApplicationVersion.ToString() }, { "platform", _applicationHost.OperatingSystemDisplayName }, { "isservice", _applicationHost.IsRunningAsService.ToString().ToLower() } }; return(_httpClient.Post(Common.Constants.Constants.MbAdminUrl + "service/registration/ping", data, cancellationToken)); }
public async Task <IEnumerable <PackageInfo> > GetAvailablePackages(CancellationToken cancellationToken) { var data = new Dictionary <string, string> { { "key", _securityManager.SupporterKey }, { "mac", _networkManager.GetMacAddress() } }; using (var json = await _httpClient.Post(Constants.Constants.MBAdminUrl + "service/package/retrieveall", data, cancellationToken).ConfigureAwait(false)) { cancellationToken.ThrowIfCancellationRequested(); var packages = _jsonSerializer.DeserializeFromStream <List <PackageInfo> >(json).ToList(); foreach (var package in packages) { package.versions = package.versions.Where(v => !string.IsNullOrWhiteSpace(v.sourceUrl)) .OrderByDescending(v => v.version).ToList(); } return(packages); } }
private string GetNewId() { // When generating an Id, base it off of the app path + mac address // But we can't fail here, so if we can't get the mac address then just use a random guid string mac; try { mac = _networkManager.GetMacAddress(); } catch { mac = Guid.NewGuid().ToString("N"); } mac += "-" + _appPaths.ApplicationPath; return(mac.GetMD5().ToString("N")); }
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 mac = _networkManager.GetMacAddress(); var data = new Dictionary <string, string> { { "feature", feature }, { "key", SupporterKey }, { "mac", mac }, { "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); }