Ejemplo n.º 1
0
 private void InsertFiles(TreeDirectory directory, bool oneLevel)
 {
     if (!oneLevel)
     {
         foreach (var subFolder in directory.Directories)
         {
             InsertFiles(subFolder, false);
         }
     }
     foreach (var commit in directory.Commits)
     {
         var item = new TreeCommitListItem(commit, true);
         item.Activated            += OnItemActivated;
         item.ContextMenuRequested += OnItemContextMenuRequested;
         _itemHost.AddSafe(item);
     }
     foreach (var file in directory.Files)
     {
         var item = new TreeFileListItem(file, true);
         item.Activated            += OnItemActivated;
         item.ContextMenuRequested += OnItemContextMenuRequested;
         _itemHost.AddSafe(item);
     }
     _trackedDirectories.Add(directory);
     if (!oneLevel)
     {
         directory.DirectoryAdded += OnDirectoryAdded2;
     }
     directory.FileAdded   += OnFileAdded;
     directory.CommitAdded += OnCommitAdded;
     directory.Deleted     += OnDirectoryDeleted;
 }
Ejemplo n.º 2
0
            internal static TreeDirectory GetHierarchicalDirectory(XmpDirectory directories)
            {
                TreeDirectory root = new TreeDirectory();

                TreeDirectory[] treeNodes = directories.XmpMeta.Properties.Where(x => x.Path != null).Select(x => new TreeDirectory(x)).ToArray();

                var possibleChildrean = treeNodes.Select(x => new
                {
                    Element           = x,
                    PossibleChildrean = treeNodes.Where(y => y.Element.Path != x.Element.Path && y.Element.Path.StartsWith(x.Element.Path)).ToArray()
                }).ToArray();
                var childOfRoot = possibleChildrean.Where(x => !possibleChildrean.Any(y => y.PossibleChildrean.Contains(x.Element))).ToArray();

                root.Childrean.AddRange(childOfRoot.Select(x => x.Element));
                foreach (var child in childOfRoot)
                {
                    child.Element.Parent = root;
                }

                foreach (var node in possibleChildrean)
                {
                    TreeDirectory[] childOfNode = node.PossibleChildrean.Where(x => !possibleChildrean.Any(y => node.PossibleChildrean.Contains(y.Element) && y.PossibleChildrean.Contains(x))).ToArray();

                    node.Element.Childrean.AddRange(childOfNode);
                    foreach (TreeDirectory child in childOfNode)
                    {
                        child.Parent = node.Element;
                    }
                }

                return(root);
            }
Ejemplo n.º 3
0
 private void UpdateCurrentDirectory(TreeDirectory directory)
 {
     if (_currentDirectory != directory)
     {
         _currentDirectory = directory;
         OnCurrentDirectoryChanged();
     }
 }
Ejemplo n.º 4
0
        public TreeDirectoriesBinding(CustomListBoxItemsCollection itemHost, TreeDirectory root, bool showRoot)
        {
            Verify.Argument.IsNotNull(itemHost, "itemHost");
            Verify.Argument.IsNotNull(root, "root");

            _itemHost = itemHost;
            _root     = root;

            InitTree(showRoot);
        }
Ejemplo n.º 5
0
        public TreeDirectoriesBinding(CustomListBoxItemsCollection itemHost, TreeDirectory root, bool showRoot)
        {
            Verify.Argument.IsNotNull(itemHost, "itemHost");
            Verify.Argument.IsNotNull(root, "root");

            _itemHost = itemHost;
            _root = root;

            InitTree(showRoot);
        }
Ejemplo n.º 6
0
 private void OnDirectoryTreeSelectionChanged(object sender, EventArgs e)
 {
     if (_directoryTree.SelectedItems.Count != 0)
     {
         var treeItem = (_directoryTree.SelectedItems[0] as TreeDirectoryListItem);
         if (_currentDirectory != treeItem.DataContext)
         {
             _currentDirectory = treeItem.DataContext;
             _treeContent.SetTree(_currentDirectory, TreeListBoxMode.ShowDirectoryContent);
             OnCurrentDirectoryChanged();
         }
     }
 }
Ejemplo n.º 7
0
        private TreeItemModel CreateDirectoryNode(DirectoryInfo directoryInfo)
        {
            var directoryNode = new TreeDirectory(directoryInfo);

            foreach (var directory in directoryInfo.GetDirectories())
            {
                directoryNode.Nodes.Add(CreateDirectoryNode(directory));
            }

            foreach (var file in directoryInfo.GetFiles())
            {
                directoryNode.Nodes.Add(new TreeFile(file));
            }

            return(directoryNode);
        }
Ejemplo n.º 8
0
        private TreeItemModel CreateDirectoryNode(DirectoriesConfigInfo directoryConfigInfo)
        {
            var directoryConfigNode = new TreeDirectory(directoryConfigInfo.DirectoryInfo, directoryConfigInfo.ConfigInfo.ToString());

            foreach (var directory in directoryConfigInfo.GetDirectories())
            {
                directoryConfigNode.Nodes.Add(CreateDirectoryNode(directory));
            }

            foreach (var file in directoryConfigInfo.GetFiles())
            {
                directoryConfigNode.Nodes.Add(new TreeFile(file.FileInfo, file.ConfigInfo.ToString()));
            }

            return(directoryConfigNode);
        }
Ejemplo n.º 9
0
 private static bool HasRevertableItems(TreeDirectory directory)
 {
     foreach (var file in directory.Files)
     {
         if (file.Status == FileStatus.Removed || file.Status == FileStatus.Modified)
         {
             return(true);
         }
     }
     foreach (var dir in directory.Directories)
     {
         if (HasRevertableItems(dir))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 10
0
        public TreeBinding(CustomListBoxItemsCollection itemHost, TreeDirectory root, bool filesOnly, bool oneLevel)
        {
            Verify.Argument.IsNotNull(itemHost, "itemHost");
            Verify.Argument.IsNotNull(root, "root");

            _itemHost = itemHost;
            _root = root;
            _plain = filesOnly;

            if(filesOnly)
            {
                InitPlain(oneLevel);
            }
            else
            {
                InitTree(oneLevel);
            }
        }
Ejemplo n.º 11
0
        public TreeBinding(CustomListBoxItemsCollection itemHost, TreeDirectory root, bool filesOnly, bool oneLevel)
        {
            Verify.Argument.IsNotNull(itemHost, nameof(itemHost));
            Verify.Argument.IsNotNull(root, nameof(root));

            _itemHost = itemHost;
            _root     = root;
            _plain    = filesOnly;

            if (filesOnly)
            {
                InitPlain(oneLevel);
            }
            else
            {
                InitTree(oneLevel);
            }
        }
Ejemplo n.º 12
0
        private void OnItemActivated(object sender, ItemEventArgs e)
        {
            var item = e.Item as TreeFileListItem;

            if (item != null)
            {
                var fileName = DataSource.Data.ExtractBlobToTemporaryFile(item.DataContext.RelativePath);
                if (!string.IsNullOrWhiteSpace(fileName))
                {
                    var process = Utility.CreateProcessFor(fileName);
                    process.EnableRaisingEvents = true;
                    process.Exited += OnFileViewerProcessExited;
                    process.Start();
                }
            }
            else
            {
                var folderItem = e.Item as TreeDirectoryListItem;
                if (folderItem != null)
                {
                    var directoryEntry = FindDirectoryEntry(folderItem.DataContext);
                    if (directoryEntry != null)
                    {
                        if (directoryEntry.IsSelected)
                        {
                            _treeContent.SetTree(folderItem.DataContext, TreeListBoxMode.ShowDirectoryContent);
                        }
                        else
                        {
                            directoryEntry.FocusAndSelect();
                        }
                    }
                    else
                    {
                        _treeContent.SetTree(folderItem.DataContext, TreeListBoxMode.ShowDirectoryContent);
                    }
                    _currentDirectory = folderItem.DataContext;
                    OnCurrentDirectoryChanged();
                }
            }
        }
        public IEnumerable <ITreeFile> CreateFileTree(IEnumerable <FileDiff> fileDiffs, string rootFileName = "test",
                                                      char separator = '/')
        {
            var entryFile = new TreeDirectory(rootFileName);

            foreach (var fileDiff in fileDiffs.Where(x => !string.IsNullOrEmpty(x.DisplayFileName.Trim())))
            {
                ITreeFile currentFile = entryFile;

                var pathChunks = fileDiff.DisplayFileName.Split(separator);
                var lastItem   = pathChunks.Last();
                foreach (var pathChunk in pathChunks)
                {
                    var tmp = currentFile.Files.Where(x => x.Name.Equals(pathChunk));
                    if (tmp.Any())
                    {
                        currentFile = tmp.Single();
                    }
                    else
                    {
                        ITreeFile newItem;
                        if (lastItem.Equals(pathChunk))
                        {
                            newItem = new TreeFile(pathChunk, fileDiff);
                        }
                        else
                        {
                            newItem = new TreeDirectory(pathChunk);
                        }

                        currentFile.Files.Add(newItem);
                        currentFile = newItem;
                    }
                }
            }

            ExpandTree(entryFile.Files);

            return(entryFile.Files);
        }
Ejemplo n.º 14
0
        public void SetTree(TreeDirectory root, TreeListBoxMode mode)
        {
            BeginUpdate();
            ShowTreeLines =
                mode != TreeListBoxMode.ShowPlainFileList &&
                mode != TreeListBoxMode.ShowDirectoryContent;
            ShowRootTreeLines = mode != TreeListBoxMode.ShowDirectoryTree;
            if (_binding != null)
            {
                _binding.Dispose();
                _binding    = null;
                _repository = null;
            }
            if (root != null)
            {
                switch (mode)
                {
                case TreeListBoxMode.ShowFullTree:
                    _binding = new TreeBinding(Items, root, false);
                    break;

                case TreeListBoxMode.ShowPlainFileList:
                    _binding = new TreeBinding(Items, root, true);
                    break;

                case TreeListBoxMode.ShowDirectoryContent:
                    _binding = new TreeBinding(Items, root, false, true);
                    break;

                case TreeListBoxMode.ShowDirectoryTree:
                    _binding = new TreeDirectoriesBinding(Items, root, true);
                    break;

                default:
                    throw new ArgumentException("Invalid mode.", "mode");
                }
                _repository = root.Repository;
            }
            EndUpdate();
        }
Ejemplo n.º 15
0
 public void SetTree(TreeDirectory root, TreeListBoxMode mode)
 {
     BeginUpdate();
     ShowTreeLines =
         mode != TreeListBoxMode.ShowPlainFileList &&
         mode != TreeListBoxMode.ShowDirectoryContent;
     ShowRootTreeLines = mode != TreeListBoxMode.ShowDirectoryTree;
     if(_binding != null)
     {
         _binding.Dispose();
         _binding = null;
         _repository = null;
     }
     if(root != null)
     {
         switch(mode)
         {
             case TreeListBoxMode.ShowFullTree:
                 _binding = new TreeBinding(Items, root, false);
                 break;
             case TreeListBoxMode.ShowPlainFileList:
                 _binding = new TreeBinding(Items, root, true);
                 break;
             case TreeListBoxMode.ShowDirectoryContent:
                 _binding = new TreeBinding(Items, root, false, true);
                 break;
             case TreeListBoxMode.ShowDirectoryTree:
                 _binding = new TreeDirectoriesBinding(Items, root, true);
                 break;
             default:
                 throw new ArgumentException("Invalid mode.", "mode");
         }
         _repository = root.Repository;
     }
     EndUpdate();
 }
Ejemplo n.º 16
0
        /// <inheritdoc />
        public IEnumerable <IDocument> Execute(IReadOnlyList <IDocument> inputs, IExecutionContext context)
        {
            return(inputs.Select(context, input =>
            {
                MetadataExtractor.Formats.Xmp.XmpDirectory xmpDirectory;
                try
                {
                    using (var stream = input.GetStream())
                    {
                        xmpDirectory = ImageMetadataReader.ReadMetadata(stream).OfType <XmpDirectory>().FirstOrDefault();
                    }
                }
                catch (Exception)
                {
                    xmpDirectory = null;
                }
                if (xmpDirectory == null)  // Try to read sidecarfile
                {
                    FilePath sourceFilePath = input.FilePath(Keys.SourceFilePath);
                    if (sourceFilePath != null)
                    {
                        IFile sidecarFile = context.FileSystem.GetInputFile(sourceFilePath.FullPath + ".xmp");
                        if (sidecarFile.Exists)
                        {
                            string xmpXml = sidecarFile.ReadAllText();
                            xmpDirectory = new XmpReader().Extract(xmpXml);
                        }
                    }
                }
                if (xmpDirectory == null)
                {
                    if (_toSearch.Any(y => y.IsMandatory))
                    {
                        Trace.Warning($"File doe not contain Metadata or sidecar file ({input.SourceString()})");
                        if (_skipElementOnMissingData)
                        {
                            return null;
                        }
                    }
                    return input;
                }

                Dictionary <string, object> newValues = new Dictionary <string, object>();

                TreeDirectory hierarchicalDirectory = TreeDirectory.GetHierarchicalDirectory(xmpDirectory);

                foreach (var search in _toSearch)
                {
                    try
                    {
                        TreeDirectory metadata = hierarchicalDirectory.Childrean.FirstOrDefault(y => search.PathWithoutNamespacePrefix == y.ElementName && search.Namespace == y.ElementNameSpace);

                        if (metadata == null)
                        {
                            if (search.IsMandatory)
                            {
                                Trace.Error($"Metadata does not Contain {search.XmpPath} ({input.SourceString()})");
                                if (_skipElementOnMissingData)
                                {
                                    return null;
                                }
                            }
                            continue;
                        }
                        object value = GetObjectFromMetadata(metadata, hierarchicalDirectory);
                        if (newValues.ContainsKey(search.MetadataKey) && _errorOnDoubleKeys)
                        {
                            Trace.Error($"This Module tries to write same Key multiple times {search.MetadataKey} ({input.SourceString()})");
                        }
                        else
                        {
                            newValues[search.MetadataKey] = value;
                        }
                    }
                    catch (Exception e)
                    {
                        Trace.Error($"An exception occurred : {e} {e.Message}");
                        if (search.IsMandatory && _skipElementOnMissingData)
                        {
                            return null;
                        }
                    }
                }
                return newValues.Any() ? context.GetDocument(input, newValues) : input;
            }).Where(x => x != null));
        }
Ejemplo n.º 17
0
 private static bool HasRevertableItems(TreeDirectory directory)
 {
     foreach(var file in directory.Files)
     {
         if(file.Status == FileStatus.Removed || file.Status == FileStatus.Modified)
         {
             return true;
         }
     }
     foreach(var dir in directory.Directories)
     {
         if(HasRevertableItems(dir))
         {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 18
0
 public TreeBinding(CustomListBoxItemsCollection itemHost, TreeDirectory root, bool filesOnly)
     : this(itemHost, root, filesOnly, false)
 {
 }
Ejemplo n.º 19
0
            internal static TreeDirectory GetHierarchicalDirectory(XmpDirectory directories)
            {
                TreeDirectory root = new TreeDirectory();

                TreeDirectory[] treeNodes = directories.XmpMeta.Properties.Where(x => x.Path != null).Select(x => new TreeDirectory(x)).ToArray();

                var possibleChildrean = treeNodes.Select(x => new
                {
                    Element = x,
                    PossibleChildrean = treeNodes.Where(y => y.Element.Path != x.Element.Path && y.Element.Path.StartsWith(x.Element.Path)).ToArray()
                }).ToArray();
                var childOfRoot = possibleChildrean.Where(x => !possibleChildrean.Any(y => y.PossibleChildrean.Contains(x.Element))).ToArray();

                root.Childrean.AddRange(childOfRoot.Select(x => x.Element));
                foreach (var child in childOfRoot)
                {
                    child.Element.Parent = root;
                }

                foreach (var node in possibleChildrean)
                {
                    TreeDirectory[] childOfNode = node.PossibleChildrean.Where(x => !possibleChildrean.Where(y => node.PossibleChildrean.Contains(y.Element)).Any(y => y.PossibleChildrean.Contains(x))).ToArray();

                    node.Element.Childrean.AddRange(childOfNode);
                    foreach (var child in childOfNode)
                    {
                        child.Parent = node.Element;
                    }

                }

                return root;
            }
Ejemplo n.º 20
0
 private static TreeDirectoryListItem FindDirectoryEntry(TreeDirectoryListItem root, TreeDirectory folder)
 {
     if (root.DataContext == folder)
     {
         return(root);
     }
     foreach (TreeDirectoryListItem item in root.Items)
     {
         var subSearch = FindDirectoryEntry(item, folder);
         if (subSearch != null)
         {
             return(subSearch);
         }
     }
     return(null);
 }
Ejemplo n.º 21
0
        private object GetObjectFromMetadata(TreeDirectory metadata, TreeDirectory hirachciDirectory)
        {
            if (metadata.Element.Options.IsArray)
            {
                IOrderedEnumerable <TreeDirectory> arreyElemnts = metadata.Childrean.Where(x => x.IsArrayElement).OrderBy(x => x.ElementArrayIndex);
                object[] array = arreyElemnts.Select(y => GetObjectFromMetadata(y, hirachciDirectory)).ToArray();
                if (_delocalizing && array.All(x => x is LocalizedString))
                {
                    CultureInfo     systemCulture  = System.Globalization.CultureInfo.CurrentCulture;
                    LocalizedString matchingString = null;
                    do
                    {
                        matchingString = array.OfType <LocalizedString>().FirstOrDefault(x => x.Culture.Equals(systemCulture));
                        if (systemCulture.Parent.Equals(systemCulture))
                        {
                            // We are at the Culture Root. so break or run for ever.
                            break;
                        }
                        systemCulture = systemCulture.Parent;
                    }while (matchingString == null);

                    if (matchingString != null)
                    {
                        return(matchingString.Value);
                    }
                }
                if (_flatten && array.Length == 1)
                {
                    return(array[0]);
                }

                return(array);
            }
            else if (metadata.Element.Options.IsStruct)
            {
                IDictionary <string, object> obj        = new System.Dynamic.ExpandoObject();
                List <TreeDirectory>         properties = metadata.Childrean; // directories.XmpMeta.Properties.Where(x => x.Path != null && x.Path.StartsWith(metadata.Path))

                foreach (TreeDirectory prop in properties)
                {
                    obj.Add(prop.ElementName, GetObjectFromMetadata(prop, hirachciDirectory));
                }
                return(obj);
            }
            else if (metadata.Element.Options.IsSimple)
            {
                // xml:lang, de

                if (metadata.Element.Options.HasLanguage)
                {
                    TreeDirectory langMetadata = metadata.Childrean.Single(x => x.ElementName == "lang" && x.ElementNameSpace == "http://www.w3.org/XML/1998/namespace");
                    System.Globalization.CultureInfo culture;
                    if (langMetadata.ElementValue == "x-default")
                    {
                        culture = CultureInfo.InvariantCulture;
                    }
                    else
                    {
                        culture = System.Globalization.CultureInfo.GetCultureInfo(langMetadata.ElementValue);
                    }

                    return(new LocalizedString()
                    {
                        Culture = culture, Value = metadata.ElementValue
                    });
                }

                return(metadata.ElementValue);
            }
            else
            {
                throw new NotSupportedException($"Option {metadata.Element.Options.GetOptionsString()} not supported.");
            }
        }
        public RepositoryTree GetRepositoryContent(bool includeCommitDetails)
        {
            var objects = new List <IRepositoryObject>();

            using (var repository = Open())
            {
                var branch = _getBranch(repository, _branchName);
                var commit = branch.Tip;

                var root = commit.Tree;
                if (!string.IsNullOrEmpty(Path.SubPath))
                {
                    root = root.FindSubPath(Path.SubPath) as Tree;
                    if (root == null)
                    {
                        return(null);
                    }
                }

                foreach (var entry in root)
                {
                    IRepositoryObject obj;

                    // Directory
                    if (entry.Mode == Mode.Directory)
                    {
                        obj = new TreeDirectory();
                    }
                    // File
                    else
                    {
                        obj = new TreeFile();
                    }

                    obj.Name = entry.Name;
                    obj.Path = entry.Path.Replace('\\', '/');

                    if (includeCommitDetails)
                    {
                        // TODO: Get file/directory details!
                        // https://github.com/libgit2/libgit2sharp/issues/89

                        // TODO: Get short hash.

                        // =============================

                        //obj.Commit = new ReducedCommit {
                        //    Hash = commit.Sha,
                        //    ShortHash = commit.Id.ToString(),
                        //    Message = commit.MessageShort,
                        //    CommitAuthor = commit.Committer.Name,
                        //    CommitDate = commit.Committer.When.UtcDateTime,
                        //};

                        // =============================

                        //foreach (var actualCommit in branch.Commits)
                        //{
                        //    var parentCommit = actualCommit.Parents.FirstOrDefault();
                        //    if (parentCommit == null)
                        //    {
                        //        // Assume that the object was part of the initial commit.
                        //        obj.Commit = new ReducedCommit
                        //        {
                        //            Hash = actualCommit.Sha,
                        //            ShortHash = actualCommit.Sha,
                        //            Message = actualCommit.MessageShort,
                        //            CommitAuthor = actualCommit.Committer.Name,
                        //            CommitDate = actualCommit.Committer.When.UtcDateTime,
                        //        };

                        //        break;
                        //    }

                        //    var changes =
                        //        repository.Diff.Compare(
                        //            parentCommit.Tree,
                        //            actualCommit.Tree);

                        //    if (changes.Any(change => change.Path.Equals(entry.Path)))
                        //    {
                        //        obj.Commit = new ReducedCommit {
                        //            Hash = actualCommit.Sha,
                        //            ShortHash = actualCommit.Sha,
                        //            Message = actualCommit.MessageShort,
                        //            CommitAuthor = actualCommit.Committer.Name,
                        //            CommitDate = actualCommit.Committer.When.UtcDateTime,
                        //        };

                        //        break;
                        //    }
                        //}
                    }

                    objects.Add(obj);
                }
            }

            return(new RepositoryTree {
                Directories = objects
            });
        }
Ejemplo n.º 23
0
 public TreeBinding(CustomListBoxItemsCollection itemHost, TreeDirectory root, bool filesOnly)
     : this(itemHost, root, filesOnly, false)
 {
 }
Ejemplo n.º 24
0
 private void InsertFiles(TreeDirectory directory, bool oneLevel)
 {
     if(!oneLevel)
     {
         foreach(var subFolder in directory.Directories)
         {
             InsertFiles(subFolder, false);
         }
     }
     foreach(var commit in directory.Commits)
     {
         var item = new TreeCommitListItem(commit, true);
         item.Activated += OnItemActivated;
         item.ContextMenuRequested += OnItemContextMenuRequested;
         _itemHost.AddSafe(item);
     }
     foreach(var file in directory.Files)
     {
         var item = new TreeFileListItem(file, true);
         item.Activated += OnItemActivated;
         item.ContextMenuRequested += OnItemContextMenuRequested;
         _itemHost.AddSafe(item);
     }
     _trackedDirectories.Add(directory);
     if(!oneLevel)
     {
         directory.DirectoryAdded += OnDirectoryAdded2;
     }
     directory.FileAdded += OnFileAdded;
     directory.CommitAdded += OnCommitAdded;
     directory.Deleted += OnDirectoryDeleted;
 }
Ejemplo n.º 25
0
        protected override async Task <IEnumerable <IDocument> > ExecuteInputAsync(IDocument input, IExecutionContext context)
        {
            XmpDirectory xmpDirectory;

            try
            {
                using (Stream stream = input.GetContentStream())
                {
                    xmpDirectory = ImageMetadataReader.ReadMetadata(stream).OfType <XmpDirectory>().FirstOrDefault();
                }
            }
            catch (Exception)
            {
                xmpDirectory = null;
            }
            if (xmpDirectory == null)
            {
                // Try to read sidecarfile
                if (!input.Source.IsNull)
                {
                    IFile sidecarFile = context.FileSystem.GetInputFile(input.Source.AppendExtension(".xmp"));
                    if (sidecarFile.Exists)
                    {
                        MemoryStream xmpBytes = new MemoryStream();
                        using (Stream xmpStream = sidecarFile.OpenRead())
                        {
                            await xmpStream.CopyToAsync(xmpBytes);
                        }
                        xmpDirectory = new XmpReader().Extract(xmpBytes.ToArray());
                    }
                }
            }
            if (xmpDirectory == null)
            {
                if (_toSearch.Any(y => y.IsMandatory))
                {
                    context.LogWarning($"File doe not contain Metadata or sidecar file ({input.ToSafeDisplayString()})");
                    if (_skipElementOnMissingData)
                    {
                        return(null);
                    }
                }
                return(input.Yield());
            }

            Dictionary <string, object> newValues = new Dictionary <string, object>();

            TreeDirectory hierarchicalDirectory = TreeDirectory.GetHierarchicalDirectory(xmpDirectory);

            foreach (XmpSearchEntry search in _toSearch)
            {
                try
                {
                    TreeDirectory metadata = hierarchicalDirectory.Childrean.Find(y => search.PathWithoutNamespacePrefix == y.ElementName && search.Namespace == y.ElementNameSpace);

                    if (metadata == null)
                    {
                        if (search.IsMandatory)
                        {
                            context.LogError($"Metadata does not Contain {search.XmpPath} ({input.ToSafeDisplayString()})");
                            if (_skipElementOnMissingData)
                            {
                                return(null);
                            }
                        }
                        continue;
                    }
                    object value = GetObjectFromMetadata(metadata, hierarchicalDirectory);
                    if (newValues.ContainsKey(search.MetadataKey) && _errorOnDoubleKeys)
                    {
                        context.LogError($"This Module tries to write same Key multiple times {search.MetadataKey} ({input.ToSafeDisplayString()})");
                    }
                    else
                    {
                        newValues[search.MetadataKey] = value;
                    }
                }
                catch (Exception e)
                {
                    context.LogError($"An exception occurred : {e} {e.Message}");
                    if (search.IsMandatory && _skipElementOnMissingData)
                    {
                        return(null);
                    }
                }
            }
            return(newValues.Count > 0 ? input.Clone(newValues).Yield() : input.Yield());
        }
Ejemplo n.º 26
0
 public TreeCommit(Repository repository, string relativePath, TreeDirectory parent, FileStatus status, string name)
     : base(repository, relativePath, parent, status, name)
 {
 }
Ejemplo n.º 27
0
 private TreeDirectoryListItem FindDirectoryEntry(TreeDirectory folder)
 {
     return(FindDirectoryEntry((TreeDirectoryListItem)_directoryTree.Items[0], folder));
 }
Ejemplo n.º 28
0
        private object GetObjectFromMetadata(TreeDirectory metadata, TreeDirectory hirachciDirectory)
        {
            if (metadata.Element.Options.IsArray)
            {
                var arreyElemnts = metadata.Childrean.Where(x => x.IsArrayElement).OrderBy(x => x.ElementArrayIndex);
                object[] array = arreyElemnts.Select(y => GetObjectFromMetadata(y, hirachciDirectory)).ToArray();
                if (_delocalizing && array.All(x => x is LocalizedString))
                {
                    CultureInfo systemCulture = System.Globalization.CultureInfo.CurrentCulture;
                    LocalizedString matchingString = null;
                    do
                    {
                        matchingString = array.OfType<LocalizedString>().FirstOrDefault(x => x.Culture.Equals(systemCulture));
                        if (systemCulture.Parent.Equals(systemCulture))
                            break; // We are at the Culture Root. so break or run for ever.
                        systemCulture = systemCulture.Parent;

                    } while (matchingString == null);

                    if (matchingString != null)
                        return matchingString.Value;
                }
                if (_flatten && array.Length == 1)
                    return array[0];
                return array;
            }
            else if (metadata.Element.Options.IsStruct)
            {
                IDictionary<string, object> obj = new System.Dynamic.ExpandoObject();
                List<TreeDirectory> properties = metadata.Childrean;// directories.XmpMeta.Properties.Where(x => x.Path != null && x.Path.StartsWith(metadata.Path))

                foreach (var prop in properties)
                {
                    obj.Add(prop.ElementName, GetObjectFromMetadata(prop, hirachciDirectory));
                }
                return obj;
            }
            else if (metadata.Element.Options.IsSimple)
            {
                //xml:lang, de

                if (metadata.Element.Options.HasLanguage)
                {
                    TreeDirectory langMetadata = metadata.Childrean.Single(x => x.ElementName == "lang" && x.ElementNameSpace == "http://www.w3.org/XML/1998/namespace");
                    System.Globalization.CultureInfo culture;
                    if (langMetadata.ElementValue == "x-default")
                    {
                        culture = System.Globalization.CultureInfo.InvariantCulture;
                    }
                    else
                    {
                        culture = System.Globalization.CultureInfo.GetCultureInfo(langMetadata.ElementValue);
                    }

                    return new LocalizedString() { Culture = culture, Value = metadata.ElementValue };

                }

                return metadata.ElementValue;
            }
            else
            {
                throw new NotSupportedException($"Option {metadata.Element.Options.GetOptionsString()} not supported.");
            }
        }
Ejemplo n.º 29
0
        private void BuildPath()
        {
            this.DisableRedraw();
            while (Items.Count != 2)
            {
                var item = Items[2];
                Items.RemoveAt(2);
                item.Dispose();
            }
            var stack  = new Stack <TreeDirectory>();
            var folder = _treeView.CurrentDirectory;

            if (folder != null)
            {
                while (folder != null)
                {
                    stack.Push(folder);
                    folder = folder.Parent;
                }
                TreeDirectory prev = null;
                while (stack.Count != 0)
                {
                    folder = stack.Pop();
                    var item = new ToolStripSplitButton(folder.Name, ImgFolder)
                    {
                        DisplayStyle = ToolStripItemDisplayStyle.ImageAndText,
                        Tag          = folder,
                    };
                    if (folder.Directories.Count != 0)
                    {
                        foreach (var subFolder in folder.Directories)
                        {
                            var subItem = new ToolStripMenuItem(subFolder.Name, ImgFolder)
                            {
                                Tag     = subFolder,
                                Checked = subFolder == prev,
                            };
                            subItem.Click += (sender, e) =>
                            {
                                _treeView.CurrentDirectory = (TreeDirectory)((ToolStripItem)sender).Tag;
                            };
                            item.DropDownItems.Add(subItem);
                        }
                    }
                    else
                    {
                        item.DropDownItems.Add(new ToolStripMenuItem(Resources.StrlNoSubdirectories.SurroundWith('<', '>'))
                        {
                            Enabled = false,
                        });
                    }
                    item.ButtonClick += (sender, e) =>
                    {
                        _treeView.CurrentDirectory = (TreeDirectory)((ToolStripItem)sender).Tag;
                    };
                    Items.Add(item);
                    prev = folder;
                }
            }
            this.EnableRedraw();
            this.RedrawWindow();
        }