private static void GeneratePropertySet(ref PropertyFilterSpec result, IEnumerable <DynamicPropertyFilterSpecGenerator.ManagedObjectDefinition> managedObjectList)
 {
     foreach (DynamicPropertyFilterSpecGenerator.ManagedObjectDefinition current in managedObjectList)
     {
         PropertySpec   propertySpec = null;
         PropertySpec[] propSet      = result.PropSet;
         for (int i = 0; i < propSet.Length; i++)
         {
             PropertySpec propertySpec2 = propSet[i];
             if (propertySpec2.Type == DynamicPropertyFilterSpecGenerator.FixTypeName(current.ObjectType))
             {
                 propertySpec = propertySpec2;
                 break;
             }
         }
         if (propertySpec != null)
         {
             if (propertySpec.All != true)
             {
                 if (current.PropertyPath == "*")
                 {
                     propertySpec.All     = new bool?(true);
                     propertySpec.PathSet = null;
                 }
                 else
                 {
                     List <string> list = new List <string>(propertySpec.PathSet);
                     if (!list.Contains(current.PropertyPath))
                     {
                         list.Add(current.PropertyPath);
                     }
                     propertySpec.PathSet = list.ToArray();
                 }
             }
         }
         else
         {
             propertySpec = new PropertySpec();
             List <PropertySpec> list2 = new List <PropertySpec>(result.PropSet);
             propertySpec.Type = DynamicPropertyFilterSpecGenerator.FixTypeName(current.ObjectType);
             if (current.PropertyPath == "*")
             {
                 propertySpec.All = new bool?(true);
             }
             else
             {
                 propertySpec.All     = new bool?(false);
                 propertySpec.PathSet = new string[]
                 {
                     current.PropertyPath
                 };
             }
             list2.Add(propertySpec);
             result.PropSet = list2.ToArray();
         }
     }
 }
        public ManagedObjectReference CreateFilter(PropertyFilterSpec spec, bool partialUpdates)
        {
            ManagedObjectReference result;

            try
            {
                CreateFilterRequestType createFilterRequestType = new CreateFilterRequestType();
                createFilterRequestType._this          = (VimApi_65.ManagedObjectReference)VIConvert.ToWsdlType(this.MoRef);
                createFilterRequestType.spec           = (VimApi_65.PropertyFilterSpec)VIConvert.ToWsdlType(spec);
                createFilterRequestType.partialUpdates = partialUpdates;
                result = (ManagedObjectReference)VIConvert.ToVim(this.VimServiceProxy.CreateFilter(new CreateFilterRequest(createFilterRequestType)).CreateFilterResponse.returnval);
            }
            catch (FaultException ex)
            {
                throw FaultUtility.HandleFault(ex);
            }
            return(result);
        }
Exemplo n.º 3
0
        public List <ViewBase> GetViewsByMorefs(IEnumerable <ManagedObjectReference> moRefs, params string[] properties)
        {
            if (moRefs == null)
            {
                throw new ArgumentNullException("moRefs");
            }
            if (this._vimService == null)
            {
                throw new InvalidOperationException(Resources.VimWebServiceNotInitialized);
            }
            if (this._serviceContent == null)
            {
                throw new InvalidOperationException(Resources.ServiceContentNotInitialized);
            }
            Dictionary <string, PropertyFilterSpec> propertyFilterSpecList = new Dictionary <string, PropertyFilterSpec>();

            foreach (ManagedObjectReference moRef in moRefs)
            {
                if (propertyFilterSpecList.ContainsKey(moRef.Type.ToLower()))
                {
                    PropertyFilterSpec propertyFilterSpec = propertyFilterSpecList[moRef.Type.ToLower()];
                    ObjectSpec[]       array = new List <ObjectSpec>((IEnumerable <ObjectSpec>)propertyFilterSpec.ObjectSet)
                    {
                        new ObjectSpec()
                        {
                            Obj = moRef
                        }
                    }.ToArray();
                    propertyFilterSpec.ObjectSet = array;
                }
                else
                {
                    PropertyFilterSpec resultPropertyFilterSpec;
                    Dictionary <string, List <string> > currentAllowedPropertyPath;
                    DynamicPropertyFilterSpecGenerator.Generate(moRef, properties, out resultPropertyFilterSpec, out currentAllowedPropertyPath);
                    propertyFilterSpecList.Add(moRef.Type.ToLower(), resultPropertyFilterSpec);
                }
            }
            PropertyFilterSpec[] propertyFilterSpecArray = new PropertyFilterSpec[propertyFilterSpecList.Values.Count];
            propertyFilterSpecList.Values.CopyTo(propertyFilterSpecArray, 0);
            ObjectContent[] objectContent = new PropertyCollector((VimClient)this, this._serviceContent.PropertyCollector).RetrieveProperties(propertyFilterSpecArray);
            return(this.GetViewsByMorefs(moRefs, objectContent, propertyFilterSpecList));
        }
Exemplo n.º 4
0
 public void UpdateViewData(params string[] properties)
 {
     PropertyCollector propertyCollector = new PropertyCollector(this._client, this._client.ServiceContent.PropertyCollector);
     PropertyFilterSpec resultPropertyFilterSpec;
     Dictionary<string, List<string>> currentAllowedPropertyPath;
     DynamicPropertyFilterSpecGenerator.Generate(this.MoRef, VimClient.MakePropertiesCamelCase(properties), out resultPropertyFilterSpec, out currentAllowedPropertyPath);
     PropertyFilterSpec[] specSet = new PropertyFilterSpec[1]
     {
 resultPropertyFilterSpec
     };
     ObjectContent[] objectContentArray = propertyCollector.RetrieveProperties(specSet);
     Dictionary<string, ObjectContent> objectContentList = new Dictionary<string, ObjectContent>();
     foreach (ObjectContent objectContent in objectContentArray)
         objectContentList.Add(objectContent.Obj.Value, objectContent);
     Dictionary<string, ViewBase> generatedManagedObjectList = new Dictionary<string, ViewBase>();
     if (properties != null)
     {
         List<string> stringList = new List<string>((IEnumerable<string>)properties);
     }
     ViewBase.SetViewData(this, (string)null, currentAllowedPropertyPath, objectContentList, generatedManagedObjectList);
 }
        internal static void Generate(ManagedObjectReference startingObject, string[] propertyPathList, out PropertyFilterSpec resultPropertyFilterSpec, out Dictionary <string, List <string> > currentAllowedPropertyPath)
        {
            resultPropertyFilterSpec = new PropertyFilterSpec();
            ObjectSpec objectSpec = new ObjectSpec();

            resultPropertyFilterSpec.ObjectSet = new ObjectSpec[]
            {
                objectSpec
            };
            objectSpec.Obj                   = startingObject;
            objectSpec.SelectSet             = new SelectionSpec[0];
            resultPropertyFilterSpec.PropSet = new PropertySpec[0];
            currentAllowedPropertyPath       = null;
            if (propertyPathList == null)
            {
                PropertySpec propertySpec = new PropertySpec();
                propertySpec.Type = startingObject.Type;
                propertySpec.All  = new bool?(true);
                resultPropertyFilterSpec.PropSet = new PropertySpec[]
                {
                    propertySpec
                };
                return;
            }
            currentAllowedPropertyPath = new Dictionary <string, List <string> >();
            for (int i = 0; i < propertyPathList.Length; i++)
            {
                DynamicPropertyFilterSpecGenerator.PropertyDefinition[]      array = DynamicPropertyFilterSpecGenerator.ParsePropertyPath(propertyPathList[i]);
                List <DynamicPropertyFilterSpecGenerator.PropertyDefinition> list  = new List <DynamicPropertyFilterSpecGenerator.PropertyDefinition>(array);
                DynamicPropertyFilterSpecGenerator.SetPropertyTypesAndFixCasing(array, startingObject.Type);
                DynamicPropertyFilterSpecGenerator.GenerateAllowedPropertyPath(ref currentAllowedPropertyPath, list.ToArray(), array);
                List <DynamicPropertyFilterSpecGenerator.ManagedObjectDefinition> list2 = DynamicPropertyFilterSpecGenerator.GenerateManagedObjectList(array, startingObject.Type);
                DynamicPropertyFilterSpecGenerator.GeneratePropertySet(ref resultPropertyFilterSpec, list2);
                resultPropertyFilterSpec.ObjectSet[0].SelectSet = DynamicPropertyFilterSpecGenerator.GenerateSelectionSet(resultPropertyFilterSpec.ObjectSet[0].SelectSet, list2.GetEnumerator(), list2.Count);
            }
        }
Exemplo n.º 6
0
        public List <ViewBase> GetViews(IEnumerable <ManagedObjectReference> moRefs, params string[] properties)
        {
            if (moRefs == null)
            {
                throw new ArgumentNullException("moRefs");
            }
            if (this._vimService == null)
            {
                throw new InvalidOperationException(Resources.VimWebServiceNotInitialized);
            }
            if (this._serviceContent == null)
            {
                throw new InvalidOperationException(Resources.ServiceContentNotInitialized);
            }
            Dictionary <string, PropertyFilterSpec> dictionary = new Dictionary <string, PropertyFilterSpec>();

            foreach (ManagedObjectReference moRef in moRefs)
            {
                if (dictionary.ContainsKey(moRef.Type.ToLower()))
                {
                    PropertyFilterSpec propertyFilterSpec = dictionary[moRef.Type.ToLower()];
                    ObjectSpec[]       array = new List <ObjectSpec>((IEnumerable <ObjectSpec>)propertyFilterSpec.ObjectSet)
                    {
                        new ObjectSpec()
                        {
                            Obj = moRef
                        }
                    }.ToArray();
                    propertyFilterSpec.ObjectSet = array;
                }
                else
                {
                    PropertySpec propertySpec = new PropertySpec();
                    propertySpec.Type = moRef.Type;
                    if (properties != null && properties.Length != 0)
                    {
                        propertySpec.All     = new bool?(false);
                        propertySpec.PathSet = VimClient.MakePropertiesCamelCase(properties);
                    }
                    else
                    {
                        propertySpec.All = new bool?(true);
                    }
                    dictionary.Add(moRef.Type.ToLower(), new PropertyFilterSpec()
                    {
                        PropSet = new PropertySpec[1] {
                            propertySpec
                        },
                        ObjectSet = new List <ObjectSpec>()
                        {
                            new ObjectSpec()
                            {
                                Obj = moRef
                            }
                        }.ToArray()
                    });
                }
            }
            PropertyFilterSpec[] propertyFilterSpecArray = new PropertyFilterSpec[dictionary.Values.Count];
            dictionary.Values.CopyTo(propertyFilterSpecArray, 0);
            return(this.GetViews(new PropertyCollector((VimClient)this, this._serviceContent.PropertyCollector).RetrieveProperties(propertyFilterSpecArray), properties));
        }