Пример #1
0
        public FetchNodeCapabilities(TreeNode node)
            : base(node)
        {
            switch (Name)
            {
            case "fetch":
                Comment = false;
                ChildTypes.Add(new ChildNodeCapabilities("entity", false));
                ChildTypes.Add(new ChildNodeCapabilities("-", true));
                ChildTypes.Add(new ChildNodeCapabilities("#comment", true));
                break;

            case "entity":
            case "link-entity":
                Delete     = true;
                Attributes = true;
                ChildTypes.Add(new ChildNodeCapabilities("-", true));
                ChildTypes.Add(new ChildNodeCapabilities("all-attributes", false));
                ChildTypes.Add(new ChildNodeCapabilities("attribute", true));
                ChildTypes.Add(new ChildNodeCapabilities("filter", true));
                ChildTypes.Add(new ChildNodeCapabilities("order", true));
                ChildTypes.Add(new ChildNodeCapabilities("link-entity", true));
                ChildTypes.Add(new ChildNodeCapabilities("-", true));
                ChildTypes.Add(new ChildNodeCapabilities("#comment", true));
                break;

            case "all-attributes":
            case "attribute":
            case "order":
                Delete = true;
                ChildTypes.Add(new ChildNodeCapabilities("#comment", true));
                break;

            case "filter":
                Delete = true;
                ChildTypes.Add(new ChildNodeCapabilities("condition", true));
                ChildTypes.Add(new ChildNodeCapabilities("filter", true));
                ChildTypes.Add(new ChildNodeCapabilities("-", true));
                ChildTypes.Add(new ChildNodeCapabilities("#comment", true));
                break;

            case "condition":
                Delete = true;
                ChildTypes.Add(new ChildNodeCapabilities("value", true));
                ChildTypes.Add(new ChildNodeCapabilities("-", true));
                ChildTypes.Add(new ChildNodeCapabilities("#comment", true));
                break;

            case "value":
                Delete = true;
                ChildTypes.Add(new ChildNodeCapabilities("#comment", true));
                break;

            case "#comment":
                Delete    = true;
                Comment   = false;
                Uncomment = true;
                break;
            }
        }
Пример #2
0
        static IEnumerable <TreeNode> EnumerateUnsafe(ShellItem shellFolder, ChildTypes childFlags,
                                                      TreeNode node, IDictionary <TreeNode, ShellItem> nodesToFolders)
        {
            var numer = shellFolder.GetChildren(childFlags, false).GetEnumerator();

            while (numer.MoveNext())
            {
                ShellItem child = numer.Current;

                //  Create a child node.
                var childNode = new TreeNode
                {
                    Text               = child.DisplayName,
                    ImageIndex         = child.IconIndex,
                    SelectedImageIndex = child.IconIndex,
                };

                //  Map the node to the shell folder.
                nodesToFolders[childNode] = child;

                //  If this item has children, add a child node as a placeholder.
                if (child.HasSubFolders)
                {
                    childNode.Nodes.Add(string.Empty);
                }

                //  Add the child node.
                node.Nodes.Add(childNode);

                yield return(childNode);
            }
        }
Пример #3
0
        private CSharpIdentifier GetPropertyType(string propertyName, OpenApiSchema?schema)
        {
            if (schema?.Type == "string" && schema.Enum.Count != 0)
            {
                var dtoEnum = new DtoEnumBuilder(propertyName, schema, Naming).BuildType();
                ChildTypes.Add(dtoEnum);
                return(dtoEnum.Identifier);
            }

            return(Naming.TypeFor(schema));
        }
Пример #4
0
        private void PopulateFields(DetailsStore store)
        {
            Logger.Trace($"Populating field details for type {rawTypeDefinition.QualifiedName}.");
            FieldDetails = rawTypeDefinition.Fields
                           .Select(field => new UnityFieldDetails(field, store))
                           .Where(fieldDetail =>
            {
                var clashingChildEnums = ChildEnums
                                         .Where(childEnum =>
                {
                    // When field does not clash with child enum, return false
                    if (!fieldDetail.PascalCaseName.Equals(childEnum.Name))
                    {
                        return(false);
                    }

                    Logger.Error($"Error in type \"{Name}\". Field \"{fieldDetail.RawFieldDefinition.Name}\" clashes with child enum \"{childEnum.Name}\".");
                    return(true);
                });

                var clashingChildTypes = ChildTypes
                                         .Where(childType =>
                {
                    // When field does not clash with child type, return false
                    if (!fieldDetail.PascalCaseName.Equals(childType.Name))
                    {
                        return(false);
                    }

                    Logger.Error($"Error in type \"{Name}\". Field \"{fieldDetail.RawFieldDefinition.Name}\" clashes with child type \"{childType.CamelCaseName}\".");
                    return(true);
                });

                // Only return true if the field has no name clashes with child enums and types
                return(!clashingChildEnums.Any() && !clashingChildTypes.Any());
            })
                           .ToList()
                           .AsReadOnly();
        }
Пример #5
0
 /// <summary>
 /// Sets up the child types.
 /// </summary>
 /// <returns>The concrete types found</returns>
 private void SetupChildTypes()
 {
     Logger.Information("Setting up child type discovery for {Name:l}", Source.Name);
     ConcreteTypes = DiscoverConcreteTypes.FindConcreteTypes(TypeGraphs);
     for (var i = 0; i < ConcreteTypes.Length; i++)
     {
         var ConcreteType = ConcreteTypes[i];
         if (ConcreteType is null)
         {
             continue;
         }
         var Types = TypeGraphs[ConcreteType]?.ToList();
         if (Types is null)
         {
             continue;
         }
         for (var x = 0; x < Types.Count; x++)
         {
             ChildTypes.Add(Types[x], ConcreteType);
         }
     }
 }
Пример #6
0
        /// <summary>
        /// Gets the child mappings.
        /// </summary>
        /// <param name="objectType">Type of the object.</param>
        /// <returns>The IMapping list associated with the object type.</returns>
        public IEnumerable <IMapping> GetChildMappings(Type objectType)
        {
            if (objectType is null)
            {
                yield break;
            }

            if (objectType.Namespace.StartsWith("AspectusGeneratedTypes", StringComparison.Ordinal))
            {
                objectType = objectType.BaseType;
            }

            if (!ChildTypes.ContainsKey(objectType))
            {
                yield break;
            }

            foreach (var Item in ChildTypes[objectType])
            {
                yield return(Mappings[Item]);
            }
        }
Пример #7
0
        /// <summary>
        /// Gets the children.
        /// </summary>
        /// <param name="childTypes">The child types.</param>
        /// <returns>
        /// The children.
        /// </returns>
        public IEnumerable <ShellItem> GetChildren(ChildTypes childTypes)
        {
            //  We'll return a list of children.
            var children = new List <ShellItem>();

            //  Create the enum flags from the childtypes.
            SHCONTF enumFlags = 0;

            if (childTypes.HasFlag(ChildTypes.Folders))
            {
                enumFlags |= SHCONTF.SHCONTF_FOLDERS;
            }
            if (childTypes.HasFlag(ChildTypes.Files))
            {
                enumFlags |= SHCONTF.SHCONTF_NONFOLDERS;
            }
            if (childTypes.HasFlag(ChildTypes.Hidden))
            {
                enumFlags |= SHCONTF.SHCONTF_INCLUDEHIDDEN;
            }

            try
            {
                //  Create an enumerator for the children.
                IEnumIDList pEnum;
                var         result = ShellFolderInterface.EnumObjects(IntPtr.Zero, enumFlags, out pEnum);

                //  Validate the result.
                if (result != 0)
                {
                    //  Throw the failure as an exception.
                    Marshal.ThrowExceptionForHR((int)result);
                }

                // TODO: This logic should go in the pidl manager.

                //  Enumerate the children, ten at a time.
                const int batchSize = 10;
                var       pidlArray = Marshal.AllocCoTaskMem(IntPtr.Size * 10);
                uint      itemsFetched;
                result = WinError.S_OK;
                do
                {
                    result = pEnum.Next(batchSize, pidlArray, out itemsFetched);

                    //  Get each pidl.
                    var pidls = new IntPtr[itemsFetched];
                    Marshal.Copy(pidlArray, pidls, 0, (int)itemsFetched);
                    foreach (var childPidl in pidls)
                    {
                        //  Create a new shell folder.
                        var childShellFolder = new ShellItem();

                        //  Initialize it.
                        try
                        {
                            childShellFolder.Initialise(childPidl, this);
                        }
                        catch (Exception exception)
                        {
                            throw new InvalidOperationException("Failed to initialise child.", exception);
                        }

                        //  Add the child.
                        children.Add(childShellFolder);

                        //  Free the PIDL, reset the result.
                        Marshal.FreeCoTaskMem(childPidl);
                    }
                } while (result == WinError.S_OK);

                Marshal.FreeCoTaskMem(pidlArray);

                //  Release the enumerator.
                if (Marshal.IsComObject(pEnum))
                {
                    Marshal.ReleaseComObject(pEnum);
                }
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException("Failed to enumerate children.", exception);
            }

            //  Sort the children.
            var sortedChildren = children.Where(c => c.IsFolder).ToList();

            sortedChildren.AddRange(children.Where(c => !c.IsFolder));

            //  Return the children.
            return(sortedChildren);
        }
Пример #8
0
        //public static int CreateViewObject(IShellFolder2 folder, IntPtr Handle, ref Guid shellViewGuid, out IntPtr iShellViewPtr)
        //{
        //    folder.CreateViewObject
        //}

        public static IEnumerable <ShellItem> GetChildren(this ShellItem parent, ChildTypes childTypes, bool lThrow = true)
        {
            //  We'll return a list of children.
            var children = new List <ShellItem>();

            //  Create the enum flags from the childtypes.
            SHCONTF enumFlags = 0;

            if (childTypes.HasFlag(ChildTypes.Folders))
            {
                enumFlags |= SHCONTF.SHCONTF_FOLDERS;
            }
            if (childTypes.HasFlag(ChildTypes.Files))
            {
                enumFlags |= SHCONTF.SHCONTF_NONFOLDERS;

                //enumFlags |= SHCONTF.SHCONTF_NAVIGATION_ENUM
                //    | SHCONTF.SHCONTF_FASTITEMS // The calling application is looking for resources that can be enumerated quickly.
                //    | SHCONTF.SHCONTF_FLATLIST; // Enumerate items as a simple list even if the folder itself is not structured in that way
            }
            if (childTypes.HasFlag(ChildTypes.Hidden))
            {
                enumFlags |= SHCONTF.SHCONTF_INCLUDEHIDDEN;
            }
            //| SHCONTF.SHCONTF_INCLUDESUPERHIDDEN;

            try
            {
                //  Create an enumerator for the children.
                IEnumIDList pEnum;
                var         result = parent.ShellFolderInterface.EnumObjects(IntPtr.Zero, enumFlags, out pEnum);

                //  Validate the result.
                if (result != 0)
                {
                    if (!lThrow)
                    {
                        return(Enumerable.Empty <ShellItem>());
                    }

                    //  Throw the failure as an exception.
                    Marshal.ThrowExceptionForHR((int)result);
                }

                // TODO: This logic should go in the pidl manager.

                //  Enumerate the children, ten at a time.
                const int batchSize = 10;
                var       pidlArray = Marshal.AllocCoTaskMem(IntPtr.Size * 10);
                uint      itemsFetched;
                result = WinError.S_OK;
                do
                {
                    result = pEnum.Next(batchSize, pidlArray, out itemsFetched);

                    //  Get each pidl.
                    var pidls = new IntPtr[itemsFetched];
                    Marshal.Copy(pidlArray, pidls, 0, (int)itemsFetched);
                    foreach (var childPidl in pidls)
                    {
                        //  Create a new shell folder.
                        var childShellFolder = new ShellItem();

                        //  Initialize it.
                        try
                        {
                            childShellFolder.Initialise(childPidl, parent);
                        }
                        catch (Exception exception)
                        {
                            throw new InvalidOperationException("Failed to initialise child.", exception);
                        }

                        //  Add the child.
                        children.Add(childShellFolder);

                        //  Free the PIDL, reset the result.
                        Marshal.FreeCoTaskMem(childPidl);
                    }
                } while (result == WinError.S_OK);

                Marshal.FreeCoTaskMem(pidlArray);

                //  Release the enumerator.
                if (Marshal.IsComObject(pEnum))
                {
                    Marshal.ReleaseComObject(pEnum);
                }
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException("Failed to enumerate children.", exception);
            }

            //  Sort the children.
            var sortedChildren = children.Where(c => c.IsFolder).ToList();

            sortedChildren.AddRange(children.Where(c => !c.IsFolder));

            //  Return the children.
            return(sortedChildren);
        }
Пример #9
0
 /// <summary>
 /// Gets the children.
 /// </summary>
 /// <param name="childTypes">The child types.</param>
 public IEnumerable <ShellItem> GetChildren(ChildTypes childTypes, bool lThrow = true)
 {
     return(ShellObject.GetChildren(this, childTypes, lThrow));
 }
Пример #10
0
        public static void DoExpand(this ShellTreeView tree, TreeNode node)
        {
            //  Clear children - which may in fact be the placeholder.
            node.Nodes.Clear();
            var nodesToFolders = tree.NodesToFolders;

            //  Get the shell folder.
            ShellItem shellFolder = nodesToFolders[node];

            //  Create the enum flags.
            ChildTypes childFlags = ChildTypes.Folders;

            if (tree.ShowFiles)
            {
                childFlags |= ChildTypes.Files;
            }
            if (tree.ShowHiddenFilesAndFolders)
            {
                childFlags |= ChildTypes.Hidden;
            }

            //  Disable update while adding children.
            tree.BeginUpdate();

            int count = 0;

            try
            {
                //  Go through each child.
                foreach (var childNode in
                         EnumerateUnsafe(shellFolder, childFlags, node, nodesToFolders))
                {
                    count++;
                    //  Fire the shell item added event.
                    tree.FireOnShellItemAdded(childNode);
                }

                if (count == 0)
                {
                    childFlags = ChildTypes.Files | ChildTypes.Hidden;

                    foreach (var childNode in
                             EnumerateUnsafe(shellFolder, childFlags, node, nodesToFolders))
                    {
                        count++;
                        //  Fire the shell item added event.
                        tree.FireOnShellItemAdded(childNode);
                    }
                    if (count > 0)
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }

                MessageBox.Show(ex.Message);
            }

            //  Enable update now that we've added the children.
            tree.EndUpdate();
        }
Пример #11
0
        /// <summary>
        /// Gets the children.
        /// </summary>
        /// <param name="childTypes">The child types.</param>
        /// <returns>
        /// The children.
        /// </returns>
        public IEnumerable <ShellItem> GetChildren(ChildTypes childTypes)
        {
            //  We'll return a list of children.
            var children = new List <ShellItem>();

            //  Create the enum flags from the childtypes.
            SHCONTF enumFlags = SHCONTF.None;

            if (childTypes.HasFlag(ChildTypes.Folders))
            {
                enumFlags |= SHCONTF.SHCONTF_FOLDERS;
            }
            if (childTypes.HasFlag(ChildTypes.Files))
            {
                enumFlags |= SHCONTF.SHCONTF_NONFOLDERS;
            }
            if (childTypes.HasFlag(ChildTypes.Hidden))
            {
                enumFlags |= SHCONTF.SHCONTF_INCLUDEHIDDEN;
            }

            try
            {
                //  Create an enumerator for the children.
                IEnumIDList pEnum;
                var         result = ShellFolderInterface.EnumObjects(IntPtr.Zero, enumFlags, out pEnum);

                //  Validate the result.
                if (result != 0)
                {
                    //  Throw the failure as an exception.
                    Marshal.ThrowExceptionForHR((int)result);
                }

                //  Start going through children.
                IntPtr childPIDL;
                int    enumResult;
                pEnum.Next(1, out childPIDL, out enumResult);

                //  Now start enumerating.
                while (childPIDL != IntPtr.Zero && enumResult == 1)
                {
                    //  Create a new shell folder.
                    var childShellFolder = new ShellItem();

                    //  Initialize it.
                    try
                    {
                        childShellFolder.Initialise(childPIDL, this);
                    }
                    catch (Exception exception)
                    {
                        throw new InvalidOperationException("Failed to initialise child.", exception);
                    }

                    //  Add the child.
                    children.Add(childShellFolder);

                    //  Free the PIDL, reset the result.
                    Marshal.FreeCoTaskMem(childPIDL);

                    //  Move onwards.
                    pEnum.Next(1, out childPIDL, out enumResult);
                }

                //  Release the enumerator.
                Marshal.ReleaseComObject(pEnum);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException("Failed to enumerate children.", exception);
            }

            //  Sort the children.
            var sortedChildren = children.Where(c => c.IsFolder).ToList();

            sortedChildren.AddRange(children.Where(c => !c.IsFolder));

            //  Return the children.
            return(sortedChildren);
        }
Пример #12
0
        /// <summary>
        /// Gets the children.
        /// </summary>
        /// <param name="childTypes">The child types.</param>
        /// <returns>
        /// The children.
        /// </returns>
        public IEnumerable<ShellItem> GetChildren(ChildTypes childTypes)
        {
            //  We'll return a list of children.
            var children = new List<ShellItem>();

            //  Create the enum flags from the childtypes.
            SHCONTF enumFlags = 0;
            if (childTypes.HasFlag(ChildTypes.Folders))
                enumFlags |= SHCONTF.SHCONTF_FOLDERS;
            if (childTypes.HasFlag(ChildTypes.Files))
                enumFlags |= SHCONTF.SHCONTF_NONFOLDERS;
            if (childTypes.HasFlag(ChildTypes.Hidden))
                enumFlags |= SHCONTF.SHCONTF_INCLUDEHIDDEN;

            try
            {
                //  Create an enumerator for the children.
                IEnumIDList pEnum;
                var result = ShellFolderInterface.EnumObjects(IntPtr.Zero, enumFlags, out pEnum);

                //  Validate the result.
                if (result != 0)
                {
                    //  Throw the failure as an exception.
                    Marshal.ThrowExceptionForHR((int)result);
                }

                // TODO: This logic should go in the pidl manager.

                //  Enumerate the children, ten at a time.
                const int batchSize = 10;
                var pidlArray = Marshal.AllocCoTaskMem(IntPtr.Size * 10);
                uint itemsFetched;
                result = WinError.S_OK;
                do
                {
                    result = pEnum.Next(batchSize, pidlArray, out itemsFetched);

                    //  Get each pidl.
                    var pidls = new IntPtr[itemsFetched];
                    Marshal.Copy(pidlArray, pidls, 0, (int) itemsFetched);
                    foreach (var childPidl in pidls)
                    {
                        //  Create a new shell folder.
                        var childShellFolder = new ShellItem();

                        //  Initialize it.
                        try
                        {
                            childShellFolder.Initialise(childPidl, this);
                        }
                        catch (Exception exception)
                        {
                            throw new InvalidOperationException("Failed to initialise child.", exception);
                        }

                        //  Add the child.
                        children.Add(childShellFolder);

                        //  Free the PIDL, reset the result.
                        Marshal.FreeCoTaskMem(childPidl);
                    }
                } while (result == WinError.S_OK);
            
                Marshal.FreeCoTaskMem(pidlArray);

                //  Release the enumerator.
                if(Marshal.IsComObject(pEnum))
                    Marshal.ReleaseComObject(pEnum);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException("Failed to enumerate children.", exception);
            }

            //  Sort the children.
            var sortedChildren = children.Where(c => c.IsFolder).ToList();
            sortedChildren.AddRange(children.Where(c => !c.IsFolder));

            //  Return the children.
            return sortedChildren;
        }
        public DefinitionNodeCapabilities(TreeNode node) : base(node)
        {
            switch (Name.ToLowerInvariant())
            {
            case "shuffledefinition":
                Comment = false;
                Delete  = false;
                CutCopy = false;
                ChildTypes.Add(new ChildNodeCapabilities("Blocks", false));
                break;

            case "blocks":
                Delete  = false;
                CutCopy = false;
                ChildTypes.Add(new ChildNodeCapabilities("DataBlock", true));
                ChildTypes.Add(new ChildNodeCapabilities("SolutionBlock", true));
                ChildTypes.Add(new ChildNodeCapabilities("#comment", true));
                break;

            case "datablock":
                ChildTypes.Add(new ChildNodeCapabilities("Export", false));
                ChildTypes.Add(new ChildNodeCapabilities("Import", false));
                ChildTypes.Add(new ChildNodeCapabilities("Relation", true));
                break;

            case "solutionblock":
                ChildTypes.Add(new ChildNodeCapabilities("Export", false));
                ChildTypes.Add(new ChildNodeCapabilities("Import", false));
                break;

            case "export":
                if (node.Parent.Name.ToLowerInvariant().StartsWith("datablock"))
                {
                    if (!node.Nodes.Cast <TreeNode>().Any(n => n.Name == "FetchXML"))
                    {
                        ChildTypes.Add(new ChildNodeCapabilities("Filter", true));
                        ChildTypes.Add(new ChildNodeCapabilities("Sort", true));
                        ChildTypes.Add(new ChildNodeCapabilities("Attributes", false));
                    }
                    if (node.Nodes.Count == 0)
                    {
                        ChildTypes.Add(new ChildNodeCapabilities("-", false));
                        ChildTypes.Add(new ChildNodeCapabilities("FetchXML", false));
                    }
                }
                else if (node.Parent.Name.ToLowerInvariant().StartsWith("solutionblock"))
                {
                    ChildTypes.Add(new ChildNodeCapabilities("Settings", false));
                }
                break;

            case "import":
                if (node.Parent.Name.ToLowerInvariant().StartsWith("datablock"))
                {
                    ChildTypes.Add(new ChildNodeCapabilities("Match", false));
                }
                else if (node.Parent.Name.ToLowerInvariant().StartsWith("solutionblock"))
                {
                    ChildTypes.Add(new ChildNodeCapabilities("PreRequisites", false));
                }
                break;

            case "attributes":
                //Delete = false;
                ChildTypes.Add(new ChildNodeCapabilities("Attribute", true));
                break;

            case "match":
                ChildTypes.Add(new ChildNodeCapabilities("Attribute", true));
                break;

            case "attribute":
                Delete = node.Parent != null && node.Parent.Nodes.Count > 1;
                break;

            case "filter":
            case "sort":
            case "relation":
            case "settings":
                break;

            case "prerequisites":
                ChildTypes.Add(new ChildNodeCapabilities("Solution", true));
                break;

            case "solution":
                Delete = node.Parent != null && node.Parent.Nodes.Count > 1;
                break;

            case "#comment":
                Comment   = false;
                Uncomment = true;
                break;
            }
        }