示例#1
0
 internal override object Execute(WorkspaceModel workspaceModel, bool events = true)
 {
     if (Model == null)
     {
         Model = workspaceModel.newTextModel();
     }
     else
     {
         workspaceModel.addTextModel((TextModel)Model);
     }
     workspaceModel.OnNewChildElement(Model);
     return(Model);
 }
示例#2
0
 internal override object Execute(WorkspaceModel workspaceModel, bool events = true)
 {
     if (Model == null)
     {
         Model = workspaceModel.newImageModel(ImgUri);
     }
     else
     {
         workspaceModel.addImageModel((ImageModel)Model);
     }
     if (events)
     {
         workspaceModel.OnNewChildElement(Model);
     }
     return(Model);
 }
示例#3
0
 internal override object Execute(WorkspaceModel workspaceModel, bool events = true)
 {
     if (Model == null)
     {
         Model = workspaceModel.newConnectionModel(From, To, ConnectionType);
     }
     else
     {
         workspaceModel.addConnectionModel((ConnectionModel)Model);
     }
     if (events)
     {
         workspaceModel.OnNewChildElement(Model);
     }
     return(Model);
 }
示例#4
0
 internal override object Execute(WorkspaceModel workspaceModel, bool events = true)
 {
     if (Model == null)
     {
         Model = workspaceModel.newPluginModel(Position,
                                               Width,
                                               Height,
                                               PluginType);
     }
     else
     {
         workspaceModel.addPluginModel((PluginModel)Model);
     }
     if (events)
     {
         workspaceModel.OnNewChildElement(Model);
     }
     return(Model);
 }
示例#5
0
        internal override object Execute(WorkspaceModel workspaceModel, bool events = true)
        {
            foreach (var visualElementModel in _copiedElements)
            {
                var pluginModel     = visualElementModel as PluginModel;
                var connectorModel  = visualElementModel as ConnectorModel;
                var connectionModel = visualElementModel as ConnectionModel;
                var textModel       = visualElementModel as TextModel;
                var imageModel      = visualElementModel as ImageModel;

                if (pluginModel != null)
                {
                    workspaceModel.AllPluginModels.Add(pluginModel);
                    pluginModel.WorkspaceModel       = workspaceModel;
                    pluginModel.SettingesHaveChanges = false;

                    //add input/output connectors of this pluginModel to the WorkspaceModel
                    foreach (var myConnectorModel in pluginModel.InputConnectors)
                    {
                        workspaceModel.AllConnectorModels.Add(myConnectorModel);
                    }
                    foreach (var myConnectorModel in pluginModel.OutputConnectors)
                    {
                        workspaceModel.AllConnectorModels.Add(myConnectorModel);
                    }
                }
                if (connectorModel != null)
                {
                    connectorModel.WorkspaceModel = workspaceModel;
                    workspaceModel.AllConnectorModels.Add(connectorModel);
                }
                if (connectionModel != null)
                {
                    connectionModel.IsCopy         = true;
                    connectionModel.WorkspaceModel = workspaceModel;
                    workspaceModel.AllConnectionModels.Add(connectionModel);
                }
                if (textModel != null)
                {
                    textModel.WorkspaceModel = workspaceModel;
                    workspaceModel.AllTextModels.Add(textModel);
                }
                if (imageModel != null)
                {
                    imageModel.WorkspaceModel = workspaceModel;
                    workspaceModel.AllImageModels.Add(imageModel);
                }
            }

            //restore all settings of each plugin
            foreach (PersistantPlugin persistantPlugin in _persistantPlugins)
            {
                if (persistantPlugin.PluginModel.Plugin.Settings == null)
                {
                    continue; // do not attempt deserialization if plugin type has no settings
                }
                foreach (PersistantSetting persistantSetting in persistantPlugin.PersistantSettingsList)
                {
                    PropertyInfo[] arrpInfo = persistantPlugin.PluginModel.Plugin.Settings.GetType().GetProperties();
                    foreach (PropertyInfo pInfo in arrpInfo)
                    {
                        try
                        {
                            DontSaveAttribute[] dontSave =
                                (DontSaveAttribute[])pInfo.GetCustomAttributes(typeof(DontSaveAttribute), false);
                            if (dontSave.Length == 0)
                            {
                                if (pInfo.Name.Equals(persistantSetting.Name))
                                {
                                    if (persistantSetting.Type.Equals("System.String"))
                                    {
                                        pInfo.SetValue(persistantPlugin.PluginModel.Plugin.Settings,
                                                       (String)persistantSetting.Value, null);
                                    }
                                    else if (persistantSetting.Type.Equals("System.Int16"))
                                    {
                                        pInfo.SetValue(persistantPlugin.PluginModel.Plugin.Settings,
                                                       System.Int16.Parse((String)persistantSetting.Value), null);
                                    }
                                    else if (persistantSetting.Type.Equals("System.Int32"))
                                    {
                                        pInfo.SetValue(persistantPlugin.PluginModel.Plugin.Settings,
                                                       System.Int32.Parse((String)persistantSetting.Value), null);
                                    }
                                    else if (persistantSetting.Type.Equals("System.Int64"))
                                    {
                                        pInfo.SetValue(persistantPlugin.PluginModel.Plugin.Settings,
                                                       System.Int64.Parse((String)persistantSetting.Value), null);
                                    }
                                    else if (persistantSetting.Type.Equals("System.Double"))
                                    {
                                        pInfo.SetValue(persistantPlugin.PluginModel.Plugin.Settings,
                                                       System.Double.Parse((String)persistantSetting.Value), null);
                                    }
                                    else if (persistantSetting.Type.Equals("System.Boolean"))
                                    {
                                        pInfo.SetValue(persistantPlugin.PluginModel.Plugin.Settings,
                                                       System.Boolean.Parse((String)persistantSetting.Value), null);
                                    }
                                    else if (pInfo.PropertyType.IsEnum)
                                    {
                                        Int32 result = 0;
                                        System.Int32.TryParse((String)persistantSetting.Value, out result);
                                        object newEnumValue = Enum.ToObject(pInfo.PropertyType, result);
                                        pInfo.SetValue(persistantPlugin.PluginModel.Plugin.Settings, newEnumValue, null);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception(
                                      String.Format(Resources.CopyOperation_Execute_Could_not_restore_the_setting___0___of_plugin___1__, persistantSetting.Name, persistantPlugin.PluginModel.Name), ex);
                        }
                    }
                }
            }

            foreach (var visualElementModel in new List <VisualElementModel>(_copiedElements))
            {
                var pluginModel     = visualElementModel as PluginModel;
                var connectionModel = visualElementModel as ConnectionModel;

                if (pluginModel != null)
                {
                    //remove connections which should not be copied
                    //deletes implicitly all PluginModels and ConnectorModels which
                    //are now not referenced any more (will be deleted by garbage collector)
                    foreach (var connectorModel in pluginModel.InputConnectors)
                    {
                        foreach (var myconnectionModel in new List <ConnectionModel>(connectorModel.InputConnections))
                        {
                            if (!_copiedElements.Contains(myconnectionModel.From.PluginModel))
                            {
                                _copiedElements.Remove(myconnectionModel);
                                connectorModel.InputConnections.Remove(myconnectionModel);
                                workspaceModel.AllConnectionModels.Remove(myconnectionModel);
                                myconnectionModel.From.OutputConnections.Remove(myconnectionModel);
                            }
                        }
                    }
                    foreach (var connectorModel in pluginModel.OutputConnectors)
                    {
                        foreach (var myconnectionModel in new List <ConnectionModel>(connectorModel.OutputConnections))
                        {
                            if (!_copiedElements.Contains(myconnectionModel.To.PluginModel))
                            {
                                _copiedElements.Remove(myconnectionModel);
                                connectorModel.OutputConnections.Remove(myconnectionModel);
                                workspaceModel.AllConnectionModels.Remove(myconnectionModel);
                                myconnectionModel.To.InputConnections.Remove(myconnectionModel);
                            }
                        }
                    }

                    //initialize plugin and register event handlers
                    try
                    {
                        pluginModel.Plugin.Initialize();
                        pluginModel.PercentageFinished = 0;
                        if (pluginModel.Plugin.Settings != null)
                        {
                            pluginModel.Plugin.Settings.Initialize();
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(String.Format(Resources.CopyOperation_Execute_Error_while_initializing___0__, pluginModel.Name), ex);
                    }
                    pluginModel.Plugin.OnGuiLogNotificationOccured += workspaceModel.GuiLogMessage;
                    pluginModel.Plugin.OnPluginProgressChanged     += pluginModel.PluginProgressChanged;
                    pluginModel.Plugin.OnPluginStatusChanged       += pluginModel.PluginStatusChanged;
                    if (pluginModel.Plugin.Settings != null)
                    {
                        pluginModel.Plugin.Settings.PropertyChanged += pluginModel.SettingsPropertyChanged;
                    }

                    //refresh language stuff and register connector model event handlers
                    //also set correct workspace model
                    foreach (ConnectorModel connectorModel in pluginModel.InputConnectors)
                    {
                        //refresh language stuff
                        foreach (var property in connectorModel.PluginModel.Plugin.GetProperties())
                        {
                            if (property.PropertyName.Equals(connectorModel.PropertyName))
                            {
                                connectorModel.ToolTip = property.ToolTip;
                                connectorModel.Caption = property.Caption;
                                break;
                            }
                        }
                        connectorModel.PluginModel.Plugin.PropertyChanged += connectorModel.PropertyChangedOnPlugin;
                        connectorModel.WorkspaceModel = workspaceModel;
                    }
                    foreach (ConnectorModel connectorModel in pluginModel.OutputConnectors)
                    {
                        //refresh language stuff
                        foreach (var property in connectorModel.PluginModel.Plugin.GetProperties())
                        {
                            if (property.PropertyName.Equals(connectorModel.PropertyName))
                            {
                                connectorModel.ToolTip = property.ToolTip;
                                connectorModel.Caption = property.Caption;
                                break;
                            }
                        }
                        connectorModel.PluginModel.Plugin.PropertyChanged += connectorModel.PropertyChangedOnPlugin;
                        connectorModel.WorkspaceModel = workspaceModel;
                    }
                }

                if (connectionModel != null)
                {
                    ConnectorModel from = connectionModel.From;
                    ConnectorModel to   = connectionModel.To;
                    try
                    {
                        if (from.IControl && to.IControl)
                        {
                            object data = null;
                            //Get IControl data from "to"
                            data = to.PluginModel.Plugin.GetType().GetProperty(to.PropertyName).GetValue(to.PluginModel.Plugin, null);
                            PropertyInfo propertyInfo = from.PluginModel.Plugin.GetType().GetProperty(from.PropertyName);
                            propertyInfo.SetValue(from.PluginModel.Plugin, data, null);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(String.Format(Resources.CopyOperation_Execute_Error_while_restoring_IControl_Connection_between___0___to___1____Workspace_surely_will_not_work_well_, from.PluginModel.Name, to.PluginModel.Name), ex);
                    }
                }
            }

            //move model elements x+50 y+50
            foreach (var visualElementModel in _copiedElements)
            {
                visualElementModel.Position = new Point(visualElementModel.Position.X + 50, visualElementModel.Position.Y + 50);
            }

            //fire events for the view to draw the elements
            foreach (var visualElementModel in _copiedElements)
            {
                if (events)
                {
                    workspaceModel.OnNewChildElement(visualElementModel);
                }
            }
            return(true);
        }
示例#6
0
 internal override void Undo(WorkspaceModel workspaceModel)
 {
     workspaceModel.addTextModel((TextModel)Model);
     workspaceModel.OnNewChildElement(Model);
 }
示例#7
0
 internal override void Undo(WorkspaceModel workspaceModel)
 {
     workspaceModel.addConnectionModel((ConnectionModel)Model);
     workspaceModel.OnNewChildElement(Model);
 }