Exemplo n.º 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="Info"></param>
 /// <param name="Ids"></param>
 /// <returns></returns>
 private bool BuildHasAnyTags(NetMessage_GetBuildsResponse.BuildInfo Info, List <Guid> Ids)
 {
     foreach (Tag Tag in Info.Tags)
     {
         if (Ids.Contains(Tag.Id))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 2
0
        /// <summary>
        /// </summary>
        /// <param name="State"></param>
        public Guid GetTargetManifestForVirtualPath(string 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 = BuildInfo.Guid;
                if (ManifestId != Guid.Empty)
                {
                    return(ManifestId);
                }
            }

            // Look through children and return latest.
            List <VirtualFileSystemNode> Children    = BuildFileSystem.GetChildren(VirtualPath);
            VirtualFileSystemNode        NewestChild = null;

            foreach (VirtualFileSystemNode Child in Children)
            {
                if (Child.Metadata != null)
                {
                    NetMessage_GetBuildsResponse.BuildInfo BuildInfo = (NetMessage_GetBuildsResponse.BuildInfo)Child.Metadata;
                    Guid ManifestId = BuildInfo.Guid;
                    if (ManifestId != Guid.Empty)
                    {
                        if (NewestChild == null || NewestChild.CreateTime < Child.CreateTime)
                        {
                            NewestChild = Child;
                        }
                    }
                }
            }

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

            return(Guid.Empty);
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Info"></param>
        /// <param name="Ids"></param>
        /// <returns></returns>
        private bool BuildHasAllTags(NetMessage_GetBuildsResponse.BuildInfo Info, List <Guid> Ids)
        {
            foreach (Guid Id in Ids)
            {
                bool Found = false;

                foreach (Tag tag in Info.Tags)
                {
                    if (tag.Id == Id)
                    {
                        Found = true;
                        break;
                    }
                }

                if (!Found)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        private void SetupFileSystem()
        {
            RequestedBuildPaths.Clear();

            Model.Nodes.Clear();

            BuildFileSystem = new VirtualFileSystem();
            BuildFileSystem.ChildrenRefreshInterval = 5 * 1000;
            BuildFileSystem.AutoRefreshChildren     = false;

            BuildFileSystem.OnRequestChildren += (FileSystem, Path) =>
            {
                if (Program.NetClient != null)
                {
                    RequestedBuildPaths.Add(Path);
                    Program.NetClient.RequestBuilds(Path);
                }
            };

            BuildFileSystem.OnNodeUpdated += (FileSystem, Node) =>
            {
                Node ModelNode = GetNodeByPath(Node.Path);
                if (ModelNode != null)
                {
                    UpdateNode(ModelNode as DownloadFileSystemTreeNode, Node);
                }

                MainTreeView.Refresh();
            };

            BuildFileSystem.OnNodeAdded += (FileSystem, Node) =>
            {
                // Ignore internal parts of the heirarchy.
                if (Node.Path.Contains("$") && !ShowInternal)
                {
                    return;
                }

                Collection <Node> NodeCollection = Model.Root.Nodes;
                if (Node.Parent != null && Node.Parent.Name != "")
                {
                    NodeCollection = GetNodeByPath(Node.Parent.Path).Nodes;
                }

                DownloadFileSystemTreeNode TrNode = new DownloadFileSystemTreeNode();
                TrNode.IsBuildContainer = false;

                DateTime SortTime = DateTime.UtcNow;
                if (Node.Metadata != null)
                {
                    NetMessage_GetBuildsResponse.BuildInfo BuildInfo = (NetMessage_GetBuildsResponse.BuildInfo)Node.Metadata;
                    SortTime = Node.CreateTime;
                }

                // Insert based on create time.
                bool Inserted = false;
                for (int i = 0; i < NodeCollection.Count; i++)
                {
                    DownloadFileSystemTreeNode SubNode = NodeCollection[i] as DownloadFileSystemTreeNode;
                    if (SubNode != null && (SubNode.CreateTime.Ticks - SortTime.Ticks) < -10000000) // At least a second off.
                    {
                        NodeCollection.Insert(i, TrNode);
                        Inserted = true;
                        break;
                    }
                }

                if (!Inserted)
                {
                    NodeCollection.Add(TrNode);
                }

                UpdateNode(TrNode, Node);

                // If parent node is expanded, then request all children of this node.
                TreeNodeAdv ParentViewNode = null;
                if (TrNode.Parent != null)
                {
                    DownloadFileSystemTreeNode ParentNode = TrNode.Parent as DownloadFileSystemTreeNode;
                    if (ParentNode != null)
                    {
                        ParentViewNode = GetViewNodeByPath(ParentNode.FullPath);
                    }
                    else
                    {
                        ParentViewNode = MainTreeView.Root;
                    }
                }

                if (ParentViewNode == null || ParentViewNode.IsExpanded)
                {
                    if (!TrNode.IsBuild)
                    {
                        BuildFileSystem.GetChildrenNames(Node.Path);
                    }
                }

                MainTreeView.FullUpdate();

                SelectNextPath();

                OnDateUpdated?.Invoke(this, null);
            };

            BuildFileSystem.OnNodeRemoved += (FileSystem, Node) =>
            {
                // Ignore internal parts of the heirarchy.
                if (Node.Path.Contains("$") && !ShowInternal)
                {
                    return;
                }

                Node ModelNode = GetNodeByPath(Node.Path);
                if (ModelNode != null && ModelNode.Parent != null)
                {
                    ModelNode.Parent.Nodes.Remove(ModelNode);
                }
            };

            BuildFileSystem.Init();
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="TrNode"></param>
        /// <param name="Node"></param>
        private void UpdateNode(DownloadFileSystemTreeNode TrNode, VirtualFileSystemNode Node)
        {
            TrNode.FullPath         = Node.Path;
            TrNode.Name             = Node.Name;
            TrNode.Icon             = Resources.appbar_box;
            TrNode.AvailabilityIcon = null;

            if (Node.Metadata != null)
            {
                NetMessage_GetBuildsResponse.BuildInfo BuildInfo = (NetMessage_GetBuildsResponse.BuildInfo)Node.Metadata;

                TrNode.IsBuild             = BuildInfo.Guid != Guid.Empty;
                TrNode.ManifestId          = BuildInfo.Guid;
                TrNode.CreateTime          = Node.CreateTime;
                TrNode.SizeFormatted       = StringUtils.FormatAsSize((long)BuildInfo.TotalSize);
                TrNode.CreateTimeFormatted = BuildInfo.CreateTime.ToString("dd/MM/yyyy HH:mm");

                // 9        = very high
                // 7,8      = high
                // 4,5,6,   = medium
                // 2,3      = low
                // 1        = very low
                // 0        = not

                TrNode.Availability = BuildInfo.AvailablePeers + " peers have entire build";
                if (BuildInfo.AvailablePeers >= 9)
                {
                    TrNode.AvailabilityIcon = Resources.appbar_connection_quality_veryhigh;
                }
                else if (BuildInfo.AvailablePeers >= 7)
                {
                    TrNode.AvailabilityIcon = Resources.appbar_connection_quality_high;
                }
                else if (BuildInfo.AvailablePeers >= 3)
                {
                    TrNode.AvailabilityIcon = Resources.appbar_connection_quality_medium;
                }
                else if (BuildInfo.AvailablePeers >= 2)
                {
                    TrNode.AvailabilityIcon = Resources.appbar_connection_quality_low;
                }
                else if (BuildInfo.AvailablePeers >= 1)
                {
                    TrNode.AvailabilityIcon = Resources.appbar_connection_quality_verylow;
                }
                else
                {
                    TrNode.AvailabilityIcon = Resources.appbar_close;
                    TrNode.Availability     = "Last available " + BuildInfo.LastSeenOnPeer.ToString("dd/MM/yyyy HH:mm");
                }

                if (BuildInfo.Tags != null)
                {
                    TrNode.Tags          = BuildInfo.Tags;
                    TrNode.TagsFormatted = "";
                    foreach (Tag Tag in BuildInfo.Tags)
                    {
                        if (TrNode.TagsFormatted.Length > 0)
                        {
                            TrNode.TagsFormatted += ", ";
                        }
                        TrNode.TagsFormatted += Tag.Name;
                    }
                }
                else
                {
                    TrNode.TagsFormatted = "";
                }
            }
            else
            {
                TrNode.IsBuild    = false;
                TrNode.ManifestId = Guid.Empty;
                TrNode.CreateTime = DateTime.UtcNow;
            }

            if (!TrNode.IsBuild)
            {
                TrNode.SizeFormatted       = "";
                TrNode.Availability        = "";
                TrNode.CreateTimeFormatted = "";
                TrNode.AvailabilityIcon    = null;
                TrNode.TagsFormatted       = "";
            }

            if (TrNode.IsBuild)
            {
                TrNode.Icon = Resources.appbar_box;
            }
            else if (TrNode.IsBuildContainer)
            {
                TrNode.Icon = Resources.appbar_database;
            }
            else
            {
                TrNode.Icon = Resources.appbar_folder_open;
            }

            // If its a build, the folder parent becomes a "container".
            if (TrNode.IsBuild && TrNode.Parent != null)
            {
                DownloadFileSystemTreeNode ParentNode = TrNode.Parent as DownloadFileSystemTreeNode;
                if (ParentNode != null)
                {
                    ParentNode.IsBuildContainer = true;
                    ParentNode.Icon             = Resources.appbar_database;
                }
            }
        }