public IPathValue NewItem(IProviderContext context, string path, string itemTypeName, object newItemValue)
        {
            IScaleDescriptor descriptor = null;
            if( null == newItemValue )
            {
                throw new ArgumentNullException( "newItemValue");
            }
            newItemValue = PSObject.AsPSObject(newItemValue).BaseObject;
            if( newItemValue is string )
            {
                descriptor = new ScaleDescriptor(newItemValue as string);
            }
            else if ( newItemValue is object[] )
            {
                descriptor = new ScaleDescriptor(newItemValue as object[] );
            }
            else
            {
                throw new ArgumentException( "the new range value must be specified as a valid range descriptor", "newItemValue" );
            }

            _dataSource.Scales.Add( new ScaleDescriptorAssignment {PropertyName = path, Scale = descriptor } );

            return Resolve(context, path).First().GetNodeValue();
        }
Esempio n. 2
0
        public IScaleDescriptor ForPropertyName(string propertyName)
        {
            if (_color.HasValue)
            {
                return(this);
            }

            if (!_propertyColorMap.ContainsKey(propertyName))
            {
                _propertyColorMap.Add(propertyName, ColorManager.AssignColor());
            }

            var color      = _propertyColorMap[propertyName];
            var descriptor = new ScaleDescriptor(this, color);


            return(descriptor);
        }
Esempio n. 3
0
        public IScaleDescriptor ForPropertyName(string propertyName)
        {
            if (_color.HasValue)
            {
                return this;
            }

            if (!_propertyColorMap.ContainsKey(propertyName))
            {
                _propertyColorMap.Add( propertyName, ColorManager.AssignColor() );
            }

            var color = _propertyColorMap[propertyName];
            var descriptor = new ScaleDescriptor( this, color );

            return descriptor;
        }
        public IPathValue NewItem(IProviderContext context, string path, string itemTypeName, object newItemValue)
        {
            var parameters = context.DynamicParameters as DataSourceNewItemParameters;
            var name = path;
            var script = ConvertToScript(newItemValue);

            if( null == script )
            {
                throw new ArgumentException( "new item value must be a script block or string", "newItemValue");
            }

            var dataSource = new PowerShellDataSource {Name = name, ScriptBlock = script, UseDispatcher = true};

            if (null != parameters )
            {
                if (parameters.MaxItemCount.HasValue)
                {
                    dataSource.DataCollectionMaxSize = parameters.MaxItemCount.Value;
                }

                if( parameters.NoDispatcher.IsPresent)
                {
                    dataSource.UseDispatcher = false;
                }

                if( null != parameters.Args )
                {
                    string propertyName = null;

                    var specs = parameters.Args.ToHashtable();

                    foreach (object key in specs.Keys)
                    {
                        var value = specs[key];
                        IScaleDescriptor descriptor = value as IScaleDescriptor;

                        if (null == descriptor)
                        {
                            if (value is Array)
                            {
                                descriptor = new ScaleDescriptor((object[])value);
                            }
                            else
                            {
                                descriptor = new ScaleDescriptor(value.ToString());
                            }
                        }

                        dataSource.Scales.Add(
                                new ScaleDescriptorAssignment
                                    {
                                        Scale = descriptor,
                                        PropertyName = key.ToString()
                                    }
                                );

                    }
                }
            }

            ITrigger trigger = Singleton<ImmediateTrigger>.Instance;
            if( null != parameters && null != parameters.Trigger )
            {
                trigger = parameters.Trigger;
            }
            dataSource.Trigger = trigger;
            _drive.Add( dataSource );

            return new PathValue( dataSource, name, true );
        }