Пример #1
0
        public Models.Responses.Control GetPlugin(Models.Plugin Plugin)
        {
            try
            {
                // Get Plugin Type
                Manager.ControlType plugintype = this.Session.Database.Server.ControlType(Plugin.Name);

                // Get Plugin Control
                ViewModel.Control plugincontrol = this.Session.Plugin(plugintype, Plugin.Context);

                return(new Models.Responses.Control(this.Session, plugincontrol));
            }
            catch (Exception e)
            {
                throw this.ProcessException(e);
            }
        }
Пример #2
0
        private Control QueueControl(ViewModel.Manager.Session Session, ViewModel.Control ViewModelControl)
        {
            // Get Model Control ID
            String id = ViewModel.Utilities.GuidToString(ViewModelControl.ID);

            // Check Queue for Control
            if (!this.QueuedControls.ContainsKey(id))
            {
                // Get Control Type
                Manager.ControlType type = Session.Database.Server.ControlType(ViewModelControl);

                // Create Control
                Control control = new Control(id, type.ClientType);

                // Add Properties to Model Control
                foreach (String name in ViewModelControl.Properties)
                {
                    // Get Type
                    Attributes.PropertyTypes propertytype = ViewModelControl.GetPropertyType(name);

                    // Create Property
                    Property property = new Property(name, propertytype, ViewModelControl.GetPropertyReadOnly(name));
                    control.Properties.Add(property);

                    // Add Value
                    object viewmodelvalue = ViewModelControl.GetPropertyValue(name);

                    switch (propertytype)
                    {
                    case ViewModel.Attributes.PropertyTypes.Boolean:

                        if (viewmodelvalue != null)
                        {
                            if (((Boolean)viewmodelvalue) == true)
                            {
                                property.Values.Add("1");
                            }
                            else
                            {
                                property.Values.Add("0");
                            }
                        }
                        else
                        {
                            property.Values.Add(null);
                        }

                        break;

                    case ViewModel.Attributes.PropertyTypes.Control:

                        if (viewmodelvalue != null)
                        {
                            if (this.QueuedViewModelControls.ContainsKey(((ViewModel.Control)viewmodelvalue).ID))
                            {
                                // Control is in Queue to ensure added first
                                Control propcontrol = this.QueueControl(Session, (ViewModel.Control)viewmodelvalue);

                                property.Values.Add(propcontrol.ID);
                            }
                            else
                            {
                                // Not in Queue to just add ID
                                property.Values.Add(ViewModel.Utilities.GuidToString(((ViewModel.Control)viewmodelvalue).ID));
                            }
                        }
                        else
                        {
                            property.Values.Add(null);
                        }

                        break;

                    case ViewModel.Attributes.PropertyTypes.ControlList:

                        if (viewmodelvalue != null)
                        {
                            IEnumerable <ViewModel.Control> controls = (IEnumerable <ViewModel.Control>)viewmodelvalue;

                            foreach (ViewModel.Control viewmodelcontrol in controls)
                            {
                                if (this.QueuedViewModelControls.ContainsKey(viewmodelcontrol.ID))
                                {
                                    // Control is in Queue to ensure added first
                                    Control propcontrol = this.QueueControl(Session, viewmodelcontrol);

                                    property.Values.Add(propcontrol.ID);
                                }
                                else
                                {
                                    // Not in Queue to just add ID
                                    property.Values.Add(ViewModel.Utilities.GuidToString(viewmodelcontrol.ID));
                                }
                            }
                        }

                        break;

                    case ViewModel.Attributes.PropertyTypes.Int32:
                        property.Values.Add(((System.Int32)viewmodelvalue).ToString());
                        break;

                    case ViewModel.Attributes.PropertyTypes.NullableInt32:

                        if (viewmodelvalue == null)
                        {
                            property.Values.Add(null);
                        }
                        else
                        {
                            property.Values.Add(((System.Int32)viewmodelvalue).ToString());
                        }

                        break;

                    case ViewModel.Attributes.PropertyTypes.String:
                        property.Values.Add((System.String)viewmodelvalue);
                        break;

                    case ViewModel.Attributes.PropertyTypes.Float:
                        property.Values.Add(((System.Double)viewmodelvalue).ToString());
                        break;

                    case ViewModel.Attributes.PropertyTypes.StringList:

                        if (viewmodelvalue != null)
                        {
                            IEnumerable <String> strings = (IEnumerable <String>)viewmodelvalue;

                            foreach (String value in (IEnumerable <String>)viewmodelvalue)
                            {
                                property.Values.Add(value);
                            }
                        }

                        break;

                    case ViewModel.Attributes.PropertyTypes.Date:

                        if (viewmodelvalue != null)
                        {
                            property.Values.Add(((System.DateTime)viewmodelvalue).ToString("yyyy-MM-ddTHH:mm:ssZ"));
                        }
                        else
                        {
                            property.Values.Add(null);
                        }

                        break;

                    case ViewModel.Attributes.PropertyTypes.Decimal:

                        if (viewmodelvalue != null)
                        {
                            property.Values.Add(((System.Decimal)viewmodelvalue).ToString());
                        }
                        else
                        {
                            property.Values.Add(null);
                        }

                        break;

                    case ViewModel.Attributes.PropertyTypes.Command:

                        if (viewmodelvalue != null)
                        {
                            property.Values.Add(ViewModel.Utilities.GuidToString(((ViewModel.Command)viewmodelvalue).ID));
                        }
                        else
                        {
                            property.Values.Add(null);
                        }

                        break;

                    default:
                        throw new NotImplementedException("PropertyType not implemented: " + propertytype.ToString());
                    }
                }

                // Queue Control
                this.ControlQueue.Add(control);
                this.QueuedControls[control.ID] = control;

                return(control);
            }
            else
            {
                return(this.QueuedControls[id]);
            }
        }