Exemplo n.º 1
0
        /*************************************/
        /**** Public Methods              ****/
        /*************************************/

        public virtual void SetItem(object item, bool sendNotification = true, bool updateOriginal = true)
        {
            if (item == null)
            {
                return;
            }

            if (updateOriginal)
            {
                m_OriginalItem = item;
            }
            SelectedItem = FromGeneric(item as dynamic);

            List <ParamInfo> oldInputs  = InputParams.ToList();
            List <ParamInfo> oldOutputs = OutputParams.ToList();

            SetComponentDetails();

            SetInputs();
            SetOutputs();

            SetInputSelectionMenu();
            SetOutputSelectionMenu();

            CompileMethod();
            CompileInputGetters();
            CompileOutputSetters();

            if (sendNotification)
            {
                MarkAsModified(new CallerUpdate
                {
                    Cause           = CallerUpdateCause.ItemSelected,
                    ComponentUpdate = new ComponentUpdate {
                        Name = Name, Description = Description
                    },
                    InputUpdates  = InputParams.Changes(oldInputs).Where(x => x.Param.IsSelected).ToList(),
                    OutputUpdates = OutputParams.Changes(oldOutputs).Where(x => x.Param.IsSelected).ToList()
                });
            }
        }
Exemplo n.º 2
0
        /*************************************/

        protected bool RestoreItem(object selectedItem, List <ParamInfo> inputParams, List <ParamInfo> outputParams)
        {
            // Finally Set the item
            SetItem(selectedItem, false);

            // Make sure that saved selection is copied over
            if (inputParams != null)
            {
                SelectInputs(inputParams.GroupBy(x => x.Name).Select(g => g.First()).ToDictionary(x => x.Name, x => x.IsSelected));
            }
            if (outputParams != null)
            {
                SelectOutputs(outputParams.GroupBy(x => x.Name).Select(g => g.First()).ToDictionary(x => x.Name, x => x.IsSelected));
            }

            // Look for changes
            CallerUpdate update = new CallerUpdate
            {
                Cause           = CallerUpdateCause.ReadFromSave,
                ComponentUpdate = new ComponentUpdate {
                    Name = Name, Description = Description
                },
                InputUpdates  = InputParams.Changes(inputParams).Where(x => x.Param.IsSelected).ToList(),
                OutputUpdates = OutputParams.Changes(outputParams).Where(x => x.Param.IsSelected).ToList()
            };

            // Record warnings if changes happened
            List <IParamUpdate> paramUpdates = update.InputUpdates.Concat(update.OutputUpdates).ToList();

            if (paramUpdates.Count > 0)
            {
                Engine.Reflection.Compute.RecordWarning("This component was upgraded. Here's the resulting changes: \n"
                                                        + paramUpdates.Select(x => "  - " + x.IToText()).Aggregate((a, b) => a + "\n" + b));
            }

            // Send the notification
            MarkAsModified(update);

            return(true);
        }