コード例 #1
0
        protected override void SetContextItemAvailability()
        {
            base.SetContextItemAvailability();

            if (ClickedNode != null)
            {
                if (ClickedNode.Tag != null && IsFileNode(ClickedNode))
                {
                    _contextOpenMergedFile.Available = _contextOpenMergedFileDir.Available = true;
                }

                if (!IsCategoryNode(ClickedNode))
                {
                    _contextDeleteMerge.Available = _contextDeleteSeparator.Available = true;
                    if (IsModNode(ClickedNode))
                    {
                        _contextDeleteAssociatedMerges.Available = true;
                        _contextDeleteAssociatedMerges.Text      = $"Delete All {ClickedNode.Text} Merges";
                    }
                }
            }
            else if (!this.IsEmpty())
            {
                ContextSelectAll.Available = CategoryNodes.Any(catNode => !catNode.Checked);

                ContextDeselectAll.Available = FileNodes.Any(fileNode => fileNode.Checked);
            }
        }
コード例 #2
0
 private void SetConnectionsFromFile(FileNodes fn)
 {
     foreach (Tuple <int, int> item in fn.Connections)
     {
         Connections.Add(new Connection(Nodes[item.Item1], Nodes[item.Item2]));
         Nodes[item.Item1].AddNeighbour(Nodes[item.Item2]);
         Nodes[item.Item2].AddNeighbour(Nodes[item.Item1]);
     }
 }
コード例 #3
0
        /// <summary>
        /// Registers a directory to the record.
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="parentId"></param>
        /// <param name="depth"></param>
        /// <returns></returns>
        /// <exception cref="ParentNotFoundException"></exception>
        public FileNode RegisterFile(string filePath, ulong parentId, ulong depth)
        {
            var fi = new FileInfo(filePath);

            var parentNode = PathNodes.FirstOrDefault(pns => pns.PathNodeId == parentId) ??
                             RegisterParent(fi.DirectoryName);

            // check if file type already exists, else create new file type
            var typeInfo = TypeInfos.FirstOrDefault(ti => ti.Name == fi.Extension) ??
                           RegisterTypeInfo(fi.Extension);

            // register the file
            var fileNode = new FileNode()
            {
                TypeInfoId = typeInfo.TypeInfoId,
                Name       = fi.Name,
                Bytes      = fi.Length,
                ParentId   = parentNode.PathNodeId,
                Depth      = depth,
            };

            FileNodes.Add(fileNode);

            // check if typeaggregate is already registered.
            var typeAggregate =
                TypeAggregates.FirstOrDefault(ta =>
                                              ta.TypeInfoId == typeInfo.TypeInfoId && ta.PathNodeId == parentNode.PathNodeId);

            if (typeAggregate == null)
            {
                typeAggregate = new TypeAggregate()
                {
                    TypeInfoId = typeInfo.TypeInfoId,
                    PathNodeId = parentNode.PathNodeId,
                    Count      = 1,
                    Bytes      = fi.Length
                };
                TypeAggregates.Add(typeAggregate);
            }
            else
            {
                typeAggregate.Count = typeAggregate.Count + 1;
                typeAggregate.Bytes = typeAggregate.Bytes + fi.Length;
            }

            Count = Count + 1;
            Bytes = Bytes + fi.Length;

            return(fileNode);
        }
コード例 #4
0
        public override void Initialize()
        {
            //InitializeRandomPositionNodes();
            //SetRandomNeighbours();
            //SetConnections();
            //SetAllVisuals();

            FileNodes fn = new FileNodes(@"C:\Users\arojo\Downloads\custom-networks\flower-network.edges", ' ');

            NodesCount = fn.greaterNode + 1;
            InitializeRandomPositionNodes();
            SetConnectionsFromFile(fn);
            SetAllVisuals();
        }
コード例 #5
0
        void ContextDeleteAssociatedMerges_Click(object sender, EventArgs e)
        {
            if (RightClickedNode == null || !IsModNode(RightClickedNode))
            {
                return;
            }

            // Find all file nodes that contain a node matching the clicked node
            var fileNodes = FileNodes.Where(node =>
                                            node.GetTreeNodes().Any(modNode =>
                                                                    modNode.Text == RightClickedNode.Text));

            Program.MainForm.DeleteMerges(fileNodes);
        }
コード例 #6
0
        public override int Create(string fileName,
                                   uint createOptions,
                                   uint grantedAccess,
                                   uint fileAttributes,
                                   byte []     securityDescriptor,
                                   ulong allocationSize,
                                   out object fileNode,
                                   out object fileDesc,
                                   out FileInfo fileInfo,
                                   out string normalizedName)
        {
            string normalizedFileName =
                fileName.Normalize(NormalizationForm.FormD).TrimEnd('\\');

            List <string> directoryDependency = normalizedFileName.
                                                Split(
                '\\',
                StringSplitOptions.RemoveEmptyEntries).
                                                SkipLast(1).
                                                ToList( );

            StringBuilder currentDirectory = new StringBuilder("\\");

            foreach (string path in directoryDependency)
            {
                currentDirectory.Append(path);

                string currentDirectoryFileName = currentDirectory.ToString( );

                FileMetadata directoryMetadata;
                lock ( DataContext )
                {
                    directoryMetadata = DataContext.FileMetadata.SingleOrDefault(
                        fileMetadata
                        => fileMetadata.
                        Name
                        == currentDirectoryFileName);
                }

                if (directoryMetadata is null)
                {
                    CreateDirectory(currentDirectoryFileName);
                }

                currentDirectory.Append('\\');
            }

            FileMetadata metadata;

            lock ( DataContext )
            {
                metadata = DataContext.FileMetadata.SingleOrDefault(
                    (fileMetadata)
                    => fileMetadata.Name
                    == normalizedFileName);
            }

            if (metadata != null)
            {
                if ((createOptions & FILE_DIRECTORY_FILE) != 0)
                {
                    //Directory

                    fileNode = null;
                }
                else
                {
                    //File

                    if (FileNodes.TryGetValue(metadata.Guid, out FileNode node))
                    {
                        node.ReferenceCount++;
                        node.ClosedTime = null;
                        fileNode        = node;
                    }
                    else
                    {
                        node = new FileNode(metadata);
                        lock ( DataContext )
                        {
                            node.Blocks = DataContext.BlockMetadata.
                                          Where(
                                block
                                => block.File
                                == metadata.Guid).
                                          OrderBy(
                                block
                                => block.BlockSequence).
                                          ToList( );
                        }

                        lock ( FileNodes )
                        {
                            FileNodes.Add(metadata.Guid, node);
                        }

                        fileNode = node;
                    }
                }
            }
            else
            {
                if ((createOptions & FILE_DIRECTORY_FILE) != 0)
                {
                    //Directory
                    metadata = CreateDirectory(
                        normalizedFileName,
                        fileAttributes,
                        securityDescriptor);

                    fileNode = null;
                }
                else
                {
                    //File

                    int allocatedBlockCount =
                        ( int )((( long )allocationSize + BlockSize - 1) / BlockSize);

                    metadata = CreateFile(
                        normalizedFileName,
                        allocatedBlockCount,
                        fileAttributes,
                        securityDescriptor);

                    List <BlockMetadata> blocks = new List <BlockMetadata> (allocatedBlockCount);

                    for (int sequenceNumber = 0;
                         sequenceNumber < allocatedBlockCount;
                         sequenceNumber++)
                    {
                        blocks.Add(CreateBlock(metadata.Guid, sequenceNumber));
                    }

                    FileNode node = new FileNode(metadata)
                    {
                        Blocks = blocks
                    };

                    FileNodes.Add(metadata.Guid, node);

                    fileNode = node;

                    FlushMetadata( );
                }
            }

            fileDesc       = metadata;
            fileInfo       = metadata.FileInfo;
            normalizedName = normalizedFileName;

            return(STATUS_SUCCESS);
        }
コード例 #7
0
 public void AddChildFile(FileNode fileNode)
 {
     FileNodes.Add(fileNode);
 }