internal void Load(IDictionary envVariables)
 {
     Data = envVariables
         .Cast<DictionaryEntry>()
         .SelectMany(AzureEnvToAppEnv)
         .Where(entry => ((string)entry.Key).StartsWith(_prefix, StringComparison.OrdinalIgnoreCase))
         .ToDictionary(
             entry => ((string)entry.Key).Substring(_prefix.Length),
             entry => (string)entry.Value,
             StringComparer.OrdinalIgnoreCase);
 }
        internal void Load(IDictionary envVariables)
        {
            Data = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

            var filteredEnvVariables = envVariables
                .Cast<DictionaryEntry>()
                .SelectMany(AzureEnvToAppEnv)
                .Where(entry => ((string)entry.Key).StartsWith(_prefix, StringComparison.OrdinalIgnoreCase));

            foreach (var envVariable in filteredEnvVariables)
            {
                var key = ((string)envVariable.Key).Substring(_prefix.Length);
                Data[key] = (string)envVariable.Value;
            }
        }
Example #3
0
        private void Initialize(string assemblyPath, IDictionary settings)
        {
            AssemblyNameOrPath = assemblyPath;

            var newSettings = settings as IDictionary<string, object>;
            Settings = newSettings ?? settings.Cast<DictionaryEntry>().ToDictionary(de => (string)de.Key, de => de.Value);

            if (Settings.ContainsKey(PackageSettings.InternalTraceLevel))
            {
                var traceLevel = (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), (string)Settings[PackageSettings.InternalTraceLevel], true);

                if (Settings.ContainsKey(PackageSettings.InternalTraceWriter))
                    InternalTrace.Initialize((TextWriter)Settings[PackageSettings.InternalTraceWriter], traceLevel);
#if !PORTABLE && !SILVERLIGHT
                else
                {
                    var workDirectory = Settings.ContainsKey(PackageSettings.WorkDirectory) ? (string)Settings[PackageSettings.WorkDirectory] : Env.DefaultWorkDirectory;
                    var logName = string.Format(LOG_FILE_FORMAT, Process.GetCurrentProcess().Id, Path.GetFileName(assemblyPath));
                    InternalTrace.Initialize(Path.Combine(workDirectory, logName), traceLevel);
                }
#endif
            }
        }
        public Module UpdateModule(string automationAccountName, IDictionary tags, string name, Uri contentLinkUri, string contentLinkVersion)
        {
            var moduleModel = this.automationManagementClient.Modules.Get(automationAccountName, name).Module;
            if(tags != null && contentLinkUri != null)
            {
                var moduleCreateParameters = new AutomationManagement.Models.ModuleCreateParameters();
                
                moduleCreateParameters.Name = name;
                moduleCreateParameters.Tags = tags.Cast<DictionaryEntry>().ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value.ToString());

                moduleCreateParameters.Properties = new ModuleCreateProperties();
                moduleCreateParameters.Properties.ContentLink = new AutomationManagement.Models.ContentLink();
                moduleCreateParameters.Properties.ContentLink.Uri = contentLinkUri;
                moduleCreateParameters.Properties.ContentLink.Version =
                    (String.IsNullOrWhiteSpace(contentLinkVersion))
                        ? Guid.NewGuid().ToString()
                        : contentLinkVersion;

                this.automationManagementClient.Modules.Create(automationAccountName,
                    moduleCreateParameters);

            }
            else if (contentLinkUri != null)
            {
                var moduleUpdateParameters = new AutomationManagement.Models.ModuleUpdateParameters();

                moduleUpdateParameters.Name = name;
                moduleUpdateParameters.Properties = new ModuleUpdateProperties();
                moduleUpdateParameters.Properties.ContentLink = new AutomationManagement.Models.ContentLink();
                moduleUpdateParameters.Properties.ContentLink.Uri = contentLinkUri;
                moduleUpdateParameters.Properties.ContentLink.Version =
                    (String.IsNullOrWhiteSpace(contentLinkVersion))
                        ? Guid.NewGuid().ToString()
                        : contentLinkVersion;

                moduleUpdateParameters.Tags = moduleModel.Tags;

                this.automationManagementClient.Modules.Update(automationAccountName, moduleUpdateParameters);
            }
            else if(tags != null)
            {
                var moduleUpdateParameters = new AutomationManagement.Models.ModuleUpdateParameters();
                
                moduleUpdateParameters.Name = name;
                moduleUpdateParameters.Tags = tags.Cast<DictionaryEntry>().ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value.ToString());
                moduleUpdateParameters.Properties = new ModuleUpdateProperties();

                this.automationManagementClient.Modules.Update(automationAccountName, moduleUpdateParameters);
            }

            var updatedModule = this.automationManagementClient.Modules.Get(automationAccountName, name).Module;
            return new Module(automationAccountName, updatedModule);
        }
        public Module CreateModule(string automationAccountName, Uri contentLink, string moduleName,
            IDictionary tags)
        {
            IDictionary<string, string> moduleTags = null;
            if (tags != null) moduleTags = tags.Cast<DictionaryEntry>().ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value.ToString());
            var createdModule = this.automationManagementClient.Modules.Create(automationAccountName,
                new AutomationManagement.Models.ModuleCreateParameters()
                {
                    Name = moduleName,
                    Tags = moduleTags,
                    Properties = new AutomationManagement.Models.ModuleCreateProperties()
                    {
                        ContentLink = new AutomationManagement.Models.ContentLink()
                        {
                            Uri = contentLink,
                            ContentHash = null,
                            Version = null
                        }
                    },
                });

            return this.GetModule(automationAccountName, moduleName);
        }
        public Connection CreateConnection(string automationAccountName, string name, string connectionTypeName, IDictionary connectionFieldValues,
            string description)
        {
            var connectionModel = this.TryGetConnectionModel(automationAccountName, name);
            if (connectionModel != null)
            {
                throw new ResourceCommonException(typeof(Connection),
                    string.Format(CultureInfo.CurrentCulture, Resources.ConnectionAlreadyExists, name));
            }

            var ccprop = new ConnectionCreateProperties()
            {
                Description = description,
                ConnectionType = new ConnectionTypeAssociationProperty() { Name = connectionTypeName },
                FieldDefinitionValues = connectionFieldValues.Cast<DictionaryEntry>().ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value.ToString())
            };

            var ccparam = new ConnectionCreateParameters() { Name = name, Properties = ccprop };

            var connection = this.automationManagementClient.Connections.Create(automationAccountName, ccparam).Connection;

            return new Connection(automationAccountName, connection);
        }
Example #7
0
        IDictionary<string, string> GetHeaders(IDictionary result)
        {
            if (result == null) return new Dictionary<string, string>();

            return result.Cast<DictionaryEntry>()
                .ToDictionary(e => (string)e.Key, e => Encoding.GetString((byte[])e.Value));
        }
 private void AssertStateItems(IDictionary expected, ISessionStateItemCollection actual)
 {
     Assert.Equal(expected.Count, actual.Count);
     foreach (var kvp in expected.Cast<DictionaryEntry>())
     {
         var name = (string)kvp.Key;
         Assert.Equal(kvp.Value, actual[name]);
     }
 }
        public Runbook CreateRunbookByName(string resourceGroupName, string automationAccountName, string runbookName, string description,
            IDictionary tags, string type, bool? logProgress, bool? logVerbose, bool overwrite)
        {
            using (var request = new RequestSettings(this.automationManagementClient))
            {
                var runbookModel = this.TryGetRunbookModel(resourceGroupName, automationAccountName, runbookName);
                if (runbookModel != null && overwrite == false)
                {
                    throw new ResourceCommonException(typeof (Runbook),
                        string.Format(CultureInfo.CurrentCulture, Resources.RunbookAlreadyExists, runbookName));
                }

                IDictionary<string, string> runbooksTags = null;
                if (tags != null) runbooksTags = tags.Cast<DictionaryEntry>().ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value.ToString());

                var rdcprop = new RunbookCreateOrUpdateDraftProperties()
                {
                    Description = description,
                    RunbookType = String.IsNullOrWhiteSpace(type) ? RunbookTypeEnum.Script : (0 == string.Compare(type, Constants.RunbookType.PowerShellWorkflow, StringComparison.OrdinalIgnoreCase)) ? RunbookTypeEnum.Script : type,
                    LogProgress =  logProgress.HasValue && logProgress.Value,
                    LogVerbose = logVerbose.HasValue && logVerbose.Value,
                    Draft = new RunbookDraft(),
                };

                var rdcparam = new RunbookCreateOrUpdateDraftParameters()
                {
                    Name = runbookName,
                    Properties = rdcprop,
                    Tags = runbooksTags,
                    Location = GetAutomationAccount(resourceGroupName, automationAccountName).Location
                };

                this.automationManagementClient.Runbooks.CreateOrUpdateWithDraft(resourceGroupName, automationAccountName, rdcparam);

                return this.GetRunbook(resourceGroupName, automationAccountName, runbookName);
            }
        }
        public Runbook UpdateRunbook(string resourceGroupName, string automationAccountName, string runbookName, string description,
            IDictionary tags, bool? logProgress, bool? logVerbose)
        {
            using (var request = new RequestSettings(this.automationManagementClient))
            {
                var runbookModel = this.TryGetRunbookModel(resourceGroupName, automationAccountName, runbookName);
                if (runbookModel == null)
                {
                    throw new ResourceCommonException(typeof (Runbook),
                        string.Format(CultureInfo.CurrentCulture, Resources.RunbookNotFound, runbookName));
                }

                var runbookUpdateParameters = new RunbookPatchParameters();
                runbookUpdateParameters.Name = runbookName;
                runbookUpdateParameters.Tags = null;

                IDictionary<string, string> runbooksTags = null;
                if (tags != null) runbooksTags = tags.Cast<DictionaryEntry>().ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value.ToString());

                runbookUpdateParameters.Properties = new RunbookPatchProperties();
                runbookUpdateParameters.Properties.Description = description ?? runbookModel.Properties.Description;
                runbookUpdateParameters.Properties.LogProgress = (logProgress.HasValue)
                    ? logProgress.Value
                    : runbookModel.Properties.LogProgress;
                runbookUpdateParameters.Properties.LogVerbose = (logVerbose.HasValue)
                    ? logVerbose.Value
                    : runbookModel.Properties.LogVerbose;
                runbookUpdateParameters.Tags = runbooksTags ?? runbookModel.Tags;

                var runbook =
                    this.automationManagementClient.Runbooks.Patch(resourceGroupName, automationAccountName, runbookUpdateParameters)
                        .Runbook;

                return new Runbook(resourceGroupName, automationAccountName, runbook);
            }
        }
        public AutomationAccount UpdateAutomationAccount(string resourceGroupName, string automationAccountName,
            string plan, IDictionary tags)
        {
            Requires.Argument("ResourceGroupName", resourceGroupName).NotNull();
            Requires.Argument("AutomationAccountName", automationAccountName).NotNull();

            var automationAccount = GetAutomationAccount(resourceGroupName, automationAccountName);

            IDictionary<string, string> accountTags = null;
            if (tags != null)
            {
                accountTags = tags.Cast<DictionaryEntry>()
                    .ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value.ToString());
            }
            else
            {
                accountTags = automationAccount.Tags.Cast<DictionaryEntry>()
                    .ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value.ToString());
                ;
            }

            var accountUpdateParameters = new AutomationAccountPatchParameters()
            {
                Name = automationAccountName,
                Properties = new AutomationAccountPatchProperties()
                {
                    Sku = new Sku()
                    {
                        Name = String.IsNullOrWhiteSpace(plan) ? automationAccount.Plan : plan,
                    }
                },
                Tags = accountTags,
            };

            var account =
                this.automationManagementClient.AutomationAccounts.Patch(resourceGroupName,
                    accountUpdateParameters).AutomationAccount;


            return new AutomationAccount(resourceGroupName, account);
        }
        public AutomationAccount CreateAutomationAccount(string resourceGroupName, string automationAccountName,
            string location, string plan, IDictionary tags)
        {
            Requires.Argument("ResourceGroupName", resourceGroupName).NotNull();
            Requires.Argument("Location", location).NotNull();
            Requires.Argument("AutomationAccountName", automationAccountName).NotNull();

            IDictionary<string, string> accountTags = null;
            if (tags != null)
                accountTags = tags.Cast<DictionaryEntry>()
                    .ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value.ToString());

            var accountCreateOrUpdateParameters = new AutomationAccountCreateOrUpdateParameters()
            {
                Location = location,
                Name = automationAccountName,
                Properties = new AutomationAccountCreateOrUpdateProperties()
                {
                    Sku = new Sku()
                    {
                        Name = String.IsNullOrWhiteSpace(plan) ? Constants.DefaultPlan : plan,
                    }
                },
                Tags = accountTags
            };

            var account =
                this.automationManagementClient.AutomationAccounts.CreateOrUpdate(resourceGroupName,
                    accountCreateOrUpdateParameters).AutomationAccount;


            return new AutomationAccount(resourceGroupName, account);
        }
 public MapType(IDictionary value)
 {
     Entry = value.Cast<DictionaryEntry>()
       .Select(entry => new MapTypeEntry
                            {
                                Key = new GenericValueType(entry.Key),
                                Value = new GenericValueType(entry.Value)
                            })
       .ToArray();
 }
        public Model.DscConfiguration CreateConfiguration(
            string resourceGroupName,
            string automationAccountName,
            string sourcePath,
            IDictionary tags, 
            string description,
            bool? logVerbose,
            bool published,
            bool overWrite)
        {
            using (var request = new RequestSettings(this.automationManagementClient))
            {
                Requires.Argument("ResourceGroupName", resourceGroupName).NotNull();
                Requires.Argument("AutomationAccountName", automationAccountName).NotNull();
                Requires.Argument("SourcePath", sourcePath).NotNull();

                string fileContent = null;
                string configurationName = String.Empty;

                try
                {
                    if (File.Exists(Path.GetFullPath(sourcePath)))
                    {
                        fileContent = System.IO.File.ReadAllText(sourcePath);
                    }
                }
                catch (Exception)
                {
                    // exception in accessing the file path
                    throw new FileNotFoundException(
                                        string.Format(
                                            CultureInfo.CurrentCulture,
                                            Resources.ConfigurationSourcePathInvalid));
                }

                // configuration name is same as filename
                configurationName = Path.GetFileNameWithoutExtension(sourcePath);

                // for the private preview, configuration can be imported in Published mode only
                // Draft mode is not implemented
                if (!published)
                {
                    throw new NotImplementedException(
                                        string.Format(
                                            CultureInfo.CurrentCulture,
                                            Resources.ConfigurationNotPublished));
                }

                // if configuration already exists, ensure overwrite flag is specified
                var configurationModel = this.TryGetConfigurationModel(
                    resourceGroupName,
                    automationAccountName,
                    configurationName);
                if (configurationModel != null)
                {
                    if (!overWrite)
                    {
                        throw new ResourceCommonException(typeof(Model.DscConfiguration),
                            string.Format(CultureInfo.CurrentCulture, Resources.ConfigurationAlreadyExists, configurationName));
                    }
                }

                // location of the configuration is set to same as that of automation account
                string location = this.GetAutomationAccount(resourceGroupName, automationAccountName).Location;

                IDictionary<string, string> configurationTags = null;
                if (tags != null) configurationTags = tags.Cast<DictionaryEntry>().ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value.ToString());

                var configurationCreateParameters = new DscConfigurationCreateOrUpdateParameters()
                                                        {
                                                            Name = configurationName,
                                                            Location = location,
                                                            Tags = configurationTags,
                                                            Properties = new DscConfigurationCreateOrUpdateProperties()
                                                                    {
                                                                        Description = String.IsNullOrEmpty(description) ? String.Empty : description,
                                                                        LogVerbose = (logVerbose.HasValue) ? logVerbose.Value : false,
                                                                        Source = new Microsoft.Azure.Management.Automation.Models.ContentSource()
                                                                                {
                                                                                    // only embeddedContent supported for now
                                                                                    ContentType = Model.ContentSourceType.embeddedContent.ToString(),
                                                                                    Value = fileContent
                                                                                }
                                                                    }
                                                        };

                var configuration =
                    this.automationManagementClient.Configurations.CreateOrUpdate(
                        resourceGroupName,
                        automationAccountName,
                        configurationCreateParameters).Configuration;

                return new Model.DscConfiguration(resourceGroupName, automationAccountName, configuration);
            }
        }
Example #15
0
        private void Initialize(string assemblyPath, IDictionary settings)
        {
            AssemblyNameOrPath = assemblyPath;

            var newSettings = settings as IDictionary<string, object>;
            Settings = newSettings ?? settings.Cast<DictionaryEntry>().ToDictionary(de => (string)de.Key, de => de.Value);

            if (Settings.ContainsKey(FrameworkPackageSettings.InternalTraceLevel))
            {
                var traceLevel = (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), (string)Settings[FrameworkPackageSettings.InternalTraceLevel], true);

                if (Settings.ContainsKey(FrameworkPackageSettings.InternalTraceWriter))
                    InternalTrace.Initialize((TextWriter)Settings[FrameworkPackageSettings.InternalTraceWriter], traceLevel);
#if !PORTABLE
                else
                {
                    var workDirectory = Settings.ContainsKey(FrameworkPackageSettings.WorkDirectory)
                        ? (string)Settings[FrameworkPackageSettings.WorkDirectory]
                        : Directory.GetCurrentDirectory();
#if NETSTANDARD1_6
                    var id = DateTime.Now.ToString("o");
#else      
                    var id = Process.GetCurrentProcess().Id;
#endif
                    var logName = string.Format(LOG_FILE_FORMAT, id, Path.GetFileName(assemblyPath));
                    InternalTrace.Initialize(Path.Combine(workDirectory, logName), traceLevel);
                }
#endif
            }
        }