Beispiel #1
0
        private void UpdateControls()
        {
            txtOutput.Text = null;
            ChoPlugInBuilder builder = lstPlugIns.SelectedValue as ChoPlugInBuilder;

            _isPlugInSelected = builder != null;
            EnableOrDisableMenuItems();
            if (builder == null)
            {
                pgPlugInProperty.SelectedObject = null;
                ttPlugIns.SetToolTip(lstPlugIns, null);
                SetScriptText(null);
                return;
            }

            pgPlugInProperty.SelectedObject = builder.PlugInBuilderProperty;
            ttPlugIns.SetToolTip(lstPlugIns, builder.PlugInBuilderProperty.Description);

            if (_prevPlugInBuilder != null && _prevPlugInBuilder.PlugInBuilderProperty is IChoScriptExtensionObject)
            {
                ((IChoScriptExtensionObject)_prevPlugInBuilder.PlugInBuilderProperty).ScriptTextChanged -= ChoPlugInEditor_ScriptTextChanged;
                _prevPlugInBuilder = null;
            }

            if (builder.PlugInBuilderProperty is IChoScriptExtensionObject)
            {
                _prevPlugInBuilder = builder;
                ((IChoScriptExtensionObject)_prevPlugInBuilder.PlugInBuilderProperty).ScriptTextChanged += ChoPlugInEditor_ScriptTextChanged;
            }

            SetScriptText(builder);
        }
Beispiel #2
0
        private void LoadPlugInsFromFile(string plugInDefFilePath)
        {
            if (plugInDefFilePath.IsNullOrWhiteSpace())
            {
                return;
            }
            if (!File.Exists(plugInDefFilePath))
            {
                return;
            }

            int counter = 0;

            foreach (ChoPlugInBuilder pb in ChoPlugInBuilder.LoadFrom(plugInDefFilePath))
            {
                if (!pb.Name.IsNullOrWhiteSpace())
                {
                    if (Int32.TryParse(Regex.Match(pb.Name, "_([0-9]+)").Groups[1].Value, out counter))
                    {
                        if (counter > _index)
                        {
                            _index = counter;
                        }
                    }
                }

                pb.PropertyChanged += (o, e1) => IsDirty = true;
                _plugInBuilderList.Add(pb);
            }
        }
Beispiel #3
0
        private void SetScriptText(ChoPlugInBuilder builder)
        {
            txtScript.Enabled         = false;
            txtScript.IsReadOnly      = !txtScript.Enabled;
            txtScript.Text            = null;
            txtOutput.Text            = null;
            grpScriptDisplayName.Text = builder == null || builder.PlugInBuilderProperty == null ? "Script" : ChoEnum.ToDescription(builder.PlugInBuilderProperty.ScriptType);

            if (builder == null || !(builder.PlugInBuilderProperty is IChoScriptExtensionObject))
            {
                return;
            }

            try
            {
                if (txtScript.Text != ((IChoScriptExtensionObject)builder.PlugInBuilderProperty).ScriptText)
                {
                    txtScript.Text = ((IChoScriptExtensionObject)builder.PlugInBuilderProperty).ScriptText;

                    //txtScript.Select(txtScript.Text.Length, 0);
                }
                txtScript.Enabled    = !((IChoScriptExtensionObject)builder.PlugInBuilderProperty).IsScriptReadonly;
                txtScript.IsReadOnly = !txtScript.Enabled;
            }
            catch (Exception ex)
            {
                txtOutput.Text       = ex.Message;
                txtScript.Enabled    = false;
                txtScript.IsReadOnly = !txtScript.Enabled;
            }
        }
Beispiel #4
0
        private void tsbPastePlugInDef_Click(object sender, EventArgs e)
        {
            ICloneable builder = _copiedBuilder as ICloneable;

            if (builder == null)
            {
                return;
            }

            try
            {
                ChoPlugInBuilder newBuilder = builder.Clone() as ChoPlugInBuilder;
                if (newBuilder == null)
                {
                    return;
                }

                newBuilder.Name = "{0}_Copy_{1}".FormatString(ChoPlugInBuilder.GetPlugInName(builder.GetType()), NextIndex());
                AddNewBuilder(newBuilder);
            }
            catch (Exception ex)
            {
                txtOutput.Text = FormatException(null, ex, "Error while pasting PlugIn.");
            }
        }
Beispiel #5
0
 protected virtual void Clone(ChoPlugInBuilder o)
 {
     o.Name              = Name;
     o.Description       = Description;
     o.DoPropertyResolve = DoPropertyResolve;
     o.Enabled           = Enabled;
 }
Beispiel #6
0
        private void lstPlugIns_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index < 0)
            {
                return;
            }

            ChoPlugInBuilder builder = ((ListBox)sender).Items[e.Index] as ChoPlugInBuilder;

            if (builder == null)
            {
                return;
            }

            // Draw the background of the ListBox control for each item.
            e.DrawBackground();
            Brush myBrush = builder.Enabled ? Brushes.DarkGreen : Brushes.Red; //or whatever...

            // Draw the current item text based on the current
            // Font and the custom brush settings.
            //
            e.Graphics.DrawString(builder.Name,
                                  e.Font, myBrush, e.Bounds, StringFormat.GenericDefault);
            // If the ListBox has focus, draw a focus rectangle
            // around the selected item.
            //
            e.DrawFocusRectangle();
        }
Beispiel #7
0
        private void tsbRunPlugInDef_Click(object sender, EventArgs e)
        {
            if (!SyncData())
            {
                return;
            }

            ChoPlugInBuilder builder = lstPlugIns.SelectedValue as ChoPlugInBuilder;

            if (builder == null)
            {
                return;
            }

            try
            {
                SetAsPlugInRunning();
                _plugInsRuntime.Reset();
                _plugInsRuntime.Add(builder.CreatePlugIn());
                _plugInsRuntime.RunAsync(txtParams.Text);
            }
            catch (Exception ex)
            {
                txtOutput.Text = FormatException(_plugInsRuntime.ActivePlugIn, ex);
                //SetAsPlugInRunComplete();
            }
        }
        public override void InitializeBuilder(ChoPlugInBuilder builder)
        {
            base.InitializeBuilder(builder);

            ChoJavaScriptFilePlugInBuilder b = builder as ChoJavaScriptFilePlugInBuilder;

            b.ScriptFilePath   = ScriptFilePath;
            b.Arguments        = new Xml.Serialization.ChoCDATA(Arguments);
            b.WorkingDirectory = WorkingDirectory;
        }
        public IEnumerable <ChoPlugInBuilder> GetPlugInBuilders(string plugInGroupName)
        {
            if (!_plugInsGroupDict.ContainsKey(plugInGroupName))
            {
                return new ChoPlugInBuilder[] {}
            }
            ;

            return(ChoPlugInBuilder.Parse(_plugInsGroupDict[plugInGroupName].ToString()));
        }
        public override void InitializeBuilder(ChoPlugInBuilder builder)
        {
            base.InitializeBuilder(builder);

            ChoCSharpCodeSnippetPlugInBuilder b = builder as ChoCSharpCodeSnippetPlugInBuilder;

            b.CodeSnippet = new ChoCDATA(CodeSnippet);
            b.Arguments   = new ChoCDATA(Arguments);
            b.Namespaces  = Namespaces;
        }
        public override void InitializeBuilder(ChoPlugInBuilder builder)
        {
            base.InitializeBuilder(builder);

            ChoDotNetAssemblyPlugInBuilder b = builder as ChoDotNetAssemblyPlugInBuilder;

            b.TypeName       = TypeName;
            b.MethodName     = MethodName;
            b.IsStaticMethod = IsStaticMethod;
            b.Arguments      = new Xml.Serialization.ChoCDATA(Arguments);
        }
Beispiel #12
0
 private void ApplyPlugInGroupChanges(string plugInGroupName, ChoPlugInBuilder[] plugInBuilderList)
 {
     if (_plugInBuilderList == null || _plugInBuilderList.Count == 0)
     {
         _plugInsDefManager.AddOrReplacePlugInGroup(plugInGroupName, ChoPlugInBuilder.ToXml(null));
     }
     else
     {
         _plugInsDefManager.AddOrReplacePlugInGroup(plugInGroupName, ChoPlugInBuilder.ToXml(plugInBuilderList.ToArray()));
     }
 }
Beispiel #13
0
        public virtual void InitializeBuilder(ChoPlugInBuilder builder)
        {
            if (builder == null)
            {
                return;
            }

            builder.Name              = Name;
            builder.Description       = Description;
            builder.DoPropertyResolve = DoPropertyResolve;
            builder.Enabled           = Enabled;
        }
Beispiel #14
0
        private void AddNewBuilder(ChoPlugInBuilder builder)
        {
            BeforeAddNewPlugIn.Raise(null, new ChoPlugInEventArgs()
            {
                PlugInBuilder = builder, PlugInGroupName = _prevPlugInsGroupName
            });

            builder.PropertyChanged += (o, e1) => IsDirty = true;

            _plugInBuilderList.Add(builder);
            IsDirty = true;
            lstPlugIns.SetSelected(Count - 1, true);
        }
Beispiel #15
0
        protected override void Clone(ChoPlugInBuilder o)
        {
            base.Clone(o);
            ChoVBNETCodeSnippetPlugInBuilder p = o as ChoVBNETCodeSnippetPlugInBuilder;

            if (p == null)
            {
                return;
            }

            p.CodeSnippet = CodeSnippet;
            p.Arguments   = Arguments;
            p.Namespaces  = Namespaces;
        }
        protected override void Clone(ChoPlugInBuilder o)
        {
            base.Clone(o);
            ChoJavaScriptPlugInBuilder p = o as ChoJavaScriptPlugInBuilder;

            if (p == null)
            {
                return;
            }

            p.Script           = Script;
            p.Arguments        = Arguments;
            p.WorkingDirectory = WorkingDirectory;
        }
        protected override void Clone(ChoPlugInBuilder o)
        {
            base.Clone(o);
            ChoDotNetAssemblyPlugInBuilder p = o as ChoDotNetAssemblyPlugInBuilder;

            if (p == null)
            {
                return;
            }

            p.TypeName       = TypeName;
            p.MethodName     = MethodName;
            p.IsStaticMethod = IsStaticMethod;
            p.Arguments      = Arguments;
        }
Beispiel #18
0
        private void tsbDeletePlugInDef_Click(object sender, EventArgs e)
        {
            ChoPlugInBuilder builder = lstPlugIns.SelectedValue as ChoPlugInBuilder;

            if (builder == null)
            {
                return;
            }
            DialogResult r = MessageBox.Show("Are you sure want to delete '{0}' plugin?".FormatString(builder.Name), Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (r == DialogResult.No)
            {
                return;
            }
            _plugInBuilderList.Remove(builder);
            IsDirty = true;
            UpdateControls();
        }
Beispiel #19
0
        private void btnAddNewPlugIn_Click(object sender, EventArgs e)
        {
            KeyValuePair <string, Type> keyValuePair = (KeyValuePair <string, Type>)cmbAvailPlugIns.SelectedItem;

            if (keyValuePair.Value == null)
            {
                return;
            }

            ChoPlugInBuilder builder = ChoActivator.CreateInstance(keyValuePair.Value) as ChoPlugInBuilder;

            if (builder == null)
            {
                return;
            }

            builder.Name = "{0}_{1}".FormatString(ChoPlugInBuilder.GetPlugInName(builder.GetType()), NextIndex());
            AddNewBuilder(builder);
        }
Beispiel #20
0
        public virtual ChoPlugInBuilder CreateBuilder()
        {
            Type type = ChoType.GetTypeFromXmlSectionName(GetType().Name);

            if (type == null)
            {
                throw new ChoPlugInException("Can't find builder for '{0}' plugin.".FormatString(GetType().Name));
            }

            ChoPlugInBuilder builder = ChoActivator.CreateInstance(type) as ChoPlugInBuilder;

            if (builder == null)
            {
                throw new ChoPlugInException("Can't find builder for '{0}' plugin.".FormatString(GetType().Name));
            }

            InitializeBuilder(builder);
            return(builder);
        }
Beispiel #21
0
        private void EnableOrDisableMenuItems()
        {
            int index = lstPlugIns.SelectedIndex;
            ChoPlugInBuilder builder          = lstPlugIns.SelectedValue as ChoPlugInBuilder;
            bool             isPlugInSelected = builder != null;

            if (!isPlugInSelected)
            {
                tsbMoveUpPlugInDef.Enabled   = false;
                tsbMoveDownPlugInDef.Enabled = false;
                tsbDeletePlugInDef.Enabled   = false;
            }
            else
            {
                tsbMoveUpPlugInDef.Enabled   = Count > 1 && index != 0;
                tsbMoveDownPlugInDef.Enabled = Count > 1 && index != Count - 1;
                tsbDeletePlugInDef.Enabled   = true;
            }
        }
Beispiel #22
0
        private void txtScript_TextChanged(object sender, EventArgs e)
        {
            if (txtScript.IsReadOnly)
            {
                return;
            }
            if (!_isPlugInSelected)
            {
                return;
            }
            ChoPlugInBuilder builder = lstPlugIns.SelectedValue as ChoPlugInBuilder;

            if (builder == null)
            {
                return;
            }
            if (!(builder.PlugInBuilderProperty is IChoScriptExtensionObject))
            {
                return;
            }

            IsDirty = true;
        }
Beispiel #23
0
        private void ChoPlugInEditor_Load(object sender, EventArgs e)
        {
            ApplySettings();

            txtParams.Text = Arguments;
            Type plugInType = null;

            SortedDictionary <string, Type> availPlugInDict = new SortedDictionary <string, Type>();

            //Load all plugins builders to combobox
            foreach (Type t in ChoType.GetTypesDerivedFrom <ChoPlugInBuilder>())
            {
                plugInType = ChoPlugInBuilder.GetPlugInType(t);

                if (plugInType != null)
                {
                    availPlugInDict.Add(ChoPlugInBuilder.GetPlugInName(t), t);
                }
            }
            cmbAvailPlugIns.DataSource    = new BindingSource(availPlugInDict, null);
            cmbAvailPlugIns.DisplayMember = "Key";
            cmbAvailPlugIns.ValueMember   = "Value";

            tsbCmbPlugInsGroup.ComboBox.SelectedValueChanged += ComboBox_SelectedValueChanged;
            tsbCmbPlugInsGroup.ComboBox.DropDown             += ComboBox_DropDown;
            Rebind();

            if (!_defaultPlugInGroupName.IsNullOrWhiteSpace())
            {
                if (tsbCmbPlugInsGroup.ComboBox.FindString(_defaultPlugInGroupName) >= 0)
                {
                    tsbCmbPlugInsGroup.ComboBox.Text = _defaultPlugInGroupName;
                }
            }

            //LoadPlugInsFromFile(PlugInDefFilePath);
        }
Beispiel #24
0
        private bool SyncData()
        {
            if (!IsDirty)
            {
                return(true);
            }
            if (txtScript.IsReadOnly)
            {
                return(true);
            }
            if (!_isPlugInSelected)
            {
                return(true);
            }
            ChoPlugInBuilder builder = lstPlugIns.SelectedValue as ChoPlugInBuilder;

            if (builder == null)
            {
                return(true);
            }
            if (!(builder.PlugInBuilderProperty is IChoScriptExtensionObject))
            {
                return(true);
            }

            try
            {
                ((IChoScriptExtensionObject)builder.PlugInBuilderProperty).ScriptText = txtScript.Text;
                return(true);
            }
            catch (Exception ex)
            {
                txtOutput.Text = ex.Message;
                return(false);
            }
        }