private void btnExit_Click(object sender, RoutedEventArgs e)
        {
            //this.Close();                       
            System.Windows.Forms.DialogResult dr;
            dr = MessageBox.ShowBox("MessageID18", BMC_Icon.Question, BMC_Button.YesNo);

            if (dr.ToString() == "No")
            {
                return;
            }
            else
            {
                //this.Visibility = Visibility.Hidden;
                // _workerTotalProcess.CancelAsync();
                App.Current.Shutdown();
                _instance = null;
            }
        }
Ejemplo n.º 2
0
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            int    iSiteCode              = 0;
            string strZonesResult         = string.Empty;
            string strBarPositionsResult  = string.Empty;
            string strMachinesResult      = string.Empty;
            string strInstallationsResult = string.Empty;
            int    iAuthResult            = 0;
            int    iServerResult          = 0;

            btnOK.IsEnabled     = false;
            btnCancel.IsEnabled = false;

            try
            {
                Cursor = System.Windows.Input.Cursors.Wait;
                statusbaritemlblStatus.Text = "Verifying with server...";
                statusbaritempbStatus.Value = 30;
                //if (txtAutCode.Text == string.Empty || txtEnterpriseURL.Text == string.Empty || txtSiteCode.Text == string.Empty)
                //{
                if (txtAutCode.Text == string.Empty || txtSiteCode.Text == string.Empty)
                {
                    MessageBox.ShowBox("MessageID20", BMC_Icon.Warning, BMC_Button.OK);
                    txtSiteCode.Focus();
                    statusbaritempbStatus.Value = 0;
                    return;
                }
                else
                {
                    if (txtSiteCode.Text.Length == 0)
                    {
                        MessageBox.ShowBox("MessageID21", BMC_Icon.Warning, BMC_Button.OK);
                        statusbaritempbStatus.Value = 0;
                        return;
                    }

                    //if (txtEnterpriseURL.Text.Length == 0)
                    //{
                    //    MessageBox.ShowBox("MessageID22", BMC_Icon.Warning, BMC_Button.OK);
                    //    statusbaritempbStatus.Value = 0;
                    //    return;
                    //}

                    //Check Site code validation
                    iSiteCode = int.Parse(txtSiteCode.Text.ToString());

                    if (!oSiteSetupConfiguration.IsValidSiteCode(iSiteCode))
                    {
                        MessageBox.ShowBox("MessageID312", BMC_Icon.Warning, BMC_Button.OK);
                        statusbaritempbStatus.Value = 0;
                        return;
                    }
                    //Check connection established with enterprise.
                    iServerResult = oSiteSetupConfiguration.EnterpriseUrlIsExists(txtEnterpriseURL.Text.ToString(), txtSiteCode.Text.ToString());
                    if (iServerResult == -1)
                    {
                        statusbaritempbStatus.Value = 0;
                        MessageBox.ShowBox("MessageID23", BMC_Icon.Warning, BMC_Button.OK);
                        statusbaritemlblStatus.Text = "Failed";
                        return;
                    }
                    else if (iServerResult == -2)
                    {
                        statusbaritempbStatus.Value = 0;
                        MessageBox.ShowBox("MessageID203", BMC_Icon.Warning, BMC_Button.OK);
                        statusbaritemlblStatus.Text = "Failed";
                        return;
                    }
                    statusbaritempbStatus.Value = 40;

                    try
                    {
                        iAuthResult = oSiteSetupConfiguration.CheckAuthorizationCode(txtAutCode.Text.Trim(), iSiteCode, "New");
                    }
                    catch (Exception exError)
                    {
                        iAuthResult = -1;
                        ExceptionManager.Publish(exError);
                    }

                    switch (iAuthResult)
                    {
                    case -1:
                    {
                        statusbaritempbStatus.Value = 0;
                        MessageBox.ShowBox("MessageID24", BMC_Icon.Warning, BMC_Button.OK);
                        statusbaritemlblStatus.Text = "Failed";
                        return;
                    }

                    case 0:
                    {
                        statusbaritempbStatus.Value = 0;
                        MessageBox.ShowBox("MessageID25", BMC_Icon.Warning, BMC_Button.OK);
                        statusbaritemlblStatus.Text = "Failed";
                        return;
                    }

                    case 1:
                    {
                        statusbaritempbStatus.Value = 0;
                        bool bUpdateStatus = oSiteSetupConfiguration.ResetTransactionKey(txtAutCode.Text.Trim(), iSiteCode);
                        MessageBox.ShowBox("MessageID25", BMC_Icon.Warning, BMC_Button.OK);
                        statusbaritemlblStatus.Text = "Failed";
                        return;
                    }

                    case 4:
                    {
                        statusbaritempbStatus.Value = 0;
                        MessageBox.ShowBox("MessageID167", BMC_Icon.Warning, BMC_Button.OK);
                        statusbaritemlblStatus.Text = "Failed";
                        return;
                    }

                    case 6:
                    {
                        statusbaritempbStatus.Value = 0;
                        MessageBox.ShowBox("MessageID28", BMC_Icon.Warning, BMC_Button.OK);
                        statusbaritemlblStatus.Text = "Failed";
                        return;
                    }

                    case 7:
                    {
                        statusbaritempbStatus.Value = 0;
                        MessageBox.ShowBox("MessageID199", BMC_Icon.Warning, BMC_Button.OK);
                        statusbaritemlblStatus.Text = "Failed";
                        return;
                    }

                    case 8:
                    {
                        statusbaritempbStatus.Value = 0;
                        MessageBox.ShowBox("MessageID200", BMC_Icon.Warning, BMC_Button.OK);
                        statusbaritemlblStatus.Text = "Failed";
                        return;
                    }
                    }

                    ////Check for NGA Asset in Enterprise.
                    //Get list of MAC Address of the local system & Send the list to Enterprise.
                    int iNGAStatus = -1;

                    try
                    {
                        string   strCheckNGAResult = oSiteSetupConfiguration.CheckNGA(GetCurentSystemMACAddress(), iSiteCode);
                        string[] strNGAResultSet   = strCheckNGAResult.Split(',');


                        foreach (string strNGAResult in strNGAResultSet)
                        {
                            if (strNGAResult.Trim().Length > 0)
                            {
                                string[] strMACList = new string[2];
                                strMACList = strNGAResult.Split('/');
                                iNGAStatus = Convert.ToInt32(strMACList[1]);

                                LogManager.WriteLog("MAC Adress - " + strMACList[0] + " Result - " + strMACList[1], LogManager.enumLogLevel.Info);

                                if (iNGAStatus > 1 && iNGAStatus < 5)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    catch (Exception exCheckNGA)
                    {
                        ExceptionManager.Publish(exCheckNGA);
                        iNGAStatus = -1;
                    }


                    //Based on the status decide course of action.
                    switch (iNGAStatus)
                    {
                    case -1:
                    case 0:
                    case 1:
                    {
                        statusbaritempbStatus.Value = 0;
                        bool bUpdateStatus = oSiteSetupConfiguration.ResetTransactionKey(txtAutCode.Text.Trim(), iSiteCode);
                        MessageBox.ShowBox("MessageID29", BMC_Icon.Warning, BMC_Button.OK);
                        statusbaritemlblStatus.Text = "Failed";
                        return;
                    }

                    case 5:
                    {
                        statusbaritempbStatus.Value = 0;
                        bool bUpdateStatus = oSiteSetupConfiguration.ResetTransactionKey(txtAutCode.Text.Trim(), iSiteCode);
                        MessageBox.ShowBox("MessageID30", BMC_Icon.Warning, BMC_Button.OK);
                        statusbaritemlblStatus.Text = "Failed";
                        return;
                    }
                    }

                    //Check database is empty or not.
                    if (oSiteSetupConfiguration.DatabaseIsEmpty() == false)
                    {
                        statusbaritempbStatus.Value = 0;
                        System.Windows.Forms.DialogResult dr;
                        dr = MessageBox.ShowBox("MessageID31", BMC_Icon.Question, BMC_Button.YesNo);
                        if (dr.ToString().ToUpper() == "NO")
                        {
                            statusbaritempbStatus.Value = 0;
                            statusbaritemlblStatus.Text = "Failed";
                            return;
                        }
                        else
                        {
                            if (oSiteSetupConfiguration.FlattenSystem())
                            {
                                MessageBox.ShowBox("MessageID32", BMC_Icon.Information, BMC_Button.OK);
                                this.Close();
                            }
                            else
                            {
                                MessageBox.ShowBox("MessageID33", BMC_Icon.Error, BMC_Button.OK);
                                this.Close();
                            }
                        }
                    }
                    if (ConfigManager.Read("ServicesListFromDB") != null)
                    {
                        if (ConfigManager.Read("ServicesListFromDB").ToUpper() == "TRUE")
                        {
                            strListarray = null;
                            strListarray = oSiteSetupConfiguration.GetSettingValue("ServiceNames").Split(',');
                            StopAllServices();
                        }
                    }

                    statusbaritempbStatus.Value = 60;
                    System.Threading.Thread.Sleep(5);
                    statusbaritempbStatus.Value = 100;

                    switch (iAuthResult)
                    {
                    case 2:
                    {
                        //Call Site Recovery mode
                        oCSitecheckpoints = new SiteCheckPoints("RECOVERY", iSiteCode);
                        this.Hide();
                        oCSitecheckpoints.Owner = this;
                        oCSitecheckpoints.Show();
                        break;
                    }

                    case 3:
                    {
                        //Call Auto Configure mode
                        oCSitecheckpoints = new SiteCheckPoints("NEW", iSiteCode);
                        this.Hide();
                        oCSitecheckpoints.Owner = this;
                        oCSitecheckpoints.Show();
                        break;
                    }
                    }
                }
            }

            catch (Exception ex)
            {
                ExceptionManager.Publish(ex);
                statusbaritempbStatus.Value = 0;
                statusbaritemlblStatus.Text = "Failed";
            }
            finally
            {
                Cursor              = System.Windows.Input.Cursors.Arrow;
                btnOK.IsEnabled     = true;
                btnCancel.IsEnabled = true;
            }
        }
        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                btnCancel.IsEnabled = false;
                System.Windows.Forms.DialogResult dr;
                dr = MessageBox.ShowBox("MessageID17", BMC_Icon.Question, BMC_Button.YesNo, tbHeader.Text);

                if (dr.ToString().ToUpper() == "NO")
                {
                    return;
                }
                else
                {
                    //this.Visibility = Visibility.Hidden;                   
                    _worker2.CancelAsync();
                    _workerTotalProcess.CancelAsync();
                    _instance = null;
                    FactoryResetMethods oFactoryMethods = FactoryResetMethods.FactoryResetMethodsInstance;
                    _oSiteSetupConfiguration.UpdateAllCheckPoints(0);
                    oFactoryMethods.RunScripts();
                    App.Current.Shutdown();
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.Publish(ex);
            }
            finally
            {
                btnCancel.IsEnabled = true;
            }
        }
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            int iSiteCode = 0;
            string strZonesResult = string.Empty;
            string strBarPositionsResult = string.Empty;
            string strMachinesResult = string.Empty;
            string strInstallationsResult = string.Empty;
            int iAuthResult = 0;
            int  iServerResult = 0;
            btnOK.IsEnabled = false;
            btnCancel.IsEnabled = false;

            try
            {
                Cursor = System.Windows.Input.Cursors.Wait;
                statusbaritemlblStatus.Text = "Verifying with server...";
                statusbaritempbStatus.Value = 30;
                //if (txtAutCode.Text == string.Empty || txtEnterpriseURL.Text == string.Empty || txtSiteCode.Text == string.Empty)
                //{
                if (txtAutCode.Text == string.Empty || txtSiteCode.Text == string.Empty)
                {
                    MessageBox.ShowBox("MessageID20", BMC_Icon.Warning, BMC_Button.OK);
                    txtSiteCode.Focus();
                    statusbaritempbStatus.Value = 0;
                    return;
                }
                else
                {
                    if (txtSiteCode.Text.Length == 0)
                    {
                        MessageBox.ShowBox("MessageID21", BMC_Icon.Warning, BMC_Button.OK);
                        statusbaritempbStatus.Value = 0;
                        return;
                    }

                    //if (txtEnterpriseURL.Text.Length == 0)
                    //{
                    //    MessageBox.ShowBox("MessageID22", BMC_Icon.Warning, BMC_Button.OK);
                    //    statusbaritempbStatus.Value = 0;
                    //    return;
                    //}

                    //Check Site code validation
                    iSiteCode = int.Parse(txtSiteCode.Text.ToString());

                    if (!oSiteSetupConfiguration.IsValidSiteCode(iSiteCode))
                    {
                        MessageBox.ShowBox("MessageID312", BMC_Icon.Warning, BMC_Button.OK);
                        statusbaritempbStatus.Value = 0;
                        return;
                    }
                    //Check connection established with enterprise.
                    iServerResult = oSiteSetupConfiguration.EnterpriseUrlIsExists(txtEnterpriseURL.Text.ToString(), txtSiteCode.Text.ToString());
                    if (iServerResult==-1)
                    {
                        statusbaritempbStatus.Value = 0;
                        MessageBox.ShowBox("MessageID23", BMC_Icon.Warning, BMC_Button.OK);
                        statusbaritemlblStatus.Text = "Failed";
                        return;
                    }
                    else if (iServerResult == -2)
                    {
                        statusbaritempbStatus.Value = 0;
                        MessageBox.ShowBox("MessageID203", BMC_Icon.Warning, BMC_Button.OK);
                        statusbaritemlblStatus.Text = "Failed";
                        return;
                    }
                    statusbaritempbStatus.Value = 40;

                    try
                    {
                        iAuthResult = oSiteSetupConfiguration.CheckAuthorizationCode(txtAutCode.Text.Trim(), iSiteCode,"New");
                    }
                    catch (Exception exError)
                    {
                        iAuthResult = -1;
                        ExceptionManager.Publish(exError);
                    }

                    switch (iAuthResult)
                    {
                        case -1:
                            {
                                statusbaritempbStatus.Value = 0;
                                MessageBox.ShowBox("MessageID24", BMC_Icon.Warning, BMC_Button.OK);
                                statusbaritemlblStatus.Text = "Failed";
                                return;
                            }
                        case 0:
                            {
                                statusbaritempbStatus.Value = 0;
                                MessageBox.ShowBox("MessageID25", BMC_Icon.Warning, BMC_Button.OK);
                                statusbaritemlblStatus.Text = "Failed";
                                return;
                            }
                        case 1:
                            {
                                statusbaritempbStatus.Value = 0;
                                bool bUpdateStatus = oSiteSetupConfiguration.ResetTransactionKey(txtAutCode.Text.Trim(), iSiteCode);
                                MessageBox.ShowBox("MessageID25", BMC_Icon.Warning, BMC_Button.OK);
                                statusbaritemlblStatus.Text = "Failed";
                                return;
                            }
                        case 4:
                            {
                                statusbaritempbStatus.Value = 0;
                                MessageBox.ShowBox("MessageID167", BMC_Icon.Warning, BMC_Button.OK);
                                statusbaritemlblStatus.Text = "Failed";
                                return;
                            }
                        case 6:
                            {
                                statusbaritempbStatus.Value = 0;
                                MessageBox.ShowBox("MessageID28", BMC_Icon.Warning, BMC_Button.OK);
                                statusbaritemlblStatus.Text = "Failed";
                                return;
                            }
                        case 7:
                            {
                                statusbaritempbStatus.Value = 0;
                                MessageBox.ShowBox("MessageID199", BMC_Icon.Warning, BMC_Button.OK);
                                statusbaritemlblStatus.Text = "Failed";
                                return;
                            }
                        case 8:
                            {
                                statusbaritempbStatus.Value = 0;
                                MessageBox.ShowBox("MessageID200", BMC_Icon.Warning, BMC_Button.OK);
                                statusbaritemlblStatus.Text = "Failed";
                                return;
                            }
                    }

                    ////Check for NGA Asset in Enterprise.
                    //Get list of MAC Address of the local system & Send the list to Enterprise.
                    int iNGAStatus = -1;

                    try
                    {
                        string strCheckNGAResult = oSiteSetupConfiguration.CheckNGA(GetCurentSystemMACAddress(), iSiteCode);
                        string[] strNGAResultSet = strCheckNGAResult.Split(',');


                        foreach (string strNGAResult in strNGAResultSet)
                        {
                            if (strNGAResult.Trim().Length > 0)
                            {
                                string[] strMACList = new string[2];
                                strMACList = strNGAResult.Split('/');
                                iNGAStatus = Convert.ToInt32(strMACList[1]);

                                LogManager.WriteLog("MAC Adress - " + strMACList[0] + " Result - " + strMACList[1], LogManager.enumLogLevel.Info);

                                if (iNGAStatus > 1 && iNGAStatus < 5)
                                {                                    
                                    break;
                                }
                            }
                        }

                    }
                    catch (Exception exCheckNGA)
                    {
                        ExceptionManager.Publish(exCheckNGA);
                        iNGAStatus = -1;
                    }
                    

                    //Based on the status decide course of action.
                    switch (iNGAStatus)
                    {
                        case -1:
                        case 0:
                        case 1:
                            {
                                statusbaritempbStatus.Value = 0;
                                bool bUpdateStatus = oSiteSetupConfiguration.ResetTransactionKey(txtAutCode.Text.Trim(), iSiteCode);
                                MessageBox.ShowBox("MessageID29", BMC_Icon.Warning, BMC_Button.OK);
                                statusbaritemlblStatus.Text = "Failed";
                                return;
                            }
                        case 5:
                            {
                                statusbaritempbStatus.Value = 0;
                                bool bUpdateStatus = oSiteSetupConfiguration.ResetTransactionKey(txtAutCode.Text.Trim(), iSiteCode);
                                MessageBox.ShowBox("MessageID30", BMC_Icon.Warning, BMC_Button.OK);
                                statusbaritemlblStatus.Text = "Failed";
                                return;
                            }
                       
                    }

                    //Check database is empty or not.                   
                    if (oSiteSetupConfiguration.DatabaseIsEmpty() == false)
                    {
                        statusbaritempbStatus.Value = 0;
                        System.Windows.Forms.DialogResult dr;
                        dr = MessageBox.ShowBox("MessageID31", BMC_Icon.Question, BMC_Button.YesNo);
                        if (dr.ToString().ToUpper() == "NO")
                        {
                            statusbaritempbStatus.Value = 0;
                            statusbaritemlblStatus.Text = "Failed";
                            return;
                        }
                        else
                        {
                            if (oSiteSetupConfiguration.FlattenSystem())
                            {
                                MessageBox.ShowBox("MessageID32", BMC_Icon.Information, BMC_Button.OK);
                                this.Close();
                            }
                            else
                            {
                                MessageBox.ShowBox("MessageID33", BMC_Icon.Error, BMC_Button.OK);
                                this.Close();
                            }
                        }                        
                    }
                    if (ConfigManager.Read("ServicesListFromDB") != null)
                    {
                        if (ConfigManager.Read("ServicesListFromDB").ToUpper() == "TRUE")
                        {
                            strListarray = null;
                            strListarray = oSiteSetupConfiguration.GetSettingValue("ServiceNames").Split(',');
                            StopAllServices();
                        }
                    }

                    statusbaritempbStatus.Value = 60;
                    System.Threading.Thread.Sleep(5);
                    statusbaritempbStatus.Value = 100;

                    switch (iAuthResult)
                    {
                        case 2:
                            {
                                //Call Site Recovery mode
                                oCSitecheckpoints = new SiteCheckPoints("RECOVERY", iSiteCode);
                                this.Hide();
                                oCSitecheckpoints.Owner = this;
                                oCSitecheckpoints.Show();
                                break;
                            }
                        case 3:
                            {
                                //Call Auto Configure mode
                                oCSitecheckpoints = new SiteCheckPoints("NEW", iSiteCode);
                                this.Hide();
                                oCSitecheckpoints.Owner = this;
                                oCSitecheckpoints.Show();
                                break;
                            }
                    }
                }
            }

            catch (Exception ex)
            {
                ExceptionManager.Publish(ex);
                statusbaritempbStatus.Value = 0;
                statusbaritemlblStatus.Text = "Failed";
            }
            finally
            {
               Cursor = System.Windows.Input.Cursors.Arrow;
               btnOK.IsEnabled = true;
               btnCancel.IsEnabled = true;
            }
        }