예제 #1
0
        /// <summary>
        /// Apply user input to the retrieved sql virtual machine.
        /// </summary>
        /// <param name="model">The sql virtual machine that will be updated<param>
        /// <returns>The model to send to the update</returns>
        protected override IEnumerable <AzureSqlVMModel> ApplyUserInputToModel(IEnumerable <AzureSqlVMModel> model)
        {
            List <AzureSqlVMModel> updateData = new List <AzureSqlVMModel>();
            AzureSqlVMModel        sqlVM      = model.FirstOrDefault();

            if (ParameterSetName.EndsWith(ParameterSet.InputObject))
            {
                sqlVM.Offer                  = InputObject.Offer ?? sqlVM.Offer;
                sqlVM.Sku                    = InputObject.Sku ?? sqlVM.Sku;
                sqlVM.LicenseType            = InputObject.LicenseType ?? sqlVM.LicenseType;
                sqlVM.SqlManagementType      = InputObject.SqlManagementType ?? sqlVM.SqlManagementType;
                sqlVM.SqlVirtualMachineGroup = InputObject.SqlVirtualMachineGroup ?? sqlVM.SqlVirtualMachineGroup;
                sqlVM.WsfcDomainCredentials  = InputObject.WsfcDomainCredentials ?? sqlVM.WsfcDomainCredentials;
                sqlVM.Tags                   = InputObject.Tags ?? sqlVM.Tags;
            }
            else
            {
                if (LicenseType != null)
                {
                    sqlVM.LicenseType = LicenseType;
                }
                if (Offer != null)
                {
                    sqlVM.Offer = Offer;
                }
                if (Sku != null)
                {
                    sqlVM.Sku = Sku;
                }
                if (SqlManagementType != null)
                {
                    sqlVM.SqlManagementType = SqlManagementType;
                }
                if (Tag != null)
                {
                    sqlVM.Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true);
                }
            }
            updateData.Add(sqlVM);
            return(updateData);
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            if (ParameterSetName.EndsWith(Microsoft.Azure.Commands.Network.Properties.Resources.SetByResource))
            {
                if (DefaultBackendAddressPool != null)
                {
                    this.DefaultBackendAddressPoolId = this.DefaultBackendAddressPool.Id;
                }
                if (DefaultBackendHttpSettings != null)
                {
                    this.DefaultBackendHttpSettingsId = this.DefaultBackendHttpSettings.Id;
                }
                if (DefaultRedirectConfiguration != null)
                {
                    this.DefaultRedirectConfigurationId = this.DefaultRedirectConfiguration.Id;
                }
                if (DefaultRewriteRuleSet != null)
                {
                    this.DefaultRewriteRuleSetId = this.DefaultRewriteRuleSet.Id;
                }
            }
        }
예제 #3
0
        protected override void ProcessRecord()
        {
            if (ParameterSetName.EndsWith("Simple"))
            {
                FileSystemSecurity2.ConvertToFileSystemFlags(appliesTo, out inheritanceFlags, out propagationFlags);
            }

            if (ParameterSetName.StartsWith("Path"))
            {
                foreach (var path in paths)
                {
                    FileSystemInfo item = null;

                    try
                    {
                        item = GetFileSystemInfo2(path);
                    }
                    catch (Exception ex)
                    {
                        WriteError(new ErrorRecord(ex, "ReadFileError", ErrorCategory.OpenError, path));
                    }

                    if (ParameterSetName == "PathSimple")
                    {
                        FileSystemSecurity2.ConvertToFileSystemFlags(appliesTo, out inheritanceFlags, out propagationFlags);
                    }

                    try
                    {
                        FileSystemAccessRule2.RemoveFileSystemAccessRule(item, account.ToList(), accessRights, accessType, inheritanceFlags, propagationFlags);
                    }
                    catch (UnauthorizedAccessException)
                    {
                        try
                        {
                            var ownerInfo     = FileSystemOwner.GetOwner(item);
                            var previousOwner = ownerInfo.Owner;

                            FileSystemOwner.SetOwner(item, System.Security.Principal.WindowsIdentity.GetCurrent().User);

                            FileSystemAccessRule2.RemoveFileSystemAccessRule(item, account.ToList(), accessRights, accessType, inheritanceFlags, propagationFlags);

                            FileSystemOwner.SetOwner(item, previousOwner);
                        }
                        catch (Exception ex2)
                        {
                            WriteError(new ErrorRecord(ex2, "RemoveAceError", ErrorCategory.WriteError, path));
                        }
                    }
                    catch (Exception ex)
                    {
                        WriteError(new ErrorRecord(ex, "RemoveAceError", ErrorCategory.WriteError, path));
                    }

                    if (passThru == true)
                    {
                        FileSystemAccessRule2.GetFileSystemAccessRules(item, true, true).ForEach(ace => WriteObject(ace));
                    }
                }
            }
            else
            {
                foreach (var sd in securityDescriptors)
                {
                    FileSystemAccessRule2.RemoveFileSystemAccessRule(sd, account.ToList(), accessRights, accessType, inheritanceFlags, propagationFlags);

                    if (passThru == true)
                    {
                        FileSystemAccessRule2.GetFileSystemAccessRules(sd, true, true).ForEach(ace => WriteObject(ace));
                    }
                }
            }
        }
예제 #4
0
        protected override void InternalProcessRecord()
        {
            bool test = false;
            ShouldProcessReason reason;

            if (!base.ShouldProcess(null, null, null, out reason))
            {
                if (reason == ShouldProcessReason.WhatIf)
                {
                    test = true;
                }
            }
            if (test)
            {
                Logger.Verbose = true;
            }

            ReplaceFieldValues rfv = new ReplaceFieldValues();

            rfv.LogFile = LogFile;
            rfv.UseInternalFieldName = UseInternalFieldName;
            if (FieldName != null)
            {
                rfv.FieldName.AddRange(FieldName);
            }
            rfv.Publish = Publish.IsPresent;
            rfv.Test    = test;
            rfv.Quiet   = !Logger.Verbose;

            if (ParameterSetName.EndsWith("_InputFile"))
            {
                rfv.ParseInputFile(InputFile, InputFileDelimiter, false);
            }
            else if (ParameterSetName.EndsWith("_XmlInputFile"))
            {
                rfv.ParseInputFile(XmlInputFile.Read());
            }
            else if (ParameterSetName.EndsWith("_ParameterInput"))
            {
                rfv.SearchStrings.Add(new ReplaceFieldValues.SearchReplaceData(SearchString, ReplaceString));
            }
            if (rfv.SearchStrings.Count == 0)
            {
                throw new SPCmdletException("No search strings were specified.");
            }

            switch (ParameterSetName)
            {
            case "WebApplication_ParameterInput":
            case "WebApplication_XmlInputFile":
            case "WebApplication_InputFile":
                SPWebApplication webApp1 = WebApplication.Read();
                if (webApp1 == null)
                {
                    throw new SPException("Web Application not found.");
                }
                rfv.ReplaceValues(webApp1);
                break;

            case "Site_ParameterInput":
            case "Site_XmlInputFile":
            case "Site_InputFile":
                using (SPSite site = Site.Read())
                {
                    rfv.ReplaceValues(site);
                }
                break;

            case "Web_ParameterInput":
            case "Web_XmlInputFile":
            case "Web_InputFile":
                using (SPWeb web = Web.Read())
                {
                    try
                    {
                        rfv.ReplaceValues(web);
                    }
                    finally
                    {
                        web.Site.Dispose();
                    }
                }
                break;

            case "List_ParameterInput":
            case "List_XmlInputFile":
            case "List_InputFile":
                SPList list = List.Read();
                try
                {
                    rfv.ReplaceValues(list);
                }
                finally
                {
                    list.ParentWeb.Dispose();
                    list.ParentWeb.Site.Dispose();
                }
                break;

            default:
                SPFarm farm = Farm.Read();
                foreach (SPService svc in farm.Services)
                {
                    if (!(svc is SPWebService))
                    {
                        continue;
                    }

                    foreach (SPWebApplication webApp2 in ((SPWebService)svc).WebApplications)
                    {
                        rfv.ReplaceValues(webApp2);
                    }
                }
                break;
            }
        }