コード例 #1
0
ファイル: WSManConfigProvider.cs プロジェクト: nickchal/pash
 private void WritePSObjectPropertiesAsWSManElementObjects(PSObject psobject, string path, string[] keys, string ExtendedTypeName, WsManElementObjectTypes WSManElementObjectType, bool recurse)
 {
     PSObject item = null;
     Collection<string> collection = new Collection<string>();
     foreach (PSPropertyInfo info in psobject.Properties)
     {
         if (!info.Name.EndsWith("___Source"))
         {
             if (WSManElementObjectType.Equals(WsManElementObjectTypes.WSManConfigElement))
             {
                 WSManConfigElement element = new WSManConfigElement(info.Name, info.Value.ToString());
                 item = new PSObject(element);
             }
             if (WSManElementObjectType.Equals(WsManElementObjectTypes.WSManConfigContainerElement))
             {
                 WSManConfigContainerElement element2 = new WSManConfigContainerElement(info.Name, info.Value.ToString(), keys);
                 item = new PSObject(element2);
             }
             if (WSManElementObjectType.Equals(WsManElementObjectTypes.WSManConfigLeafElement))
             {
                 string str = info.Name + "___Source";
                 object sourceOfValue = null;
                 if (psobject.Properties[str] != null)
                 {
                     sourceOfValue = psobject.Properties[str].Value;
                 }
                 WSManConfigLeafElement element3 = null;
                 if (!info.Value.ToString().Equals("Container"))
                 {
                     element3 = new WSManConfigLeafElement(info.Name, info.Value, info.TypeNameOfValue, sourceOfValue);
                 }
                 else
                 {
                     element3 = new WSManConfigLeafElement(info.Name, null, info.Value.ToString(), null);
                 }
                 if (element3 != null)
                 {
                     item = new PSObject(element3);
                 }
             }
             if (!string.IsNullOrEmpty(ExtendedTypeName))
             {
                 StringBuilder builder = new StringBuilder("");
                 if (item != null)
                 {
                     builder.Append(item.ImmediateBaseObject.GetType().FullName);
                     builder.Append("#");
                     builder.Append(ExtendedTypeName);
                     item.TypeNames.Insert(0, builder.ToString());
                 }
             }
             if (!info.Value.ToString().Equals("Container"))
             {
                 string str2 = "WSMan".Equals(path, StringComparison.OrdinalIgnoreCase) ? info.Name : (path + '\\' + info.Name);
                 base.WriteItemObject(item, str2, false);
             }
             else
             {
                 string str3 = "WSMan".Equals(path, StringComparison.OrdinalIgnoreCase) ? info.Name : (path + '\\' + info.Name);
                 base.WriteItemObject(item, str3, true);
                 if (recurse)
                 {
                     collection.Add(info.Name);
                 }
             }
         }
     }
     if (recurse)
     {
         foreach (string str4 in collection)
         {
             this.GetChildItemsRecurse(path, str4, ProviderMethods.GetChildItems, recurse);
         }
     }
 }
コード例 #2
0
ファイル: ConfigProvider.cs プロジェクト: dfinke/powershell
        /// <summary>
        /// Used to Write WSMan objects to the output console. Used by GetChildItem, GetItem and NewItem.
        /// </summary>
        /// <param name="psobject"></param>
        /// <param name="path"></param>
        /// <param name="keys"></param>
        /// <param name="ExtendedTypeName"></param>
        /// <param name="WSManElementObjectType"></param>
        /// <param name="recurse"></param>
        private void WritePSObjectPropertiesAsWSManElementObjects(PSObject psobject, string path, string[] keys, string ExtendedTypeName, WsManElementObjectTypes WSManElementObjectType, bool recurse)
        {
            PSObject mshObject = null;
            Collection<string> directory = new Collection<string>();
            foreach (PSPropertyInfo prop in psobject.Properties)
            {
                if (prop.Name.EndsWith(WSManStringLiterals.HiddenSuffixForSourceOfValue))
                {
                    continue;
                }

                if (WSManElementObjectType.Equals(WsManElementObjectTypes.WSManConfigElement))
                {
                    WSManConfigElement element = new WSManConfigElement(prop.Name, prop.Value.ToString());
                    mshObject = new PSObject(element);
                }
                if (WSManElementObjectType.Equals(WsManElementObjectTypes.WSManConfigContainerElement))
                {
                    WSManConfigContainerElement element = new WSManConfigContainerElement(prop.Name, prop.Value.ToString(), keys);
                    mshObject = new PSObject(element);
                }
                if (WSManElementObjectType.Equals(WsManElementObjectTypes.WSManConfigLeafElement))
                {
                    string sourceProp = prop.Name + WSManStringLiterals.HiddenSuffixForSourceOfValue;
                    object source = null;
                    if (psobject.Properties[sourceProp] != null)
                    {
                        source = psobject.Properties[sourceProp].Value;
                    }

                    WSManConfigLeafElement element = null;
                    if (!prop.Value.ToString().Equals(WSManStringLiterals.ContainerChildValue))
                    {
                        element = new WSManConfigLeafElement(prop.Name, prop.Value, prop.TypeNameOfValue, source);
                    }
                    else
                    {
                        element = new WSManConfigLeafElement(prop.Name, null, prop.Value.ToString());
                    }
                    if (element != null)
                    {
                        mshObject = new PSObject(element);
                    }
                }
                if (!String.IsNullOrEmpty(ExtendedTypeName))
                {
                    StringBuilder types = new StringBuilder("");
                    if (mshObject != null)
                    {
                        types.Append(mshObject.ImmediateBaseObject.GetType().FullName);
                        types.Append("#");
                        types.Append(ExtendedTypeName);
                        mshObject.TypeNames.Insert(0, types.ToString());
                    }
                }
                if (!prop.Value.ToString().Equals(WSManStringLiterals.ContainerChildValue))
                {
                    // This path is used by WriteItemObject to construct PSPath.
                    // PSPath is a provider qualified path and we dont need to specify
                    // provider root in this path..So I am trying to eliminate provider root
                    // in this case.
                    string pathToUse = WSManStringLiterals.rootpath.Equals(path, StringComparison.OrdinalIgnoreCase) ?
                        prop.Name :
                        (path + WSManStringLiterals.DefaultPathSeparator + prop.Name);
                    WriteItemObject(mshObject, pathToUse, false);
                }
                else
                {
                    // This path is used by WriteItemObject to construct PSPath.
                    // PSPath is a provider qualified path and we dont need to specify
                    // provider root in this path..So I am trying to eliminate provider root
                    // in this case.
                    string pathToUse = WSManStringLiterals.rootpath.Equals(path, StringComparison.OrdinalIgnoreCase) ?
                        prop.Name :
                        (path + WSManStringLiterals.DefaultPathSeparator + prop.Name);
                    WriteItemObject(mshObject, pathToUse, true);
                    if (recurse)
                    {
                        directory.Add(prop.Name);
                    }
                }
            }
            if (recurse)
            {
                foreach (string dir in directory)
                {
                    GetChildItemsRecurse(path, dir, ProviderMethods.GetChildItems, recurse);
                }
            }
        }
コード例 #3
0
ファイル: WSManConfigProvider.cs プロジェクト: nickchal/pash
 private PSObject GetItemPSObjectWithTypeName(string Name, string TypeNameOfElement, object Value, string[] keys, string ExtendedTypeName, WsManElementObjectTypes WSManElementObjectType, PSObject input = null)
 {
     PSObject obj2 = null;
     if (WSManElementObjectType.Equals(WsManElementObjectTypes.WSManConfigElement))
     {
         WSManConfigElement element = new WSManConfigElement(Name, TypeNameOfElement);
         obj2 = new PSObject(element);
     }
     if (WSManElementObjectType.Equals(WsManElementObjectTypes.WSManConfigContainerElement))
     {
         WSManConfigContainerElement element2 = new WSManConfigContainerElement(Name, TypeNameOfElement, keys);
         obj2 = new PSObject(element2);
     }
     if (WSManElementObjectType.Equals(WsManElementObjectTypes.WSManConfigLeafElement))
     {
         object sourceOfValue = null;
         if (input != null)
         {
             string str = Name + "___Source";
             if (input.Properties[str] != null)
             {
                 sourceOfValue = input.Properties[str].Value;
             }
         }
         WSManConfigLeafElement element3 = new WSManConfigLeafElement(Name, Value, TypeNameOfElement, sourceOfValue);
         obj2 = new PSObject(element3);
     }
     if (!string.IsNullOrEmpty(ExtendedTypeName))
     {
         StringBuilder builder = new StringBuilder("");
         if (obj2 != null)
         {
             builder.Append(obj2.ImmediateBaseObject.GetType().FullName);
             builder.Append("#");
             builder.Append(ExtendedTypeName);
             obj2.TypeNames.Insert(0, builder.ToString());
         }
     }
     return obj2;
 }
コード例 #4
0
ファイル: ConfigProvider.cs プロジェクト: dfinke/powershell
        /// <summary>
        /// Returns the object to be written to the console.
        /// </summary>        
        /// <param name="Name"></param>
        /// <param name="TypeNameOfElement"></param>
        /// <param name="Value"></param>
        /// <param name="keys"></param>
        /// <param name="ExtendedTypeName"></param>
        /// <param name="WSManElementObjectType"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        private PSObject GetItemPSObjectWithTypeName(string Name, string TypeNameOfElement, object Value, string[] keys, string ExtendedTypeName, WsManElementObjectTypes WSManElementObjectType, PSObject input = null)
        {
            PSObject mshObject = null;
            if (WSManElementObjectType.Equals(WsManElementObjectTypes.WSManConfigElement))
            {
                WSManConfigElement element = new WSManConfigElement(Name, TypeNameOfElement);
                mshObject = new PSObject(element);
            }
            if (WSManElementObjectType.Equals(WsManElementObjectTypes.WSManConfigContainerElement))
            {
                WSManConfigContainerElement element = new WSManConfigContainerElement(Name, TypeNameOfElement, keys);
                mshObject = new PSObject(element);
            }
            if (WSManElementObjectType.Equals(WsManElementObjectTypes.WSManConfigLeafElement))
            {
                object source = null;

                if (input != null)
                {
                    string sourceProp = Name + WSManStringLiterals.HiddenSuffixForSourceOfValue;                
                    if (input.Properties[sourceProp] != null)
                    {
                        source = input.Properties[sourceProp].Value;
                    }
                }

                WSManConfigLeafElement element = new WSManConfigLeafElement(Name, Value, TypeNameOfElement, source);
                mshObject = new PSObject(element);
            }
            if (!String.IsNullOrEmpty(ExtendedTypeName))
            {
                StringBuilder types = new StringBuilder("");
                if (mshObject != null)
                {
                    types.Append(mshObject.ImmediateBaseObject.GetType().FullName);
                    types.Append("#");
                    types.Append(ExtendedTypeName);
                    mshObject.TypeNames.Insert(0, types.ToString());
                }
            }
            return mshObject;
        }