Example #1
0
 public static Changeset GetChangeset(this IScmProvider provider, string id)
 {
     return(provider.GetChangesets(new GetChangesetsArgs
     {
         Query = id
     }).LastOrDefault());
 }
Example #2
0
        /// <summary>
        /// </summary>
        /// <param name="Provider"></param>
        public void RemoveProvider(IScmProvider Provider)
        {
            Logger.Log(LogLevel.Info, LogCategory.Scm, "Removing scm provider: {0}", Provider.ToString());

            Provider.Terminate();
            Providers.Remove(Provider);
        }
Example #3
0
 public static Changeset GetCurrentChangeset(this IScmProvider provider)
 {
     return(provider.GetChangesets(new GetChangesetsArgs
     {
         Current = true
     }).LastOrDefault());
 }
Example #4
0
 public Repository(string folder, IScmProvider provider)
 {
     if (provider == null)
     {
         provider = ScmProviderFactory.Instance.FindProviderByPath(folder);
     }
     Provider = provider;
     Folder   = folder;
 }
Example #5
0
        public static void ThrowNotSupportedException(this IScmProvider provider, string message = "")
        {
            var msg = new StringBuilder();

            msg.AppendLine($"The requested operation is not supported by {provider.Name}");
            if (!String.IsNullOrEmpty(message))
            {
                msg.AppendLine(message);
            }
            throw new NotSupportedException(msg.ToString());
        }
Example #6
0
        /// <summary>
        /// </summary>
        public void AddProvider(IScmProvider Provider)
        {
            Logger.Log(LogLevel.Info, LogCategory.Scm, "Adding scm provider: {0}", Provider.ToString());

            Providers.Add(Provider);
        }
Example #7
0
        /// <summary>
        /// </summary>
        /// <param name="State"></param>
        /// <returns></returns>
        public Guid GetTargetManifestForState(DownloadState State)
        {
            string VirtualPath = State.VirtualPath;

            VirtualFileSystemNode Node = BuildFileSystem.GetNodeByPath(VirtualPath);

            if (Node == null)
            {
                return(Guid.Empty);
            }


            // Node is a build in and of itself, use its id.
            if (Node.Metadata != null)
            {
                NetMessage_GetBuildsResponse.BuildInfo BuildInfo = (NetMessage_GetBuildsResponse.BuildInfo)Node.Metadata;
                Guid ManifestId = (Guid)BuildInfo.Guid;
                if (ManifestId != Guid.Empty)
                {
                    return(ManifestId);
                }
            }

            List <VirtualFileSystemNode> Children      = BuildFileSystem.GetChildren(VirtualPath);
            VirtualFileSystemNode        SelectedChild = null;

            List <VirtualFileSystemNode> BuildChildren = new List <VirtualFileSystemNode>();

            foreach (VirtualFileSystemNode Child in Children)
            {
                if (Child.Metadata != null)
                {
                    NetMessage_GetBuildsResponse.BuildInfo BuildInfo = (NetMessage_GetBuildsResponse.BuildInfo)Child.Metadata;
                    Guid ManifestId = (Guid)BuildInfo.Guid;
                    if (ManifestId != Guid.Empty)
                    {
                        BuildChildren.Add(Child);
                    }
                }
            }

            // Remove all children without included tags.
            for (int i = 0; i < BuildChildren.Count; i++)
            {
                VirtualFileSystemNode Child = BuildChildren[i];
                if (Child.Metadata != null)
                {
                    NetMessage_GetBuildsResponse.BuildInfo BuildInfo = (NetMessage_GetBuildsResponse.BuildInfo)Child.Metadata;
                    if (!BuildHasAllTags(BuildInfo, State.IncludeTags))
                    {
                        BuildChildren.RemoveAt(i);
                        i--;
                    }
                }
            }

            // Remove all children with any tags..
            for (int i = 0; i < BuildChildren.Count; i++)
            {
                VirtualFileSystemNode Child = BuildChildren[i];
                if (Child.Metadata != null)
                {
                    NetMessage_GetBuildsResponse.BuildInfo BuildInfo = (NetMessage_GetBuildsResponse.BuildInfo)Child.Metadata;
                    if (BuildHasAnyTags(BuildInfo, State.ExcludeTags))
                    {
                        BuildChildren.RemoveAt(i);
                        i--;
                    }
                }
            }

            List <VirtualFileSystemNode> FilteredChildren = new List <VirtualFileSystemNode>();

            switch (State.SelectionFilter)
            {
            case BuildSelectionFilter.None:
            {
                FilteredChildren = BuildChildren;
                break;
            }

            case BuildSelectionFilter.BuildTimeBeforeScmSyncTime:
            {
                IScmProvider Workspace = ScmManager.GetProvider(State.ScmWorkspaceLocation);
                if (Workspace != null)
                {
                    DateTime ScmSyncTime = Workspace.GetSyncTime();
                    if (ScmSyncTime != DateTime.MinValue)
                    {
                        foreach (VirtualFileSystemNode Child in BuildChildren)
                        {
                            if (Child.CreateTime <= ScmSyncTime)
                            {
                                FilteredChildren.Add(Child);
                            }
                        }
                    }
                }

                break;
            }

            case BuildSelectionFilter.BuildTimeAfterScmSyncTime:
            {
                IScmProvider Workspace = ScmManager.GetProvider(State.ScmWorkspaceLocation);
                if (Workspace != null)
                {
                    DateTime ScmSyncTime = Workspace.GetSyncTime();
                    if (ScmSyncTime != DateTime.MinValue)
                    {
                        foreach (VirtualFileSystemNode Child in BuildChildren)
                        {
                            if (Child.CreateTime >= ScmSyncTime)
                            {
                                FilteredChildren.Add(Child);
                            }
                        }
                    }
                }

                break;
            }

            case BuildSelectionFilter.BuildNameBelowFileContents:
            {
                string FilePath     = Path.Combine(State.ScmWorkspaceLocation, State.SelectionFilterFilePath);
                string FileContents = FileContentsCache.Get(FilePath);

                int Value = 0;
                if (int.TryParse(FileContents, out Value))
                {
                    foreach (VirtualFileSystemNode Child in BuildChildren)
                    {
                        int ChildValue = 0;
                        if (int.TryParse(Child.Name, out ChildValue))
                        {
                            if (Value <= ChildValue)
                            {
                                FilteredChildren.Add(Child);
                            }
                        }
                    }
                }

                break;
            }

            case BuildSelectionFilter.BuildNameAboveFileContents:
            {
                string FilePath     = Path.Combine(State.ScmWorkspaceLocation, State.SelectionFilterFilePath);
                string FileContents = FileContentsCache.Get(FilePath);

                int Value = 0;
                if (int.TryParse(FileContents, out Value))
                {
                    foreach (VirtualFileSystemNode Child in BuildChildren)
                    {
                        int ChildValue = 0;
                        if (int.TryParse(Child.Name, out ChildValue))
                        {
                            if (Value >= ChildValue)
                            {
                                FilteredChildren.Add(Child);
                            }
                        }
                    }
                }

                break;
            }

            case BuildSelectionFilter.BuildNameEqualsFileContents:
            {
                string FilePath     = Path.Combine(State.ScmWorkspaceLocation, State.SelectionFilterFilePath);
                string FileContents = FileContentsCache.Get(FilePath);

                foreach (VirtualFileSystemNode Child in BuildChildren)
                {
                    if (FileContents == Child.Name)
                    {
                        FilteredChildren.Add(Child);
                    }
                }

                break;
            }

            default:
            {
                Debug.Assert(false);
                break;
            }
            }

            switch (State.SelectionRule)
            {
            case BuildSelectionRule.Newest:
            {
                foreach (VirtualFileSystemNode Child in FilteredChildren)
                {
                    if (SelectedChild == null || SelectedChild.CreateTime < Child.CreateTime)
                    {
                        SelectedChild = Child;
                    }
                }

                break;
            }

            case BuildSelectionRule.Oldest:
            {
                foreach (VirtualFileSystemNode Child in FilteredChildren)
                {
                    if (SelectedChild == null || SelectedChild.CreateTime > Child.CreateTime)
                    {
                        SelectedChild = Child;
                    }
                }

                break;
            }
            }

            if (SelectedChild != null)
            {
                NetMessage_GetBuildsResponse.BuildInfo BuildInfo = (NetMessage_GetBuildsResponse.BuildInfo)SelectedChild.Metadata;
                return(BuildInfo.Guid);
            }

            return(Guid.Empty);
        }