コード例 #1
0
        private void RecoverTickets(int orgID, LoginUser loginUser)
        {
            Tickets    badTickets = new Tickets(GetCorrupteLoginUser());
            SqlCommand command    = new SqlCommand();

            command.CommandText = @"
        SELECT 
          * 
        FROM 
          Tickets 
        WHERE 
          OrganizationID = @OrganizationID
          AND DateCreated > '2015-09-17 05:56:00'
          AND TicketSource != 'EMail'
          AND IgnoreMe = 0
      ";
            command.CommandType = CommandType.Text;
            command.Parameters.AddWithValue("@OrganizationID", orgID);
            badTickets.Fill(command, "");

            Organizations existingCompanies = new Organizations(loginUser);

            existingCompanies.LoadByParentID(orgID, false);

            foreach (Ticket badTicket in badTickets)
            {
                try
                {
                    //Copy Ticket
                    Ticket goodTicket = (new Tickets(loginUser)).AddNewTicket();
                    goodTicket.CopyRowData(badTicket);
                    //Product
                    if (badTicket.ProductID != null)
                    {
                        Product goodProduct = _goodProducts.FindByProductID((int)badTicket.ProductID);
                        if (goodProduct == null)
                        {
                            Product badProduct = _badProducts.FindByProductID((int)badTicket.ProductID);
                            goodProduct = _goodProducts.FindByName(badProduct.Name);
                            if (goodProduct != null)
                            {
                                goodTicket.ProductID = goodProduct.ProductID;
                            }
                            else
                            {
                                goodTicket.ProductID = null;
                            }
                        }
                    }
                    //Version
                    if (goodTicket.ProductID != null && badTicket.ReportedVersionID != null)
                    {
                        ProductVersion goodProductVersion = _goodProductVersions.FindByProductVersionID((int)badTicket.ReportedVersionID);
                        if (goodProductVersion == null)
                        {
                            ProductVersion badProductVersion = _badProductVersions.FindByProductVersionID((int)badTicket.ReportedVersionID);
                            goodProductVersion = _goodProductVersions.FindByVersionNumber(badProductVersion.VersionNumber, (int)goodTicket.ProductID);
                            if (goodProductVersion != null)
                            {
                                goodTicket.ReportedVersionID = goodProductVersion.ProductVersionID;
                            }
                            else
                            {
                                goodTicket.ReportedVersionID = null;
                            }
                        }
                    }
                    //Solved Version
                    if (goodTicket.ProductID != null && badTicket.SolvedVersionID != null)
                    {
                        ProductVersion goodProductVersion = _goodProductVersions.FindByProductVersionID((int)badTicket.SolvedVersionID);
                        if (goodProductVersion == null)
                        {
                            ProductVersion badProductVersion = _badProductVersions.FindByProductVersionID((int)badTicket.SolvedVersionID);
                            goodProductVersion = _goodProductVersions.FindByVersionNumber(badProductVersion.VersionNumber, (int)goodTicket.ProductID);
                            if (goodProductVersion != null)
                            {
                                goodTicket.SolvedVersionID = goodProductVersion.ProductVersionID;
                            }
                            else
                            {
                                goodTicket.SolvedVersionID = null;
                            }
                        }
                    }
                    //Group
                    if (badTicket.GroupID != null)
                    {
                        Group goodGroup = _goodGroups.FindByGroupID((int)badTicket.GroupID);
                        if (goodGroup == null)
                        {
                            Group badGroup = _badGroups.FindByGroupID((int)badTicket.GroupID);
                            goodGroup = _goodGroups.FindByName(badGroup.Name);
                            if (goodGroup != null)
                            {
                                goodTicket.GroupID = goodGroup.GroupID;
                            }
                            else
                            {
                                goodTicket.GroupID = null;
                            }
                        }
                    }
                    //Assigned User
                    if (badTicket.UserID != null)
                    {
                        User goodUser = _goodUsers.FindByUserID((int)badTicket.UserID);
                        if (goodUser == null)
                        {
                            User badUser = _badUsers.FindByUserID((int)badTicket.UserID);
                            goodUser = _goodUsers.FindByEmail(badUser.Email);
                            if (goodUser != null)
                            {
                                goodTicket.UserID = goodUser.UserID;
                            }
                            else
                            {
                                goodTicket.UserID = null;
                            }
                        }
                    }
                    //Type
                    TicketType goodTicketType = _goodTicketTypes.FindByTicketTypeID(badTicket.TicketTypeID);
                    if (goodTicketType == null)
                    {
                        TicketType badTicketType = _badTicketTypes.FindByTicketTypeID(badTicket.TicketTypeID);
                        goodTicketType = _goodTicketTypes.FindByName(badTicketType.Name);
                        if (goodTicketType != null)
                        {
                            goodTicket.TicketTypeID = goodTicketType.TicketTypeID;
                        }
                        else
                        {
                            goodTicket.TicketTypeID = _goodTicketTypes[0].TicketTypeID;
                        }
                    }

                    //Status
                    TicketStatus goodTicketStatus = _goodTicketStatuses.FindByTicketStatusID(badTicket.TicketStatusID);
                    if (goodTicketStatus == null)
                    {
                        TicketStatus badTicketStatus = _badTicketStatuses.FindByTicketStatusID(badTicket.TicketStatusID);
                        goodTicketStatus = _goodTicketStatuses.FindByName(badTicketStatus.Name, goodTicket.TicketTypeID);
                        if (goodTicketStatus != null)
                        {
                            goodTicket.TicketStatusID = goodTicketStatus.TicketStatusID;
                        }
                        else
                        {
                            goodTicketStatus          = _goodTicketStatuses.FindTopOne(goodTicket.TicketTypeID);
                            goodTicket.TicketStatusID = goodTicketStatus.TicketStatusID;
                        }
                    }


                    //Severity
                    TicketSeverity goodTicketSeverity = _goodTicketSeverities.FindByTicketSeverityID(badTicket.TicketSeverityID);
                    if (goodTicketSeverity == null)
                    {
                        TicketSeverity badTicketSeverity = _badTicketSeverities.FindByTicketSeverityID(badTicket.TicketSeverityID);
                        goodTicketSeverity = _goodTicketSeverities.FindByName(badTicketSeverity.Name);
                        if (goodTicketSeverity != null)
                        {
                            goodTicket.TicketSeverityID = goodTicketSeverity.TicketSeverityID;
                        }
                        else
                        {
                            goodTicket.TicketSeverityID = _goodTicketSeverities[0].TicketSeverityID;
                        }
                    }

                    //Knowledgebase Cat
                    if (badTicket.KnowledgeBaseCategoryID != null)
                    {
                        KnowledgeBaseCategory goodKBCategory = _goodTicketKBCategories.FindByCategoryID((int)badTicket.KnowledgeBaseCategoryID);
                        if (goodKBCategory == null)
                        {
                            KnowledgeBaseCategory badKBCategory = _badTicketKBCategories.FindByCategoryID((int)badTicket.KnowledgeBaseCategoryID);
                            goodKBCategory = _goodTicketKBCategories.FindByName(badKBCategory.CategoryName);
                            if (goodKBCategory != null)
                            {
                                goodTicket.KnowledgeBaseCategoryID = goodKBCategory.CategoryID;
                            }
                            else
                            {
                                goodTicket.KnowledgeBaseCategoryID = null;
                            }
                        }
                    }

                    //Parent Ticket (NOTE from MT:  we decided as a team to null out this field to ensure no bad relationships can happen since we don't know the ticketID is a preserved field for every ticket.
                    goodTicket.ParentID = null;

                    //Closing User
                    if (badTicket.CloserID != null)
                    {
                        User goodUser = _goodUsers.FindByUserID((int)badTicket.CloserID);
                        if (goodUser == null)
                        {
                            User badUser = _badUsers.FindByUserID((int)badTicket.CloserID);
                            goodUser = _goodUsers.FindByEmail(badUser.Email);
                            if (goodUser != null)
                            {
                                goodTicket.CloserID = goodUser.UserID;
                            }
                            else
                            {
                                goodTicket.CloserID = null;
                            }
                        }
                    }


                    //Reset ticket dates
                    goodTicket.DateCreated  = badTicket.DateCreatedUtc;
                    goodTicket.DateModified = badTicket.DateModifiedUtc;
                    goodTicket.ParentID     = null;
                    goodTicket.ImportID     = _importID;
                    if (badTicket.CreatorID > 0)
                    {
                        User creator = _usersAndContacts.FindByUserID(badTicket.CreatorID);
                        if (creator != null)
                        {
                            goodTicket.CreatorID = creator.UserID;
                        }
                        else
                        {
                            goodTicket.CreatorID = -5;
                        }
                    }
                    else
                    {
                        goodTicket.CreatorID = badTicket.CreatorID;
                    }

                    if (badTicket.ModifierID > 0)
                    {
                        User modifier = _usersAndContacts.FindByUserID(badTicket.ModifierID);
                        if (modifier != null)
                        {
                            goodTicket.ModifierID = modifier.UserID;
                        }
                        else
                        {
                            goodTicket.ModifierID = -5;
                        }
                    }
                    else
                    {
                        goodTicket.ModifierID = badTicket.ModifierID;
                    }
                    goodTicket.TicketNumber = 0;
                    goodTicket.Collection.Save();
                    EmailPosts.DeleteImportEmails(loginUser);

                    Actions badActions = new Actions(GetCorrupteLoginUser());
                    badActions.LoadByTicketID(badTicket.TicketID);

                    foreach (TeamSupport.Data.Action badAction in badActions)
                    {
                        TeamSupport.Data.Action goodAction = new Actions(loginUser).AddNewAction();
                        goodAction.CopyRowData(badAction);
                        goodAction.DateCreated  = badAction.DateCreatedUtc;
                        goodAction.DateModified = badAction.DateCreatedUtc;
                        goodAction.TicketID     = goodTicket.TicketID;
                        goodAction.ImportID     = _importID;
                        if (badAction.CreatorID > 0)
                        {
                            User creator = _usersAndContacts.FindByUserID(badAction.CreatorID);
                            if (creator != null)
                            {
                                goodAction.CreatorID = creator.UserID;
                            }
                            else
                            {
                                goodAction.CreatorID = -5;
                            }
                        }
                        else
                        {
                            goodAction.CreatorID = badAction.CreatorID;
                        }

                        if (badAction.ModifierID > 0)
                        {
                            User modifier = _usersAndContacts.FindByUserID(badAction.ModifierID);
                            if (modifier != null)
                            {
                                goodAction.ModifierID = modifier.UserID;
                            }
                            else
                            {
                                goodAction.ModifierID = -5;
                            }
                        }
                        else
                        {
                            goodAction.ModifierID = badAction.ModifierID;
                        }
                        goodAction.Collection.Save();
                        EmailPosts.DeleteImportEmails(loginUser);
                    }


                    Organizations orgs = new Organizations(GetCorrupteLoginUser());
                    orgs.LoadBTicketID(badTicket.TicketID);

                    foreach (Organization org in orgs)
                    {
                        Organization goodCompany = existingCompanies.FindByName(org.Name);
                        if (org.ParentID == orgID && goodCompany != null)
                        {
                            goodTicket.Collection.AddOrganization(goodCompany.OrganizationID, goodTicket.TicketID);
                            EmailPosts.DeleteImportEmails(loginUser);
                        }
                    }

                    RecoverTicketCustomValues(orgID, badTicket.TicketID, goodTicket.TicketID);
                    EmailPosts.DeleteImportEmails(loginUser);
                }
                catch (Exception ex)
                {
                    _exceptionOcurred = true;
                    ExceptionLogs.LogException(GetCorrupteLoginUser(), ex, "recover");
                }
            }
        }
コード例 #2
0
        //private void RecoverContacts(int orgID)
        //{
        //  // check corrupt db for different products,if so craete the new products, but do not use ID's
        //  Users badContacts = new Users(GetCorrupteLoginUser());
        //  badContacts.LoadContacts(orgID, false);

        //  Users goodContacts = new Users(GetReviewLoginUser());
        //  goodContacts.LoadContacts(orgID, false);

        //  foreach (User badContact in badContacts)
        //  {
        //    User goodContact = goodContacts.FindBy(badCompany.Name);
        //    if (goodCompany == null)
        //    {
        //      goodCompany = (new Organizations(GetReviewLoginUser())).AddNewOrganization();
        //      goodCompany.Name = badCompany.Name;
        //      goodCompany.Description = badCompany.Description;
        //      goodCompany.Website = badCompany.Website;
        //      goodCompany.CompanyDomains = badCompany.CompanyDomains;
        //      goodCompany.SAExpirationDate = badCompany.SAExpirationDate;
        //      goodCompany.SlaLevelID = badCompany.SlaLevelID;
        //      goodCompany.DateCreated = badCompany.DateCreated;
        //      goodCompany.SupportHoursMonth = badCompany.SupportHoursMonth;
        //      goodCompany.IsActive = badCompany.IsActive;
        //      goodCompany.HasPortalAccess = badCompany.HasPortalAccess;
        //      goodCompany.IsApiEnabled = badCompany.IsApiEnabled;
        //      goodCompany.IsApiActive = badCompany.IsApiActive;
        //      goodCompany.InActiveReason = badCompany.InActiveReason;

        //      goodCompany.ExtraStorageUnits = badCompany.ExtraStorageUnits;
        //      goodCompany.IsCustomerFree = badCompany.IsCustomerFree;
        //      goodCompany.PortalSeats = badCompany.PortalSeats;
        //      goodCompany.ProductType = badCompany.ProductType;
        //      goodCompany.UserSeats = badCompany.UserSeats;
        //      goodCompany.NeedsIndexing = badCompany.NeedsIndexing;
        //      goodCompany.SystemEmailID = badCompany.SystemEmailID;
        //      goodCompany.WebServiceID = badCompany.WebServiceID;
        //      {
        //        User defaultSupportUser = _usersAndContacts.FindByUserID((int)badCompany.DefaultSupportUserID);
        //        if (defaultSupportUser != null)
        //        {
        //          goodCompany.DefaultSupportUserID = defaultSupportUser.UserID;
        //        }
        //      }
        //      if (badCompany.CreatorID > 0)
        //      {
        //        User creator = _usersAndContacts.FindByUserID(badCompany.CreatorID);
        //        if (creator != null)
        //        {
        //          goodCompany.CreatorID = creator.UserID;
        //        }
        //        else
        //        {
        //          goodCompany.CreatorID = -1;
        //        }
        //      }
        //      else
        //      {
        //        goodCompany.CreatorID = badCompany.CreatorID;
        //      }
        //      goodCompany.ParentID = orgID;
        //      goodCompany.ImportID = _importID;
        //      goodCompany.Collection.Save();
        //    }
        //  }
        //}

        /*
         * private void RecoverAssets(int orgID)
         * {
         * // check corrupt db for different products,if so craete the new products, but do not use ID's
         * Assets badAssets = new Assets(GetCorrupteLoginUser());
         * badAssets.LoadByOrganizationIDCreatedAfterRestore(orgID);
         *
         * Assets goodAssets = new Assets(GetReviewLoginUser());
         * goodAssets.LoadByOrganizationID(orgID);
         *
         * foreach (Asset badAsset in badAssets)
         * {
         *  Asset goodAsset = goodAssets.FindByName(badAsset.Name);
         *  try
         *  {
         *    if (goodAsset == null)
         *    {
         *      goodAsset = (new Assets(GetReviewLoginUser())).AddNewAsset();
         *      goodAsset.CopyRowData(badAsset);
         *      goodAsset.DateCreated = badAsset.DateCreatedUtc;
         *      goodAsset.DateModified = badAsset.DateModifiedUtc;
         *      goodAsset.OrganizationID = orgID;
         *      goodAsset.ImportID = _importID;
         *      goodAsset.Collection.Save();
         *      if (goodAsset.Location == "1")
         *      {
         *        AssetAssignmentsView assetAssignments = new AssetAssignmentsView(GetCorrupteLoginUser());
         *        assetAssignments.LoadByAssetID(badAsset.AssetID);
         *        foreach (AssetAssignmentsViewItem assetAssignment in assetAssignments)
         *        {
         *          AssetHistory assetHistory = new AssetHistory(GetReviewLoginUser());
         *          AssetHistoryItem assetHistoryItem = assetHistory.AddNewAssetHistoryItem();
         *
         *          DateTime now = DateTime.UtcNow;
         *
         *          assetHistoryItem.AssetID = goodAsset.AssetID;
         *          assetHistoryItem.OrganizationID = orgID;
         *          assetHistoryItem.ActionTime = assetAssignment.ActionTime;
         *          assetHistoryItem.ActionDescription = assetAssignment.ActionDescription;
         *          assetHistoryItem.ShippedFrom = assetAssignment.ShippedFrom;
         *          assetHistoryItem.ShippedFromRefType = assetAssignment.ShippedFromRefType;
         *          assetHistoryItem.ShippedTo = assetAssignment.ShippedTo;
         *          assetHistoryItem.TrackingNumber = assetAssignment.TrackingNumber;
         *          assetHistoryItem.ShippingMethod = assetAssignment.ShippingMethod;
         *          assetHistoryItem.ReferenceNum = assetAssignment.ReferenceNum;
         *          assetHistoryItem.Comments = assetAssignment.Comments;
         *
         *          assetHistoryItem.DateCreated = assetAssignment.DateCreatedUtc;
         *          assetHistoryItem.Actor = assetAssignment.Actor;
         *          assetHistoryItem.RefType = assetAssignment.RefType;
         *          assetHistoryItem.DateModified = now;
         *
         *          assetHistory.Save();
         *
         *          AssetAssignments goodAssetAssignments = new AssetAssignments(GetReviewLoginUser());
         *          AssetAssignment goodAssetAssignment = goodAssetAssignments.AddNewAssetAssignment();
         *
         *          goodAssetAssignment.HistoryID = assetHistoryItem.HistoryID;
         *
         *          goodAssetAssignments.Save();
         *        }
         *      }
         *    }
         *
         *  }
         *  catch (Exception ex)
         *  {
         *    SaveOrgResults(orgID, "Failure: " + ex.Message);
         *    ExceptionLogs.LogException(GetCorrupteLoginUser(), ex, "recover");
         *  }
         * }
         * }
         */
        private void RecoverActionsFromOldTickets(int orgID, LoginUser loginUser)
        {
            Actions    badActions = new Actions(GetCorrupteLoginUser());
            SqlCommand command    = new SqlCommand();

            command.CommandText = @"SELECT a.*, t.TicketNumber, t.OrganizationID FROM Actions a
LEFT JOIN Tickets t ON t.TicketID = a.TicketID
WHERE (t.OrganizationID = @OrganizationID) 
AND a.DateCreated > '2015-09-17 05:56:00'
AND t.DateCreated < '2015-09-17 05:56:00'";

            command.CommandType = CommandType.Text;
            command.Parameters.AddWithValue("@OrganizationID", orgID);
            badActions.Fill(command, "");

            foreach (TeamSupport.Data.Action badAction in badActions)
            {
                try
                {
                    TeamSupport.Data.Action goodAction = new Actions(loginUser).AddNewAction();
                    goodAction.CopyRowData(badAction);
                    goodAction.DateCreated  = badAction.DateCreatedUtc;
                    goodAction.DateModified = badAction.DateModifiedUtc;
                    goodAction.TicketID     = badAction.TicketID;
                    if (badAction.CreatorID > 0)
                    {
                        User creator = _usersAndContacts.FindByUserID(badAction.CreatorID);
                        if (creator != null)
                        {
                            goodAction.CreatorID = creator.UserID;
                        }
                        else
                        {
                            goodAction.CreatorID = -5;
                        }
                    }
                    else
                    {
                        goodAction.CreatorID = badAction.CreatorID;
                    }

                    if (badAction.ModifierID > 0)
                    {
                        User modifier = _usersAndContacts.FindByUserID(badAction.ModifierID);
                        if (modifier != null)
                        {
                            goodAction.ModifierID = modifier.UserID;
                        }
                        else
                        {
                            goodAction.ModifierID = -5;
                        }
                    }
                    else
                    {
                        goodAction.ModifierID = badAction.ModifierID;
                    }
                    goodAction.ImportID = _importID;
                    goodAction.Collection.Save();

                    Ticket ticket = Tickets.GetTicket(loginUser, goodAction.TicketID);
                    ticket.ImportID = _importID;
                    ticket.Collection.Save();

                    EmailPosts.DeleteImportEmails(loginUser);
                }
                catch (Exception ex)
                {
                    _exceptionOcurred = true;
                    ExceptionLogs.LogException(GetCorrupteLoginUser(), ex, "recover");
                }
            }
        }