Ejemplo n.º 1
0
        private void ProcessUnsafeRecord()
        {
            string continueStr;
            string whatIfStr;

            if (ParameterSetName == ParameterSet.RawProperty)
            {
                var vals   = RawValue.Select(v => $"'{v}'").ToList();
                var plural = vals.Count > 1 ? "s" : "";

                continueStr = $"property '{RawProperty}' to value{plural} {string.Join(", ", vals)}";
                whatIfStr   = "{RawProperty} = '{RawValue}'";
            }
            else if (ParameterSetName == ParameterSet.Raw)
            {
                var vals = parameters.Select(p => $"{p.Name} = '{p.Value}'");
                whatIfStr   = $"{string.Join(", ", vals)}";
                continueStr = $"properties {whatIfStr}";
            }
            else
            {
                throw new NotImplementedException($"Don't know how to handle parameter set '{ParameterSetName}'");
            }

            if (Force || ShouldContinue($"Are you sure you want to set raw object {continueStr} on {Object.BaseType.ToString().ToLower()} '{Object.Name}'? This may cause minor corruption if the specified value is not valid for the target property. Only proceed if you know what you are doing.", "WARNING!"))
            {
                if (ShouldProcess($"{Object.Name} (ID: {Object.Id})", $"Set-ObjectProperty {whatIfStr}"))
                {
                    ExecuteOrQueue(Object);
                }
            }
        }
Ejemplo n.º 2
0
        private void ProcessUnsafeRecord()
        {
            string continueStr;
            string whatIfStr;

            if (IsRawPropertyParameterSet)
            {
                var vals   = RawValue.Select(v => $"'{v}'").ToList();
                var plural = vals.Count > 1 ? "s" : "";

                continueStr = $"property '{RawProperty}' to value{plural} {string.Join(", ", vals)}";
                whatIfStr   = $"{RawProperty} = {RawValue.ToQuotedList()}"; //todo: bug? progress said it was setting property to system.object[] (it just did rawp.tostring()); we need to expand it to a quoted list or something
            }
            else if (IsRawParameterSet)
            {
                var vals = parameters.Select(p => $"{p.Name} = '{p.Value}'");
                whatIfStr   = $"{string.Join(", ", vals)}";
                continueStr = $"properties {whatIfStr}";
            }
            else
            {
                throw new NotImplementedException($"Don't know how to handle parameter set '{ParameterSetName}'.");
            }

            var objectNameStr = Object != null ? $"'{Object.Name}'" : $"{("ID".Plural(Id))} {(string.Join(", ", Id))}";

            if (Force || ShouldContinue($"Are you sure you want to set raw object {continueStr} on {TypeDescriptionOrDefault(Object)} {objectNameStr}? This may cause minor corruption if the specified value is not valid for the target property. Only proceed if you know what you are doing.", "WARNING!"))
            {
                if (ShouldProcess(BasicShouldProcessMessage, $"{MyInvocation.MyCommand} {whatIfStr}"))
                {
                    ExecuteOrQueue(Object);
                }
            }
        }