示例#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
        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;
        }
示例#3
0
        static XmlSerializer ConstructXmlSerializer()
        {
            XmlSerializer xmlSerializer = new Microsoft.PowerShell.Cmdletization.Xml.PowerShellMetadataSerializer();

            return(xmlSerializer);
        }
示例#4
0
 static XmlSerializer ConstructXmlSerializer()
 {
     XmlSerializer xmlSerializer = new Microsoft.PowerShell.Cmdletization.Xml.PowerShellMetadataSerializer();
     return xmlSerializer;
 }