예제 #1
0
        private void CreateArrayInstanceTypes(NodeDescriptor descriptor)
        {
            if (descriptor.Instance != null)
            {
                IEnumerable collection = (IEnumerable)descriptor.Instance;
                foreach (object obj in collection)
                {
                    NodeDescriptor child = Types.GetOrCreate(descriptor.Info, obj, descriptor);

                    if (Types.Add(child, descriptor))
                    {
                        FindTypes(child);
                    }
                }
            }

            Type itemType = GetArrayItemType(descriptor);

            if (itemType != null)
            {
                NodeDescriptor child = Types.GetOrCreate(itemType);
                descriptor.CollectionItem = child;
                if (Types.Add(child, descriptor))
                {
                    FindTypes(child);
                }
            }
        }
예제 #2
0
        private void CreateArrayType(NodeDescriptor descriptor, NodeDescriptor parent)
        {
            // the object type is a GenericType in it self, therefore ignore it.
            if (descriptor.ObjectType.IsGenericType)
            {
                //Type itemType = null;
                //Type[] argTypes = descriptor.ObjectType.GetBaseGenericArguments();
                //if (argTypes != null && argTypes.Length > 0)
                //{
                //    itemType = argTypes[0];

                //    if (itemType.IsPrimitive || itemType == typeof(Guid) || itemType == typeof(string))
                //    {
                //        return;
                //    }
                //}
                return;
            }


            if (descriptor.IsStandardCollection)
            {
                return;
            }

            if (Types.Add(descriptor, parent))
            {
                // Do not find the property types in this collection
                // FindTypes(descriptor);

                CreateCollectionTypes(descriptor);
            }
        }
        private NodeDescriptor FindCollectionItemType()
        {
            NodeDescriptor result = null;

            foreach (NodeDescriptor parent in this.Descriptor.AttachTo)
            {
                if (parent.CollectionItem != null)
                {
                    if (result == null || result == parent.CollectionItem)
                    {
                        result = parent.CollectionItem;
                    }
                    else
                    {
                        result = null;
                        break;
                    }
                }
                else
                {
                    result = null;
                    break;
                }
            }

            return(result);
        }
예제 #4
0
 private void CreateSingleType(NodeDescriptor descriptor, NodeDescriptor parent)
 {
     // Add objects that is not collections
     if (descriptor.ObjectType.IsClass && !descriptor.IsSimpleType)
     {
         if (Types.Add(descriptor, parent))
         {
             FindTypes(descriptor);
         }
     }
 }
예제 #5
0
        public void Run()
        {
            Type           farmType   = SPFarm.Local.GetType();
            NodeDescriptor descriptor = Types.GetOrCreate(null, SPFarm.Local, null);

            Types.Add(descriptor, null);

            Console.Write("Finding types...");
            FindTypes(descriptor);
            Console.WriteLine("Found : " + this.Types.Keys.Count);
            Console.WriteLine("Updating AttachTo...");
            UpdateAttachTo(descriptor);
            Console.WriteLine("Building files...");
            BuildFiles();
        }
예제 #6
0
        private Type GetArrayItemType(NodeDescriptor descriptor)
        {
            Type itemType = null;

            Type[] argTypes = descriptor.ObjectType.GetBaseGenericArguments();
            if (argTypes != null && argTypes.Length > 0)
            {
                itemType = argTypes[0];

                if (itemType.IsPrimitive || itemType == typeof(Guid) || itemType == typeof(string))
                {
                    itemType = null;
                }
            }
            return(itemType);
        }
예제 #7
0
        private void CreateCollectionTypes(NodeDescriptor descriptor)
        {
            ClientCallableTypeAttribute attr = descriptor.ObjectType.GetAttribute <ClientCallableTypeAttribute>(true);

            if (descriptor.ObjectType.InheritFrom("SPBaseCollection") && attr != null)
            {
                Type itemType = attr.CollectionChildItemType;
                if (itemType != null)
                {
                    NodeDescriptor child = Types.GetOrCreate(itemType);
                    descriptor.CollectionItem = child;
                    if (Types.Add(child, descriptor))
                    {
                        FindTypes(child);
                    }
                }
            }
            else
            {
                CreateArrayInstanceTypes(descriptor);
            }
        }
예제 #8
0
        private void FindTypes(NodeDescriptor descriptor)
        {
            PropertyInfo[] properties = descriptor.ObjectType.GetProperties();

            if (properties != null)
            {
                foreach (PropertyInfo info in properties)
                {
                    NodeDescriptor child = Types.GetOrCreate(info, descriptor);

                    if (!child.IsSimpleType && !child.IsSystem)
                    {
                        if (child.IsEnumerable)
                        {
                            CreateArrayType(child, descriptor);
                        }
                        else
                        {
                            CreateSingleType(child, descriptor);
                        }
                    }
                }
            }
        }
예제 #9
0
        private void UpdateAttachTo(NodeDescriptor descriptor)
        {
            descriptor.Visited = true;
            AttachToPath.Add(descriptor);

            foreach (NodeDescriptor child in descriptor.Children)
            {
                if (!AttachToPath.Contains(child) || child.Equals(descriptor.CollectionItem))
                {
                    child.AttachTo.Append(descriptor);
                    if (!child.Visited)
                    {
                        UpdateAttachTo(child);
                    }
                }
                else
                {
                    //child.Excludes.Append(descriptor);
                    //if(child.AttachTo.Contains(
                }
            }

            AttachToPath.Remove(descriptor);
        }
        private void Fillin()
        {
            this.PropertyTitle = this.Descriptor.Title;

            var list = from p in this.Descriptor.AttachTo
                       select String.Format(AttachToTemplate, p.NodeFullName);

            this.AttachTo = String.Join("\r\n\t", list.ToArray());

            this.ClassName                = this.Descriptor.NodeName;
            this.SharePointType           = this.Descriptor.ObjectType.AssemblyQualifiedName;
            this.SharePointTypeName       = this.Descriptor.ObjectType.Name;
            this.SharePointTypeSimpleName = this.SharePointTypeName;
            if (this.SharePointTypeName.StartsWith("SP"))
            {
                this.SharePointTypeSimpleName = this.SharePointTypeName.Substring(2);
            }

            if (this.Descriptor.ObjectType.IsPublic &&
                this.Descriptor.ObjectType.Namespace.StartsWith("Microsoft.SharePoint") &&
                !this.Descriptor.ObjectType.Namespace.StartsWith("Microsoft.SharePoint.Portal"))
            {
                this.SharePointTypeProperty = string.Format(SharePointTypePropertyTemplate, this.SharePointTypeName, this.SharePointTypeSimpleName);
                this.SharePointTypeUsing    = string.Format(SharePointTypeUsingTemplate, this.Descriptor.ObjectType.Namespace);
            }

            this.Icon = String.Format(IconTemplate, this.Icon);

            if (this.Descriptor.PropertyTitle != null)
            {
                this.TitlePropertyName = String.Format(TitlePropertyNameTemplate, this.Descriptor.PropertyTitle);
            }
            else
            {
                this.TitlePropertyName = String.Format(TitleTemplate, this.PropertyTitle);
            }


            if (this.Descriptor.IsEnumerable)
            {
                this.BaseType = BaseCollectionTypeTemplate;
                //Type itemType = null;
                //Type[] argTypes = this.Descriptor.ObjectType.GetBaseGenericArguments();
                //if (argTypes != null && argTypes.Length > 0)
                //{
                //    itemType = argTypes[0];
                //    this.BaseType = String.Format(BaseCollectionTypeTemplate, this.SharePointType, GetClassName(itemType.FullName));
                //}
            }
            else
            {
                NodeDescriptor item = FindCollectionItemType();

                if (item != null && item.NodeName != this.Descriptor.NodeName)
                {
                    this.BaseType = item.NodeName;
                }
                else
                {
                    this.BaseType = String.Format(BaseTypeTemplate);
                }
            }
        }
        public ReplacementParameters(NodeDescriptor descriptor)
        {
            this.Descriptor = descriptor;

            Fillin();
        }