Пример #1
0
        public IEnumerable <IVCDiffItem> GetFolderSubDiffItems(IVCDiffItem folderDiffItem)
        {
            List <IVCDiffItem> diffItems = new List <IVCDiffItem>();

            try
            {
                string directoryPath = m_clearCaseServer.GetViewLocalPathFromServerPath(folderDiffItem.ServerPath);
                if (Directory.Exists(directoryPath))
                {
                    foreach (string file in Directory.GetFiles(directoryPath))
                    {
                        string serverPath = m_clearCaseServer.GetServerPathFromViewLocalPath(file);
                        diffItems.Add(new ClearCaseDiffItem(serverPath, file, VCItemType.File));
                    }

                    foreach (string subDirectory in Directory.GetDirectories(directoryPath))
                    {
                        string serverPath = m_clearCaseServer.GetServerPathFromViewLocalPath(subDirectory);
                        if (ClearCasePath.Equals(ClearCasePath.GetFileName(serverPath), ClearCasePath.LostFoundFolder))
                        {
                            continue;
                        }
                        diffItems.Add(new ClearCaseDiffItem(serverPath, null, VCItemType.Folder));
                    }
                }
            }
            catch (Exception ex)
            {
                throw new VersionControlDiffException(string.Format(CultureInfo.InvariantCulture,
                                                                    CCResources.GetDiffItemsException, folderDiffItem.ServerPath, ex.Message), ex);
            }

            return(diffItems);
        }
        private void addRename(CCBatchedItem item)
        {
            string removeItem = null;

            foreach (KeyValuePair <string, CCBatchedItem> renameItemInlist in m_unresolvedRenames)
            {
                if (ClearCasePath.Equals(ClearCasePath.MakeRelative(item.Target, renameItemInlist.Value.Target),
                                         ClearCasePath.MakeRelative(item.Source, renameItemInlist.Value.Source)))
                {
                    // Parent rename is already added, just return.
                    return;
                }
                else if (ClearCasePath.Equals(ClearCasePath.MakeRelative(renameItemInlist.Value.Target, item.Target),
                                              ClearCasePath.MakeRelative(renameItemInlist.Value.Source, item.Source)))
                {
                    // A child rename is already, remove the child rename.
                    removeItem = renameItemInlist.Key;
                    break;
                }
            }

            if (!string.IsNullOrEmpty(removeItem))
            {
                m_unresolvedRenames.Remove(removeItem);
            }

            m_unresolvedRenames.Add(item.Target, item);
        }
Пример #3
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);
            }
        }
Пример #4
0
        /// <summary>
        /// Find the mapping entry for the given path.
        /// </summary>
        /// <param name="serverPath"></param>
        /// <returns>Null if the path is not mapped or cloaked. Otherwise, return the mapping entry.</returns>
        internal static MappingEntry FindMappedPath(string serverPath, ConfigurationService configurationService)
        {
            MappingEntry mostSpecificMapping = null;

            foreach (MappingEntry current in configurationService.Filters)
            {
                if (ClearCasePath.IsSubItem(serverPath, ClearCasePath.GetFullPath(current.Path)))
                {
                    if (mostSpecificMapping == null ||
                        ClearCasePath.IsSubItem(ClearCasePath.GetFullPath(current.Path),
                                                ClearCasePath.GetFullPath(mostSpecificMapping.Path)))
                    {
                        mostSpecificMapping = current;
                    }
                }
            }

            if ((mostSpecificMapping != null) && (!mostSpecificMapping.Cloak))
            {
                return(mostSpecificMapping);
            }
            else
            {
                return(null);
            }
        }
Пример #5
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);
                }
            }
        }
Пример #6
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;
        }
Пример #7
0
        /// <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);
        }
        private void addDelete(CCBatchedItem item)
        {
            string removeItem = null;

            foreach (KeyValuePair <string, CCBatchedItem> deleteItemInlist in m_unresolvedDeletes)
            {
                if (ClearCasePath.IsSubItem(item.Target, deleteItemInlist.Value.Target))
                {
                    // Parent delete is already added, just return.
                    return;
                }
                else if (ClearCasePath.IsSubItem(deleteItemInlist.Value.Target, item.Target))
                {
                    // A child delete is already added, remove the child delete.
                    removeItem = deleteItemInlist.Key;
                    break;
                }
            }

            if (!string.IsNullOrEmpty(removeItem))
            {
                m_unresolvedDeletes.Remove(removeItem);
            }

            m_unresolvedDeletes.Add(item.Target, item);
        }
Пример #9
0
        /// <summary>
        /// Generate a CCHistoryRecord instance from a historyRow string.
        /// </summary>
        /// <param name="historyRow">A history row string returned from query history command</param>
        /// <returns>The CCHistoryRecord created or null if the creation failed.</returns>
        public static CCHistoryRecord CreateInstance(string historyRow)
        {
            if (string.IsNullOrEmpty(historyRow))
            {
                return(null);
            }

            if (historyRow.Contains("ClearCase object not found."))
            {
                TraceManager.TraceInformation("Invalid history record - {0}", historyRow);
                return(null);
            }

            string[] historyColumns =
                historyRow.Split(new string[] { ClearCaseCommandSpec.HISTORYRECORD_COLUMNDELIMINATOR }, StringSplitOptions.None);
            if (historyColumns.Length < 7)
            {
                TraceManager.TraceInformation("Wrong numbers of columns in history record - {0}", historyRow);
                return(null);
            }
            string[] strEventId =
                historyColumns[0].Split(new string[] {
                "event", ":"
            },
                                        StringSplitOptions.RemoveEmptyEntries);
            long eventId;

            if (!long.TryParse(strEventId[0], out eventId))
            {
                TraceManager.TraceInformation("Invalid event id in history record - {0}", historyRow);
                return(null);
            }

            DateTime versionTime;

            if (!DateTime.TryParse(historyColumns[5], out versionTime))
            {
                TraceManager.TraceInformation("Invalid version time in history record - {0}", historyRow);
                return(null);
            }
            CCHistoryRecord instance = new CCHistoryRecord
            {
                EventId              = eventId,
                OperationType        = Operation.GetOperationType(historyColumns[2]),
                VersionExtendedPath  = historyColumns[1],
                OperationDescription = historyColumns[3],
                VersionTime          = versionTime,
                Comment              = historyColumns[6],
                UserComment          = historyColumns[7].Trim(new char[] { '(', ')' }),
                AbsoluteVobPath      = ClearCasePath.GetAbsoluteVobPathFromVersionExtendedPath(historyColumns[1])
            };

            return(instance);
        }
Пример #10
0
 /// <summary>
 /// For a list of paths, check whether an element's ancestor is in the list.
 /// </summary>
 /// <param name="listToBeChecked"></param>
 /// <param name="element"></param>
 /// <returns></returns>
 public static bool IsElementAncestorInList(HashSet <string> listToBeChecked, string element)
 {
     while (!ClearCasePath.IsVobRoot(element))
     {
         if (listToBeChecked.Contains(element))
         {
             return(true);
         }
         element = ClearCasePath.GetFolderName(element);
     }
     return(false);
 }
Пример #11
0
        //********************************************************************************************
        /// <summary>
        ///  Returns the number of levels of path elements in this spec up to the maximum depth.
        ///  \ will return 0
        ///  \foo will return 1
        ///  \foo\bar will return 2, and so on...
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        //********************************************************************************************
        public static int GetFolderDepth(String item)
        {
            int count = 0;

            if (!ClearCasePath.Equals(item, Separator))
            {
                // Count the slashes
                for (int lastIndex = item.IndexOf(Separator); (lastIndex != -1); lastIndex = item.IndexOf(Separator, lastIndex + 1))
                {
                    count++;
                }
            }

            return(count);
        }
Пример #12
0
        private ChangeGroup createMigrationAction(CCHistoryRecord historyRecord, Guid actionId)
        {
            string versionExtendedPath;

            if (m_clearCaseServer.UsePrecreatedView)
            {
                versionExtendedPath = historyRecord.VersionExtendedPath;
            }
            else
            {
                versionExtendedPath =
                    ClearCasePath.removeViewLocationFromVersion(historyRecord.VersionExtendedPath, m_clearCaseServer.ViewRootPath);
            }
            ChangeGroup oldChangeGroup;
            ChangeGroup currentChangeGroup = m_changeGroupService.AddMigrationActionToDeltaTable(historyRecord.EventId.ToString(CultureInfo.InvariantCulture),
                                                                                                 historyRecord.Comment,
                                                                                                 null,
                                                                                                 historyRecord.EventId,
                                                                                                 actionId,
                                                                                                 new ClearCaseMigrationItem(
                                                                                                     m_ccConfiguration.GetViewName("Analysis"),
                                                                                                     versionExtendedPath,
                                                                                                     historyRecord.IsDirectory),
                                                                                                 historyRecord.AbsoluteVobPathFrom,
                                                                                                 historyRecord.AbsoluteVobPath,
                                                                                                 null,
                                                                                                 null,
                                                                                                 historyRecord.IsDirectory ? WellKnownContentType.VersionControlledFolder.ReferenceName
                : WellKnownContentType.VersionControlledFile.ReferenceName,
                                                                                                 null,
                                                                                                 historyRecord.VersionTime,
                                                                                                 out oldChangeGroup);

            m_hwmEventId.Update(historyRecord.EventId);

            if ((oldChangeGroup != null) && (oldChangeGroup != currentChangeGroup))
            {
                oldChangeGroup.Save();
                m_changeGroupService.PromoteDeltaToPending();
                m_hwmDelta.Update(historyRecord.VersionTime);
            }
            return(currentChangeGroup);
        }
Пример #13
0
        /// <summary>
        /// Add a new load rule of the pName into the existing config spec
        /// </summary>
        /// <param name="existingConfigSpec"></param>
        /// <param name="pName"></param>
        public static string AddLoadRule(string existingConfigSpec, string pName)
        {
            StringReader existingConfigSpecReader = new StringReader(existingConfigSpec);
            StringWriter newConfigSpecWriter      = new StringWriter();
            bool         needToAddLoadRule        = true;

            while (true)
            {
                string line = existingConfigSpecReader.ReadLine();
                if (line == null)
                {
                    break;
                }
                else
                {
                    line = line.Trim();
                }
                if (line.StartsWith("load", StringComparison.InvariantCultureIgnoreCase))
                {
                    // Todo, it is possible to have multiple pnames in one load rule line.
                    string loadedPName = line.Substring(5).Trim();
                    if (ClearCasePath.IsSubItem(pName, loadedPName))
                    {
                        // The parent is already loaded.
                        needToAddLoadRule = false;
                    }
                    else if (ClearCasePath.IsSubItem(loadedPName, pName))
                    {
                        // There is a child load rule. Add the parent load rule instead and continue;
                        newConfigSpecWriter.Write(string.Format(CCResources.CCConfigSpecLoadRule, pName) + '\n');
                        needToAddLoadRule = false;
                        continue;
                    }
                }
                newConfigSpecWriter.Write(line + '\n');
            }
            if (needToAddLoadRule)
            {
                newConfigSpecWriter.Write(string.Format(CCResources.CCConfigSpecLoadRule, pName) + '\n');
            }

            return(newConfigSpecWriter.ToString());
        }
Пример #14
0
        /// <summary>
        /// Constructor
        /// </summary>
        public CCHistoryRecord(string historyRow)
        {
            if (String.IsNullOrEmpty(historyRow))
            {
                throw new ArgumentNullException("historyRow");
            }

            string[] historyColumns =
                historyRow.Split(new string[] { ClearCaseCommandSpec.HISTORYRECORD_COLUMNDELIMINATOR }, StringSplitOptions.None);
            string[] strEventId =
                historyColumns[0].Split(new string[] {
                "event", ":"
            },
                                        StringSplitOptions.RemoveEmptyEntries);
            EventId              = long.Parse(strEventId[0]);
            VersionExtendedPath  = historyColumns[1];
            OperationType        = Operation.GetOperationType(historyColumns[2]);
            OperationDescription = historyColumns[3];
            VersionTime          = DateTime.Parse(historyColumns[5]);
            Comment              = historyColumns[6];
            UserComment          = historyColumns[7].Trim(new char[] { '(', ')' });
            AbsoluteVobPath      = ClearCasePath.GetAbsoluteVobPathFromVersionExtendedPath(VersionExtendedPath);
        }
 public bool IsSubItemOf(string folderPath)
 {
     return(ServerPath == null ? false : ClearCasePath.IsSubItem(ServerPath, folderPath));
 }
        private void detectConflicts()
        {
            // Add and Rename list
            // First, remove all rename for rename|undelete that was changed to rename|add.
            List <string> renameToBeRemoved = new List <string>();

            foreach (string renameToName in m_unresolvedRenames.Keys)
            {
                if (m_unresolvedAdds.ContainsKey(renameToName))
                {
                    renameToBeRemoved.Add(renameToName);
                }
            }

            foreach (string renameToName in renameToBeRemoved)
            {
                m_unresolvedRenames.Remove(renameToName);
            }

            foreach (CCBatchedItem addItem in m_unresolvedAdds.Values)
            {
                foreach (CCBatchedItem renameItem in m_unresolvedRenames.Values)
                {
                    if (ClearCasePath.IsSubItem(addItem.Target, renameItem.Target))
                    {
                        // Add folder2/1.txt, Rename folder1 to folder2.
                        scheduleItem(addItem, renameItem);
                    }
                    else if (ClearCasePath.IsSubItem(renameItem.Target, addItem.Target))
                    {
                        // Rename folder1/1.txt to folder1/2.txt, Add folder1
                        scheduleItem(renameItem, addItem);
                    }
                    else if (ClearCasePath.IsSubItem(addItem.Target, renameItem.Source))
                    {
                        // Rename folder1 to folder2, Add folder1/1.txt
                        scheduleItem(addItem, renameItem);
                    }
                    else if (ClearCasePath.Equals(renameItem.Source, addItem.Target) && ClearCasePath.IsSubItem(renameItem.Target, addItem.Target))
                    {
                        // ToDo Rename to below itself.
                        throw new NotImplementedException("Don't know how to handle rename to below itself problem.");
                    }
                    else
                    {
                        Debug.Assert(!ClearCasePath.IsSubItem(renameItem.Source, addItem.Target), "Rename source cannot be the sub item of an Add");
                    }
                }
                m_unresolvedChanges.Add(addItem);
            }

            // Rename and itself
            foreach (CCBatchedItem renameItemOutLoop in m_unresolvedRenames.Values)
            {
                foreach (CCBatchedItem renameItemInnerLoop in m_unresolvedRenames.Values)
                {
                    if (ClearCasePath.Equals(renameItemInnerLoop.Target, renameItemOutLoop.Target))
                    {
                        continue;
                    }
                    if (ClearCasePath.IsSubItem(renameItemInnerLoop.Target, renameItemOutLoop.Source))
                    {
                        scheduleItem(renameItemInnerLoop, renameItemOutLoop);
                    }
                }
                m_unresolvedChanges.Add(renameItemOutLoop);
            }
        }
Пример #17
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();
        }
Пример #18
0
 /// <summary>
 /// Downloads the TFS server item to the specified path.  If the item is a directory, just create it.
 /// </summary>
 /// <param name="localPath">The local path to download the TFS server item to.</param>
 public void Download(string localPath)
 {
     if (!IsDirectory)
     {
         Utils.EnsurePathToFileExists(localPath);
         ClearCaseServer clearCaseServer = ClearCaseServer.GetInstance(m_viewName);
         string          getCmd          = string.Format("get -to \"{0}\" \"{1}\"", localPath, ClearCasePath.MakeRelative(m_versionExtendedPath));
         try
         {
             string cmdOutput = clearCaseServer.ExecuteClearToolCommand(getCmd);
         }
         catch (Exception)
         {
             throw;
         }
     }
     else
     {
         Directory.CreateDirectory(localPath);
     }
 }
Пример #19
0
        /// <summary>
        /// Process the change group.
        /// </summary>
        /// <param name="group"></param>
        /// <returns></returns>
        public ConversionResult ProcessChangeGroup(ChangeGroup group)
        {
            ConversionResult  rslt;
            CCBatchingContext ctx = new CCBatchingContext(m_clearCaseServer, GetChangeComment(group),
                                                          group, m_ccConfiguration.DownloadFolder, m_conflictManagementService, m_ccConfiguration, m_overrideTargetChange);

            int processedActionCount = 0;

            m_changeGroupHighWaterMark.Reload();

            if (m_changeGroupHighWaterMark.Value == group.ChangeGroupId)
            {
                // Todo get the last action id from ClearCase history
            }

            try
            {
                foreach (MigrationAction action in group.Actions)
                {
                    if (processedActionCount > 50000)
                    {
                        TraceManager.TraceInformation("Processed 50,000 actions");
                        processedActionCount = 0;
                    }

                    processedActionCount++;

                    if (action.State != ActionState.Pending)
                    {
                        continue;
                    }

                    if (action.Action == WellKnownChangeActionId.Add)
                    {
                        if (string.Equals(action.ItemTypeReferenceName, WellKnownContentType.VersionControlLabel.ReferenceName, StringComparison.Ordinal))
                        {
                            ctx.CacheLabel(action);
                        }
                        else if (string.Equals(action.ItemTypeReferenceName, WellKnownContentType.VersionControlLabelItem.ReferenceName, StringComparison.Ordinal) ||
                                 string.Equals(action.ItemTypeReferenceName, WellKnownContentType.VersionControlRecursiveLabelItem.ReferenceName, StringComparison.Ordinal))
                        {
                            ctx.CacheLabelItem(action);
                        }
                        else
                        {
                            // Todo handle branch and undelete seperately.
                            if (ClearCasePath.IsVobRoot(ClearCasePath.GetFullPath(action.Path)))
                            {
                                TraceManager.TraceWarning("Skipped the change action that creates vob itself");
                                continue;
                            }
                            ctx.AddSingleItem(action, WellKnownChangeActionId.Add);
                        }
                    }
                    else if ((action.Action == WellKnownChangeActionId.Branch) ||
                             (action.Action == WellKnownChangeActionId.BranchMerge) ||
                             (action.Action == WellKnownChangeActionId.Undelete))
                    {
                        // Todo handle branch and undelete seperately.
                        if (ClearCasePath.IsVobRoot(ClearCasePath.GetFullPath(action.Path)))
                        {
                            TraceManager.TraceWarning("Skipped the change action that creates vob itself");
                            continue;
                        }
                        ctx.AddSingleItem(action, WellKnownChangeActionId.Add);
                    }
                    else if (action.Action == WellKnownChangeActionId.Edit)
                    {
                        ctx.AddSingleItem(action, WellKnownChangeActionId.Edit);
                    }
                    else if (action.Action == WellKnownChangeActionId.Delete)
                    {
                        ctx.AddSingleItem(action, WellKnownChangeActionId.Delete);
                    }
                    else if (action.Action == WellKnownChangeActionId.Rename)
                    {
                        if (ClearCasePath.Equals(action.Path, action.FromPath))
                        {
                            // Skip case-only rename.
                            continue;
                        }
                        ctx.AddSingleItem(action, WellKnownChangeActionId.Rename);
                    }
                    else if (action.Action == WellKnownChangeActionId.Merge)
                    {
                        continue;
                    }
                    else if (action.Action == WellKnownChangeActionId.AddFileProperties)
                    {
                        ctx.AddSingleItem(action, WellKnownChangeActionId.AddFileProperties);
                    }
                }

                rslt          = new ConversionResult(m_configurationService.SourceId, m_configurationService.MigrationPeer);
                rslt.ChangeId = m_clearCaseServer.GetRelativePathFromVobAbsolutePath(ctx.Flush());
                rslt.ItemConversionHistory.Add(new ItemConversionHistory(group.Name, string.Empty, rslt.ChangeId, string.Empty));
                rslt.ContinueProcessing = true;
                m_changeGroupHighWaterMark.Update(group.ChangeGroupId);
                if (m_hwmLastSyncedTfsChangeset != null)
                {
                    m_hwmLastSyncedTfsChangeset.Update(int.Parse(group.Name));
                }
            }
            catch (Exception e)
            {
                // Undo any pending checkouts that would have been checked in by the call to ctx.Flush() if no exception occurred.
                // (If ctx.Flush() has already been called, this will just return.)
                // It will catch and log any exception as an error, but will not throw it so that the original exception is raised as the conflict.
                ctx.CancelCachedCheckouts();

                if (!(e is MigrationUnresolvedConflictException))
                {
                    TraceManager.TraceInformation("Raising generic conflict for exception: {0}", e.Message);
                    createGenericConflict(e, group);
                }

                rslt = new ConversionResult(Guid.Empty, group.SourceId);
                rslt.ContinueProcessing = false;
            }

            return(rslt);
        }