Esempio n. 1
0
        public static void CheckShowHelpInformation(this SPFunctions Functions, string args, Action Void)
        {
            var argsArr = Extentions.CommandLineParse(args);
            var help    = argsArr.Where(k => (k.Key.ToLower() == "help" || k.Key.ToLower() == "?")).FirstOrDefault();

            if (help.Key != null)
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("'ExecuteParams' functions:");

                foreach (var Function in Functions)
                {
                    var Name        = Function.Key;
                    var Description = Function.Description;
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.Write(Name);
                    if (!String.IsNullOrEmpty(Description))
                    {
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.Write(" - " + Description);
                    }
                    Console.WriteLine();
                }

                Console.ResetColor();
            }
            else
            {
                Void();
            }
        }
Esempio n. 2
0
        public static void RunCSOM(string args, SPFunctions Functions, string Description = "")
        {
            Description.Echo();

            CheckShowHelpInformation(Functions, args, () =>
            {
                RunCSOM(args, null, Functions);
            });
        }
Esempio n. 3
0
        public static void Run(string args, Options ConnectionOptions, SPFunctions Functions, string Description = "")
        {
            Description.Echo();

            CheckShowHelpInformation(Functions, args, () =>
            {
                GetParams(args, ConnectionOptions, Functions, ExtOptions =>
                {
                    ExtOptions.ExecuteMappedFunctions(Functions);
                });
            });
        }
Esempio n. 4
0
        public static void ExecuteMappedFunctions(this ExtendedOptions ExtOptions, SPFunctions Functions)
        {
            string ExecuteParamsString = ExtOptions.LoadedSettings["custom"]["executeParams"].ToString();

            List <string> FunctionsToExecute = ExecuteParamsString.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToList();

            FunctionsToExecute.ForEach(FunctionName =>
            {
                var Function = Functions.Where(k => k.Key.ToLower() == FunctionName.ToLower()).FirstOrDefault();
                if (Function != null && Function.Void != null)
                {
                    Function.Void(ExtOptions);
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("There is no function for key " + FunctionName);
                    Console.ResetColor();
                }
            });
        }
Esempio n. 5
0
        public static string InlineMenu(SPFunctions Functions, string Description, string DefaultValue)
        {
            Console.CursorVisible = false;

            var TopPosition = Console.CursorTop;

            var Value         = "";
            var SelectedValue = Functions[0].Key;

            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.Write("? ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.Write(Description + " ");
            Console.ForegroundColor = ConsoleColor.Gray;

            if (!String.IsNullOrEmpty(DefaultValue.ToString()))
            {
                Console.Write("(" + DefaultValue.ToString() + ") ");
            }

            Console.WriteLine();
            var ConsoleValue = DefaultValue.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).Where(x => Functions.FirstOrDefault(y => y.Key == x) != null).ToList();

            if (ConsoleValue.Count > 0)
            {
                SelectedValue = ConsoleValue[0];
            }

            var StartedPosition = Console.CursorTop;

            while (true)
            {
                ClearCurrentConsoleLine(StartedPosition);
                var index         = 0;
                var selectedIndex = 0;
                foreach (var Function in Functions)
                {
                    ClearCurrentConsoleLine();
                    var Name          = Function.Key;
                    var InDescription = Function.Description;

                    if (Name == SelectedValue)
                    {
                        Console.ForegroundColor = ConsoleColor.DarkCyan;
                        Console.Write("> ");
                        selectedIndex = index;
                    }
                    else
                    {
                        Console.Write("  ");
                    }
                    Console.Write(" [");
                    if (ConsoleValue.Contains(Name))
                    {
                        Console.Write("X");
                    }
                    else
                    {
                        Console.Write(" ");
                    }
                    Console.Write("] ");
                    Console.Write(Name);
                    if (!String.IsNullOrEmpty(InDescription))
                    {
                        Console.Write(" (" + InDescription + ") ");
                    }
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine();

                    index += 1;
                }

                Console.ResetColor();

                ConsoleKeyInfo i = Console.ReadKey(true);
                if (i.Key == ConsoleKey.Enter)
                {
                    Value = String.Join(" ", ConsoleValue.ToArray());
                    ClearCurrentConsoleLine(TopPosition);
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.Write("? ");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.Write(Description + " ");
                    Console.ForegroundColor = ConsoleColor.DarkCyan;
                    Console.Write(Value);
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine();
                    ClearCurrentConsoleLine(StartedPosition);

                    Functions.ForEach(f =>
                    {
                        ClearCurrentConsoleLine();
                        Console.WriteLine();
                    });
                    Console.SetCursorPosition(0, StartedPosition);

                    break;
                }
                if (i.Key == ConsoleKey.DownArrow)
                {
                    selectedIndex += 1;
                    if (selectedIndex >= Functions.Count)
                    {
                        selectedIndex = 0;
                    }

                    SelectedValue = Functions[selectedIndex].Key;
                }
                if (i.Key == ConsoleKey.UpArrow)
                {
                    selectedIndex -= 1;
                    if (selectedIndex < 0)
                    {
                        selectedIndex = Functions.Count - 1;
                    }
                    SelectedValue = Functions[selectedIndex].Key;
                }
                if (i.Key == ConsoleKey.Spacebar)
                {
                    var CurrentKey = Functions[selectedIndex].Key;
                    if (ConsoleValue.Contains(CurrentKey))
                    {
                        ConsoleValue = ConsoleValue.Where(val => val != CurrentKey).ToList();
                    }
                    else
                    {
                        ConsoleValue.Add(CurrentKey);
                    }
                }
            }
            Console.CursorVisible = true;

            return(Value);
        }
Esempio n. 6
0
        public static void GetParams(string args, Options ConnectionOptions, SPFunctions Functions, Action <ExtendedOptions> OnSuccess)
        {
            var tempArgs = Extentions.CommandLineParse(args);

            args = Extentions.CommandLineJoin(tempArgs);

            if (ConnectionOptions == null)
            {
                ConnectionOptions = SPAuth.GetAuth(args);
            }

            var saveConfigOnDisk = (bool)ConnectionOptions.Settings.saveConfigOnDisk;

            var ParsedArgs = Extentions.CommandLineParse(args.ModParams());

            var extoptions = new ExtendedOptions(ParsedArgs);

            extoptions.configPath = ConnectionOptions.Settings.configPath;
            extoptions.Options    = ConnectionOptions;
            dynamic LoadedSettings = saveConfigOnDisk ? Extentions.LoadSettings(extoptions.configPath) : JsonConvert.DeserializeObject <dynamic>("{}");

            if (LoadedSettings != null)
            {
                LoadedSettings = Extentions.AddExpandoProperty(LoadedSettings, "custom");
                var CustomProperties = Extentions.AddExpandoProperty(LoadedSettings["custom"], "executeParams", false);


                foreach (var ParsedArg in ParsedArgs)
                {
                    if (ParsedArg.Key.ToLower().IndexOf("custom.") != -1)
                    {
                        //CustomProperties.Add(ParsedArg.Key.Replace("custom.","").Trim(), ParsedArg.Value);
                        CustomProperties = Extentions.AddExpandoProperty(CustomProperties, ParsedArg.Key.Replace("custom.", "").Trim(), ParsedArg.Value);
                    }
                }
                LoadedSettings["custom"] = CustomProperties;

                extoptions.LoadedSettings = LoadedSettings;

                var ExecuteParams = CustomProperties["executeParams"];

                var forcePrompts = extoptions.forcePrompts || String.IsNullOrEmpty(ExecuteParams);
                if (forcePrompts)
                {
                    List <string> CustomPropertiesKeys = new List <string>(CustomProperties.Keys);

                    foreach (var CustomPropertyKey in CustomPropertiesKeys)
                    {
                        var Description = CustomPropertyKey;
                        if (CustomPropertyKey == "executeParams")
                        {
                            Description = Extentions.ExecuteParamsDescription;
                            CustomProperties[CustomPropertyKey] = Extentions.InlineMenu(Functions, Description, CustomProperties[CustomPropertyKey].ToString());
                        }
                        else
                        {
                            CustomProperties[CustomPropertyKey] = Extentions.InlineParam(Description, CustomProperties[CustomPropertyKey].ToString());
                        }
                    }
                }
                else
                {
                    Extentions.EchoParams(extoptions);
                }
                if (saveConfigOnDisk)
                {
                    Extentions.SaveSettings(LoadedSettings, extoptions.configPath);
                }

                OnSuccess(extoptions);
            }
        }