Ejemplo n.º 1
0
 // will run a checkup for modifications on the controls in the current page
 public static Task SendPropertyUpdateFromServer(FSWManager manager, CoreServerAnswer coreServerAnswer)
 {
     try
     {
         return(SendAsync_ID(manager.Page.ID, "propertyUpdateFromServer", JsonConvert.SerializeObject(coreServerAnswer)));
     }
     catch (Exception e)
     {
         if (manager.Page.OverrideErrorHandle is null)
         {
             throw;
         }
         else
         {
             return(manager.Page.OverrideErrorHandle(e));
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Process the changed values of all the properties for the controls in the specified page
        /// </summary>
        /// <param name="pageId"></param>
        /// <returns></returns>
        internal async Task <CoreServerAnswer> ProcessPropertyChange(bool forceAllProperties)
        {
            await(OnBeforeServerUnlocked?.Invoke(Page) ?? Task.CompletedTask);

            var answer = new CoreServerAnswer();


            // chose between ALL controls and just the newly modified ones, depending on the parameter provided
            var controls = forceAllProperties ? Controls.Select(x => new
            {
                x.Key,
                Properties = (IReadOnlyCollection <Property>)x.Value.Properties.Values
            }) : Page.ChangedProperties.Select(x => new
            {
                Key        = x.Key.Id,
                Properties = (IReadOnlyCollection <Property>)x.Value
            });

            Page.ChangedProperties = new Dictionary <ControlBase, Queue <Property> >(); // reset it in case someone changes anything inside

            // for each controls
            foreach (var controlWithChangedProperties in controls)
            {
                if (controlWithChangedProperties.Key == null) // shouldn't happen but hey.. who knows..
                {
                    continue;
                }

                ControlBase control;
                try
                {
                    control = GetControl(controlWithChangedProperties.Key);
                }
                catch (KeyNotFoundException)
                {
                    continue; // skip error, the control is probably simply deleted already
                }

                if (control.NewlyAddedDynamicControl)
                {
                    continue;
                }

                var controlProperties = new ExistingControlProperty()
                {
                    id = controlWithChangedProperties.Key
                };

                // for each properties that has changed in the control
                foreach (var property in controlWithChangedProperties.Properties)
                {
                    // add the property to be sent to client
                    controlProperties.properties.Add(new ControlProperty_NoId()
                    {
                        property = property.Name,
                        value    = property.ParseValueToClient == null ? property.Value : property.ParseValueToClient(property.Value)
                    });
                    // call the update from server event
                    property.UpdateValue();
                }
                if (controlProperties.properties.Count != 0)
                {
                    answer.ChangedProperties.Add(controlProperties);
                }

                var events = control.ExtractPendingCustomEvents();
                if (events.Count != 0)
                {
                    answer.CustomEvents[control.Id] = events;
                }
            }

            foreach (var pendingNewControl in PendingNewControls)
            {
                var events = pendingNewControl.Value.ExtractPendingCustomEvents();
                if (events.Count != 0)
                {
                    answer.CustomEvents[pendingNewControl.Value.Id] = events;
                }
            }
            answer.NewControls = GetNewDynamicControls();


            if (PendingDeletionControls.Count != 0)
            {
                answer.DeletedControls  = PendingDeletionControls;
                PendingDeletionControls = new List <string>();
            }
            if (answer.ChangedProperties.Count == 0)
            {
                answer.ChangedProperties = null;
            }
            if (answer.CustomEvents.Count == 0)
            {
                answer.CustomEvents = null;
            }
            if (answer.NewControls.Count == 0)
            {
                answer.NewControls = null;
            }
            return(answer);
        }