public VplServiceContext(IVplService vplService, IEnumerable <IVplPlugin> plugins = null)
        {
            if (vplService == null)
            {
                throw new ArgumentNullException(nameof(vplService));
            }
            _vplService = vplService;
            _plugins    = plugins?.ToArray() ?? new IVplPlugin[] {};

            _customResources = _plugins.SelectMany(p => p.Resources);

            var customFactories = _plugins.SelectMany(p => p.ElementFactories);

            _elementFactoryManager = new ElementFactoryManager(customFactories);

            //These are the "built-in" types
            var types = new List <IVplType>
            {
                new VplType(VplTypeId.Boolean, "Boolean", () => new BooleanValueCheckBoxView(), false, typeof(bool)),
                new VplType(VplTypeId.Float, "Float", () => new DoubleValueView(), 0.0, typeof(double)),
                new VplType(VplTypeId.Any, "Any", () => new TextValueView(), null, typeof(object)),
                new VplType(VplTypeId.String, "String", () => new TextValueView(), "", typeof(string)),
                new VplType(VplTypeId.Int, "Int", () => new Int32ValueView(), 0, typeof(int)),
                new VplType(VplTypeId.Byte, "Byte", () => new ByteValueView(), (byte)0, typeof(byte)),
                new VplType(VplTypeId.UInt16, "UInt16", () => new TextValueView(), (ushort)0, typeof(ushort)),
                new VplType(VplTypeId.UInt32, "UInt32", () => new TextValueView(), (uint)0, typeof(uint)),
                new VplType(VplTypeId.Single, "Single", () => new TextValueView(), (float)0, typeof(float)),
                new VplType(VplTypeId.SByte, "Int8", () => new TextValueView(), (sbyte)0, typeof(sbyte)),
                new VplType(VplTypeId.Int16, "Int16", () => new Int16ValueView(), (short)0, typeof(short)),
                new VplType(VplTypeId.DateTime, "DateTime", () => new DateTimeValueView(), DateTime.Now, typeof(DateTime)),
                new VplType(VplTypeId.UInt64, "UInt64", () => new TextValueView(), (ulong)0, typeof(ulong)),
                new VplType(VplTypeId.Int64, "Int64", () => new TextValueView(), (long)0, typeof(long)),
                new VplType(VplTypeId.Decimal, "Decimal", () => new TextValueView(), (decimal)0, typeof(decimal))
            };

            //Add the plugin types
            foreach (var plugin in _plugins)
            {
                types.AddRange(plugin.Types);
            }

            //Create the array of types
            _types = types
                     .OrderBy(t => t.Name)
                     .ToArray();

            //Create the services
            _services = _plugins
                        .SelectMany(p => p.Services)
                        .ToArray();

            //Create an element builder
            _elementBuilder = new ElementBuilder(_elementFactoryManager, this);
        }
        static HostViewModelLocator()
        {
            var customResources = new View.CustomResources();

            customResources.InitializeComponent();

            var commentFactory = new ElementFactory(CustomElementTypeIds.Comment, "Custom", "Comment",
                                                    context => new CommentViewModel(context), typeof(CommentViewModel));

            var functionService = new FunctionService(GetFunctions, GetFunction, EditFunction);

            IRuntimeServiceFactory[] runtimeServiceFactories = new IRuntimeServiceFactory[]
            {
                new MyRuntimeServiceFactory(),
            };

            var factories = new IElementFactory[]
            {
                commentFactory,
            };

            //Create the plugin
            var plugin = new VplPlugin(
                "Host",
                factories,
                new[] { customResources },
                services: new[] { functionService },
                runtimeServiceFactories: runtimeServiceFactories);

            //var plugin1 = new VplPlugin("Alert",
            //    new IElementFactory[]
            //    {
            //        new ElementFactory(new Guid("FBB6804C-B90C-4A88-B28B-8B733C1A9F0D"), "Interaction", "Alert", context => new Alert(context), typeof(Alert)),
            //    });

            var plugins = SystemPluginFactory.CreateAllPlugins()
                          .ToList();

            plugins.Add(plugin);
            //plugins.Add(plugin1);

            //Create the service
            VplService = new VplService(plugins);
        }
示例#3
0
        static HostViewModelLocator()
        {
            var customResources = new View.CustomResources();

            customResources.InitializeComponent();

            var commentFactory = new ElementFactory(CustomElementTypeIds.Comment, "Custom", "Comment",
                context => new CommentViewModel(context), typeof(CommentViewModel));

            var functionService = new FunctionService(GetFunctions, GetFunction);

            var factories = new IElementFactory[]
            {
                commentFactory,
            };

            //Create the plugin
            var plugin = new VplPlugin(
                "Host",
                factories,
                new[] { customResources },
                services: new[] { functionService });

            var plugin1 = new VplPlugin("Alert",
                new IElementFactory[]
                {
                    new ElementFactory(new Guid("FBB6804C-B90C-4A88-B28B-8B733C1A9F0D"), "Interaction", "Alert", context => new Alert(context), typeof(Alert)),
                });

            var plugins = SystemPluginFactory.CreateAllPlugins()
                .ToList();

            plugins.Add(plugin);
            plugins.Add(plugin1);

            VplService = new VplService(plugins);
        }