Esempio n. 1
0
        public override bool NewAzureStorageQueue(string QueueName)
        {
            PowerShell ps = GetPowerShellInstance();

            ps.AddCommand("New-AzureStorageQueue");
            ps.BindParameter("Name", QueueName);
            AddCommonParameters(ps);

            Test.Info(CmdletLogFormat, MethodBase.GetCurrentMethod().Name, GetCommandLine(ps));

            ParseCollection(ps.Invoke());
            ParseErrorMessages(ps);

            return(!ps.HadErrors);
        }
Esempio n. 2
0
        public override bool GetAzureStorageContainerByPrefix(string Prefix)
        {
            PowerShell ps = GetPowerShellInstance();

            ps.AddCommand("Get-AzureStorageContainer");
            ps.BindParameter("Prefix", Prefix);
            AddCommonParameters(ps);

            Test.Info(CmdletLogFormat, MethodBase.GetCurrentMethod().Name, GetCommandLine(ps));

            ParseContainerCollection(ps.Invoke());
            ParseErrorMessages(ps);

            return(!ps.HadErrors);
        }
Esempio n. 3
0
        public override bool RemoveAzureStorageTable(string TableName, bool Force = true)
        {
            PowerShell ps = GetPowerShellInstance();

            AttachPipeline(ps);
            ps.AddCommand("Remove-AzureStorageTable");
            ps.BindParameter("Name", TableName);

            AddCommonParameters(ps, Force);

            Test.Info(CmdletLogFormat, MethodBase.GetCurrentMethod().Name, GetCommandLine(ps));

            ParseCollection(ps.Invoke());
            ParseErrorMessages(ps);

            return(!ps.HadErrors);
        }
Esempio n. 4
0
        public override bool StartAzureStorageBlobCopy(string srcContainerName, string srcBlobName, string destContainerName, string destBlobName, object destContext = null, bool force = true)
        {
            PowerShell ps = GetPowerShellInstance();

            ps.AddCommand("Start-AzureStorageBlobCopy");
            ps.BindParameter("SrcContainer", srcContainerName);
            ps.BindParameter("SrcBlob", srcBlobName);
            ps.BindParameter("DestContainer", destContainerName);
            ps.BindParameter("Force", force);
            ps.BindParameter("DestBlob", destBlobName);
            ps.BindParameter("DestContext", destContext);

            return(InvokeStoragePowerShell(ps));
        }
Esempio n. 5
0
        public override bool SetAzureStorageBlobContent(string FileName, string ContainerName, BlobType Type, string BlobName = "",
                                                        bool Force = true, int ConcurrentCount = -1, Hashtable properties = null, Hashtable metadata = null)
        {
            PowerShell ps = GetPowerShellInstance();

            AttachPipeline(ps);
            ps.AddCommand("Set-AzureStorageBlobContent");
            ps.BindParameter("File", FileName);
            ps.BindParameter("Blob", BlobName);
            ps.BindParameter("Container", ContainerName);
            ps.BindParameter("Properties", properties);
            ps.BindParameter("Metadata", metadata);

            if (Type == BlobType.BlockBlob)
            {
                ps.BindParameter("BlobType", "Block");
            }
            else if (Type == BlobType.PageBlob)
            {
                ps.BindParameter("BlobType", "Page");
            }

            if (ConcurrentCount != -1)
            {
                ps.BindParameter("ConcurrentCount", ConcurrentCount);
            }

            AddCommonParameters(ps, Force);

            Test.Info(CmdletLogFormat, MethodBase.GetCurrentMethod().Name, GetCommandLine(ps));

            ParseBlobCollection(ps.Invoke());
            ParseErrorMessages(ps);

            return(!ps.HadErrors);
        }
 /// <summary>
 /// Add the common parameters
 ///     -Context ...
 /// </summary>        
 internal void AddCommonParameters(PowerShell ps)
 {
     if (UseContextParam && AgentContext != null)
     {
         ps.BindParameter(ContextParameterName, AgentContext);
     }
 }
        /// <summary>
        /// Add the common parameters
        ///     -Context ...
        ///     -Force ...
        /// </summary>        
        internal void AddCommonParameters(PowerShell ps, bool Force)
        {
            AddCommonParameters(ps);

            if (Force)
            {
                ps.BindParameter("Force");
            }
        }
        private bool InvokeStoragePowerShell(PowerShell ps, object context = null)
        {
            if (context == null)
            {
                AddCommonParameters(ps);
            }
            else
            {
                ps.BindParameter(ContextParameterName, context);
            }

            Test.Info(CmdletLogFormat, MethodBase.GetCurrentMethod().Name, GetCommandLine(ps));

            //TODO We should add a time out for this invoke. Bad news, powershell don't support buildin time out for invoking.
            try
            {
                ParseCollection(ps.Invoke());
            }
            catch (Exception e)
            {
                Test.Info(e.Message);
            }

            ParseErrorMessages(ps);

            return !ps.HadErrors;
        }
        /// <summary>
        /// Attach some script to the current PowerShell instance
        ///     Attach Rule :
        ///         1. If the script is start with "$", we directly add it to the pipeline
        ///         2. If the current script is storage cmdlet, we need to add the current storage context to it.
        ///         3. Otherwise, split the script into [CommandName] and many [-Parameter][Value] pairs, attach them using PowerShell command interface(AddParameter/AddCommand/etc)
        ///         //TODO update the step 3
        /// </summary>
        /// <param name="ps">PowerShell instance</param>
        private void AttachPipeline(PowerShell ps)
        {
            foreach (string cmd in pipeLine)
            {
                if (cmd.Length > 0 && cmd[0] == '$')
                {
                    ps.AddScript(cmd);
                }
                else
                {
                    string[] cmdOpts = cmd.Split(' ');
                    string cmdName = cmdOpts[0];
                    ps.AddCommand(cmdName);

                    string opts = string.Empty;
                    bool skip = false;
                    for (int i = 1; i < cmdOpts.Length; i++)
                    {
                        if (skip)
                        {
                            skip = false;
                            continue;
                        }

                        if (cmdOpts[i].IndexOf("-") != 0)
                        {
                            ps.AddArgument(cmdOpts[i]);
                        }
                        else
                        {
                            if (i + 1 < cmdOpts.Length && cmdOpts[i + 1].IndexOf("-") != 0)
                            {
                                ps.BindParameter(cmdOpts[i].Substring(1), cmdOpts[i + 1]);
                                skip = true;
                            }
                            else
                            {
                                ps.BindParameter(cmdOpts[i].Substring(1));
                                skip = false;
                            }
                        }
                    }

                    //add storage context for azure storage cmdlet
                    //It make sure all the storage cmdlet in pipeline use the same storage context
                    if (cmdName.ToLower().IndexOf("-azurestorage") != -1)
                    {
                        AddCommonParameters(ps);
                    }
                }
            }
        }