Changeset 1617


Ignore:
Timestamp:
Jun 10, 2010, 3:26:32 PM (11 years ago)
Author:
kopal
Message:
  • a delete of a plugin now leads to the delete of all left connections
  • added a first version of a Settings to the WorkspaceManager
  • some small bug fixes
Location:
trunk/CrypPlugins/WorkspaceManager
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/WorkspaceManager/Execution/ExecutionEngine.cs

    r1608 r1617  
    3232    /// <summary>
    3333    /// Engine to execute a model of the WorkspaceManager
     34    /// This class needs a WorkspaceManager to be instantiated
     35    /// To run an execution process it also needs a WorkspaceModel
     36    ///
     37    /// This class uses Gears4Net to execute the plugins
    3438    /// </summary>
    3539    public class ExecutionEngine
     
    5862
    5963        /// <summary>
    60         /// Execute the current Model
     64        /// Execute the given Model
    6165        /// </summary>
    6266        /// <param name="workspaceModel"></param>
     
    6973                IsRunning = true;
    7074
     75                //Here we create n = "ProcessorsCount * 2" Gears4Net schedulers
     76                //We do this, because measurements showed that we get the best performance if we
     77                //use this amount of schedulers
    7178                schedulers = new Scheduler[System.Environment.ProcessorCount*2];
    7279                for(int i=0;i<System.Environment.ProcessorCount*2;i++){
     
    7481                }
    7582
     83                //We have to reset all states of PluginModels, ConnectorModels and ConnectionModels:
    7684                workspaceModel.resetStates();
     85
     86                //The UpdateGuiProtocol is a kind of "daemon" which will update the view elements if necessary
    7787                UpdateGuiProtocol updateGuiProtocol = new UpdateGuiProtocol(schedulers[0], workspaceModel, this);
    7888                schedulers[0].AddProtocol(updateGuiProtocol);
    7989                updateGuiProtocol.Start();
    8090
     91                //The CheckExecutableProtocl is also a kind of "daemon" which will check from time to time if a
     92                //plugin can be executed again
    8193                CheckExecutableProtocol checkExecutableProtocol = new CheckExecutableProtocol(schedulers[0], workspaceModel, this);
    8294                schedulers[0].AddProtocol(checkExecutableProtocol);
    8395                checkExecutableProtocol.Start();
    8496
     97                //Here we create for each PluginModel an own PluginProtocol
     98                //By using round-robin we give each protocol to another scheduler to gain
     99                //a good average load balancing of the schedulers
    85100                int counter=0;
    86101                foreach (PluginModel pluginModel in workspaceModel.AllPluginModels)
     
    97112     
    98113        /// <summary>
    99         /// Stop the execution
     114        /// Stop the execution process:
     115        /// calls shutdown on all schedulers + calls stop() on each plugin
    100116        /// </summary>
    101117        public void Stop()
     
    219235
    220236    /// <summary>
    221     /// A Protocol for updating the GUI in time intervals
     237    /// A Protocol for checking if plugins are executable in time intervals
    222238    /// </summary>
    223239    public class CheckExecutableProtocol : ProtocolBase
     
    287303        /// <summary>
    288304        /// The main function of the protocol
     305        ///
     306        /// states are here:
     307        ///
     308        ///     PreExecution -> Execution -> PostExecution
     309        ///        /\                           |
     310        ///         |---------------------------|
     311        ///         
    289312        /// </summary>
    290313        /// <param name="stateMachine"></param>
     
    307330
    308331        /// <summary>
    309         /// Handler function for a message.
    310         /// This handler must not block, because it executes inside the thread of the scheduler.
     332        /// Call the pre execution function of the wrapped IPlugin
    311333        /// </summary>
    312334        /// <param name="msg"></param>
     
    318340
    319341        /// <summary>
    320         /// Handler function for a message.
    321         /// This handler must not block, because it executes inside the thread of the scheduler.
     342        /// Call the execution function of the wrapped IPlugin
    322343        /// </summary>
    323344        /// <param name="msg"></param>
     
    343364
    344365        /// <summary>
    345         /// Handler function for a message.
    346         /// This handler must not block, because it executes inside the thread of the scheduler.
     366        /// Call the post execution function of the wrapped IPlugin
    347367        /// </summary>
    348368        /// <param name="msg"></param>
  • trunk/CrypPlugins/WorkspaceManager/Model/PluginModel.cs

    r1610 r1617  
    3737        [NonSerialized]
    3838        private IPlugin plugin;
    39      
     39       
     40        /// <summary>
     41        /// This is the current index of the image which should be shown
     42        /// on the plugins view
     43        /// </summary>
    4044        private int imageIndex = 0;
    4145       
     
    5256        /// <summary>
    5357        /// The wrapped IPlugin of this PluginModel
     58        /// if there is currently no plugin instance it
     59        /// will automatically create one. Otherwise
     60        /// this acts as singleton and returns the created
     61        /// instance
    5462        /// </summary>
    5563        public IPlugin Plugin{
     
    177185        /// <summary>
    178186        /// Checks wether this PluginModel is executable or not and sets the isExecutable bool
    179         /// </summary>
    180         /// <returns></returns>
     187        ///
     188        /// There are 3 ways in that a plugin can be executable:
     189        ///     1. All mandatory inputs are set + all outputs are "free"
     190        ///     2. There are no mandatory inputs and at least one non-mandatory input is set + all outputs are "free"
     191        ///     3. There are no inputs + all outputs are "free"
     192        /// </summary>
    181193        public void checkExecutable(ProtocolBase protocolBase)
    182194        {                           
    183195            bool AtLeastOneInputSet = false;
    184196            //First test if every mandatory Connector has data
     197            //or one non-mandatory input has data
    185198            foreach (ConnectorModel connectorModel in this.InputConnectors)
    186199            {
     
    196209            }
    197210
    198             //Next test if every connected Connection is not active
     211            //Next test if every connected output Connection is not active
    199212            foreach (ConnectorModel connectorModel in this.OutputConnectors)
    200213            {
     
    212225                MessagePreExecution msg = new MessagePreExecution();
    213226                msg.PluginModel = this;
    214                 protocolBase.BroadcastMessageReliably(msg);
     227               
     228                //protocolBase is set at Startup of the ExecutionEngine
     229                //but it could be that we have an event before setting
     230                //of the protocl base (triggered by user clicking on
     231                //a plugins presentation (button or so))
     232                if (protocolBase != null)
     233                {
     234                    protocolBase.BroadcastMessageReliably(msg);
     235                }
    215236            }
    216237            return;
     
    224245        public void PluginProgressChanged(IPlugin sender, PluginProgressEventArgs args)
    225246        {
     247            //Calculate % of the plugins process
    226248            this.PercentageFinished = args.Value / args.Max;
     249            //Tell the ExecutionEngine that this plugin needs a gui update
     250            this.GuiNeedsUpdate = true;
    227251        }
    228252
     
    237261            {
    238262                this.imageIndex = args.ImageIndex;
    239                 if (this.WorkspaceModel.WorkspaceManagerEditor.isExecuting())
    240                 {
    241                     this.GuiNeedsUpdate = true;
    242                 }
    243                 else
    244                 {
    245                     this.WorkspaceModel.WorkspaceManagerEditor.Presentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    246                     {
    247                         this.UpdateableView.update();
    248                     }, null);
    249                 }
    250             }
    251         }
    252 
    253         /// <summary>
    254         ///
     263            }
     264               
     265            if (this.WorkspaceModel.WorkspaceManagerEditor.isExecuting())
     266            {
     267                this.GuiNeedsUpdate = true;
     268            }
     269            else
     270            {
     271                this.WorkspaceModel.WorkspaceManagerEditor.Presentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     272                {
     273                    this.UpdateableView.update();
     274                }, null);
     275            }           
     276        }
     277
     278        /// <summary>
     279        /// The pluginProtocol of the current ExecutionEngine run to set/get
    255280        /// </summary>
    256281        public PluginProtocol PluginProtocol { get; set; }
  • trunk/CrypPlugins/WorkspaceManager/Model/VisualElementModel.cs

    r1607 r1617  
    3333    public abstract class VisualElementModel
    3434    {
     35        /// <summary>
     36        /// Called when this object is deleted
     37        /// </summary
     38        public event EventHandler<EventArgs> OnDelete;
    3539
    3640        /// <summary>
    37         /// I will be deleted
    38         /// </summary
    39         public event EventHandler<EventArgs> Delete;
     41        /// Triggers event OnDelete
     42        /// </summary>
     43        public void onDelete(){
     44            if(OnDelete != null){
     45                EventArgs args = new EventArgs();         
     46                OnDelete.Invoke(this, args);
     47            }
     48        }
    4049
    4150        public Point Position { get; set; }
  • trunk/CrypPlugins/WorkspaceManager/Model/WorkspaceModel.cs

    r1600 r1617  
    1414   limitations under the License.
    1515*/
    16 
    1716
    1817using System;
     
    3130    public class WorkspaceModel
    3231    {
    33 
    3432        /// <summary>
    3533        /// The surrounding WorkspaceManagerEditor
     
    132130            {
    133131                // remove all InputConnectors belonging to this pluginModel from our WorkspaceModel
    134                 foreach (ConnectorModel inputConnector in pluginModel.InputConnectors)
     132                foreach (ConnectorModel inputConnector in new List<ConnectorModel>(pluginModel.InputConnectors))
    135133                {
    136134                    deleteConnectorModel(inputConnector);
     
    138136
    139137                // remove all OutputConnectors belonging to this pluginModel from our WorkspaceModel
    140                 foreach (ConnectorModel outputConnector in pluginModel.OutputConnectors)
     138                foreach (ConnectorModel outputConnector in new List<ConnectorModel>(pluginModel.OutputConnectors))
    141139                {
    142140                    deleteConnectorModel(outputConnector);
    143141                }
    144142                pluginModel.Plugin.Dispose();
     143                pluginModel.onDelete();
    145144                return this.AllPluginModels.Remove(pluginModel);
    146145            }           
     
    160159
    161160                //remove all output ConnectionModels belonging to this Connector from our WorkspaceModel
    162                 foreach (ConnectionModel outputConnection in connectorModel.OutputConnections)
     161                foreach (ConnectionModel outputConnection in new List<ConnectionModel>(connectorModel.OutputConnections))
    163162                {
    164163                    deleteConnectionModel(outputConnection);
     
    170169                    deleteConnectionModel(connectorModel.InputConnection);
    171170                }
     171                connectorModel.onDelete();
    172172                return this.AllConnectorModels.Remove(connectorModel);
    173173            }
     
    187187            connectionModel.From.OutputConnections.Remove(connectionModel);
    188188            connectionModel.To.InputConnection = null;
     189            connectionModel.onDelete();
    189190            return this.AllConnectionModels.Remove(connectionModel);
    190191        }
     
    194195        /// </summary>
    195196        public void resetStates()
    196         {           
     197        {
    197198            foreach (ConnectionModel connection in this.AllConnectionModels)
    198199            {
  • trunk/CrypPlugins/WorkspaceManager/View/Container/WorkSpaceEditorView.xaml.cs

    r1609 r1617  
    6969        void PluginDelete(object sender, PluginContainerViewDeleteViewEventArgs e)
    7070        {
    71             for(int i = 0; i< e.container.ConnectorViewList.Count; i++)
     71            /*for(int i = 0; i< e.container.ConnectorViewList.Count; i++)
    7272            {
    7373                for(int j = 0; j< e.container.ConnectorViewList[i].Model.OutputConnections.Count; j++)
     
    8282                }
    8383                Model.deleteConnectionModel(e.container.ConnectorViewList[i].Model.InputConnection);
    84             }
     84            }*/
     85            Model.deletePluginModel(e.container.Model);
    8586            root.Children.Remove(e.container);
    8687        }
     
    113114            ConnectionModel connectionModel = this.Model.newConnectionModel(((ConnectorView)source).Model, ((ConnectorView)target).Model, ((ConnectorView)source).Model.ConnectorType);
    114115            CryptoLineView conn = new CryptoLineView(connectionModel);
     116            connectionModel.UpdateableView = conn;
     117            connectionModel.OnDelete += DeleteConnection;
    115118            conn.SetBinding(CryptoLineView.StartPointProperty, CreateConnectorBinding(source));
    116119            conn.SetBinding(CryptoLineView.EndPointProperty, CreateConnectorBinding(target));
     
    120123        }
    121124
     125        public void DeleteConnection(Object sender, EventArgs args)
     126        {
     127            if (sender is ConnectionModel)
     128            {
     129                if (((ConnectionModel)sender).UpdateableView != null)
     130                {
     131                    UIElement uielement = (UIElement)((ConnectionModel)sender).UpdateableView;
     132                    root.Children.Remove(uielement);
     133                }
     134            }
     135        }
     136
    122137        private void AddConnectionSource(IConnectable source, CryptoLineView conn)
    123138        {
     
    226241        {
    227242            DragDropDataObject obj = e.Data.GetData("Cryptool.PluginBase.Editor.DragDropDataObject") as DragDropDataObject;
     243            PluginModel pluginModel = Model.newPluginModel(DragDropDataObjectToPluginConverter.CreatePluginInstance(obj.AssemblyFullName, obj.TypeFullName));
    228244            if(obj != null)
    229                 this.AddPluginContainerView(e.GetPosition(root), Model.newPluginModel(DragDropDataObjectToPluginConverter.CreatePluginInstance(obj.AssemblyFullName, obj.TypeFullName)));
     245                this.AddPluginContainerView(e.GetPosition(root), pluginModel);
    230246        }
    231247
  • trunk/CrypPlugins/WorkspaceManager/View/VisualComponents/CryptoLineView.cs

    r1600 r1617  
    1313namespace WorkspaceManager.View.VisualComponents
    1414{
    15         public sealed class CryptoLineView : Shape, IConnection
     15        public sealed class CryptoLineView : Shape, IConnection, IUpdateableView
    1616    {
    1717        #region Variables
     
    194194               
    195195                #endregion
    196         }
     196
     197        #region IUpdateableView Members
     198
     199        public void update()
     200        {
     201           
     202        }
     203
     204        #endregion
     205    }
    197206}
  • trunk/CrypPlugins/WorkspaceManager/WorkspaceManager.cs

    r1609 r1617  
    4343    [EditorInfo("cwm")]
    4444    [Author("Viktor Matkovic,Nils Kopal", "nils.kopal@cryptool.org", "Universität Duisburg-Essen", "http://www.uni-due.de")]
    45     [PluginInfo("WorkspaceManager.Resources.Attributes", false, "Workspace Manager", "Graphical plugin editor for the CrypTool workspace", "WorkspaceManager/DetailedDescription/Description.xaml",
     45    [PluginInfo("WorkspaceManager.Resources.Attributes", false, "Workspace Manager", "Graphical plugin editor for the CrypTool workspace", null,
    4646      "AnotherEditor/icon.png",
    4747      "AnotherEditor/Images/addWorkspace.png",
     
    5656        public WorkspaceManager()
    5757        {
     58            Settings = new WorkspaceManagerSettings();
    5859            New();                                 
    5960        }
     
    159160        public void Add(Type type)
    160161        {
    161             if (!executing)
     162            /*if (!executing)
    162163            {
    163164                PluginModel newPluginModel = WorkspaceModel.newPluginModel(new Point(10, 10), 100, 100, type);
    164165                GuiLogMessage("Added by double click: " + newPluginModel.Name, NotificationLevel.Info);
    165166                HasChanges = true;
    166             }
     167            }*/
    167168        }
    168169
  • trunk/CrypPlugins/WorkspaceManager/WorkspaceManager.csproj

    r1607 r1617  
    115115    </Compile>
    116116    <Compile Include="WorkspaceManager.cs" />
     117    <Compile Include="WorkspaceManagerSettings.cs" />
    117118  </ItemGroup>
    118119  <ItemGroup>
Note: See TracChangeset for help on using the changeset viewer.