Beispiel #1
0
        protected void btnSubmit_Click(Object Sender, EventArgs e)
        {
            int    intUser   = 0;
            string strAssets = "";

            if (Int32.TryParse(Request.Form["hdnAJAXValue"], out intUser) == true && intUser > 0)
            {
                foreach (RepeaterItem ri in rptDevices.Items)
                {
                    CheckBox chkDevice    = (CheckBox)ri.FindControl("chkDevice");
                    Label    lblName      = (Label)ri.FindControl("lblName");
                    Label    lblSerial    = (Label)ri.FindControl("lblSerial");
                    Label    lblStatus    = (Label)ri.FindControl("lblStatus");
                    bool     boolComplete = lblStatus.Text.ToUpper().Contains("COMPLETED");
                    oLog.AddEvent(lblName.Text, lblSerial.Text, "RECOMMISSION: Started by " + oUser.GetFullNameWithLanID(intProfile), LoggingType.Information);

                    if (chkDevice.Checked == true)
                    {
                        if (chkDevice.ToolTip[0].ToString() == "S")
                        {
                            int     intServer = Int32.Parse(chkDevice.ToolTip.Substring(1));
                            DataSet dsServers = oServer.GetAssetsServer(intServer);
                            foreach (DataRow drServer in dsServers.Tables[0].Rows)
                            {
                                int    intAsset = Int32.Parse(drServer["assetid"].ToString());
                                string strName  = lblName.Text;
                                if (drServer["dr"].ToString() == "1")
                                {
                                    strName += "-DR";
                                }
                                // Update Recommission Reason
                                oAsset.UpdateDecommissionRecommission(intAsset, intUser, txtReason.Text);
                                // Set status to InUse
                                oAsset.AddStatus(intAsset, strName, (int)AssetStatus.InUse, intUser, DateTime.Now);
                                // Clear cv_servers_assets DECOM field
                                oServer.UpdateAssetDecom(intServer, intAsset, "");
                                if (boolComplete == true)
                                {
                                    DataSet dsOrders = oAssetOrder.GetByAsset(intAsset, false);
                                    foreach (DataRow drOrders in dsOrders.Tables[0].Rows)
                                    {
                                        int intOrder = Int32.Parse(drOrders["orderid"].ToString());
                                        // Cancel Resource Requests
                                        int intResource = 0;
                                        if (Int32.TryParse(drOrders["resourceid"].ToString(), out intResource) == true)
                                        {
                                            oResourceRequest.UpdateStatusOverallWorkflow(intResource, (int)ResourceRequestStatus.Cancelled);
                                        }
                                        // Delete Order
                                        oAssetOrder.DeleteOrder(intOrder);
                                        // Delete Asset Order Asset Selection
                                        oAssetOrder.DeleteAssetOrderAssetSelection(intOrder, intAsset);
                                    }
                                    // Set NewOrderID = 0
                                    oAsset.updateNewOrderId(0, intAsset);
                                }
                                // Set strAssets to assets recommissioned (for status message on postback)
                                if (strAssets != "")
                                {
                                    strAssets += strSplit[0].ToString();
                                }
                                strAssets += intAsset.ToString();
                            }
                            // Remove previous decom records
                            if (boolComplete == true)
                            {
                                bool boolPNC = (oServer.Get(intServer, "pnc") == "1");
                                // Update Server Name Record
                                int intName = Int32.Parse(oServer.Get(intServer, "nameid"));
                                if (boolPNC)
                                {
                                    oServerName.UpdateFactory(intName, 0);
                                }
                                else
                                {
                                    oServerName.Update(intName, 0);
                                }
                            }
                            // Clear cv_servers DECOM field
                            oServer.UpdateDecommissioned(intServer, "");
                            // Update IP Address(es) availability
                            DataSet dsIP = oServer.GetIP(intServer, 0, 0, 0, 0);
                            foreach (DataRow drIP in dsIP.Tables[0].Rows)
                            {
                                int intIP = Int32.Parse(drIP["ipaddressid"].ToString());
                                oIPAddresses.UpdateAvailable(intIP, 0);
                            }
                            // Restore Avamar Group(s)
                            if (chkAvamar.Checked)
                            {
                                Avamar                       oAvamar             = new Avamar(0, dsn);
                                AvamarRegistration           oAvamarRegistration = new AvamarRegistration(0, dsn);
                                ClearViewWebServices         oWebService         = new ClearViewWebServices();
                                System.Net.NetworkCredential oCredentialsDNS     = new System.Net.NetworkCredential(oVariable.ADUser(), oVariable.ADPassword(), oVariable.Domain());
                                oWebService.Credentials = oCredentialsDNS;
                                oWebService.Url         = oVariable.WebServiceURL();
                                string strError = "";

                                // First, query for groups.
                                DataSet dsGroups = oAvamar.GetDecoms(lblName.Text);
                                if (dsGroups.Tables[0].Rows.Count > 0)
                                {
                                    string client = dsGroups.Tables[0].Rows[0]["client"].ToString();
                                    string grid   = dsGroups.Tables[0].Rows[0]["grid"].ToString();
                                    string domain = dsGroups.Tables[0].Rows[0]["domain"].ToString();
                                    // Second, add the groups.
                                    foreach (DataRow drGroup in dsGroups.Tables[0].Rows)
                                    {
                                        if (String.IsNullOrEmpty(strError) == false)
                                        {
                                            break;
                                        }
                                        AvamarReturnType restore = oAvamarRegistration.API(oWebService.AddAvamarGroup(grid, domain, client, drGroup["group"].ToString()));
                                        if (restore.Error == true)
                                        {
                                            strError = restore.Message;
                                        }
                                    }
                                    // Third, remove the /Decom group
                                    AvamarReturnType decom = oAvamarRegistration.API(oWebService.DeleteAvamarGroup(grid, domain, client, oAvamar.DecomGroup));
                                    if (decom.Error == false)
                                    {
                                        // Fourth, recommission the saved decom groups.
                                        oAvamar.UpdateDecom(client);
                                    }
                                    else
                                    {
                                        strError = decom.Message;
                                    }
                                }
                                if (String.IsNullOrEmpty(strError))
                                {
                                    oLog.AddEvent(lblName.Text, lblSerial.Text, "RECOMMISSION: Avamar completed.", LoggingType.Information);
                                }
                                else
                                {
                                    oLog.AddEvent(lblName.Text, lblSerial.Text, "RECOMMISSION: Avamar encountered an error = " + strError, LoggingType.Error);
                                }
                            }
                            // Add log entry
                            oLog.AddEvent(lblName.Text, lblSerial.Text, "Asset Recommissioned (Client = " + oUser.GetFullName(intUser) + ")", LoggingType.Information);
                        }
                        else
                        {
                            // Manual recommission - just delete the resource request to get out of the person's queue
                            int intResource = Int32.Parse(chkDevice.ToolTip.Substring(1));
                            oResourceRequest.UpdateStatusOverall(intResource, -2);
                        }
                    }
                }
            }
            Response.Redirect(Request.Path + "?assets=" + strAssets);
        }