示例#1
0
        /// <summary>
        /// Process all the history revisions
        /// </summary>
        /// <param name="sourceWIId"></param>
        /// <param name="imWorkItem"></param>
        /// <param name="setMigStatusDone"></param>
        /// <returns></returns>
        public bool WriteHistoryItems(string sourceWIId, InMemoryWorkItem imWorkItem, bool setMigStatusDone)
        {
            m_revision            = m_currentWorkItem.Rev - 1;
            m_vstsWorkItem.Id     = m_currentWorkItem.Id;
            m_vstsWorkItem.areaId = m_currentWorkItem.AreaId;

            m_sourceWorkItemId = sourceWIId;
            string currentMigStatus = (string)m_currentWorkItem[m_migrationStatusFieldName];
            int    revCount         = 0;
            bool   isMigStatusInt   = int.TryParse(currentMigStatus, out revCount);

            Debug.Assert(isMigStatusInt); // should be able to parse always.. otherwise a code bug

            // process all history revisions and save in each call
            for (int historyIdx = 0; historyIdx < imWorkItem.HistoryItems.Count; historyIdx++)
            {
                // create new webs service call xml fragment
                WSHelper webServiceHelper = new WSHelper(WSHelper.WebServiceType.UpdateWorkItem);

                // set the required attributes
                webServiceHelper.SetWorkItemAndRevision(m_currentWorkItem.Id, ++m_revision);

                InMemoryHistoryItem imHistoryItem = (InMemoryHistoryItem)imWorkItem.HistoryItems[historyIdx];

                if (historyIdx == imWorkItem.HistoryItems.Count - 1 && // last history item
                    imWorkItem.Attachments.Count == 0 &&               // no attachments
                    imWorkItem.Links.Count == 0 &&                     // no links
                    setMigStatusDone)                                  // caller asked for it
                {
                    // last item.. set mig status to done
                    ProcessRevision(webServiceHelper, imHistoryItem.UpdatedView, "Done");
                }
                else
                {
                    ProcessRevision(webServiceHelper, imHistoryItem.UpdatedView, (++revCount).ToString());
                }

                try
                {
                    webServiceHelper.Save();
                }
                finally
                {
                }
            }

            if (imWorkItem.Attachments.Count > 0 ||
                imWorkItem.Links.Count > 0)
            {
                return(ProcessAttachmentsAndLinks(imWorkItem, setMigStatusDone));
            }

            return(true);
        }
示例#2
0
        } // end of Populate()

        /// <summary>
        /// Processes the history for current record.
        /// </summary>
        /// <param name="initialView">First history item structure</param>
        /// <param name="migratedHistory">No of history items already migrated</param>
        /// <returns>List of history items except first one</returns>
        private ArrayList ProcessHistory(Hashtable initialView, int migratedHistory)
        {
            int       noOfHistory  = 0;
            ArrayList historyItems = new ArrayList();

            try
            {
                Logger.Write(LogSource.CQ, TraceLevel.Verbose, "Processing History for {0} : {1}", m_entityName, m_sourceId);

                // record all history items except the first one
                Hashtable        currentHistory = null;
                OAdHistoryFields cqHistFields   = CQWrapper.GetHistoryFields(m_CQEntity);
                int historyFldCount             = CQWrapper.HistoryFieldsCount(cqHistFields);
                for (int histFldIndex = 0; histFldIndex < historyFldCount; histFldIndex++)
                {
                    object          ob           = (object)histFldIndex;
                    OAdHistoryField historyField = CQWrapper.HistoryFieldsItem(cqHistFields, ref ob);

                    int historyCount = CQWrapper.HistoryFieldHistoriesCount(historyField);
                    for (int histIndex = migratedHistory; histIndex < historyCount; histIndex++)
                    {
                        if (histIndex == 0)
                        {
                            // first history.. use the initial view to record history
                            currentHistory = initialView;
                        }
                        else
                        {
                            // create a new instance to record history
                            InMemoryHistoryItem imHistItem = new InMemoryHistoryItem();
                            historyItems.Add(imHistItem);
                            currentHistory = imHistItem.UpdatedView;
                        }

                        object     obHistIndex  = (object)histIndex;
                        OAdHistory aHistory     = CQWrapper.HistoryFieldHistoriesItem(historyField, ref obHistIndex);
                        string[]   parsedString = CQWrapper.HistoryValue(aHistory).Split('\t');
                        Debug.Assert(parsedString != null && parsedString.Length >= 6);
                        string date     = parsedString[1];
                        string user     = parsedString[2];
                        string action   = parsedString[3];
                        string oldstate = parsedString[4];
                        string newstate = parsedString[5];

                        DateTime changedDate = DateTime.Parse(date, CultureInfo.CurrentCulture);

                        Logger.Write(LogSource.CQ, TraceLevel.Verbose, "History Item : [{0}] [{1}] [{2}] [{3}]",
                                     changedDate, user, oldstate, newstate);

                        string historyval = UtilityMethods.Format(CQResource.CQ_HISTORY_STRING, changedDate.ToString(CultureInfo.CurrentCulture),
                                                                  user, action, oldstate, newstate);
                        currentHistory.Add("History", historyval);
                        currentHistory.Add("user_name", user);
                        currentHistory.Add("Reason", action);

                        if (!String.Equals("N/A", newstate, StringComparison.Ordinal))
                        {
                            // add state only if state is valid
                            currentHistory.Add("State", newstate);
                        }
                        noOfHistory++;
#if DEBUG
                        CommonConstants.NoOfHistory++;
#endif
                    }
                }
            }
            finally
            {
            }
            return(historyItems);
        } // end of ProcessHistory()