Exemple #1
0
        internal static PSModuleInfo RehydratePSModuleInfo(PSObject deserializedModuleInfo)
        {
            DeserializingTypeConverter.RehydrationFlags flags = DeserializingTypeConverter.RehydrationFlags.MissingPropertyOk | DeserializingTypeConverter.RehydrationFlags.NullValueOk;
            string       name = DeserializingTypeConverter.GetPropertyValue <string>(deserializedModuleInfo, "Name", flags);
            string       path = DeserializingTypeConverter.GetPropertyValue <string>(deserializedModuleInfo, "Path", flags);
            PSModuleInfo info = new PSModuleInfo(name, path, null, null);

            info.SetGuid(DeserializingTypeConverter.GetPropertyValue <Guid>(deserializedModuleInfo, "Guid", flags));
            info.SetModuleType(DeserializingTypeConverter.GetPropertyValue <ModuleType>(deserializedModuleInfo, "ModuleType", flags));
            info.SetVersion(DeserializingTypeConverter.GetPropertyValue <Version>(deserializedModuleInfo, "Version", flags));
            info.AccessMode              = DeserializingTypeConverter.GetPropertyValue <ModuleAccessMode>(deserializedModuleInfo, "AccessMode", flags);
            info.Author                  = DeserializingTypeConverter.GetPropertyValue <string>(deserializedModuleInfo, "Author", flags);
            info.ClrVersion              = DeserializingTypeConverter.GetPropertyValue <Version>(deserializedModuleInfo, "ClrVersion", flags);
            info.CompanyName             = DeserializingTypeConverter.GetPropertyValue <string>(deserializedModuleInfo, "CompanyName", flags);
            info.Copyright               = DeserializingTypeConverter.GetPropertyValue <string>(deserializedModuleInfo, "Copyright", flags);
            info.Description             = DeserializingTypeConverter.GetPropertyValue <string>(deserializedModuleInfo, "Description", flags);
            info.DotNetFrameworkVersion  = DeserializingTypeConverter.GetPropertyValue <Version>(deserializedModuleInfo, "DotNetFrameworkVersion", flags);
            info.PowerShellHostName      = DeserializingTypeConverter.GetPropertyValue <string>(deserializedModuleInfo, "PowerShellHostName", flags);
            info.PowerShellHostVersion   = DeserializingTypeConverter.GetPropertyValue <Version>(deserializedModuleInfo, "PowerShellHostVersion", flags);
            info.PowerShellVersion       = DeserializingTypeConverter.GetPropertyValue <Version>(deserializedModuleInfo, "PowerShellVersion", flags);
            info.ProcessorArchitecture   = DeserializingTypeConverter.GetPropertyValue <ProcessorArchitecture>(deserializedModuleInfo, "ProcessorArchitecture", flags);
            info.DeclaredAliasExports    = RehydrateHashtableKeys(deserializedModuleInfo, "ExportedAliases");
            info.DeclaredCmdletExports   = RehydrateHashtableKeys(deserializedModuleInfo, "ExportedCmdlets");
            info.DeclaredFunctionExports = RehydrateHashtableKeys(deserializedModuleInfo, "ExportedFunctions");
            info.DeclaredVariableExports = RehydrateHashtableKeys(deserializedModuleInfo, "ExportedVariables");
            return(info);
        }
Exemple #2
0
 private PSSenderInfo(SerializationInfo info, StreamingContext context)
 {
     if (info != null)
     {
         string source = null;
         try
         {
             source = info.GetValue("CliXml", typeof(string)) as string;
         }
         catch (Exception)
         {
             return;
         }
         if (source != null)
         {
             try
             {
                 PSSenderInfo info2 = DeserializingTypeConverter.RehydratePSSenderInfo(PSObject.AsPSObject(PSSerializer.Deserialize(source)));
                 this.userPrinicpal        = info2.userPrinicpal;
                 this.clientTimeZone       = info2.ClientTimeZone;
                 this.connectionString     = info2.connectionString;
                 this.applicationArguments = info2.applicationArguments;
             }
             catch (Exception)
             {
                 return;
             }
         }
     }
 }
        internal static PSModuleInfo RehydratePSModuleInfo(PSObject deserializedModuleInfo)
        {
            var rehydrationFlags = DeserializingTypeConverter.RehydrationFlags.NullValueOk |
                                   DeserializingTypeConverter.RehydrationFlags.MissingPropertyOk;
            string       name       = DeserializingTypeConverter.GetPropertyValue <string>(deserializedModuleInfo, "Name", rehydrationFlags);
            string       path       = DeserializingTypeConverter.GetPropertyValue <string>(deserializedModuleInfo, "Path", rehydrationFlags);
            PSModuleInfo moduleInfo = new PSModuleInfo(name, path, context: null, sessionState: null);

            moduleInfo.SetGuid(DeserializingTypeConverter.GetPropertyValue <Guid>(deserializedModuleInfo, "Guid", rehydrationFlags));
            moduleInfo.SetModuleType(DeserializingTypeConverter.GetPropertyValue <ModuleType>(deserializedModuleInfo, "ModuleType", rehydrationFlags));
            moduleInfo.SetVersion(DeserializingTypeConverter.GetPropertyValue <Version>(deserializedModuleInfo, "Version", rehydrationFlags));
            moduleInfo.SetHelpInfoUri(DeserializingTypeConverter.GetPropertyValue <string>(deserializedModuleInfo, "HelpInfoUri", rehydrationFlags));

            moduleInfo.AccessMode             = DeserializingTypeConverter.GetPropertyValue <ModuleAccessMode>(deserializedModuleInfo, "AccessMode", rehydrationFlags);
            moduleInfo.Author                 = DeserializingTypeConverter.GetPropertyValue <string>(deserializedModuleInfo, "Author", rehydrationFlags);
            moduleInfo.ClrVersion             = DeserializingTypeConverter.GetPropertyValue <Version>(deserializedModuleInfo, "ClrVersion", rehydrationFlags);
            moduleInfo.CompanyName            = DeserializingTypeConverter.GetPropertyValue <string>(deserializedModuleInfo, "CompanyName", rehydrationFlags);
            moduleInfo.Copyright              = DeserializingTypeConverter.GetPropertyValue <string>(deserializedModuleInfo, "Copyright", rehydrationFlags);
            moduleInfo.Description            = DeserializingTypeConverter.GetPropertyValue <string>(deserializedModuleInfo, "Description", rehydrationFlags);
            moduleInfo.DotNetFrameworkVersion = DeserializingTypeConverter.GetPropertyValue <Version>(deserializedModuleInfo, "DotNetFrameworkVersion", rehydrationFlags);
            moduleInfo.PowerShellHostName     = DeserializingTypeConverter.GetPropertyValue <string>(deserializedModuleInfo, "PowerShellHostName", rehydrationFlags);
            moduleInfo.PowerShellHostVersion  = DeserializingTypeConverter.GetPropertyValue <Version>(deserializedModuleInfo, "PowerShellHostVersion", rehydrationFlags);
            moduleInfo.PowerShellVersion      = DeserializingTypeConverter.GetPropertyValue <Version>(deserializedModuleInfo, "PowerShellVersion", rehydrationFlags);
            moduleInfo.ProcessorArchitecture  = DeserializingTypeConverter.GetPropertyValue <Reflection.ProcessorArchitecture>(deserializedModuleInfo, "ProcessorArchitecture", rehydrationFlags);

            moduleInfo.DeclaredAliasExports    = RehydrateHashtableKeys(deserializedModuleInfo, "ExportedAliases");
            moduleInfo.DeclaredCmdletExports   = RehydrateHashtableKeys(deserializedModuleInfo, "ExportedCmdlets");
            moduleInfo.DeclaredFunctionExports = RehydrateHashtableKeys(deserializedModuleInfo, "ExportedFunctions");
            moduleInfo.DeclaredVariableExports = RehydrateHashtableKeys(deserializedModuleInfo, "ExportedVariables");

            var compatiblePSEditions = DeserializingTypeConverter.GetPropertyValue <string[]>(deserializedModuleInfo, "CompatiblePSEditions", rehydrationFlags);

            if (compatiblePSEditions != null && compatiblePSEditions.Length > 0)
            {
                foreach (var edition in compatiblePSEditions)
                {
                    moduleInfo.AddToCompatiblePSEditions(edition);
                }
            }

            // PowerShellGet related properties
            var tags = DeserializingTypeConverter.GetPropertyValue <string[]>(deserializedModuleInfo, "Tags", rehydrationFlags);

            if (tags != null && tags.Length > 0)
            {
                foreach (var tag in tags)
                {
                    moduleInfo.AddToTags(tag);
                }
            }

            moduleInfo.ReleaseNotes             = DeserializingTypeConverter.GetPropertyValue <string>(deserializedModuleInfo, "ReleaseNotes", rehydrationFlags);
            moduleInfo.ProjectUri               = DeserializingTypeConverter.GetPropertyValue <Uri>(deserializedModuleInfo, "ProjectUri", rehydrationFlags);
            moduleInfo.LicenseUri               = DeserializingTypeConverter.GetPropertyValue <Uri>(deserializedModuleInfo, "LicenseUri", rehydrationFlags);
            moduleInfo.IconUri                  = DeserializingTypeConverter.GetPropertyValue <Uri>(deserializedModuleInfo, "IconUri", rehydrationFlags);
            moduleInfo.RepositorySourceLocation = DeserializingTypeConverter.GetPropertyValue <Uri>(deserializedModuleInfo, "RepositorySourceLocation", rehydrationFlags);

            return(moduleInfo);
        }
Exemple #4
0
        private static Collection <string> RehydrateHashtableKeys(PSObject pso, string propertyName)
        {
            DeserializingTypeConverter.RehydrationFlags flags = DeserializingTypeConverter.RehydrationFlags.MissingPropertyOk | DeserializingTypeConverter.RehydrationFlags.NullValueOk;
            Hashtable hashtable = DeserializingTypeConverter.GetPropertyValue <Hashtable>(pso, propertyName, flags);

            if (hashtable == null)
            {
                return(new Collection <string>());
            }
            return(new Collection <string>((from k in hashtable.Keys.Cast <object>()
                                            where k != null
                                            select k.ToString() into s
                                            where s != null
                                            select s).ToList <string>()));
        }
Exemple #5
0
        private static Collection <string> RehydrateHashtableKeys(PSObject pso, string propertyName)
        {
            const DeserializingTypeConverter.RehydrationFlags rehydrationFlags = DeserializingTypeConverter.RehydrationFlags.NullValueOk |
                                                                                 DeserializingTypeConverter.RehydrationFlags.MissingPropertyOk;
            Hashtable hashtable = DeserializingTypeConverter.GetPropertyValue <Hashtable>(pso, propertyName, rehydrationFlags);

            if (hashtable == null)
            {
                return(new Collection <string>());
            }
            else
            {
                List <string> list = hashtable
                                     .Keys
                                     .Cast <object>()
                                     .Where(static k => k != null)
Exemple #6
0
        /// <summary>
        /// Deserialization constructor
        /// </summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        private PSSenderInfo(SerializationInfo info, StreamingContext context)
        {
            if (info == null)
            {
                return;
            }

            string serializedData = null;

            try
            {
                serializedData = info.GetValue("CliXml", typeof(string)) as string;
            }
            catch (Exception)
            {
                // When a workflow is run locally, there won't be PSSenderInfo
                return;
            }

            if (serializedData == null)
            {
                return;
            }

            try
            {
                PSObject     result     = PSObject.AsPSObject(PSSerializer.Deserialize(serializedData));
                PSSenderInfo senderInfo = DeserializingTypeConverter.RehydratePSSenderInfo(result);

                UserInfo              = senderInfo.UserInfo;
                ConnectionString      = senderInfo.ConnectionString;
                _applicationArguments = senderInfo._applicationArguments;

#if !CORECLR // TimeZone Not In CoreCLR
                this.clientTimeZone = senderInfo.ClientTimeZone;
#endif
            }
            catch (Exception)
            {
                // Ignore conversion errors
                return;
            }
        }