コード例 #1
0
        public List <SAWItemInfo> GetFileHistory(string path)
        {
            bool   Cancelled;
            string ResultDescription;
            var    FileHistoryParam = new SAWSFileHistoryParam();
            bool   IsPinned;
            var    HistorySet = new SAWSHistorySet();
            bool   bDir       = false;

            if (0 != sdkObject.GetFileHistory(SAWCommon.ConvertPath(path), FileHistoryParam, out IsPinned, out HistorySet, out Cancelled, out ResultDescription))
            {
                var FolderHistoryParam = new SAWSProjectHistoryParam();
                if (0 != sdkObject.GetProjectHistory(SAWCommon.ConvertPath(path), FolderHistoryParam, out HistorySet, out Cancelled, out ResultDescription))
                {
                    return(null);
                }
                bDir = true;
            }

            var set = new List <SAWItemInfo>();

            for (int i = 0; i < HistorySet.Count; i++)
            {
                SAWSHistory w   = HistorySet.Item(i) as SAWSHistory;
                var         his = new SAWItemInfo();
                his.comment = w.Comment == null ? "" : w.Comment;
                his.date    = w.ActionDateTime;
                his.name    = w.ItemName;
                his.size    = w.FileSizeLow;
                his.user    = w.UserName;
                his.version = w.VersionNumberLow;
                his.type    = (EnumActionType)w.ActionType;
                his.isdir   = bDir;
                set.Add(his);
            }
            return(set);
        }
コード例 #2
0
ファイル: SAWHClient.cs プロジェクト: massilp/SAWHtoGit
        // Given a project, return all of the associated changesets
        public IDictionary <long, Changeset> GetProjectHistory(string project, IDictionary <string, string> movedFiles)
        {
            long ResultValue;
            SAWSProjectHistoryParam HistoryParams;
            SAWSHistorySet          HistorySet;
            bool               Cancelled;
            string             ResultDescription;
            SAWSHistoryOrderBy HistoryOrderBy;

            SortedDictionary <long, Changeset> History = new SortedDictionary <long, Changeset>();

            HistoryOrderBy = new SAWSHistoryOrderBy();
            HistoryOrderBy.HistorySortBy = Enum_HistorySortBy.Enum_HistorySortByDate;
            HistoryParams             = new SAWSProjectHistoryParam();
            HistoryParams.IsRecursive = true;
            HistoryParams.AddOrder(HistoryOrderBy);

            // ACTION: You can further tailor the history fetched by adding additional filters, such as the date one below. Note, dates are in UTC.
            //HistoryParams.DateFrom = new DateTime(2013, 1, 14).ToUniversalTime();

            Console.WriteLine("Fetching history for project {0}", project);

            ResultValue = sawObject.GetProjectHistory(project, HistoryParams, out HistorySet, out Cancelled, out ResultDescription);
            if (ResultValue == 0)
            {
                long Count = HistorySet.Count;

                foreach (ISAWSHistory HistoryItem in HistorySet)
                {
                    /*
                     * // Debugging info on the fetched history item
                     * Console.WriteLine("History Item: {0}\t{1}\t{2}\t{3}",
                     *      HistoryItem.ChangeSetIdLow | (HistoryItem.ChangeSetIdHigh << 32),
                     *      HistoryItem.HistoryIdLow | (HistoryItem.HistoryIdHigh <<32),
                     *      HistoryItem.ActionType.ToString(), HistoryItem.ActionDescription);
                     * Console.WriteLine("\tby: {0}: {1}", HistoryItem.UserName, HistoryItem.Comment);
                     * Console.WriteLine("\tItem: v{0}\t{1}\t{2}", HistoryItem.VersionNumberLow | (HistoryItem.VersionNumberHigh << 32), HistoryItem.ItemIdLow | (HistoryItem.ItemIdHigh << 32), HistoryItem.ItemName);
                     * Console.WriteLine("\ton: {0}\t{1}\t{2}", HistoryItem.ActionDateTime, HistoryItem.CheckinDateTime, HistoryItem.ModificationDateTime);
                     * Console.WriteLine("\tMerge: {0}\tProject: {1}", HistoryItem.IsMergable, HistoryItem.IsProject);
                     */

                    if (!HistoryItem.IsProject)
                    {
                        Changeset changes;
                        long      historyId = HistoryItem.HistoryIdLow | (HistoryItem.HistoryIdHigh << 32);
                        long      key       = HistoryItem.CheckinDateTime.Ticks;
                        string    filename  = HistoryItem.ItemName;

                        // Establish the associated changeset
                        if (!History.TryGetValue(key, out changes))
                        {
                            // Create new Changeset
                            changes            = new Changeset();
                            changes.CommitDate = HistoryItem.CheckinDateTime;
                            changes.Comment    = HistoryItem.Comment;
                            changes.Author     = HistoryItem.UserName;
                            changes.Id         = historyId;
                            changes.Files      = new List <SourceFile>();

                            History[key] = changes;
                        }

                        // For folders that have moved within source control, map them to the "new" path so SAW can find them
                        foreach (KeyValuePair <string, string> mapping in movedFiles)
                        {
                            if (filename.StartsWith(mapping.Key))
                            {
                                filename = filename.Replace(mapping.Key, mapping.Value);
                            }
                        }

                        // Add the current file to a changeset
                        changes.Files.Add(new SourceFile(filename, HistoryItem.VersionNumberLow, HistoryItem.VersionNumberHigh, HistoryItem.IsMergable ? SourceFile.FileType.Text : SourceFile.FileType.Binary, HistoryItem.ItemIdLow, HistoryItem.ItemIdHigh));
                    }
                }

                Console.WriteLine("Wrote {1} changesets containing {0} versions", Count, History.Count);

                /*
                 * // Debug code to enumerate all found changesets
                 * foreach (Changeset change in History.Values)
                 * {
                 *      Console.WriteLine("Change: {0} by {1} on {2}: \"{3}\"", change.Id, change.Author, change.CommitDate, change.Comment);
                 *      foreach (SourceFile file in change.Files)
                 *      {
                 *              Console.WriteLine("\tFile: {0} {1} {2}", file.VersionLow, file.ItemId, file.SourceName);
                 *      }
                 * }
                 */
            }

            return(History);
        }