public void Execute(ParameterParser parser)
        {
            var parameters = parser.GetActiveParameters(this);

            Console.WriteLine(Locale.Current["please-wait"]);

            Api.Current.StaticData.UpdateStaticDataAsync().RunSync();
            Api.Current.CachePriceAsync().RunSync();

            var itemTypes = new Func <string, IEnumerable <KeyValuePair <long, ItemType> > >(searchString =>
                                                                                             Api.Current.StaticData.ItemTypes
                                                                                             .Where(x => x.Value.IsPublished &&
                                                                                                    (x.Value.Name.Contains(searchString, StringComparison.CurrentCultureIgnoreCase) ||
                                                                                                     x.Value.GroupName.Contains(searchString, StringComparison.CurrentCultureIgnoreCase)))
                                                                                             .OrderBy(x => x.Value.Name)
                                                                                             .ThenBy(x => x.Value.GroupName)
                                                                                             .ThenBy(x => x.Value.Id)
                                                                                             .Take(20));

            if (parameters.Contains(nameof(ItemIdOf)))
            {
                if (string.IsNullOrEmpty(this.ItemIdOf))
                {
                    throw new InvalidOperationException("Invalid value");
                }

                var items = itemTypes(this.ItemIdOf);

                if (this.PricesOf)
                {
                    ConsoleUtils.WriteTable(new ConsoleTableColumn[]
                    {
                        new ConsoleTableColumn(items.Select(x => x.Value.Id.ToString())),
                        new ConsoleTableColumn(items.Select(x => x.Value.Name))
                        {
                            Width = 4
                        },
                        new ConsoleTableColumn(items.Select(x => Locale.Current[Api.Current.GetItemAveragePrice(x.Value.Id)] + " ISK"))
                        {
                            Width = 2, Alignment = ColumnAlignment.Right
                        }
                    });
                }
                else
                {
                    ConsoleUtils.WriteTable(new ConsoleTableColumn[]
                    {
                        new ConsoleTableColumn(items.Select(x => x.Value.Id.ToString())),
                        new ConsoleTableColumn(items.Select(x => x.Value.Name))
                        {
                            Width = 4
                        },
                        new ConsoleTableColumn(items.Select(x => x.Value.Group.Name))
                        {
                            Width = 2
                        }
                    });
                }
            }
        }
        /// <summary>
        /// Starts the execution of the group
        /// </summary>
        /// <param name="parser">The <see cref="ParameterParser"/> instanced that executed the group</param>
        public void Execute(ParameterParser parser)
        {
            var parameters = parser.GetActiveParameters(this);

            if (this.Help)
            {
                parser.ShowHelp();
                return;
            }

            if (this.ServiceInfo)
            {
                var configJson = JsonConvert.DeserializeObject <Configuration>(
                    Assemblies.GetManifestResource(x => x.Filename.EndsWith("configuration.json", StringComparison.InvariantCultureIgnoreCase) &&
                                                   x.Assembly == Assembly.GetEntryAssembly())
                    .TryEncode());

                var properties = configJson
                                 .GetType()
                                 .GetProperties()
                                 .Select(x => new { Attrib = x.GetCustomAttribute <JsonPropertyAttribute>(), Property = x })
                                 .Where(x => x != null);

                ConsoleUtils.WriteTable(new ConsoleTableColumn[]
                {
                    new ConsoleTableColumn(properties.Select(x => x.Attrib.PropertyName.ToUpper()))
                    {
                        Foreground = ConsoleColor.Gray, WrapWords = false
                    },
                    new ConsoleTableColumn(properties.Select(x => x.Property.GetValue(configJson)?.ToString()))
                    {
                        Foreground = ConsoleColor.Green, Width = 2f
                    }
                });
            }

            if (parameters.Contains(nameof(Install)) && parameters.Contains(nameof(UnInstall)))
            {
                throw new InvalidOperationException(Locale.Current["exception-0"]);
            }

            if (parameters.Contains(nameof(Install)))
            {
                new TInstaller().Install();
            }
            else if (parameters.Contains(nameof(UnInstall)))
            {
                new TInstaller().Uninstall();
            }
        }
Beispiel #3
0
        public void Execute(ParameterParser parser)
        {
            var parameters = parser.GetActiveParameters(this);

            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(Locale.Current["please-wait"]);
            Console.ForegroundColor = ConsoleColor.Cyan;

            var itemTypes = EveApi.GetPrices().Where(x =>
            {
                if (this.UseRegex)
                {
                    return(Regex.IsMatch(x.Type.Name, this.SearchString));
                }
                else
                {
                    return(x.Type.Name.Contains(this.SearchString, StringComparison.InvariantCultureIgnoreCase));
                }
            }).ToArray();
            var consoleColumns = new List <ConsoleTableColumn>();

            if (ItemIdOf)
            {
                consoleColumns.Add(new ConsoleTableColumn(itemTypes.Select(x => x.Type.Id.ToString("00000")))
                {
                    Width = 0.5f
                });
            }

            consoleColumns.Add(new ConsoleTableColumn(itemTypes.Select(x => x.Type.Name))
            {
                Width = 2
            });
            consoleColumns.Add(new ConsoleTableColumn(itemTypes.Select(x => x.AdjustedPrice.ToString("C3", CultureInfo.CreateSpecificCulture("is-IS"))))
            {
                Alignment = ColumnAlignment.Right
            });

            if (PricesOf)
            {
                consoleColumns.Add(new ConsoleTableColumn(itemTypes.Select(x => x.AveragePrice.ToString("C3", CultureInfo.CreateSpecificCulture("is-IS"))))
                {
                    Alignment = ColumnAlignment.Right
                });
            }

            ConsoleUtils.WriteTable(consoleColumns.ToArray());
        }
Beispiel #4
0
        public void Execute(ParameterParser parser)
        {
            var parameters = parser.GetActiveParameters(this);

            if (parameters.Contains(nameof(CreateATask)))
            {
                if (!Utils.StartElevated(parser.Parameters))
                {
                    var task = TaskService.Instance.GetTask(HostBlockTaskName);

                    if (task != null)
                    {
                        TaskService.Instance.RootFolder.DeleteTask(HostBlockTaskName, false);
                    }

                    using (var taskService = new TaskService())
                    {
                        var taskDefinition = taskService.NewTask();
                        taskDefinition.Actions.Add(new ExecAction(typeof(InstallationExecutionGroup).Assembly.Location, "--u --H", ApplicationInfo.ApplicationPath.FullName));
                        taskDefinition.Triggers.Add(new LogonTrigger());
                        taskDefinition.Principal.RunLevel  = TaskRunLevel.Highest;
                        taskDefinition.Principal.LogonType = TaskLogonType.ServiceAccount;
                        taskDefinition.Settings.DisallowStartIfOnBatteries = false;
                        taskDefinition.Principal.UserId = "SYSTEM";

                        taskService.RootFolder.RegisterTaskDefinition(HostBlockTaskName, taskDefinition);
                        TaskService.Instance.GetTask(HostBlockTaskName)?.Run();
                    }

                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("New Scheduled Task added: " + HostBlockTaskName);
                }
            }
            else if (parameters.Contains(nameof(RemoveTask)))
            {
                if (!Utils.StartElevated(parser.Parameters))
                {
                    TaskService.Instance.RootFolder.DeleteTask(HostBlockTaskName, false);

                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("Removed Scheduled Task: " + HostBlockTaskName);
                }
            }
        }
Beispiel #5
0
        public void Execute(ParameterParser parser)
        {
            var parameters = parser.GetActiveParameters(this);

            if (parameters.Contains(nameof(Language)))
            {
                if (string.IsNullOrEmpty(this.Language))
                {
                    Console.WriteLine(Locale.Current.CultureInfo.DisplayName);
                }
                else
                {
                    Locale.Current.CultureInfo = new CultureInfo(this.Language);
                    Console.WriteLine(Locale.Current.CultureInfo.DisplayName);
                }
            }

            if (this.Help)
            {
                parser.ShowHelp();
            }
        }