Пример #1
0
 internal ScriptWriter(TextReader cmdletizationXmlReader, string moduleName, string defaultObjectModelWrapper, InvocationInfo invocationInfo, GenerationOptions generationOptions)
 {
     XmlReader xmlReader = XmlReader.Create(cmdletizationXmlReader, xmlReaderSettings);
     try
     {
         XmlSerializer serializer = new PowerShellMetadataSerializer();
         this.cmdletizationMetadata = (PowerShellMetadata) serializer.Deserialize(xmlReader);
     }
     catch (InvalidOperationException exception)
     {
         XmlSchemaException innerException = exception.InnerException as XmlSchemaException;
         if (innerException != null)
         {
             throw new XmlException(innerException.Message, innerException, innerException.LineNumber, innerException.LinePosition);
         }
         XmlException exception3 = exception.InnerException as XmlException;
         if (exception3 != null)
         {
             throw exception3;
         }
         if (exception.InnerException != null)
         {
             throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, CmdletizationCoreResources.ScriptWriter_ConcatenationOfDeserializationExceptions, new object[] { exception.Message, exception.InnerException.Message }), exception.InnerException);
         }
         throw;
     }
     string valueToConvert = this.cmdletizationMetadata.Class.CmdletAdapter ?? defaultObjectModelWrapper;
     this.objectModelWrapper = (Type) LanguagePrimitives.ConvertTo(valueToConvert, typeof(Type), CultureInfo.InvariantCulture);
     if (this.objectModelWrapper.IsGenericType)
     {
         throw new XmlException(string.Format(CultureInfo.CurrentCulture, CmdletizationCoreResources.ScriptWriter_ObjectModelWrapperIsStillGeneric, new object[] { valueToConvert }));
     }
     Type objectModelWrapper = this.objectModelWrapper;
     while (!objectModelWrapper.IsGenericType || (objectModelWrapper.GetGenericTypeDefinition() != typeof(CmdletAdapter<>)))
     {
         objectModelWrapper = objectModelWrapper.BaseType;
         if (objectModelWrapper.Equals(typeof(object)))
         {
             throw new XmlException(string.Format(CultureInfo.CurrentCulture, CmdletizationCoreResources.ScriptWriter_ObjectModelWrapperNotDerivedFromObjectModelWrapper, new object[] { valueToConvert, typeof(CmdletAdapter<>).FullName }));
         }
     }
     this.objectInstanceType = objectModelWrapper.GetGenericArguments()[0];
     this.moduleName = moduleName;
     this.invocationInfo = invocationInfo;
     this.generationOptions = generationOptions;
 }
Пример #2
0
 private void Write38_PowerShellMetadata(string n, string ns, PowerShellMetadata o, bool isNullable, bool needType)
 {
     if (o == null)
     {
         if (isNullable)
         {
             base.WriteNullTagLiteral(n, ns);
         }
     }
     else
     {
         if (!needType && !(o.GetType() == typeof(PowerShellMetadata)))
         {
             throw base.CreateUnknownTypeException(o);
         }
         base.WriteStartElement(n, ns, o, false, null);
         if (needType)
         {
             base.WriteXsiType(null, "http://schemas.microsoft.com/cmdlets-over-objects/2009/11");
         }
         this.Write35_ClassMetadata("Class", "http://schemas.microsoft.com/cmdlets-over-objects/2009/11", o.Class, false, false);
         EnumMetadataEnum[] enums = o.Enums;
         if (enums != null)
         {
             base.WriteStartElement("Enums", "http://schemas.microsoft.com/cmdlets-over-objects/2009/11", null, false);
             for (int i = 0; i < enums.Length; i++)
             {
                 this.Write37_EnumMetadataEnum("Enum", "http://schemas.microsoft.com/cmdlets-over-objects/2009/11", enums[i], false, false);
             }
             base.WriteEndElement();
         }
         base.WriteEndElement(o);
     }
 }
Пример #3
0
 private PowerShellMetadata Read38_PowerShellMetadata(bool isNullable, bool checkType)
 {
     XmlQualifiedName type = checkType ? base.GetXsiType() : null;
     bool flag = false;
     if (isNullable)
     {
         flag = base.ReadNull();
     }
     if ((checkType && (type != null)) && ((type.Name != this.id4_Item) || (type.Namespace != this.id2_Item)))
     {
         throw base.CreateUnknownTypeException(type);
     }
     if (flag)
     {
         return null;
     }
     PowerShellMetadata o = new PowerShellMetadata();
     bool[] flagArray = new bool[2];
     while (base.Reader.MoveToNextAttribute())
     {
         if (!base.IsXmlnsAttribute(base.Reader.Name))
         {
             base.UnknownNode(o);
         }
     }
     base.Reader.MoveToElement();
     if (base.Reader.IsEmptyElement)
     {
         base.Reader.Skip();
         return o;
     }
     base.Reader.ReadStartElement();
     base.Reader.MoveToContent();
     int whileIterations = 0;
     int readerCount = base.ReaderCount;
     while ((base.Reader.NodeType != XmlNodeType.EndElement) && (base.Reader.NodeType != XmlNodeType.None))
     {
         if (base.Reader.NodeType == XmlNodeType.Element)
         {
             if ((!flagArray[0] && (base.Reader.LocalName == this.id118_Class)) && (base.Reader.NamespaceURI == this.id2_Item))
             {
                 o.Class = this.Read35_ClassMetadata(false, true);
                 flagArray[0] = true;
             }
             else if ((base.Reader.LocalName == this.id119_Enums) && (base.Reader.NamespaceURI == this.id2_Item))
             {
                 if (!base.ReadNull())
                 {
                     EnumMetadataEnum[] a = null;
                     int index = 0;
                     if (base.Reader.IsEmptyElement)
                     {
                         base.Reader.Skip();
                     }
                     else
                     {
                         base.Reader.ReadStartElement();
                         base.Reader.MoveToContent();
                         int num4 = 0;
                         int num5 = base.ReaderCount;
                         while ((base.Reader.NodeType != XmlNodeType.EndElement) && (base.Reader.NodeType != XmlNodeType.None))
                         {
                             if (base.Reader.NodeType == XmlNodeType.Element)
                             {
                                 if ((base.Reader.LocalName == this.id80_Enum) && (base.Reader.NamespaceURI == this.id2_Item))
                                 {
                                     a = (EnumMetadataEnum[]) base.EnsureArrayIndex(a, index, typeof(EnumMetadataEnum));
                                     a[index++] = this.Read37_EnumMetadataEnum(false, true);
                                 }
                                 else
                                 {
                                     base.UnknownNode(null, "http://schemas.microsoft.com/cmdlets-over-objects/2009/11:Enum");
                                 }
                             }
                             else
                             {
                                 base.UnknownNode(null, "http://schemas.microsoft.com/cmdlets-over-objects/2009/11:Enum");
                             }
                             base.Reader.MoveToContent();
                             base.CheckReaderCount(ref num4, ref num5);
                         }
                         base.ReadEndElement();
                     }
                     o.Enums = (EnumMetadataEnum[]) base.ShrinkArray(a, index, typeof(EnumMetadataEnum), false);
                 }
             }
             else
             {
                 base.UnknownNode(o, "http://schemas.microsoft.com/cmdlets-over-objects/2009/11:Class, http://schemas.microsoft.com/cmdlets-over-objects/2009/11:Enums");
             }
         }
         else
         {
             base.UnknownNode(o, "http://schemas.microsoft.com/cmdlets-over-objects/2009/11:Class, http://schemas.microsoft.com/cmdlets-over-objects/2009/11:Enums");
         }
         base.Reader.MoveToContent();
         base.CheckReaderCount(ref whileIterations, ref readerCount);
     }
     base.ReadEndElement();
     return o;
 }
Пример #4
0
        internal ScriptWriter(
            TextReader cmdletizationXmlReader,
            string moduleName,
            string defaultObjectModelWrapper,
            InvocationInfo invocationInfo,
            GenerationOptions generationOptions)
        {
            Dbg.Assert(cmdletizationXmlReader != null, "Caller should verify that cmdletizationXmlReader != null");
            Dbg.Assert(!string.IsNullOrEmpty(moduleName), "Caller should verify that moduleName != null");
            Dbg.Assert(invocationInfo != null, "Caller should verify that invocationInfo != null");
            Dbg.Assert(!string.IsNullOrEmpty(defaultObjectModelWrapper), "Caller should verify that defaultObjectModelWrapper != null");

            XmlReader xmlReader = XmlReader.Create(cmdletizationXmlReader, ScriptWriter.s_xmlReaderSettings);
            try
            {
                var xmlSerializer = new PowerShellMetadataSerializer();
                _cmdletizationMetadata = (PowerShellMetadata)xmlSerializer.Deserialize(xmlReader);
            }
            catch (InvalidOperationException e)
            {
#if !CORECLR    // No XmlSchema Validation In CoreCLR
                XmlSchemaException schemaException = e.InnerException as XmlSchemaException;
                if (schemaException != null)
                {
                    throw new XmlException(schemaException.Message, schemaException, schemaException.LineNumber, schemaException.LinePosition);
                }
#endif
                XmlException xmlException = e.InnerException as XmlException;
                if (xmlException != null)
                {
                    throw xmlException;
                }

                if (e.InnerException != null)
                {
                    string message = string.Format(
                        CultureInfo.CurrentCulture,
                        CmdletizationCoreResources.ScriptWriter_ConcatenationOfDeserializationExceptions,
                        e.Message,
                        e.InnerException.Message);

                    throw new InvalidOperationException(message, e.InnerException);
                }

                throw;
            }

            string objectModelWrapperName = _cmdletizationMetadata.Class.CmdletAdapter ?? defaultObjectModelWrapper;
            _objectModelWrapper = (Type)LanguagePrimitives.ConvertTo(objectModelWrapperName, typeof(Type), CultureInfo.InvariantCulture);
            TypeInfo objectModelWrapperTypeInfo = _objectModelWrapper.GetTypeInfo();
            if (objectModelWrapperTypeInfo.IsGenericType)
            {
                string message = string.Format(
                    CultureInfo.CurrentCulture,
                    CmdletizationCoreResources.ScriptWriter_ObjectModelWrapperIsStillGeneric,
                    objectModelWrapperName);
                throw new XmlException(message);
            }
            Type baseType = _objectModelWrapper;
            TypeInfo baseTypeInfo = objectModelWrapperTypeInfo;
            while ((!baseTypeInfo.IsGenericType) || baseTypeInfo.GetGenericTypeDefinition() != typeof(CmdletAdapter<>))
            {
                baseType = baseTypeInfo.BaseType;
                if (baseType == typeof(object))
                {
                    string message = string.Format(
                        CultureInfo.CurrentCulture,
                        CmdletizationCoreResources.ScriptWriter_ObjectModelWrapperNotDerivedFromObjectModelWrapper,
                        objectModelWrapperName,
                        typeof(CmdletAdapter<>).FullName);
                    throw new XmlException(message);
                }
                baseTypeInfo = baseType.GetTypeInfo();
            }
            _objectInstanceType = baseType.GetGenericArguments()[0];

            _moduleName = moduleName;
            _invocationInfo = invocationInfo;
            _generationOptions = generationOptions;
        }