Esempio n. 1
0
        /// <summary>
        /// Update Bug in PS using the PS SDK
        /// </summary>
        /// <param name="bugChangeList"></param>
        /// <param name="bugFieldMappingCollection"></param>
        /// <param name="updateAction"></param>
        public void UpdateBug(PSBugChangeList psBugChangeList)
        {
            DatastoreItem psItem = null;
            bool hasInvalidField = false;

            try
            {
                psItem = this.psDataStore.GetDatastoreItem(PsDatastoreItemTypeEnum.psDatastoreItemTypeBugs, psBugChangeList.BugId, null);
                switch (psBugChangeList.Action)
                {
                    case PSUpdateAction.Update:
                        psItem.Edit(PsItemEditActionEnum.psDatastoreItemEditActionEdit, null, PsApplyRulesMask.psApplyRulesAll);
                        break;

                    case PSUpdateAction.Resolve:
                        psItem.Edit(PsItemEditActionEnum.psBugEditActionResolve, null, PsApplyRulesMask.psApplyRulesAll);
                        break;

                    case PSUpdateAction.Close:
                        psItem.Edit(PsItemEditActionEnum.psBugEditActionClose, null, PsApplyRulesMask.psApplyRulesAll);
                        break;

                    case PSUpdateAction.Activate:
                        psItem.Edit(PsItemEditActionEnum.psBugEditActionActivate, null, PsApplyRulesMask.psApplyRulesAll);
                        break;
                }

                foreach (string psFieldName in psBugChangeList.BugChanges.Keys)
                {
                    // We need to skip these values as they are auto filled by PS.
                    if (string.Compare(psFieldName, "Closed By", true) == 0 ||
                        string.Compare(psFieldName, "Resolved By", true) == 0 ||
                        string.Compare(psFieldName, "Changed By", true) == 0)
                    {
                        continue;
                    }
                    Field psField = null;
                    // PendingChangelist doesn't have mapping value in DB because Sync Service doesn't handle it, so we have to map it to a PS value manually.
                    if (string.Compare(psFieldName, BugFields.PendingChangelist.ToString(), true) == 0)
                    {
                        psField = psItem.Fields["ChangelistInfo"];
                    }
                    else
                    {
                        psField = psItem.Fields[psFieldName];
                    }

                    if (psField == null)
                    {
                        throw new Exception("Failed to find property [" + psFieldName + "]");
                    }
                    else if (psField.IsReadOnly)
                    {
                        // We need to do some logging here as we skip some read-only psField when doing update
                        //throw new Exception("Failed to update read-only property [" + psFieldName + "]");
                        continue;
                    }
                    else
                    {
                        // SLA Date in PS is string, but in SysBugItem is DateTime, there comes is datetime string or null
                        if (string.Compare(psField.Name, "SLA Date", true) == 0)
                        {
                            DateTime slaDate;

                            if (DateTime.TryParse(psBugChangeList.BugChanges[psFieldName].ToString(), out slaDate) == true)
                            {
                                psField.Value = string.Format("{0:MM/dd/yyyy}", slaDate);
                            }
                            else
                            {
                                psField.Value = null;
                            }
                        }
                        // PendingChangelist doesn't have mapping value in DB because Sync Service doesn't handle it, so we have to map it to a PS value manually.
                        else if (string.Compare(psField.Name, "ChangelistInfo", true) == 0)
                        {
                            Dictionary<string, ChangelistInfo> changelistDict = new Dictionary<string, ChangelistInfo>(StringComparer.OrdinalIgnoreCase);
                            string changeListInfos = psField.Value;

                            ChangelistInfo newPendingChangelist = psBugChangeList.BugChanges[psFieldName] as ChangelistInfo;

                            if (string.IsNullOrEmpty(changeListInfos) == false && changeListInfos.Length > 0)
                            {
                                Regex r = new Regex(@"^\s*\d+,.+,.+,.+,.+,.*$");

                                string[] split = changeListInfos.Split("\r".ToCharArray());
                                foreach (string s in split)
                                {
                                    // 722: Handle changelist with linefeed in description
                                    if (r.IsMatch(s.Trim("\n".ToCharArray())))
                                    {
                                        ChangelistInfo info = new ChangelistInfo(s.Trim("\n".ToCharArray()));
                                        // If the changelist is related and it also ends with $$SEPortal$$, we will discard them, not adding them into the dictionary
                                        if (string.Compare(info.Relation, "related", true) == 0
                                            && info.Description.EndsWith("$$SEPortal$$") == true)
                                        {
                                            continue;
                                        }
                                        // If the changelist has the same id as the new changelist, we will discard it, not adding it into the dictionary
                                        if (newPendingChangelist != null
                                            && string.Compare(info.ChangelistId, newPendingChangelist.ChangelistId, true) == 0)
                                        {
                                            continue;
                                        }
                                        // Add the changelist to the dictionary if it is not already added
                                        if (changelistDict.ContainsKey(info.ChangelistId) == false)
                                        {
                                            changelistDict.Add(info.ChangelistId, info);
                                        }
                                    }
                                }
                            }

                            if (newPendingChangelist != null)
                            {
                                changelistDict.Add(newPendingChangelist.ChangelistId, newPendingChangelist);
                            }

                            string pendingChangelistStr = string.Empty;
                            foreach (ChangelistInfo changelistInfo in changelistDict.Values)
                            {
                                if (newPendingChangelist != null
                                    && string.Compare(newPendingChangelist.Relation, "Related", true) == 0
                                    && string.Compare(newPendingChangelist.ChangelistId, changelistInfo.ChangelistId, true) == 0)
                                {
                                    pendingChangelistStr += changelistInfo.ToString() + " $$SEPortal$$\r";
                                }
                                else
                                {
                                    pendingChangelistStr += changelistInfo.ToString() + "\r";
                                }
                            }
                            psField.Value = pendingChangelistStr;
                        }
                        else
                        {
                            if (psBugChangeList.BugChanges[psFieldName] != null)
                            {
                                psField.Value = psBugChangeList.BugChanges[psFieldName].ToString();
                            }
                            else
                            {
                                psField.Value = null;
                            }
                        }
                    }
                }

                // Verify that all fields are valid before saving
                foreach (ProductStudio.Field field in psItem.Fields)
                {
                    if (field.Validity != PsFieldStatusEnum.psFieldStatusValid)
                    {
                        hasInvalidField = true;
                        throw new Exception("Updating Field (" + field.Name + ") with Value (" + field.Value + ") is invalid. Counld not edit bug " + psBugChangeList.BugId.ToString());
                    }
                }

                // Commit the save if there is no invalid field
                if (hasInvalidField)
                {
                    throw new Exception("Invalid Field(s) were found. Could not edit bug " + psBugChangeList.BugId.ToString());
                }
                else
                {
                    psItem.Save();
                }
            }
            catch (Exception e)
            {
                throw new Exception(String.Format("Failed to update bug {0} in {1} database.",
                    psBugChangeList.BugId, this.productName), e);
            }
        }
Esempio n. 2
0
        public BugData(Int32 teamId,
            Int32 bugId,
            String portalStatus,
            String description,
            String devResolutionNotes,
            String kbNumber,
            String qfeTriageStatus,
            String pss,
            String product,
            DateTime? qfeAcceptDate,
            DateTime? checkinSubmissionDate,
            DateTime? buildFinishDate,
            DateTime? releaseDate,
            String binaries,
            DateTime? customerVerifyFinishDate,
            String qfeStatus,
            String customer,
            String pmOwner,
            String developer,
            String title,
            String status,
            String changedBy,
            DateTime? resolvedDate,
            String resolver,
            String resolution,
            String bugOwner,
            String issueType,
            Int32 severity,
            String closedBy,
            Int32 priority,
            DateTime? bugOpenedDate,
            String bugFiler,
            String cause,
            DateTime? closeDate,
            DateTime? lastModifiedTime,
            String feature,
            DateTime? fixETA,
            DateTime? mustFixBy,
            DateTime? bundleCreationDate,
            String testReviewer,
            DateTime? slaDate,
            String workItemState,
            DateTime? qfeAssignedDate,
            String path,
            String openbuild,
            String resolvedBuild,
            String devOwner,
            String testOwner,
            String buildOwner,
            String builder,
            String releasePM,
            DateTime? qfeRejectDate,
            DateTime? investigationAssignDate,
            DateTime? investigationDue,
            DateTime? investigationFinishDate,
            DateTime? codeReviewRequestDate,
            String codeReviewStatus,
            String codeReviewer,
            String codeReviewFile,
            DateTime? codeReviewFinishDate,
            String testCase,
            DateTime? privateTestRequestDate,
            String privateTestStatus,
            String privateTester,
            DateTime? privateTestFinishDate,
            DateTime? checkinRequestDate,
            String checkinStatus,
            DateTime? checkinApproveDate,
            DateTime? buildRequestDate,
            DateTime? bvtAssignDate,
            String bvtStatus,
            String bvtTester,
            DateTime? bvtFinishDate,
            DateTime? regressionAssignDate,
            String regressionStatus,
            String regressionTester,
            DateTime? regressionFinishDate,
            DateTime? codeSignRequestDate,
            DateTime? codeSignFinishDate,
            String codeSignRequestNumber,
            DateTime? rfxSubmitted,
            ChangelistInfo changelist,
            String securityRank,
            String securityEffect,
            String approvedBy,
            String milestone,
            DateTime? rfxTriagedDate,
            DateTime? investigationCompleteDate
            )
        {
            this.TeamId = new IntegerField();
            this.TeamId.FieldName = BugFields.TeamId;
            this.TeamId.FieldValue = teamId;

            this.BugId = new IntegerField();
            this.BugId.FieldName = BugFields.BugId;
            this.BugId.FieldValue = bugId;

            this.Description = new StringField();
            this.Description.FieldName = BugFields.Description;
            this.Description.FieldValue = description;

            this.DevResolutionNotes = new StringField();
            this.DevResolutionNotes.FieldName = BugFields.DevResolutionNotes;
            this.DevResolutionNotes.FieldValue = devResolutionNotes;

            this.KbNumber = new StringField();
            this.KbNumber.FieldName = BugFields.KbNumber;
            this.KbNumber.FieldValue = kbNumber;

            this.QfeTriageStatus = new StringField();
            this.QfeTriageStatus.FieldName = BugFields.QfeTriageStatus;
            this.QfeTriageStatus.FieldValue = qfeTriageStatus;

            this.PSS = new StringField();
            this.PSS.FieldName = BugFields.PSS;
            this.PSS.FieldValue = pss;

            this.Product = new StringField();
            this.Product.FieldName = BugFields.Product;
            this.Product.FieldValue = product;

            this.QfeAcceptDate = new DatetimeField();
            this.QfeAcceptDate.FieldName = BugFields.QfeAcceptDate;
            this.QfeAcceptDate.FieldValue = qfeAcceptDate;

            this.CheckinSubmitDate = new DatetimeField();
            this.CheckinSubmitDate.FieldName = BugFields.CheckinSubmitDate;
            this.CheckinSubmitDate.FieldValue = checkinSubmissionDate;

            this.BuildFinishDate = new DatetimeField();
            this.BuildFinishDate.FieldName = BugFields.BuildFinishDate;
            this.BuildFinishDate.FieldValue = buildFinishDate;

            this.ReleaseDate = new DatetimeField();
            this.ReleaseDate.FieldName = BugFields.ReleaseDate;
            this.ReleaseDate.FieldValue = releaseDate;

            this.Binaries = new StringField();
            this.Binaries.FieldName = BugFields.Binaries;
            this.Binaries.FieldValue = binaries;

            this.CustomerVerifyFinishDate = new DatetimeField();
            this.CustomerVerifyFinishDate.FieldName = BugFields.CustomerVerifyFinishDate;
            this.CustomerVerifyFinishDate.FieldValue = customerVerifyFinishDate;

            this.QfeStatus = new StringField();
            this.QfeStatus.FieldName = BugFields.QfeStatus;
            this.QfeStatus.FieldValue = qfeStatus;

            this.Customer = new StringField();
            this.Customer.FieldName = BugFields.Customer;
            this.Customer.FieldValue = customer;

            this.PMOwner = new StringField();
            this.PMOwner.FieldName = BugFields.PMOwner;
            this.PMOwner.FieldValue = pmOwner;

            this.Developer = new StringField();
            this.Developer.FieldName = BugFields.Developer;
            this.Developer.FieldValue = developer;

            this.Title = new StringField();
            this.Title.FieldName = BugFields.Title;
            this.Title.FieldValue = title;

            this.Status = new StringField();
            this.Status.FieldName = BugFields.Status;
            this.Status.FieldValue = status;

            this.ChangedBy = new StringField();
            this.ChangedBy.FieldName = BugFields.ChangedBy;
            this.ChangedBy.FieldValue = changedBy;

            this.ResolvedDate = new DatetimeField();
            this.ResolvedDate.FieldName = BugFields.ResolvedDate;
            this.ResolvedDate.FieldValue = resolvedDate;

            this.Resolver = new StringField();
            this.Resolver.FieldName = BugFields.Resolver;
            this.Resolver.FieldValue = resolver;

            this.Resolution = new StringField();
            this.Resolution.FieldName = BugFields.Resolution;
            this.Resolution.FieldValue = resolution;

            this.BugOwner = new StringField();
            this.BugOwner.FieldName = BugFields.BugOwner;
            this.BugOwner.FieldValue = bugOwner;

            this.IssueType = new StringField();
            this.IssueType.FieldName = BugFields.IssueType;
            this.IssueType.FieldValue = issueType;

            this.Severity = new StringField();
            this.Severity.FieldName = BugFields.Severity;
            this.Severity.FieldValue = severity.ToString();

            this.ClosedBy = new StringField();
            this.ClosedBy.FieldName = BugFields.ClosedBy;
            this.ClosedBy.FieldValue = closedBy;

            this.Priority = new StringField();
            this.Priority.FieldName = BugFields.Priority;
            this.Priority.FieldValue = priority.ToString();

            this.BugOpenedDate = new DatetimeField();
            this.BugOpenedDate.FieldName = BugFields.BugOpenedDate;
            this.BugOpenedDate.FieldValue = bugOpenedDate;

            this.BugFiler = new StringField();
            this.BugFiler.FieldName = BugFields.BugFiler;
            this.BugFiler.FieldValue = bugFiler;

            this.Cause = new StringField();
            this.Cause.FieldName = BugFields.Cause;
            this.Cause.FieldValue = cause;

            this.CloseDate = new DatetimeField();
            this.CloseDate.FieldName = BugFields.CloseDate;
            this.CloseDate.FieldValue = closeDate;

            this.LastModifiedTime = new DatetimeField();
            this.LastModifiedTime.FieldName = BugFields.LastModifiedTime;
            this.LastModifiedTime.FieldValue = lastModifiedTime;

            this.Feature = new StringField();
            this.Feature.FieldName = BugFields.Feature;
            this.Feature.FieldValue = feature;

            this.FixETA = new DatetimeField();
            this.FixETA.FieldName = BugFields.FixETA;
            this.FixETA.FieldValue = fixETA;

            this.MustFixBy = new DatetimeField();
            this.MustFixBy.FieldName = BugFields.MustFixBy;
            this.MustFixBy.FieldValue = mustFixBy;

            this.BundleCreateDate = new DatetimeField();
            this.BundleCreateDate.FieldName = BugFields.BundleCreateDate;
            this.BundleCreateDate.FieldValue = bundleCreationDate;

            this.TestReviewer = new StringField();
            this.TestReviewer.FieldName = BugFields.TestReviewer;
            this.TestReviewer.FieldValue = testReviewer;

            this.SLADate = new DatetimeField();
            this.SLADate.FieldName = BugFields.SLADate;
            this.SLADate.FieldValue = slaDate;

            this.WorkItemState = new StringField();
            this.WorkItemState.FieldName = BugFields.WorkItemState;
            this.WorkItemState.FieldValue = workItemState;

            this.QfeAssignedDate = new DatetimeField();
            this.QfeAssignedDate.FieldName = BugFields.QfeAssignedDate;
            this.QfeAssignedDate.FieldValue = qfeAssignedDate;

            this.Path = new StringField();
            this.Path.FieldName = BugFields.Path;
            this.Path.FieldValue = path;

            this.OpenedBuild = new StringField();
            this.OpenedBuild.FieldName = BugFields.OpenedBuild;
            this.OpenedBuild.FieldValue = openbuild;

            this.ResolvedBuild = new StringField();
            this.ResolvedBuild.FieldName = BugFields.ResolvedBuild;
            this.ResolvedBuild.FieldValue = resolvedBuild;

            this.DevOwner = new StringField();
            this.DevOwner.FieldName = BugFields.DevOwner;
            this.DevOwner.FieldValue = devOwner;

            this.TestOwner = new StringField();
            this.TestOwner.FieldName = BugFields.TestOwner;
            this.TestOwner.FieldValue = testOwner;

            this.BuildOwner = new StringField();
            this.BuildOwner.FieldName = BugFields.BuildOwner;
            this.BuildOwner.FieldValue = buildOwner;

            this.Builder = new StringField();
            this.Builder.FieldName = BugFields.Builder;
            this.Builder.FieldValue = builder;

            this.ReleasePM = new StringField();
            this.ReleasePM.FieldName = BugFields.ReleasePM;
            this.ReleasePM.FieldValue = releasePM;

            this.QfeRejectDate = new DatetimeField();
            this.QfeRejectDate.FieldName = BugFields.QfeRejectDate;
            this.QfeRejectDate.FieldValue = qfeRejectDate;

            this.InvestigationAssignDate = new DatetimeField();
            this.InvestigationAssignDate.FieldName = BugFields.InvestigationAssignDate;
            this.InvestigationAssignDate.FieldValue = investigationAssignDate;

            this.InvestigationDue = new DatetimeField();
            this.InvestigationDue.FieldName = BugFields.InvestigationDue;
            this.InvestigationDue.FieldValue = investigationDue;

            this.InvestigationFinishDate = new DatetimeField();
            this.InvestigationFinishDate.FieldName = BugFields.InvestigationFinishDate;
            this.InvestigationFinishDate.FieldValue = investigationFinishDate;

            this.CodeReviewRequestDate = new DatetimeField();
            this.CodeReviewRequestDate.FieldName = BugFields.CodeReviewRequestDate;
            this.CodeReviewRequestDate.FieldValue = codeReviewRequestDate;

            this.CodeReviewStatus = new StringField();
            this.CodeReviewStatus.FieldName = BugFields.CodeReviewStatus;
            this.CodeReviewStatus.FieldValue = codeReviewStatus;

            this.CodeReviewer = new StringField();
            this.CodeReviewer.FieldName = BugFields.CodeReviewer;
            this.CodeReviewer.FieldValue = codeReviewer;

            this.CodeReviewFile = new StringField();
            this.CodeReviewFile.FieldName = BugFields.CodeReviewFile;
            this.CodeReviewFile.FieldValue = codeReviewFile;

            this.CodeReviewFinishDate = new DatetimeField();
            this.CodeReviewFinishDate.FieldName = BugFields.CodeReviewFinishDate;
            this.CodeReviewFinishDate.FieldValue = codeReviewFinishDate;

            this.TestCase = new StringField();
            this.TestCase.FieldName = BugFields.TestCase;
            this.TestCase.FieldValue = testCase;

            this.PrivateTestRequestDate = new DatetimeField();
            this.PrivateTestRequestDate.FieldName = BugFields.PrivateTestRequestDate;
            this.PrivateTestRequestDate.FieldValue = privateTestRequestDate;

            this.PrivateTestStatus = new StringField();
            this.PrivateTestStatus.FieldName = BugFields.PrivateTestStatus;
            this.PrivateTestStatus.FieldValue = privateTestStatus;

            this.PrivateTester = new StringField();
            this.PrivateTester.FieldName = BugFields.PrivateTester;
            this.PrivateTester.FieldValue = privateTester;

            this.PrivateTestFinishDate = new DatetimeField();
            this.PrivateTestFinishDate.FieldName = BugFields.PrivateTestFinishDate;
            this.PrivateTestFinishDate.FieldValue = privateTestFinishDate;

            this.CheckinRequestDate = new DatetimeField();
            this.CheckinRequestDate.FieldName = BugFields.CheckinRequestDate;
            this.CheckinRequestDate.FieldValue = checkinRequestDate;

            this.CheckinStatus = new StringField();
            this.CheckinStatus.FieldName = BugFields.CheckinStatus;
            this.CheckinStatus.FieldValue = checkinStatus;

            this.CheckinApproveDate = new DatetimeField();
            this.CheckinApproveDate.FieldName = BugFields.CheckinApproveDate;
            this.CheckinApproveDate.FieldValue = checkinApproveDate;

            this.BuildRequestDate = new DatetimeField();
            this.BuildRequestDate.FieldName = BugFields.BuildRequestDate;
            this.BuildRequestDate.FieldValue = buildRequestDate;

            this.BVTAssignDate = new DatetimeField();
            this.BVTAssignDate.FieldName = BugFields.BVTAssignDate;
            this.BVTAssignDate.FieldValue = bvtAssignDate;

            this.BVTStatus = new StringField();
            this.BVTStatus.FieldName = BugFields.BVTStatus;
            this.BVTStatus.FieldValue = bvtStatus;

            this.BVTTester = new StringField();
            this.BVTTester.FieldName = BugFields.BVTTester;
            this.BVTTester.FieldValue = bvtTester;

            this.BVTFinishDate = new DatetimeField();
            this.BVTFinishDate.FieldName = BugFields.BVTFinishDate;
            this.BVTFinishDate.FieldValue = bvtFinishDate;

            this.RegressionStatus = new StringField();
            this.RegressionStatus.FieldName = BugFields.RegressionStatus;
            this.RegressionStatus.FieldValue = regressionStatus;

            this.RegressionTester = new StringField();
            this.RegressionTester.FieldName = BugFields.RegressionTester;
            this.RegressionTester.FieldValue = regressionTester;

            this.RegressionFinishDate = new DatetimeField();
            this.RegressionFinishDate.FieldName = BugFields.RegressionFinishDate;
            this.RegressionFinishDate.FieldValue = regressionFinishDate;

            this.CodeSignRequestDate = new DatetimeField();
            this.CodeSignRequestDate.FieldName = BugFields.CodeSignRequestDate;
            this.CodeSignRequestDate.FieldValue = codeSignRequestDate;

            this.CodeSignFinishDate = new DatetimeField();
            this.CodeSignFinishDate.FieldName = BugFields.CodeSignFinishDate;
            this.CodeSignFinishDate.FieldValue = codeSignFinishDate;

            this.CodeSignRequestNumber = new StringField();
            this.CodeSignRequestNumber.FieldName = BugFields.CodeSignRequestNumber;
            this.CodeSignRequestNumber.FieldValue = codeSignRequestNumber;

            this.RfxSubmitted = new DatetimeField();
            this.RfxSubmitted.FieldName = BugFields.RfxSubmitted;
            this.RfxSubmitted.FieldValue = rfxSubmitted;

            this.PendingChangelist = new PendingChangelistField();
            this.PendingChangelist.FieldName = BugFields.PendingChangelist;
            this.PendingChangelist.FieldValue = changelist;

            this.SecurityRank = new StringField();
            this.SecurityRank.FieldName = BugFields.SecurityRank;
            this.SecurityRank.FieldValue = securityRank;

            this.SecurityEffect = new StringField();
            this.SecurityEffect.FieldName = BugFields.SecurityEffect;
            this.SecurityEffect.FieldValue = securityEffect;

            this.ApprovedBy = new StringField();
            this.ApprovedBy.FieldName = BugFields.ApprovedBy;
            this.ApprovedBy.FieldValue = approvedBy;

            this.Milestone = new StringField();
            this.Milestone.FieldName = BugFields.Milestone;
            this.Milestone.FieldValue = milestone;

            this.RFxTriagedDate = new DatetimeField();
            this.RFxTriagedDate.FieldName = BugFields.RFxTriagedDate;
            this.RFxTriagedDate.FieldValue = rfxTriagedDate;

            this.InvestigationCompleteDate = new DatetimeField();
            this.InvestigationCompleteDate.FieldName = BugFields.InvestigationCompleteDate;
            this.InvestigationCompleteDate.FieldValue = investigationCompleteDate;
        }