示例#1
0
        protected override sealed DevSetupCommandResult ExecuteCommand()
        {
            using (PowerShell powerShellInstance = PowerShell.Create())
            {
                // Directly invoke the MSI Installer
                powerShellInstance.AddScript("gem install breakpoint");

                IAsyncResult psResult = powerShellInstance.BeginInvoke();

                while (psResult.IsCompleted == false)
                {
                    Console.WriteLine("Waiting for pipeline to finish");
                    Thread.Sleep(1000);
                }
            }

            DevSetupCommandResult result = new DevSetupCommandResult()
            {
                CommandName = GetType().Name, CommandResult = true
            };

            result.CommandResult = true;
            result.Message       = "front-end libraries for UND project were installed successfully on this machine";

            return(result);
        }
示例#2
0
        /// <summary>
        /// IDevSetupCommand method that provides clients with a way to execute the command.
        /// This method follows 'Template Method' design pattern.
        /// The command results are populated here; try-catch logic is encapsulated here as well.
        /// </summary>
        public void Execute()
        {
            DevSetupCommandResult result = new DevSetupCommandResult()
            {
                CommandName = GetType().Name
            };

            try
            {
                if (ValidateParameters())
                {
                    result = ExecuteCommand();
                }
            }
            catch (Exception ex)
            {
                result.CommandResult = false;
                result.Message       = ex.Message;
            }
            finally
            {
                if (result.Message != null)
                {
                    CommandResults.Add(result);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Uses reflection to validate PowerShell parameters that are marked as mandatory.
        /// </summary>
        /// <returns></returns>
        protected bool ValidateParameters()
        {
            var validationPassed = true;

            foreach (PropertyInfo propInfo in GetType().GetProperties())
            {
                if (Attribute.GetCustomAttribute(propInfo, typeof(ParameterAttribute)) is ParameterAttribute attribute && attribute.Mandatory)
                {
                    string value = propInfo.GetValue(this) as string;
                    if (string.IsNullOrEmpty(value))
                    {
                        DevSetupCommandResult result = new DevSetupCommandResult()
                        {
                            CommandName = GetType().Name, CommandResult = false
                        };
                        result.Message = string.Format("{0} Cmdlet Parameter was not supplied.", propInfo.Name);
                        CommandResults.Add(result);

                        validationPassed = false;
                    }
                }
            }

            return(validationPassed);
        }
        protected override sealed DevSetupCommandResult ExecuteCommand()
        {
            using (ServerManager serverManager = new ServerManager())
            {
                ApplicationPool newPool = serverManager.ApplicationPools.Add(AppPoolName);
                newPool.ManagedRuntimeVersion = "v4.0";
                newPool.Enable32BitAppOnWin64 = false;
                newPool.ManagedPipelineMode   = ManagedPipelineMode.Integrated;
                newPool.QueueLength           = 1000;

                // Set NetworkService as App Pool Identity
                newPool.ProcessModel.IdentityType = ProcessModelIdentityType.NetworkService;

                serverManager.CommitChanges();
            }

            DevSetupCommandResult result = new DevSetupCommandResult()
            {
                CommandName = GetType().Name, CommandResult = true
            };

            result.Message = "New App Pool was created Successfully";

            return(result);
        }
        private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
        {
            var result = new DevSetupCommandResult();

            result.CommandResult = true;
            result.CommandName   = GetType().Name;
            result.Message       = e.Data;

            CommandResults.Add(result);
        }
示例#6
0
        protected override sealed DevSetupCommandResult ExecuteCommand()
        {
            // Create the Directory on file system, if it does not exist
            //var directoryInfo = Directory.CreateDirectory(PhysicalPath);

            //var basicAuthentication = new BasicAuthentication(UserName, Password, BitBucketRepoUrl);
            //var sharpBucket = new SharpBucketV1();
            //sharpBucket.BasicAuthentication(UserName, Password);

            //var endPoint = sharpBucket.RepositoriesEndPoint();
            //var res = endPoint.BranchResource("agency-oasis", "understood.org");

            //var branch = res.ListBranches().Where(c => c.name == "develop").FirstOrDefault();

            //// getting the User end point
            //var userEndPoint = sharpBucket.UserEndPoint();

            // querying the Bitbucket API for various info
            //var info = userEndPoint.
            //var privileges = userEndPoint.ListPrivileges();
            //var follows = userEndPoint.ListFollows();
            //var userRepos = userEndPoint.ListRepositories();

            //sharpBucket


            var creds = Base64Encode(String.Format("{0}:{1}", UserName, Password));

            var url = String.Concat(GitHubRepoUrl, @"/get/tip.zip");

            string zipFilePath = Path.Combine(Path.GetTempPath(), "test.zip");

            using (var client = new WebClient())
            {
                client.Headers.Add("Authorization", "Basic " + creds);
                client.Headers.Add("Content-Type", "application/octet-stream");
                client.DownloadFile(url, zipFilePath);
            }

            DevSetupCommandResult result = new DevSetupCommandResult()
            {
                CommandName = GetType().Name, CommandResult = true
            };

            result.Message = "New IIS Site was created Successfully";

            return(result);
        }
        protected override sealed DevSetupCommandResult ExecuteCommand()
        {
            Process process = new Process();

            process.EnableRaisingEvents       = true;
            process.StartInfo.FileName        = "cmd.exe";
            process.StartInfo.UseShellExecute = false;

            // Redirect the following streams
            process.StartInfo.RedirectStandardInput  = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError  = true;

            // Capture cmd output and cmd errors by subscribing to events
            process.OutputDataReceived += Process_OutputDataReceived;
            process.ErrorDataReceived  += Process_ErrorDataReceived;

            // do not create a cmd window
            process.StartInfo.CreateNoWindow = true;
            //process.StartInfo.Arguments = "/C ";

            process.Start();
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();

            using (StreamWriter input = process.StandardInput)
            {
                input.WriteLine("gem install -V sass -v 3.4.18");
                input.WriteLine("gem install -V compass -v 1.0.3");
                input.WriteLine("gem install -V breakpoint");
                input.WriteLine("gem install -V digest");

                input.Close();
            }

            process.WaitForExit();
            process.Close();

            DevSetupCommandResult result = new DevSetupCommandResult()
            {
                CommandName = GetType().Name, CommandResult = true
            };

            result.Message = "front-end libraries for UND project were installed successfully on this machine";

            return(result);
        }
        protected override sealed DevSetupCommandResult ExecuteCommand()
        {
            if (!ValidateParameters())
            {
                return(null);
            }

            var rubyFilePath = Path.Combine(Path.GetTempPath(), DownloadFilename);

            // Download Ruby Installer File
            using (var webClient = new WebClient())
            {
                webClient.DownloadFile(DownloadUrl, rubyFilePath);
            }

            Process installerProcess = Process.Start(rubyFilePath, "/q");

            while (installerProcess.HasExited == false)
            {
                //indicate progress to user

                Console.WriteLine("Waiting for the Ruby program to install");
                Thread.Sleep(250);
            }

            // Directly invoke the EXE using System Diagnostics Process class
            //ProcessStartInfo psi = new ProcessStartInfo();
            //psi.Arguments = "/s /v /qn /min";
            //psi.CreateNoWindow = true;
            //psi.WindowStyle = ProcessWindowStyle.Hidden;
            //psi.FileName = rubyFilePath;
            //psi.UseShellExecute = false;
            //Process.Start(psi);

            DevSetupCommandResult result = new DevSetupCommandResult()
            {
                CommandName = GetType().Name, CommandResult = true
            };

            result.Message = "Ruby was installed successfully on this machine";

            return(result);
        }
示例#9
0
        protected override sealed DevSetupCommandResult ExecuteCommand()
        {
            using (ServerManager serverManager = new ServerManager())
            {
                // Add URL Rewite Module to IIS
                Configuration        config         = serverManager.GetAdministrationConfiguration();
                ConfigurationSection modulesSection = config.GetSection("modules");

                ConfigurationElementCollection modulesCollection = modulesSection.GetCollection();
                ConfigurationElement           addElement        = modulesCollection.CreateElement("add");
                addElement["name"] = @"Rewrite";
                modulesCollection.Add(addElement);

                //var real_name = modulesCollection.Attributes.Where(n => n.Value.ToString().ToLower().Contains("rewrite"));

                //var real_name = modulesCollection.Where(c => c.Attributes[0].Value.ToString().ToLower().Contains("Modules"));

                //var real_name_1 = modulesCollection.Where(c => c.Attributes[0].Value.ToString().ToLower().Contains("rewrite"));

                //foreach (var mod in modulesCollection)
                //{
                //    var name = mod.ToString();
                //    var name1 = mod.GetType();

                //}

                serverManager.CommitChanges();
            }

            DevSetupCommandResult result = new DevSetupCommandResult()
            {
                CommandName = GetType().Name, CommandResult = true
            };

            result.Message = "URL Rewrite Module was added Successfully";

            return(result);
        }
示例#10
0
        protected override sealed DevSetupCommandResult ExecuteCommand()
        {
            using (ServerManager serverManager = new ServerManager())
            {
                // If the physical directory does not exist, create it.
                Directory.CreateDirectory(PhysicalPath);

                // Create a new IIS Site
                Site site = serverManager.Sites.Add(SiteName, PhysicalPath, 80);

                // Retrieve reference to Binding Info of new site
                BindingCollection bindingCollection = site.Bindings;
                bindingCollection.Clear();

                // Add two Bindings
                string bindingInfo = string.Format("{0}:{1}:{2}", "*", "80", SiteName);
                bindingCollection.Add(bindingInfo, "http");
                bindingInfo = string.Format("{0}:{1}:{2}", "*", "80", "be." + SiteName);
                bindingCollection.Add(bindingInfo, "http");

                if (!string.IsNullOrEmpty(AppPoolName))
                {
                    site.ApplicationDefaults.ApplicationPoolName = AppPoolName;
                }

                serverManager.CommitChanges();
            }

            DevSetupCommandResult result = new DevSetupCommandResult()
            {
                CommandName = GetType().Name, CommandResult = true
            };

            result.Message = "New IIS Site was created Successfully";

            return(result);
        }