public static string GetReadableName( PSScriptProperty prop )
        {
            var getter = prop.GetterScript;

            var name = getter.ToString().Replace("if( -not($_) ){ $_ = $this; } ", "");
            return String.Format("{{ {0} }}", name);
        }
Beispiel #2
0
 public override PSMemberInfo Copy()
 {
     PSScriptProperty destiny = new PSScriptProperty(base.name, this.GetterScript, this.SetterScript) {
         shouldCloneOnAccess = this.shouldCloneOnAccess
     };
     base.CloneBaseProperties(destiny);
     return destiny;
 }
Beispiel #3
0
        public override PSMemberInfo Copy()
        {
            PSScriptProperty psScriptProperty = new PSScriptProperty(this.name, this.getterScript, this.setterScript);

            psScriptProperty.shouldCloneOnAccess = this.shouldCloneOnAccess;
            this.CloneBaseProperties((PSMemberInfo)psScriptProperty);
            return((PSMemberInfo)psScriptProperty);
        }
Beispiel #4
0
        public override PSMemberInfo Copy()
        {
            PSScriptProperty destiny = new PSScriptProperty(base.name, this.GetterScript, this.SetterScript)
            {
                shouldCloneOnAccess = this.shouldCloneOnAccess
            };

            base.CloneBaseProperties(destiny);
            return(destiny);
        }
        public DynamicMemberSpecification(object[] plotItems, object againstItem, PSScriptProperty acrossSpecifier, PSScriptProperty indexSpecifier,
            IDictionary<Regex,IScaleDescriptor> scaleDescriptors )
        {
            if (plotItems == null)
            {
                throw new ArgumentNullException("plotItems");
            }

            _scaleDescriptors = scaleDescriptors;
            _plotItemDescriptors = new List<DynamicMemberDescriptor>();
            _plotItems = plotItems;
            _againstItem = againstItem;
            _acrossSpecifier = acrossSpecifier;
            _indexSpecifier = indexSpecifier;
        }
        object TransformItem( EngineIntrinsics engineIntrinsics, object inputData )
        {
            var inputObject = inputData.ToPSObject().BaseObject;

            var scriptBlock = inputObject as ScriptBlock;
            if (null == scriptBlock)
            {
                return inputData;
            }

            scriptBlock = ScriptBlock.Create(  "if( -not($_) ){ $_ = $this; } " + scriptBlock );

            var property = new PSScriptProperty( "_" + Guid.NewGuid().ToString("N"), scriptBlock);

            return property;
        }
        public override object Transform(EngineIntrinsics engineIntrinsics, object inputData)
        {
            if (null == inputData)
            {
                return inputData;
            }

            var inputObject = inputData.ToPSObject().BaseObject;

            var name = inputObject as string;
            if (null == name)
            {
                return inputData;
            }

            var scriptBlock = ScriptBlock.Create( "@($this | select-object -expand '" + name + "' )");

            var property = new PSScriptProperty("_SelectExpand" + Guid.NewGuid().ToString("N"), scriptBlock);

            return property;
        }
        public override object Transform(EngineIntrinsics engineIntrinsics, object inputData)
        {
            if (null == inputData)
            {
                return inputData;
            }

            var inputObject = inputData.ToPSObject().BaseObject;

            var name = inputObject as string;
            if (null == name)
            {
                return inputData;
            }

            var scriptBlock = ScriptBlock.Create("group-object -property '" + name + "'" );

            var property = new PSScriptProperty("_GroupObject" + name, scriptBlock);

            return property;
        }
        public override object Transform(EngineIntrinsics engineIntrinsics, object inputData)
        {
            if (null == inputData)
            {
                return inputData;
            }

            var inputObject = inputData.ToPSObject().BaseObject;

            var name = inputObject as ScriptBlock;
            if (null == name)
            {
                return inputData;
            }

            var scriptBlock = ScriptBlock.Create("group-object -property {" + name + "}");

            var property = new PSScriptProperty("_GroupObjectScript_" + Guid.NewGuid().ToString("N"), scriptBlock);

            return property;
        }
 public DynamicMemberSpecification(object[] plotItems, object againstItem, PSScriptProperty acrossSpecifier, PSScriptProperty indexSpecifier)
     : this(plotItems, againstItem, acrossSpecifier, indexSpecifier,new Dictionary<Regex, IScaleDescriptor>())
 {
 }
        private IEnumerable<DynamicMemberDescriptor> CreateByItemMemberDescriptors(DynamicMemberSpecification spec, PSObject ps)
        {
            if (null == spec.AcrossSpecifier)
            {
                return new DynamicMemberDescriptor[]{ };
            }
            var list = new List<DynamicMemberDescriptor>();
            var acrossAccessorName = spec.AcrossSpecifier.Name;
            ps.Properties.Add(spec.AcrossSpecifier);
            var sps = new PSObjectSolidifier().AsConcreteType(ps) as SolidPSObjectBase;
            object oitem = sps.GetPropValue<object>(acrossAccessorName);
            ps.Properties.Remove(acrossAccessorName);

            var items = oitem as ICollection;
            if (null == items)
            {
                items = new object[] { oitem };
            }

            if (null == spec.IndexSpecifier)
            {

                for (int i = 0; i < items.Count; ++i)
                {
                    var byItemScript = String.Format("$this.'{1}' | select-object -index '{0}'", i, acrossAccessorName);
                    var prop = new PSScriptProperty(
                        acrossAccessorName + i,
                        System.Management.Automation.ScriptBlock.Create(byItemScript));
                    var scale = ( from sd in spec.ScaleDescriptors
                                where sd.Key.IsMatch(prop.Name)
                                select sd.Value ).FirstOrDefault();
                    list.Add( new DynamicMemberDescriptor( prop, scale, "Index " + i ));
                }
            }
            else
            {
                foreach (var item in items)
                {
                    var pso = item.ToPSObject();
                    var tempProperty = new PSScriptProperty(
                        "_" + Guid.NewGuid().ToString("N"),
                        System.Management.Automation.ScriptBlock.Create(
                            "$this | " + spec.IndexSpecifier.GetterScript));
                    pso.Properties.Add(tempProperty);
                    var specValue = pso.Properties[tempProperty.Name].Value.ToPSObject();
                    pso.Properties.Remove(tempProperty.Name);
                    var name = specValue.Properties["Name"].Value;

                    var byItemScript =
                        String.Format("$this.'{1}' | {2} | where {{ $_.Name -eq '{0}' }} | select -expand Group",
                                      name, acrossAccessorName, spec.IndexSpecifier.GetterScript);
                    var prop = new PSScriptProperty(
                                 acrossAccessorName + "_" + name,
                                 System.Management.Automation.ScriptBlock.Create(byItemScript));
                    var scale = (from sd in spec.ScaleDescriptors
                                 where sd.Key.IsMatch(prop.Name)
                                 select sd.Value).FirstOrDefault();
                    list.Add( new DynamicMemberDescriptor( prop, scale, name));
                }
            }
            return list;
        }
        private void CreateDynamicMemberProperty(ref PSPropertyInfo plotMember, string name, string proxyPropertyName)
        {
            if (String.IsNullOrEmpty(proxyPropertyName))
            {
                return;
            }

            var pm = plotMember as PSScriptProperty;
            var script = String.Format("$this.'{0}' | foreach-object  {{ {1} }}", proxyPropertyName, pm.GetterScript);
            plotMember = new PSScriptProperty(name, System.Management.Automation.ScriptBlock.Create(script));
        }