Exemple #1
0
        private void reviseNameForRename(CCHistoryRecord historyRecord, Dictionary <string, string> renameList)
        {
            if (renameList.Count == 0)
            {
                return;
            }

            string path = historyRecord.AbsoluteVobPath;

            while (!ClearCasePath.IsVobRoot(path))
            {
                if (renameList.ContainsKey(path))
                {
                    historyRecord.AbsoluteVobPath =
                        ClearCasePath.Combine(renameList[path], historyRecord.AbsoluteVobPath.Substring(path.Length));
                    break;
                }
                path = ClearCasePath.GetFolderName(path);
            }

            if (historyRecord.ChangeAction == WellKnownChangeActionId.Rename)
            {
                string fromPath = historyRecord.AbsoluteVobPathFrom;
                while (!ClearCasePath.IsVobRoot(fromPath))
                {
                    if (renameList.ContainsKey(fromPath))
                    {
                        historyRecord.AbsoluteVobPathFrom =
                            ClearCasePath.Combine(renameList[fromPath], historyRecord.AbsoluteVobPathFrom.Substring(fromPath.Length));
                        break;
                    }
                    fromPath = ClearCasePath.GetFolderName(fromPath);
                }
            }
        }
Exemple #2
0
        private void reviseRenameList(CCHistoryRecord renameHistoryRecord, Dictionary <string, string> renameList)
        {
            bool          needToAddToRenameList     = true;
            List <string> subItemRenameToBeModified = new List <string>();

            foreach (string renameToPath in renameList.Keys)
            {
                if (ClearCasePath.Equals(renameList[renameToPath], renameHistoryRecord.AbsoluteVobPath))
                {
                    subItemRenameToBeModified.Add(renameToPath);
                    needToAddToRenameList = false;
                    continue;
                }
                if (ClearCasePath.IsSubItem(renameList[renameToPath], renameHistoryRecord.AbsoluteVobPath))
                {
                    subItemRenameToBeModified.Add(renameToPath);
                }
            }

            foreach (string subItem in subItemRenameToBeModified)
            {
                renameList[subItem] =
                    ClearCasePath.Combine(renameHistoryRecord.AbsoluteVobPathFrom, renameList[subItem].Substring(renameHistoryRecord.AbsoluteVobPath.Length));
            }

            if (needToAddToRenameList)
            {
                renameList.Add(renameHistoryRecord.AbsoluteVobPath, renameHistoryRecord.AbsoluteVobPathFrom);
            }
        }
        /// <summary>
        /// Given the output of checkin command, return list of element versions checked in.
        /// </summary>
        /// <param name="cmdOutput"></param>
        /// <returns></returns>
        public static List <string> ParseCheckInCommand(string cmdOutput)
        {
            if (string.IsNullOrEmpty(cmdOutput))
            {
                return(null);
            }
            StringReader  strReader = new StringReader(cmdOutput);
            string        line;
            List <string> versionList = new List <string>();

            while (true)
            {
                line = strReader.ReadLine();
                if (string.IsNullOrEmpty(line))
                {
                    break;
                }
                if (line.StartsWith(CheckedInPrefix))
                {
                    string [] split = line.Split(new char[] { '\"' });
                    if (split.Length < 4)
                    {
                        TraceManager.TraceWarning(string.Format("Don't know how to parse checkin command return - {0}", line));
                    }
                    else
                    {
                        versionList.Add(ClearCasePath.Combine(split[1], split[3]));
                    }
                }
            }
            return(versionList);
        }
Exemple #4
0
        /// <summary>
        /// Constructor.
        /// Construct the clearcase item from a version object on ClearCase
        /// </summary>
        /// <param name="version"></param>
        public CCItem(CCVersion version, string vobName)
        {
            ItemType            = ItemType.Version;
            VersionExtendedPath = version.ExtendedPath;
            AbsoluteVobPath     = vobName;

            string[] splittedPath = VersionExtendedPath.Split(new string[] { ClearCasePath.ExtendedNamingSuffix }, StringSplitOptions.None);
            Branch = ClearCasePath.GetBranchName(splittedPath[splittedPath.Length - 1]);

            List <string> parentPaths = new List <string>();

            while (!ClearCasePath.IsVobRoot(version.Element.Path))
            {
                parentPaths.Add(ClearCasePath.GetFileName(version.Element.Path));
                try
                {
                    version = version.Parent;
                }
                catch (COMException)
                {
                    // This is a ClearCase CAL bug.
                    // Ignore the root node.
                    parentPaths.RemoveAt(parentPaths.Count - 1);
                    break;
                }
            }
            parentPaths.Reverse();

            foreach (string parentPath in parentPaths)
            {
                AbsoluteVobPath = ClearCasePath.Combine(AbsoluteVobPath, parentPath);
            }
            AbsoluteVobPath             = AbsoluteVobPath;
            AbsoluteVobPathAtTheVersion = AbsoluteVobPath;
        }
Exemple #5
0
        private void queryHistory(ChangeGroupService changeGroupService)
        {
            m_hwmDelta.Reload();
            DateTime since = m_hwmDelta.Value;
            List <CCHistoryRecord> historyRecordList = m_clearCaseServer.GetHistoryRecords(m_configurationService.Filters, since, true);

            historyRecordList.Sort();

            CCVersion version;
            CCItem    currentItem                      = null;
            CCItem    previousLnItem                   = null;
            string    previousLnItemLeafName           = null;
            string    previousMkElemItemPath           = null;
            List <CCHistoryRecord> processedRecordList = new List <CCHistoryRecord>();

            foreach (CCHistoryRecord historyRecord in historyRecordList)
            {
                switch (historyRecord.OperationType)
                {
                case OperationType.Checkin:
                    version     = m_clearCaseServer.ApplicationClass.get_Version(historyRecord.VersionExtendedPath);
                    currentItem = new CCItem(version, ClearCasePath.GetVobName(historyRecord.AbsoluteVobPath));
                    if (string.Equals(historyRecord.OperationDescription, OperationDescription.Version))
                    {
                        if (ClearCasePath.Equals(previousMkElemItemPath, currentItem.AbsoluteVobPath))
                        {
                            // File version checkin following a mkelem, create an Add
                            historyRecord.AbsoluteVobPath = currentItem.AbsoluteVobPath;
                            historyRecord.ChangeAction    = WellKnownChangeActionId.Add;
                            historyRecord.IsDirectory     = version.IsDirectory;
                            processedRecordList.Add(historyRecord);
                            previousMkElemItemPath = null;
                        }
                        else
                        {
                            // File version checkin following a mkelem, create an Edit
                            historyRecord.AbsoluteVobPath = currentItem.AbsoluteVobPath;
                            historyRecord.ChangeAction    = WellKnownChangeActionId.Edit;
                            historyRecord.IsDirectory     = version.IsDirectory;
                            processedRecordList.Add(historyRecord);
                        }
                    }
                    else if (string.Equals(historyRecord.OperationDescription, OperationDescription.DirectoryVersion) &&
                             (ClearCasePath.Equals(previousMkElemItemPath, currentItem.AbsoluteVobPath)))
                    {
                        // Directory version checkin following a mkelem, create an Add
                        historyRecord.AbsoluteVobPath = currentItem.AbsoluteVobPath;
                        historyRecord.ChangeAction    = WellKnownChangeActionId.Add;
                        historyRecord.IsDirectory     = version.IsDirectory;
                        processedRecordList.Add(historyRecord);
                        previousMkElemItemPath = null;
                    }
                    break;

                case OperationType.Mkattr:
                case OperationType.Mkpool:
                case OperationType.Mkreplica:
                case OperationType.Mktype:
                    // ToDo
                    // writeHistoryRecord(historyFields);
                    break;

                case OperationType.Lnname:
                    version                = m_clearCaseServer.ApplicationClass.get_Version(historyRecord.VersionExtendedPath);
                    currentItem            = new CCItem(version, ClearCasePath.GetVobName(historyRecord.AbsoluteVobPath));
                    previousLnItem         = currentItem;
                    previousLnItemLeafName = ClearCaseEventSpec.ParseLnNameComment(historyRecord.Comment);
                    break;

                case OperationType.Mkbranch:
                    // ToDo
                    if (string.Equals(historyRecord.OperationDescription, OperationDescription.Version) ||
                        string.Equals(historyRecord.OperationDescription, OperationDescription.DirectoryVersion))
                    {
                        /*version = m_clearCaseServer.ApplicationClass.get_Version(historyRecord.VersionExtendedPath);
                         * currentItem = new CCItem(version, vob);
                         * historyRecord.AbsoluteVobPath = currentItem.AbsoluteVobPath;
                         * historyRecord.ChangeAction = WellKnownChangeActionId.Add;
                         * historyRecord.IsDirectory = version.IsDirectory;
                         * historyRecordList.Add(historyRecord);
                         * */
                    }
                    break;

                case OperationType.Mkelem:
                    if (string.Equals(historyRecord.OperationDescription, OperationDescription.DirectoryElement))
                    {
                        // Todo

                        /*if (currentState == OperationState.Initialized)
                         * {
                         *  currentState = OperationState.CreateDirectoryElement;
                         *  currentItem = new Item(historyFields[1], ItemType.Element, m_vobName);
                         * }
                         * else
                         * {
                         *  logStateTransitionError(currentState, operationType, operationDescription);
                         * }*/
                    }
                    else if (string.Equals(historyRecord.OperationDescription, OperationDescription.Branch))
                    {
                        // Todo

                        /*
                         * if ((currentState == OperationState.AddDirectoryToParent)
                         || (currentState == OperationState.CreateDirectoryElement))
                         ||{
                         || currentState = OperationState.CreateDirectoryBranch;
                         || currentItem = new Item(historyFields[1], ItemType.Branch, m_vobName);
                         ||}
                         ||else
                         ||{
                         || logStateTransitionError(currentState, operationType, operationDescription);
                         ||}
                         * */
                    }
                    else if (string.Equals(historyRecord.OperationDescription, OperationDescription.DirectoryVersion) ||
                             string.Equals(historyRecord.OperationDescription, OperationDescription.Version))
                    {
                        version                = m_clearCaseServer.ApplicationClass.get_Version(historyRecord.VersionExtendedPath);
                        currentItem            = new CCItem(version, ClearCasePath.GetVobName(historyRecord.AbsoluteVobPath));
                        previousMkElemItemPath = currentItem.AbsoluteVobPath;
                        //if (currentState == OperationState.CreateDirectoryBranch)
                        //{

                        /*version = m_clearCaseServer.ApplicationClass.get_Version(historyFields[1]);
                         * currentItem = new Item(version, vob);
                         * if (IsPathMapped(currentItem.AbsoluteVobPath) &&
                         *  IsOurChange(ClearCasePath.removeViewLocationFromVersion(version.ExtendedPath, m_clearCaseServer.ViewRootPath)))
                         * {
                         *  createMigrationAction(
                         *  version,
                         *  null,
                         *  currentItem.AbsoluteVobPath,
                         *  versionTime,
                         *  WellKnownChangeActionId.Add,
                         *  version.IsDirectory);
                         * }*/

                        // Verify the version to be 0
                        //currentState = OperationState.Initialized;
                        //}
                        //else
                        //{
                        //    logStateTransitionError(currentState, operationType, operationDescription);
                        //}
                    }
                    else
                    {
                        //logStateTransitionError(currentState, operationType, operationDescription);
                    }
                    break;

                case OperationType.Mkhlink:
                    // ToDo
                    // writeHistoryRecord(historyFields);
                    break;

                case OperationType.Mklabel:
                    break;

                case OperationType.Rmname:
                    bool   isDirectory;
                    string rmItemName = ClearCaseEventSpec.ParseRmNameComment(historyRecord.Comment, out isDirectory);
                    if (rmItemName == null)
                    {
                        TraceManager.TraceWarning(String.Format("Skipping rmname operation: Unable to determine element type from history record comment: '{0}'", historyRecord.Comment));
                        continue;
                    }
                    version     = m_clearCaseServer.ApplicationClass.get_Version(historyRecord.VersionExtendedPath);
                    currentItem = new CCItem(version, ClearCasePath.GetVobName(historyRecord.AbsoluteVobPath));
                    if (currentItem.Equals(previousLnItem))
                    {
                        historyRecord.AbsoluteVobPath     = ClearCasePath.Combine(currentItem.AbsoluteVobPath, previousLnItemLeafName);
                        historyRecord.AbsoluteVobPathFrom = ClearCasePath.Combine(currentItem.AbsoluteVobPath, rmItemName);
                        historyRecord.ChangeAction        = WellKnownChangeActionId.Rename;
                        historyRecord.IsDirectory         = isDirectory;
                        processedRecordList.Add(historyRecord);
                        previousLnItem         = null;
                        previousLnItemLeafName = null;
                        // todo, path not mapped exception
                    }
                    else
                    {
                        // delete operation
                        historyRecord.AbsoluteVobPath = ClearCasePath.Combine(currentItem.AbsoluteVobPath, rmItemName);
                        historyRecord.ChangeAction    = WellKnownChangeActionId.Delete;
                        historyRecord.IsDirectory     = isDirectory;
                        processedRecordList.Add(historyRecord);
                    }
                    break;

                case OperationType.Undefined:
                    break;

                case OperationType.Mkvob:
                // Add of Vob itself.
                // ToDo
                // writeHistoryRecord(historyFields);
                default:
                    break;
                }
            }

            reviseHistoryRecordsForRename(processedRecordList);

            m_hwmEventId.Reload();
            long lastProcessedEventId = m_hwmEventId.Value;

            foreach (CCHistoryRecord historyRecord in processedRecordList)
            {
                if (historyRecord.EventId <= lastProcessedEventId)
                {
                    // The event has been processed in previous sync.
                    TraceManager.TraceInformation("Skipping history record because the event was processed in a previous sync pass of this session");
                    continue;
                }
                if (Utils.IsOurChange(historyRecord))
                {
                    TraceManager.TraceInformation("Skipping history record because it represents a change migrated by the Integration Platform");
                    continue;
                }
                if (Utils.IsPathMapped(historyRecord.AbsoluteVobPath, m_configurationService))
                {
                    if (historyRecord.ChangeAction == WellKnownChangeActionId.Rename)
                    {
                        if (Utils.IsPathMapped(historyRecord.AbsoluteVobPathFrom, m_configurationService))
                        {
                            m_currentChangeGroup = createMigrationAction(historyRecord, historyRecord.ChangeAction);
                        }
                        else
                        {
                            // ToDo Path not mapped conflict
                            m_currentChangeGroup = createMigrationAction(historyRecord, WellKnownChangeActionId.Add);
                        }
                    }
                    else
                    {
                        m_currentChangeGroup = createMigrationAction(historyRecord, historyRecord.ChangeAction);
                    }
                }
                else
                {
                    // ToDo path not mapped conflict
                    if ((historyRecord.ChangeAction == WellKnownChangeActionId.Rename) && (Utils.IsPathMapped(historyRecord.AbsoluteVobPathFrom, m_configurationService)))
                    {
                        m_currentChangeGroup = createMigrationAction(historyRecord, WellKnownChangeActionId.Delete);
                    }
                    else
                    {
                        TraceManager.TraceWarning("Skipping history record because the path '{0}' is not mapped in a filter string", historyRecord.AbsoluteVobPath);
                    }
                }
            }
            if (m_currentChangeGroup != null)
            {
                m_currentChangeGroup.Save();
            }
            if (processedRecordList.Count > 0)
            {
                m_hwmDelta.Update(processedRecordList.Last().VersionTime);
            }
            m_changeGroupService.PromoteDeltaToPending();
        }