public void startStopPool(ServerAndPool sap, string connectionString, string typeStatus, string publishType, string path, string type)
        {
            sap.getServer(connectionString, typeStatus, publishType);
            servers = sap.Getservers();
            sap.getPool(connectionString, typeStatus);
            pools = sap.Getpools();

            //testingjerie
            //string[] _servers = { "Z000S-ITPSAP25" };
            //string[] _pools = { "test" };

            try
            {
                RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
                Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration);
                runspace.Open();
                RunspaceInvoke scriptInvoker = new RunspaceInvoke(runspace);
                Pipeline       pipeline      = runspace.CreatePipeline();

                //Here's how you add a new script with arguments
                Command          myCommand = new Command(path);
                CommandParameter a         = new CommandParameter("server", servers);
                CommandParameter b         = new CommandParameter("appPool", pools);
                //testingjerie
                //CommandParameter a = new CommandParameter("server", _servers);
                //CommandParameter b = new CommandParameter("appPool", _pools);
                CommandParameter c = new CommandParameter("type", type);
                myCommand.Parameters.Add(a);
                myCommand.Parameters.Add(b);
                myCommand.Parameters.Add(c);
                pipeline.Commands.Add(myCommand);

                // Execute PowerShell script
                Collection <PSObject> results = pipeline.Invoke();
                //logData += string.Join(", ", _pools);
                logData += string.Join(", ", pools);

                //foreach (var svr in _servers)
                foreach (var svr in servers)
                {
                    //foreach (var pool in _pools)
                    foreach (var pool in pools)
                    {
                        //write to event viewer
                        EventLog appLog = new EventLog("");
                        appLog.Source = "Application Pool";
                        if (type == "stop")
                        {
                            appLog.WriteEntry("The IIS 7 Application Pool named " + pool + " on " + svr +
                                              ".corp.ai.astra.co.id is unavailable as the Application Pool has been stopped.", EventLogEntryType.Information);
                        }
                        else if (type == "start")
                        {
                            appLog.WriteEntry("The IIS 7 Application Pool named " + pool + " on " + svr +
                                              ".corp.ai.astra.co.id is available as the Application Pool has been started.", EventLogEntryType.Information);
                        }
                    }
                }
                MessageBox.Show(type + " sudah selesai.");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error : " + ex);
            }
        }
Ejemplo n.º 2
0
        public void LoadBackupFiles(string publishType, ServerAndPool sap, String connectionString, string typeStatus, Button stopPoolsButton,
                                    DataGridView dataGridView1, string path, string backupPath, string backupServer, string pathStg, string localPath,
                                    string appServer, TextBox ssisFileName, BackgroundWorker bgwLoadBackup, Label backupFileInfo)
        {
            if (publishType == null)
            {
                MessageBox.Show("pilih dulu apps, web apps, atau ssis!");
            }
            //else
            //{
            //    sap.getServer(connectionString, typeStatus, publishType);
            //    servers = sap.Getservers();
            //}

            if (publishType == "Web Apps")
            {
                stopPoolsButton.Invoke((MethodInvoker) delegate
                {
                    stopPoolsButton.Enabled = true;
                });
                //dataGridView1.Invoke((MethodInvoker)delegate
                //{
                //    dataGridView1.Rows.Clear();
                //});
                backupFileInfo.Invoke((MethodInvoker) delegate
                {
                    backupFileInfo.Text = "Copying files";
                });
                if (typeStatus == "PSS4W")
                {
                    //sourceFolders = new string[] { @"\pss4w", @"\tdms", @"\pss4wservice", @"\tdmsservice" };
                    server  = "A000S-ITPSAP03";
                    ps1path = @"\\a000s-drrpt1\MigrationUploadData\Abud\Taufiq\Publishing tools\copyfiles.ps1";
                    eps.execToPowerShell(server, DateTime.Now.ToString("yyMMdd"), ps1path);
                }
                else if (typeStatus == "PSS2W")
                {
                    //sourceFolders = new string[] { @"\psshsoho", @"\psshsom29", @"\pss2w", @"\pss2w1" };
                    server  = "A000S-ITPSAP15";
                    ps1path = @"\\a000s-drrpt1\MigrationUploadData\Abud\Taufiq\Publishing tools\copyfiles.ps1";
                    eps.execToPowerShell(server, DateTime.Now.ToString("yyMMdd"), ps1path);
                }
                else if (typeStatus == "TAM")
                {
                    //sourceFolders = new string[] { @"\TAM", @"\Webservice_TAM" };
                    server  = "A000S-PSSAPT1";
                    ps1path = @"\\a000s-drrpt1\MigrationUploadData\Abud\Taufiq\Publishing tools\copyfiles.ps1";
                    eps.execToPowerShell(server, DateTime.Now.ToString("yyMMdd"), ps1path);
                }
                backupFileInfo.Invoke((MethodInvoker) delegate
                {
                    backupFileInfo.Text = "Done";
                });
                //foreach (var server in servers)
                //{
                //int i = 0;
                //arraySource = new string[sourceFolders.Length];
                //arrayDestination = new string[sourceFolders.Length];
                //foreach (var srcFd in sourceFolders)
                //{
                //    if (typeStatus == "PSS4W")
                //    {
                //        server = "A000S-ITPSAP03";
                //        source = @"\\" + server + path + srcFd;
                //        destination = @"\\" + backupServer + backupPath + @"\" + server + @"\" + publishType + srcFd;
                //    }
                //    else if (typeStatus == "TAM")
                //    {
                //        server = "A000S-PSSAPT1";
                //        source = @"\\" + server + path + srcFd;
                //        destination = @"\\" + backupServer + backupPath + @"\" + server + @"\" + publishType + srcFd;
                //    }
                //    else if (typeStatus == "PSS2W")
                //    {
                //        server = "A000S-ITPSAP15";
                //        source = @"\\" + server + path + srcFd;
                //        destination = backupPath + srcFd;
                //    }
                //    if (!Directory.Exists(destination))
                //    {
                //        Directory.CreateDirectory(destination);
                //    }
                //    arraySource[i] = source;
                //    arrayDestination[i] = destination;
                //    i++;

                //    //bgwLoadBackup.ReportProgress(0,"Adding security..");
                //    ////gives authorization
                //    //SetPermissions.AddDirectorySecurity(source, @"CORPAI\ciptha952839", FileSystemRights.FullControl, AccessControlType.Allow);
                //    //bgwLoadBackup.ReportProgress(0,"Listing..");

                //    //foreach (string files in Directory.GetFiles(source, "*.*", SearchOption.AllDirectories))
                //    //{
                //    //    //dataGridView1.Rows.Clear();
                //    //    //dataGridView1.Rows[i].Cells[0].Value = files;
                //    //    //dataGridView1.Rows[i].Cells[1].Value = files.Replace(source, destination);
                //    //    //i++;
                //    //    dataGridView1.Invoke((MethodInvoker)delegate
                //    //    {
                //    //        dataGridView1.Rows.Add(files, files.Replace(source, destination));
                //    //    });
                //    //}
                //}

                //if (File.Exists(Path.GetFileName(destination)))
                //{
                //    File.SetAttributes(Path.GetFileName(destination), FileAttributes.Normal);
                //    File.Delete(Path.GetFileName(destination));
                //}

                //for (i = 0; i < arraySource.Length; i++)
                //{
                //    backupFileInfo.Invoke((MethodInvoker)delegate
                //    {
                //        backupFileInfo.Text = "Copying files " + arraySource[i];
                //    });
                //    PowerShell ps = PowerShell.Create();
                //    ps.AddCommand("Copy-Item");

                //    IDictionary parameters = new Dictionary<String, String>();
                //    parameters.Add(0,arraySource[i]);
                //    parameters.Add(1,arrayDestination[i]);
                //    parameters.Add(2,"-recurse");
                //    parameters.Add(3,"-force");
                //    parameters.Add(4,"-ErrorAction");
                //    parameters.Add(5,"SilentlyContinue");

                //    ps.AddParameters(parameters);

                //    ps.Invoke();
                //}

                ////exec script
                //RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
                //Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration);
                //runspace.Open();
                //RunspaceInvoke scriptInvoker = new RunspaceInvoke(runspace);
                //Pipeline pipeline = runspace.CreatePipeline();
                //myCommand = new Command(@"\\a000s-drrpt1\MigrationUploadData\Abud\Taufiq\Publishing tools\copyfiles.ps1");
                ////myCommand.Parameters.Add("source",arraySource);
                ////myCommand.Parameters.Add("destination",arrayDestination);

                //myCommand.Parameters.Add("source", @"U:\tes");
                //myCommand.Parameters.Add("destination", @"U:\tes2");
                //pipeline.Commands.Add(myCommand);


                //// Execute PowerShell script
                //Collection<PSObject> results = pipeline.Invoke();


                ////double a = j++ / (sourceFolders.Length);
                //double a = 1;
                //bgwLoadBackup.ReportProgress(Convert.ToInt32(a * 100));
                //}
            }
            else if (publishType == "Apps")
            {
                dataGridView1.Invoke((MethodInvoker) delegate
                {
                    dataGridView1.Rows.Clear();
                });
                //foreach (var server in servers)
                //{

                if (typeStatus == "PSS4W")
                {
                    switch (appServer)
                    {
                    case "server2":
                    //source = @"\\" + server + path;
                    //destination = @"\\" + backupServer + backupPath + @"\" + server + @"\" + publishType;
                    //break;
                    case "server3":
                    //server = "A000S-ITPSAP03";
                    //source = @"\\" + server + path;
                    //destination = @"\\" + backupServer + backupPath + @"\" + server + @"\" + publishType;
                    //break;
                    case "server4":
                    //server = "A000S-ITPSAP04";
                    //source = @"\\" + server + path;
                    //destination = @"\\" + backupServer + backupPath + @"\" + server + @"\" + publishType;
                    //break;
                    case "server5":
                        string[] servers = { "A000S-ITPSAP02", "A000S-ITPSAP03", "A000S-ITPSAP04", "A000S-ITPSAP05" };
                        ps1path = @"\\a000s-drrpt1\MigrationUploadData\Abud\Taufiq\Publishing tools\copyfiles.ps1";
                        eps.execToPowerShell(servers, DateTime.Now.ToString("yyMMdd"), ps1path);
                        //server = "A000S-ITPSAP05";
                        //source = @"\\" + server + path;
                        //destination = @"\\" + backupServer + backupPath + @"\" + server + @"\" + publishType;
                        break;

                    case "staging":
                        server  = "A000S-PSSTG1";
                        ps1path = @"\\a000s-drrpt1\MigrationUploadData\Abud\Taufiq\Publishing tools\copyfiles.ps1";
                        eps.execToPowerShell(server, DateTime.Now.ToString("yyMMdd"), ps1path);
                        //source = @"\\" + server + pathStg;
                        //destination = @"\\" + backupServer + backupPath + @"\" + server + @"\" + publishType;
                        break;

                    default:
                        break;
                    }
                }
                else if (typeStatus == "TAM")
                {
                    string[] servers = { "A000S-PSSAPT1", "A000S-PSSAPT3" };
                    ps1path = @"\\a000s-drrpt1\MigrationUploadData\Abud\Taufiq\Publishing tools\copyfiles.ps1";
                    eps.execToPowerShell(servers, DateTime.Now.ToString("yyMMdd"), ps1path);
                    //foreach (var server in servers)
                    //{
                    //    source = @"\\" + server + pathStg;
                    //    destination = @"\\" + backupServer + backupPath + @"\" + server + @"\" + publishType;
                    //}
                }

                //if (appServer == "server2")
                //{
                //    source = @"\\" + "A000S-ITPSAP2" + pathStg;
                //    destination = @"\\" + backupServer + backupPath + @"\" + server + @"\" + publishType;

                //}
                //else
                //{
                //    source = @"\\" + server + path;
                //    destination = @"\\" + backupServer + backupPath + @"\" + server + @"\" + publishType;
                //}
                //bgwLoadBackup.ReportProgress(0, "Adding security..");
                ////gives authorization
                //SetPermissions.AddDirectorySecurity(source, @"CORPAI\ciptha952839", FileSystemRights.FullControl, AccessControlType.Allow);
                //bgwLoadBackup.ReportProgress(0, "Listing..");
                //foreach (string files in Directory.GetFiles(source, "*.*", SearchOption.AllDirectories))
                //{
                //    //if (Directory.Exists(Path.GetDirectoryName(files).Replace(source, localPath)))
                //    //{
                //    //dataGridView1.Rows[i].Cells[0].Value = files;
                //    //dataGridView1.Rows[i].Cells[1].Value = files.Replace(source, destination);
                //    //i++;
                //    dataGridView1.Invoke((MethodInvoker)delegate
                //    {
                //        dataGridView1.Rows.Add(files, files.Replace(source, destination));
                //    });
                //    //}
                //}
                //}
            }
            //else if (publishType == "SSIS")
            //{
            //    tempPublishType = publishType;
            //    publishType = @"SSIS\" + publishType;
            //    dataGridView1.Invoke((MethodInvoker)delegate
            //    {
            //        dataGridView1.Rows.Clear();
            //    });
            //    foreach (var server in servers)
            //    {
            //        source = @"\\" + server + path;
            //        destination = @"\\" + backupServer + backupPath + @"\" + server + @"\" + publishType;

            //        //bgwLoadBackup.ReportProgress(0, "Adding security..");
            //        ////gives authorization
            //        //SetPermissions.AddDirectorySecurity(source, @"CORPAI\ciptha952839", FileSystemRights.FullControl, AccessControlType.Allow);
            //        bgwLoadBackup.ReportProgress(0, "Listing..");
            //        //foreach (string files in Directory.GetFiles(source, "*.*", SearchOption.AllDirectories))
            //        //{
            //        //    string filesLocal = files.Replace(source, localPath);
            //        //    if (File.Exists(filesLocal))
            //        //    {
            //        //        if (!Directory.Exists(Path.GetDirectoryName(files).Replace(source, destination)))
            //        //        {
            //        //            Directory.CreateDirectory(Path.GetDirectoryName(files).Replace(source, destination));
            //        //        }
            //        //        if (File.Exists(files.Replace(source, destination)))
            //        //        {
            //        //            File.Delete(files.Replace(source, destination));
            //        //        }
            //        //        File.Copy(files, files.Replace(source, destination), true);
            //        //        logData += files.Replace(source, destination) + "\n";
            //        //        double a = i++ / (fullProg - 1);
            //        //        //backupProgressBar.Value = Convert.ToInt32(a * 100);
            //        //    }

            //        //}
            //        foreach (string files in Directory.GetFiles(source, "*.*", SearchOption.AllDirectories))
            //        {
            //            //string configPath = source + @"\SSISConfig";
            //            //string packagePath = source + @"\SSISPackage";
            //            ssisFileName.Invoke((MethodInvoker)delegate
            //            {
            //                if (files.Contains(ssisFileName.Text))
            //                {
            //                    dataGridView1.Invoke((MethodInvoker)delegate
            //                    {
            //                        dataGridView1.Rows.Add(files, files.Replace(source, destination));
            //                    });
            //                }
            //            });
            //            //if (Directory.Exists(Path.GetDirectoryName(files).Replace(configPath, localPath)))
            //            //{
            //            //    //dataGridView1.Rows.Clear();
            //            //    //dataGridView1.Rows[i].Cells[0].Value = files;
            //            //    //dataGridView1.Rows[i].Cells[1].Value = files.Replace(source, destination);
            //            //    //i++;
            //            //    dataGridView1.Invoke((MethodInvoker)delegate
            //            //    {
            //            //        dataGridView1.Rows.Add(files, files.Replace(source, destination));
            //            //    });
            //            //}
            //            //if (Directory.Exists(Path.GetDirectoryName(files).Replace(packagePath, localPath)))
            //            //{
            //            //    //dataGridView1.Rows.Clear();
            //            //    //dataGridView1.Rows[i].Cells[0].Value = files;
            //            //    //dataGridView1.Rows[i].Cells[1].Value = files.Replace(source, destination);
            //            //    //i++;
            //            //    dataGridView1.Invoke((MethodInvoker)delegate
            //            //    {
            //            //        dataGridView1.Rows.Add(files, files.Replace(source, destination));
            //            //    });
            //            //}
            //        }
            //    }
            //    publishType = tempPublishType;
            //}
            //else
            //{
            //    dataGridView1.Invoke((MethodInvoker)delegate
            //    {
            //        dataGridView1.Rows.Clear();
            //    });
            //    foreach (var server in servers)
            //    {
            //        source = @"\\" + server + path;
            //        destination = @"\\" + backupServer + backupPath + @"\" + server + @"\" + publishType;

            //        //bgwLoadBackup.ReportProgress(0, "Adding security..");
            //        ////gives authorization
            //        //SetPermissions.AddDirectorySecurity(source, @"CORPAI\ciptha952839", FileSystemRights.FullControl, AccessControlType.Allow);
            //        bgwLoadBackup.ReportProgress(0, "Listing..");
            //        foreach (string files in Directory.GetFiles(source, "*.*", SearchOption.AllDirectories))
            //        {
            //            if (Directory.Exists(Path.GetDirectoryName(files).Replace(source, localPath)))
            //            {
            //                //dataGridView1.Rows.Clear();
            //                //dataGridView1.Rows[i].Cells[0].Value = files;
            //                //dataGridView1.Rows[i].Cells[1].Value = files.Replace(source, destination);
            //                //i++;
            //                dataGridView1.Invoke((MethodInvoker)delegate
            //                {
            //                    dataGridView1.Rows.Add(files, files.Replace(source, destination));
            //                });
            //            }
            //        }
            //    }
            //}
        }