Ejemplo n.º 1
0
        public Models.Response UpdateControl(String ID, Models.Control Control)
        {
            try
            {
                Guid viewmodelid          = ViewModel.Utilities.StringToGuid(ID);
                ViewModel.Control control = this.Session.Control(viewmodelid);

                foreach (Models.Property property in Control.Properties)
                {
                    if (!property.ReadOnly)
                    {
                        switch (property.Type)
                        {
                        case ViewModel.Attributes.PropertyTypes.Boolean:
                            control.SetPropertyValue(property.Name, property.Values[0].Equals("1"));
                            break;

                        case ViewModel.Attributes.PropertyTypes.Int32:
                            control.SetPropertyValue(property.Name, Convert.ToInt32(property.Values[0]));
                            break;

                        case ViewModel.Attributes.PropertyTypes.NullableInt32:

                            if (property.Values[0] == null)
                            {
                                control.SetPropertyValue(property.Name, null);
                            }
                            else
                            {
                                control.SetPropertyValue(property.Name, Convert.ToInt32(property.Values[0]));
                            }

                            break;

                        case ViewModel.Attributes.PropertyTypes.String:
                            control.SetPropertyValue(property.Name, property.Values[0]);
                            break;

                        case ViewModel.Attributes.PropertyTypes.Float:
                            control.SetPropertyValue(property.Name, Convert.ToDouble(property.Values[0]));
                            break;

                        case ViewModel.Attributes.PropertyTypes.Control:
                            String id = property.Values[0];

                            if (id != null)
                            {
                                control.SetPropertyValue(property.Name, this.Session.Control(ViewModel.Utilities.StringToGuid(id)));
                            }
                            else
                            {
                                control.SetPropertyValue(property.Name, null);
                            }

                            break;

                        case ViewModel.Attributes.PropertyTypes.ControlList:

                            List <ViewModel.Control> values = new List <ViewModel.Control>();

                            foreach (String thisid in property.Values)
                            {
                                values.Add(this.Session.Control(ViewModel.Utilities.StringToGuid(thisid)));
                            }

                            ((ViewModel.ObservableControlList <ViewModel.Control>)control.GetPropertyValue(property.Name)).Replace(values);

                            break;

                        case ViewModel.Attributes.PropertyTypes.Date:

                            if (property.Values[0] == null)
                            {
                                control.SetPropertyValue(property.Name, null);
                            }
                            else
                            {
                                control.SetPropertyValue(property.Name, Convert.ToDateTime(property.Values[0]));
                            }

                            break;

                        case ViewModel.Attributes.PropertyTypes.Decimal:

                            if (property.Values[0] == null)
                            {
                                control.SetPropertyValue(property.Name, null);
                            }
                            else
                            {
                                control.SetPropertyValue(property.Name, Convert.ToDecimal(property.Values[0]));
                            }

                            break;

                        case ViewModel.Attributes.PropertyTypes.Command:

                            if (property.Values[0] == null)
                            {
                                control.SetPropertyValue(property.Name, null);
                            }
                            else
                            {
                                control.SetPropertyValue(property.Name, this.Session.Command(ViewModel.Utilities.StringToGuid(property.Values[0])));
                            }

                            break;

                        default:
                            throw new NotImplementedException("PropertyType not implemented: " + property.Type);
                        }
                    }
                }

                return(new Models.Responses.Empty(this.Session));
            }
            catch (Exception e)
            {
                throw this.ProcessException(e);
            }
        }
Ejemplo n.º 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]);
            }
        }