Пример #1
0
        private async Task ServerListLoad()
        {
            //StatusChange("Requested");
            try
            {
                ControlHelpers.ButtonStatusChange(buttonServerListReload, "Requested");
                await fileDb.ReadTable(FileDb.TableName.TBL_SERVER);

                List <string> instanceNoList = new List <string>();

                foreach (var a in fileDb.TBL_SERVER.Data)
                {
                    if (a.Value.serverInstanceNo != "NULL")
                    {
                        instanceNoList.Add(a.Value.serverInstanceNo);
                    }
                }

                List <serverInstance> serverInstances = await ServerOperation.GetServerInstanceList(instanceNoList);

                await fileDb.ReadTable(FileDb.TableName.TBL_SERVER);

                dgvServerList.InvokeIfRequired(async s =>
                {
                    try
                    {
                        List <string> deleteServerNameList = new List <string>();

                        s.Rows.Clear();
                        foreach (var a in fileDb.TBL_SERVER.Data)
                        {
                            var serverInstance = serverInstances.Find(x => x.serverName == a.Key.serverName);

                            if (serverInstance != null)
                            {
                                int n = s.Rows.Add();
                                s.Rows[n].Cells["CheckBox"].Value   = false;
                                s.Rows[n].Cells["Name"].Value       = a.Key.serverName;
                                s.Rows[n].Cells["ZoneNo"].Value     = a.Value.zoneNo + "(" + serverInstance.zone.zoneCode + ")";
                                s.Rows[n].Cells["InstanceNo"].Value = a.Value.serverInstanceNo;
                                s.Rows[n].Cells["PublicIp"].Value   = a.Value.serverPublicIp;
                                s.Rows[n].Cells["PrivateIp"].Value  = a.Value.serverPrivateIp;
                                s.Rows[n].Cells["Status"].Value     = serverInstance.serverInstanceStatus.code;
                                s.Rows[n].Cells["Operation"].Value  = serverInstance.serverInstanceOperation.code;
                            }
                            else
                            {
                                deleteServerNameList.Add(a.Key.serverName);
                            }
                        }

                        foreach (var a in deleteServerNameList)
                        {
                            var p = new List <KeyValuePair <string, string> >();
                            p.Add(new KeyValuePair <string, string>("serverName", a));
                            await fileDb.DeleteTable(FileDb.TableName.TBL_SERVER, p);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                });
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                ControlHelpers.ButtonStatusChange(buttonServerListReload, "Reload");
            }
        }
Пример #2
0
        private async void buttonSetSqlServer_Click(object sender, EventArgs e)
        {
            try
            {
                if (ControlHelpers.CheckBoxCheckedCnt(dgvServerList) == 0)
                {
                    throw new Exception("select a server");
                }

                DialogResult result = MessageBox.Show("Do you really want to run?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (result != DialogResult.Yes)
                {
                    return;
                }

                ControlHelpers.ButtonStatusChange(buttonSetSqlServer, "Requested");
                buttonServerListReload.Enabled = false;
                await DbSave();

                foreach (DataGridViewRow item in dgvServerList.Rows)
                {
                    if (bool.Parse(item.Cells["CheckBox"].Value.ToString()))
                    {
                        string publicIp = item.Cells["PublicIp"].Value.ToString();
                        if (publicIp == null || publicIp.Length == 0)
                        {
                            throw new Exception("publicip is null");
                        }
                        else
                        {
                            item.Cells["SetupStatus"].Value = "Working...";

                            string ip = item.Cells["PublicIp"].Value.ToString();

                            var psCmds = ReadPowerShell(psTemplateChanged);

                            int totalCmdCount = psCmds.Count();
                            int currentCmd    = 0;
                            foreach (var psCmd in psCmds)
                            {
                                currentCmd++;
                                CurrentStepName = psCmd.Key.ToString().Substring(4);
                                CurrentPercent  = (double)currentCmd / (double)totalCmdCount * (double)100;
                                if (CurrentPercent == 100)
                                {
                                    CurrentPercent = 99;
                                }

                                progressBarPercentChange(
                                    CurrentPercent
                                    , CurrentStepName
                                    );


                                //try
                                //{
                                var   task = Execute(psCmd.Value, ip);
                                await task;
                                //}
                                //catch (Exception ex)
                                //{
                                //    if (ex.Message.ToString().Contains("object reference not set"))
                                //    {
                                //        // sql not started...
                                //    }
                                //}
                            }

                            CurrentStepName = "98. Sql Id and Pass Setting";
                            progressBarPercentChange(
                                99
                                , CurrentStepName
                                );
                            var wcfResponse = await SqlConnectionStringSetting(ip);

                            if (!wcfResponse.IsSuccess)
                            {
                                throw new Exception($"Error SqlConnectionStringSetting {wcfResponse.ResultMessage} + {wcfResponse.ErrorMessage}");
                            }

                            var   taskDelay = Task.Delay(10000);
                            await taskDelay;

                            CurrentStepName = "99. Default ObjectStorage Setting";
                            progressBarPercentChange(
                                99
                                , CurrentStepName
                                );

                            await DefualtObjectStorageSettingWithRetry(ip);

                            string serverInstanceNo = item.Cells["InstanceNo"].Value.ToString();
                            var    serverList       = new List <string>();
                            serverList.Add(serverInstanceNo);

                            await ServerOperation.RebootServerInstances(serverList);

                            item.Cells["SetupStatus"].Value = "Completed";
                        }
                    }
                }
                MessageBox.Show("server restart requested!");

                CurrentStepName = "Completed";
                progressBarPercentChange(
                    100
                    , CurrentStepName
                    );
            }
            catch (Exception ex)
            {
                CurrentStepName = "Sql Setting Error... Try Again...";
                MessageBox.Show(ex.Message);
            }
            finally
            {
                ControlHelpers.ButtonStatusChange(buttonSetSqlServer, "Set Sql Server");
                buttonServerListReload.Enabled = true;
            }
        }