示例#1
0
        // Module defining this command


        // Optional custom code for this activity


        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of Sytem.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (InputObject.Expression != null)
            {
                targetCommand.AddParameter("InputObject", InputObject.Get(context));
            }

            if (FilterScript.Expression != null)
            {
                targetCommand.AddParameter("FilterScript", FilterScript.Get(context));
            }

            if (Property.Expression != null)
            {
                targetCommand.AddParameter("Property", Property.Get(context));
            }

            if (Value.Expression != null)
            {
                targetCommand.AddParameter("Value", Value.Get(context));
            }

            if (EQ.Expression != null)
            {
                targetCommand.AddParameter("EQ", EQ.Get(context));
            }

            if (CEQ.Expression != null)
            {
                targetCommand.AddParameter("CEQ", CEQ.Get(context));
            }

            if (NE.Expression != null)
            {
                targetCommand.AddParameter("NE", NE.Get(context));
            }

            if (CNE.Expression != null)
            {
                targetCommand.AddParameter("CNE", CNE.Get(context));
            }

            if (GT.Expression != null)
            {
                targetCommand.AddParameter("GT", GT.Get(context));
            }

            if (CGT.Expression != null)
            {
                targetCommand.AddParameter("CGT", CGT.Get(context));
            }

            if (LT.Expression != null)
            {
                targetCommand.AddParameter("LT", LT.Get(context));
            }

            if (CLT.Expression != null)
            {
                targetCommand.AddParameter("CLT", CLT.Get(context));
            }

            if (GE.Expression != null)
            {
                targetCommand.AddParameter("GE", GE.Get(context));
            }

            if (CGE.Expression != null)
            {
                targetCommand.AddParameter("CGE", CGE.Get(context));
            }

            if (LE.Expression != null)
            {
                targetCommand.AddParameter("LE", LE.Get(context));
            }

            if (CLE.Expression != null)
            {
                targetCommand.AddParameter("CLE", CLE.Get(context));
            }

            if (Like.Expression != null)
            {
                targetCommand.AddParameter("Like", Like.Get(context));
            }

            if (CLike.Expression != null)
            {
                targetCommand.AddParameter("CLike", CLike.Get(context));
            }

            if (NotLike.Expression != null)
            {
                targetCommand.AddParameter("NotLike", NotLike.Get(context));
            }

            if (CNotLike.Expression != null)
            {
                targetCommand.AddParameter("CNotLike", CNotLike.Get(context));
            }

            if (Match.Expression != null)
            {
                targetCommand.AddParameter("Match", Match.Get(context));
            }

            if (CMatch.Expression != null)
            {
                targetCommand.AddParameter("CMatch", CMatch.Get(context));
            }

            if (NotMatch.Expression != null)
            {
                targetCommand.AddParameter("NotMatch", NotMatch.Get(context));
            }

            if (CNotMatch.Expression != null)
            {
                targetCommand.AddParameter("CNotMatch", CNotMatch.Get(context));
            }

            if (Contains.Expression != null)
            {
                targetCommand.AddParameter("Contains", Contains.Get(context));
            }

            if (CContains.Expression != null)
            {
                targetCommand.AddParameter("CContains", CContains.Get(context));
            }

            if (NotContains.Expression != null)
            {
                targetCommand.AddParameter("NotContains", NotContains.Get(context));
            }

            if (CNotContains.Expression != null)
            {
                targetCommand.AddParameter("CNotContains", CNotContains.Get(context));
            }

            if (In.Expression != null)
            {
                targetCommand.AddParameter("In", In.Get(context));
            }

            if (CIn.Expression != null)
            {
                targetCommand.AddParameter("CIn", CIn.Get(context));
            }

            if (NotIn.Expression != null)
            {
                targetCommand.AddParameter("NotIn", NotIn.Get(context));
            }

            if (CNotIn.Expression != null)
            {
                targetCommand.AddParameter("CNotIn", CNotIn.Get(context));
            }

            if (Is.Expression != null)
            {
                targetCommand.AddParameter("Is", Is.Get(context));
            }

            if (IsNot.Expression != null)
            {
                targetCommand.AddParameter("IsNot", IsNot.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
示例#2
0
        static async Task MainAsync(string[] args)
        {
            try
            {
                if (Program.searchParameter(args, "-test") == 0)
                {
                    Console.WriteLine("Connection: " + Program.settings.ConnectionString + "\nDatabase: " + Program.settings.Database);
                    await(new ForecastDB(Program.settings.ConnectionString, Program.settings.Database)).testConnectionAsync();
                }
                else if (Program.searchParameter(args, "-share") == 0)
                {
                    CSocialNetworks socialNetworks = new CSocialNetworks();
                    await socialNetworks.shareForecast();
                }
                // Check the first parameter to validate if the action is export (-out) or import (-in)
                else if (Program.searchParameter(args, "-out") == 0)
                {
                    int path = Program.searchParameter(args, "-p");
                    Program.validateParameter(path, "-p");
                    COut output = new COut();
                    // Export states
                    // -out -s "prec" -p "C:\Users\hsotelo\Desktop\test export\\" -start 1981 -end 2013
                    int s = Program.searchParameter(args, "-s");
                    if (s >= 0)
                    {
                        int start = Program.searchParameter(args, "-start");
                        Program.validateParameter(start, "-start");
                        int end = Program.searchParameter(args, "-end");
                        Program.validateParameter(end, "-end");

                        Console.WriteLine("Exporting historical climate by states");
                        await output.exportStatesHistoricalClimateAsync(args[path + 1], (MeasureClimatic)Enum.Parse(typeof(MeasureClimatic), args[s + 1], true), int.Parse(args[start + 1]), int.Parse(args[end + 1]));
                    }
                    // Export configuration files from weather stations
                    // -out -wf -p "C:\Users\hsotelo\Desktop\test export\\" -name "daily"
                    int wf = Program.searchParameter(args, "-wf");
                    if (wf >= 0)
                    {
                        int name = Program.searchParameter(args, "-name");
                        Program.validateParameter(name, "-name");
                        Console.WriteLine("Exporting configuration file by weather station");
                        await output.exportFilesWeatherStationAsync(args[path + 1], args[name + 1]);
                    }
                    // Export coords from weather stations
                    // -out -co -p "C:\Users\hsotelo\Desktop\test export\\" -name "daily"
                    int co = Program.searchParameter(args, "-co");
                    if (co >= 0)
                    {
                        Console.WriteLine("Exporting coordinates of the weather stations");
                        await output.exportCoordsWeatherStationAsync(args[path + 1]);
                    }
                    // Export forecast setup
                    // -out -fs -p "C:\Users\hsotelo\Desktop\test export\\"
                    int fs = Program.searchParameter(args, "-fs");
                    if (fs >= 0)
                    {
                        Console.WriteLine("Exporting forecast setup");
                        await output.exportForecastSetupAsync(args[path + 1]);
                    }
                    // Export cpt setup
                    // -out -cpt -p "C:\Users\hsotelo\Desktop\test export\\"
                    int cpt = Program.searchParameter(args, "-cpt");
                    if (cpt >= 0)
                    {
                        Console.WriteLine("Exporting CPT setup");
                        await output.exportCPTSetupAsync(args[path + 1]);
                    }
                    // Export emails users
                    // -out -usr -p "C:\Users\hsotelo\Desktop\test export\\"
                    int usr = Program.searchParameter(args, "-usr");
                    if (usr >= 0)
                    {
                        Console.WriteLine("Exporting Users");
                        await output.exportUsersEmailsAsync(args[path + 1]);
                    }
                }
                else if (Program.searchParameter(args, "-in") == 0)
                {
                    int path = Program.searchParameter(args, "-p");
                    Program.validateParameter(path, "-p");
                    CIn cin = new CIn();
                    // Import forecast
                    // -in -fs -p "C:\Users\hsotelo\Desktop\test export\\" -cf 0.5
                    int fs = Program.searchParameter(args, "-fs");
                    if (fs >= 0)
                    {
                        int cf = Program.searchParameter(args, "-cf");
                        Program.validateParameter(cf, "-cf");
                        Console.WriteLine("Importing forecast");
                        await cin.importForecastAsync(args[path + 1], double.Parse(args[cf + 1]));
                    }
                    //-in -hs -s "prec" -type 1 -p "C:\data.csv"
                    int hs = Program.searchParameter(args, "-hs");
                    if (hs >= 0)
                    {
                        int s = Program.searchParameter(args, "-s");
                        Program.validateParameter(s, "-s");
                        int type = Program.searchParameter(args, "-type");
                        Program.validateParameter(type, "-type");
                        Console.WriteLine("Importing historical data");
                        await cin.importHistoricalAsync(args[path + 1], (MeasureClimatic)Enum.Parse(typeof(MeasureClimatic), args[s + 1]), int.Parse(args[type + 1]));
                    }
                }
                else if (Program.searchParameter(args, "-help") == 0)
                {
                    foreach (var l in File.ReadAllLines("help.txt"))
                    {
                        Console.WriteLine(l);
                    }
                }
                else
                {
                    throw new Exception("The first parameter should indicate if you want export (-out) or import (-in).\nRecommend execute with parameter -help to get more information");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine("For more information you can execute the following command:");
                Console.WriteLine("-help");
            }
        }