示例#1
0
        /// <summary>
        /// Method to send get request to license engine.
        /// </summary>
        /// <param name="key">License key string.</param>
        /// <returns></returns>
        public async Task <LicenseItem> CheckLicense(string key)
        {
            LicenseItem result = null;

            try
            {
                HttpClient httpClient = new HttpClient();

                string url = string.Format(Properties.Constants.LicenseEngineCheckLicenseFormat,
                                           key,
                                           GetHDDSerial());

                HttpResponseMessage response = await httpClient.GetAsync(url);

                string jsonString = await response.Content.ReadAsStringAsync();

                if (string.IsNullOrEmpty(jsonString) == false)
                {
                    result = JsonConvert.DeserializeObject <LicenseItem>(jsonString);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError($"Exception occured while check license in license engine. {ex.Message}");
            }

            return(result);
        }
示例#2
0
        public async Task InitializeAsync(IConnection connection)
        {
            modelService = await modelServiceFactory.CreateAsync(connection);

            Title = string.Format(CultureInfo.CurrentCulture, Resources.CreateTitle, connection.HostAddress.Title);

            accounts = modelService.GetAccounts()
                       .ObserveOn(RxApp.MainThreadScheduler)
                       .ToProperty(this, vm => vm.Accounts, initialValue: new ReadOnlyCollection <IAccount>(new IAccount[] { }));

            this.WhenAny(x => x.Accounts, x => x.Value)
            .Select(accts => accts?.FirstOrDefault())
            .WhereNotNull()
            .Subscribe(a => SelectedAccount = a);

            GitIgnoreTemplates = TrackingCollection.CreateListenerCollectionAndRun(
                modelService.GetGitIgnoreTemplates(),
                new[] { GitIgnoreItem.None },
                OrderedComparer <GitIgnoreItem> .OrderByDescending(item => GitIgnoreItem.IsRecommended(item.Name)).Compare,
                x =>
            {
                if (x.Name.Equals("VisualStudio", StringComparison.OrdinalIgnoreCase))
                {
                    SelectedGitIgnoreTemplate = x;
                }
            });

            Licenses = TrackingCollection.CreateListenerCollectionAndRun(
                modelService.GetLicenses(),
                new[] { LicenseItem.None },
                OrderedComparer <LicenseItem> .OrderByDescending(item => LicenseItem.IsRecommended(item.Name)).Compare);
        }
示例#3
0
 IObservable <IEnumerable <LicenseCacheItem> > GetOrderedLicensesFromApi()
 {
     return(apiClient.GetLicenses()
            .WhereNotNull()
            .Select(LicenseCacheItem.Create)
            .ToList()
            .Select(licenses => licenses.OrderByDescending(lic => LicenseItem.IsRecommended(lic.Key))));
 }
        public void AddLicenseItem(LicenseItem licenseItem)
        {
            LicenseItemControl licenseitem = new LicenseItemControl();

            licenseitem.IsSelect      = false;
            licenseitem.PropertyName  = licenseItem.PropertyName;
            licenseitem.PropertyValue = licenseItem.PropertyValue;
            Canvas.SetLeft(licenseitem, licenseItem.Left);
            Canvas.SetTop(licenseitem, licenseItem.Top);
            _canvasPanel.Children.Add(licenseitem);
        }
示例#5
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _btnSave_Click(object sender, RoutedEventArgs e)
        {
            LicenseTemplete licenseTemplete = new LicenseTemplete();

            licenseTemplete.ActivityGuid = CO_IA.Client.RiasPortal.ModuleContainer.Activity.Guid;
            licenseTemplete.Height       = double.Parse(this._txtHeight.Text);
            licenseTemplete.Width        = double.Parse(this._txtWidth.Text);

            licenseTemplete.IsShowImage     = _chkImage.IsChecked.Value;
            licenseTemplete.BackgroundImage = this.backgroundImageSource;

            licenseTemplete.IsShowQRCode = _chkQRCode.IsChecked.Value;
            if (this.QRCodeImageSource == null)
            {
                MessageBox.Show("请生成二维码");
                return;
            }
            else
            {
                licenseTemplete.QRCode = this.QRCodeImageSource;
            }

            if (_canvasPanel.Children.Count > 0)
            {
                foreach (FrameworkElement itemcontrol in _canvasPanel.Children)
                {
                    if (itemcontrol.GetType() == typeof(LicenseItemControl))
                    {
                        LicenseItemControl licenseControl = (LicenseItemControl)itemcontrol;

                        LicenseItem licenseitem = new LicenseItem();
                        licenseitem.Left         = (double)licenseControl.GetValue(Canvas.LeftProperty);
                        licenseitem.Top          = (double)licenseControl.GetValue(Canvas.TopProperty);
                        licenseitem.PropertyName = licenseControl.PropertyName;
                        licenseTemplete.LicenseItems.Add(licenseitem);
                    }
                }
            }
            else
            {
                MessageBox.Show("请添加模板内容");
                return;
            }
            licenseTemplete.XMLLicenseItems = GetXmlByLicenseTemplete(licenseTemplete);
            try
            {
                SaveLicenseTemplete(licenseTemplete);
                MessageBox.Show("保存成功");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.GetExceptionMessage());
            }
        }
 internal static void UnRegisterItem(Item item)
 {
     if (_myServerLicense != null)
     {
         LicenseItem li = new LicenseItem()
         {
             Id = item.FQID.ObjectId.ToString(), Name = item.Name
         };
         _myServerLicense.UnRegisterConfiguredLicenseItem(li);
         _myServerLicense.Counter--;
     }
 }
        internal static void RegisterItem(List <Item> items, Item item)
        {
            LicenseItem li = new LicenseItem()
            {
                Id = item.FQID.ObjectId.ToString(), Name = item.Name
            };

            li.ItemTrial    = true;
            li.ItemTrialEnd = DateTime.Now + TimeSpan.FromDays(14);
            _myServerLicense.RegisterConfiguredLicenseItem(li);
            _myServerLicense.Counter++;
        }
示例#8
0
        private void RefreshLicenseItems()
        {
            bool canGetDistributableLicense = false;

            foreach (LicenseItemData data in LicenseItems)
            {
                if (License == null)
                {
                    data.State = LicenseItemState.Blocked;
                    continue;
                }

                LicenseItem licenseItem = License.Items[data.Name];
                if (licenseItem == null)
                {
                    data.State = LicenseItemState.Blocked;
                }
                else if (LicenseState == LicenseState.Evaluation || LicenseState == LicenseState.EvaluationExpired)
                {
                    if (licenseItem.OverrideExpirationDate)
                    {
                        data.State = LicenseItemState.Granted;
                    }
                    else if (LicenseState == LicenseState.Evaluation)
                    {
                        data.State = LicenseItemState.Evaluated;
                    }
                    else
                    {
                        data.State = LicenseItemState.Blocked;
                    }
                }
                else
                {
                    data.State = LicenseItemState.Granted;
                }

                if (data.State == LicenseItemState.Granted)
                {
                    canGetDistributableLicense = true;
                }
            }
            CanGetDistributableLicense = canGetDistributableLicense;
        }
        internal void FillContent(Item item)
        {
            textBoxName.Text = item.Name;
            LicenseItem        li = null;
            LicenseInformation licenseInformation =
                EnvironmentManager.Instance.LicenseManager.ReservedLicenseManager.GetLicenseInformation(
                    ServerConnectionDefinition.ServerConnectionPluginId, ServerConnectionDefinition.ServerLicenseId);

            if (licenseInformation != null)
            {
                li = licenseInformation.GetConfiguredLicenseItem(item.FQID.ObjectId.ToString());
            }

            if (li != null)
            {
                if (licenseInformation.Expire.Year != 9999 && licenseInformation.Expire < li.ItemTrialEnd)
                {
                    // Check for entire licens to expire
                    if (licenseInformation.Expire < DateTime.UtcNow)
                    {
                        textBoxLicenseInfo.Text = "License expired on " + licenseInformation.Expire.ToLongDateString();
                    }
                    else
                    {
                        textBoxLicenseInfo.Text = "License will expire on " + licenseInformation.Expire.ToLongDateString();
                    }
                }
                else
                {
                    // Check for each item to expire
                    if (li.ItemTrial == false)
                    {
                        textBoxLicenseInfo.Text = "Licensed";
                    }
                    else
                    {
                        textBoxLicenseInfo.Text = "Trial until: " + li.ItemTrialEnd.ToLongDateString();
                    }
                }
            }
        }
示例#10
0
        public static List <LicenseItem> XMLLicenseItems(XmlNode xmlnode)
        {
            List <LicenseItem> items = new List <LicenseItem>();

            if (xmlnode != null && xmlnode.HasChildNodes)
            {
                XmlNodeList licensenodelst = xmlnode.ChildNodes;
                foreach (XmlNode node in licensenodelst)
                {
                    LicenseItem licenseitem = new LicenseItem();
                    XmlElement  xe          = (XmlElement)node;
                    if (xe != null)
                    {
                        licenseitem.PropertyName = node.Name.ToString();
                        licenseitem.Left         = double.Parse(xe.GetAttribute("Left"));
                        licenseitem.Top          = double.Parse(xe.GetAttribute("Top"));
                        items.Add(licenseitem);
                    }
                }
            }
            return(items);
        }
        public RepositoryCreationViewModel(
            IConnection connection,
            IModelServiceFactory modelServiceFactory,
            IOperatingSystem operatingSystem,
            IRepositoryCreationService repositoryCreationService,
            IUsageTracker usageTracker)
        {
            Guard.ArgumentNotNull(connection, nameof(connection));
            Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory));
            Guard.ArgumentNotNull(operatingSystem, nameof(operatingSystem));
            Guard.ArgumentNotNull(repositoryCreationService, nameof(repositoryCreationService));
            Guard.ArgumentNotNull(usageTracker, nameof(usageTracker));

            this.operatingSystem           = operatingSystem;
            this.repositoryCreationService = repositoryCreationService;
            this.usageTracker = usageTracker;

            Title = string.Format(CultureInfo.CurrentCulture, Resources.CreateTitle, connection.HostAddress.Title);
            SelectedGitIgnoreTemplate = GitIgnoreItem.None;
            SelectedLicense           = LicenseItem.None;

            modelService = modelServiceFactory.CreateBlocking(connection);

            accounts = modelService.GetAccounts()
                       .ObserveOn(RxApp.MainThreadScheduler)
                       .ToProperty(this, vm => vm.Accounts, initialValue: new ReadOnlyCollection <IAccount>(new IAccount[] {}));

            this.WhenAny(x => x.Accounts, x => x.Value)
            .Select(accts => accts?.FirstOrDefault())
            .WhereNotNull()
            .Subscribe(a => SelectedAccount = a);

            browseForDirectoryCommand.Subscribe(_ => ShowBrowseForDirectoryDialog());

            BaseRepositoryPathValidator = ReactivePropertyValidator.ForObservable(this.WhenAny(x => x.BaseRepositoryPath, x => x.Value))
                                          .IfNullOrEmpty(Resources.RepositoryCreationClonePathEmpty)
                                          .IfTrue(x => x.Length > 200, Resources.RepositoryCreationClonePathTooLong)
                                          .IfContainsInvalidPathChars(Resources.RepositoryCreationClonePathInvalidCharacters)
                                          .IfPathNotRooted(Resources.RepositoryCreationClonePathInvalid);

            var nonNullRepositoryName = this.WhenAny(
                x => x.RepositoryName,
                x => x.BaseRepositoryPath,
                (x, y) => x.Value)
                                        .WhereNotNull();

            RepositoryNameValidator = ReactivePropertyValidator.ForObservable(nonNullRepositoryName)
                                      .IfNullOrEmpty(Resources.RepositoryNameValidatorEmpty)
                                      .IfTrue(x => x.Length > 100, Resources.RepositoryNameValidatorTooLong)
                                      .IfTrue(IsAlreadyRepoAtPath, Resources.RepositoryNameValidatorAlreadyExists);

            SafeRepositoryNameWarningValidator = ReactivePropertyValidator.ForObservable(nonNullRepositoryName)
                                                 .Add(repoName =>
            {
                var parsedReference = GetSafeRepositoryName(repoName);
                return(parsedReference != repoName ? String.Format(CultureInfo.CurrentCulture, Resources.SafeRepositoryNameWarning, parsedReference) : null);
            });

            this.WhenAny(x => x.BaseRepositoryPathValidator.ValidationResult, x => x.Value)
            .Subscribe();

            CreateRepository = InitializeCreateRepositoryCommand();

            canKeepPrivate = CanKeepPrivateObservable.CombineLatest(CreateRepository.IsExecuting,
                                                                    (canKeep, publishing) => canKeep && !publishing)
                             .ToProperty(this, x => x.CanKeepPrivate);

            isCreating = CreateRepository.IsExecuting
                         .ToProperty(this, x => x.IsCreating);

            GitIgnoreTemplates = TrackingCollection.CreateListenerCollectionAndRun(
                modelService.GetGitIgnoreTemplates(),
                new[] { GitIgnoreItem.None },
                OrderedComparer <GitIgnoreItem> .OrderByDescending(item => GitIgnoreItem.IsRecommended(item.Name)).Compare,
                x =>
            {
                if (x.Name.Equals("VisualStudio", StringComparison.OrdinalIgnoreCase))
                {
                    SelectedGitIgnoreTemplate = x;
                }
            });

            Licenses = TrackingCollection.CreateListenerCollectionAndRun(
                modelService.GetLicenses(),
                new[] { LicenseItem.None },
                OrderedComparer <LicenseItem> .OrderByDescending(item => LicenseItem.IsRecommended(item.Name)).Compare);

            BaseRepositoryPath = repositoryCreationService.DefaultClonePath;
        }
        internal static void Init(ServerConnectionItemManager itemManager)
        {
            _regLicenseReceiver = EnvironmentManager.Instance.RegisterReceiver(NewLicense,
                                                                               new MessageIdFilter(
                                                                                   MessageId.System.LicenseChangedIndication));

            _activatedServerLicense = EnvironmentManager.Instance.LicenseManager.GetLicense(
                ServerConnectionDefinition.ServerConnectionPluginId,
                ServerConnectionDefinition.ServerLicenseId);
            _myServerLicense = EnvironmentManager.Instance.LicenseManager.ReservedLicenseManager.GetLicenseInformation(
                ServerConnectionDefinition.ServerConnectionPluginId,
                ServerConnectionDefinition.ServerLicenseId);

            if (_myServerLicense == null)
            {
                // If real license already activated, use that one as a starting point
                if (_activatedServerLicense != null)
                {
                    _myServerLicense = _activatedServerLicense;
                }
                else
                {
                    // If no license is available, store today + 30 days as the trial period
                    _myServerLicense = new LicenseInformation()
                    {
                        PluginId            = ServerConnectionDefinition.ServerConnectionPluginId,
                        Counter             = 0,
                        CustomData          = "Here we can add some custom data",
                        LicenseType         = ServerConnectionDefinition.ServerLicenseId,
                        Name                = "Server Connection License Sample",
                        Expire              = DateTime.UtcNow + TimeSpan.FromDays(30),
                        TrialMode           = true,
                        ItemIdentifications = new System.Collections.ObjectModel.Collection <LicenseItem>(),
                        CounterMethod       = LicenseInformation.CounterMethodEnum.CountByItemIdentifications
                    };
                }
                EnvironmentManager.Instance.LicenseManager.ReservedLicenseManager.SaveLicenseInformation(_myServerLicense);
            }

            // Now check for consistancy
            List <Item> items = itemManager.GetItems();
            Dictionary <string, Item> dictionaryItems = new Dictionary <string, Item>();

            foreach (Item item in items)
            {
                dictionaryItems.Add(item.FQID.ObjectId.ToString(), item);
            }

            Dictionary <string, LicenseItem> alreadyRegistreredItems = new Dictionary <string, LicenseItem>();
            List <LicenseItem> toRemove = new List <LicenseItem>();

            foreach (LicenseItem li in _myServerLicense.ItemIdentifications)
            {
                if (dictionaryItems.ContainsKey(li.Id) == false)
                {
                    toRemove.Add(li);
                }
                alreadyRegistreredItems.Add(li.Id, li);
            }

            // Lets remove any residuals (In case of crash or hack)
            foreach (LicenseItem li in toRemove)
            {
                _myServerLicense.UnRegisterConfiguredLicenseItem(li);
            }

            // Now add any missing items (crash or hack)
            foreach (Item item in items)
            {
                if (alreadyRegistreredItems.ContainsKey(item.FQID.ObjectId.ToString()) == false)
                {
                    LicenseItem li = new LicenseItem()
                    {
                        Id           = item.FQID.ObjectId.ToString(),
                        Name         = item.Name,
                        ItemTrial    = true,
                        ItemTrialEnd = DateTime.UtcNow + TimeSpan.FromDays(14)
                    };
                    _myServerLicense.RegisterConfiguredLicenseItem(li);
                }
            }

            // In this sample the number of reserved Items is also the counter for 'used' licenses
            _myServerLicense.Counter       = _myServerLicense.ItemIdentifications.Count;
            _myServerLicense.CounterMethod = LicenseInformation.CounterMethodEnum.CountByItemIdentifications;
        }
示例#13
0
        private void RunLicenseCheckForItem(Item item)
        {
            if (item == null || item.IsAir)
            {
                this.LicenseMode = 0;
                return;
            }

            // If the item is a type of License, we engage the respective mode:
            if (item.type == ModContent.ItemType <LicenseItem>())
            {
                this.LicenseMode = 1;
                return;
            }
            if (item.type == ModContent.ItemType <TrialLicenseItem>())
            {
                this.LicenseMode = 2;
                return;
            }

            string         realItemName = ItemAttributeHelpers.GetQualifiedName(item);
            ItemDefinition itemDef      = new ItemDefinition(item.type);

            bool isTrialed  = this.TrialLicensedItems.Contains(itemDef);
            bool isLicensed = this.LicensedItems.Contains(itemDef) ||
                              LicensesMod.Config.FreeStarterItems.Contains(itemDef);

            // When the item is NOT licenses, we apply the licensing effect to the item, if we can:
            switch (this.LicenseMode)
            {
            case 1:
                this.LicenseMode = 0;

                if (!isLicensed)
                {
                    if (LicenseItem.AttemptToLicenseItem(this.player, item))
                    {
                        Main.NewText(item.Name + " is now usable.", Color.Lime);
                    }
                    else
                    {
                        int needed = LicenseItem.ComputeCost(item);
                        Main.NewText("Not enough licenses for " + realItemName + ": " + needed + " needed", Color.Red);
                    }
                }
                else
                {
                    Main.NewText(item.Name + " is already licensed.", Color.Yellow);
                }
                break;

            case 2:
                this.LicenseMode = 0;

                if (!isLicensed && (!isTrialed || !LicensesMod.Config.TrialLicenseOncePerItem))
                {
                    if (TrialLicenseItem.AttemptToTemporaryLicenseItem(this.player, item))
                    {
                        Main.NewText(realItemName + " is now licensed for " + (LicensesMod.Config.TrialLicenseDurationInTicks / 60) + " seconds.", Color.LimeGreen);
                    }
                    else
                    {
                        int needed = LicenseItem.ComputeCost(item);
                        Main.NewText("Not enough trial licenses for " + realItemName + ": " + needed + " needed", Color.Red);
                    }
                }
                else
                {
                    if (isLicensed)
                    {
                        Main.NewText(item.Name + " is already licensed.", Color.Yellow);
                    }
                    else if (isTrialed)
                    {
                        Main.NewText(item.Name + " has already been trialed.", Color.Yellow);
                    }
                }

                break;
            }
        }