コード例 #1
0
		public WorkingSet(Model model,string id,User user, string name)
		{
			Model = model;
			Id = id;
			User = user;
			Name = name;
		}
コード例 #2
0
        public string Invoke(Model model, string text)
        {
            if (Method != null)
            {
                try
                {
                    // Invoke the method itself. The string returned by the method winds up in s
                    // substitute default parameter by Type.Missing
                    if (IsTextRequired)
                    {
                        // use Type.Missing for optional parameters
                        switch (Method.GetParameters().Length)
                        {
                            case 1:
                                Method.Invoke(null, new object[] {model.Repository, text});
                                break;
                            case 2:
                                Method.Invoke(null, new[] {model.Repository, text, Type.Missing});
                                break;
                            case 3:
                                Method.Invoke(null, new[] {model.Repository, text, Type.Missing, Type.Missing});
                                break;
                            default:
                                Method.Invoke(null,
                                    new[] {model.Repository, text, Type.Missing, Type.Missing, Type.Missing});
                                break;
                        }
                    }
                    else
                    {
                        // use Type.Missing for optional parameters
                        switch (Method.GetParameters().Length)
                        {
                            case 1:
                                Method.Invoke(null, new object[] {model.Repository});
                                break;
                            case 2:
                                Method.Invoke(null, new[] {model.Repository, Type.Missing});
                                break;
                            case 3:
                                Method.Invoke(null, new[] {model.Repository, Type.Missing, Type.Missing});
                                break;
                            default:
                                Method.Invoke(null, new[] {model.Repository, Type.Missing, Type.Missing, Type.Missing});
                                break;
                        }

                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show($"{e}\n\nCan't invoke {Method.Name}  Return:'{Method.ReturnParameter}'  {Method}",
                        $"Error Invoking service '{Method.Name}'");
                    return null;
                }
            }
            return null;
        }
コード例 #3
0
        /// <summary>
        /// Run selected script with 2/3 parameters for all rows of SQL. 
        /// If you choose isWithAsk=true
        /// </summary>
        /// <param name="model"></param>
        /// <param name="sql"></param>
        /// <param name="function"></param>
        /// <param name="isWithAsk">Ask if execute, skip script execution or break altogether</param>
        /// <returns></returns>
        public static bool RunScriptWithAsk(Model model, string sql, ScriptFunction function, bool isWithAsk = false)
        {
            string scriptName = function.Owner.Name;
            string functionName = function.Name;
            int scriptParCount = function.NumberOfParameters;

            // Check parameter count of function
            if (scriptParCount < 2 || scriptParCount > 3)
            {
                MessageBox.Show($"Function: '{scriptName}:{functionName} count of parameters={scriptParCount}", @"Count of parameters for function shall be 2 or 3 (object_type, Id, Model), Break!!!!");
                return false;
            }

            // get SQL
            string xml = model.SqlQueryWithException(sql);
            if (xml == null) return false;

            // Output the query in EA Search Window
            string target = model.MakeEaXmlOutput(xml);
            model.Repository.RunModelSearch("", "", "", target);

            // get rows / items to call function
            List<EaItem> eaItemList = model.MakeEaItemListFromQuery(XDocument.Parse(xml));
            int countCurrent = 0;
            int count = eaItemList.Count;
            foreach (EaItem item in eaItemList)
            {

                switch (scriptParCount)
                {
                    case 2:
                    case 3:
                        // run script
                        bool run = true;
                        if (isWithAsk)
                        {
                            // run the function with two or three parameters
                            DialogResult result = MessageBox.Show($"Function '{functionName}', Item {countCurrent} of {count}", @"YES=Execute,No=Skip execution, Cancel=Break,", MessageBoxButtons.YesNoCancel);
                            if (result.Equals(DialogResult.No)) run = false;
                            if (result.Equals(DialogResult.Cancel)) return false;
                        }
                        if (run)  // run script
                        {
                            countCurrent += 1;
                            if (countCurrent%20 == 0)
                                    model.Repository.WriteOutput("Script", $"{functionName}: {countCurrent} of {count}", 0);
                            if (ScriptUtility.RunScriptFunction(model, function, item.EaObjectType, item.EaObject) == false) return false;
                        }
                        continue;
                    default:
                        MessageBox.Show($"Script parameter count shall be 2 or 3, is {scriptParCount}", @"Invalid count of function parameters, Break!!!!");
                        break;

                }
            }
            return true;
        }
コード例 #4
0
        /// <summary>
        /// Constructor with
        /// </summary>
        /// <param name="settings">Object with settings</param>
        /// <param name="addinControl">Object with Control</param>
        public FrmSettingsToolbar(AddinSettings settings, AddinControlGui addinControl)
        {
            InitializeComponent();

            _settings = settings;
            _addinControl = addinControl;
            _model = addinControl.Model;

        }
コード例 #5
0
        private void Init(Model model, string name, string type, string language, string groupGuid, string code)
        {
            _groupGuid = groupGuid;
            _name = name;
            _type = type;
            _language = language;
            _model = model;
            _code = code;

        }
 /// <summary>
 /// Invokes the ScriptFunction with 2 or 3 Parameters.
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public string Invoke(Model model)
 {
     if (ScriptFunction != null)
     {
         EA.ObjectType eaObjectType = model.Repository.GetContextItemType();
         object eaObject = model.Repository.GetContextObject();
         ScriptUtility.RunScriptFunction(model, ScriptFunction, eaObjectType, eaObject);
     }
     return null;
 }
        public string Invoke(Model model)
        {
            if (Function != null)
            {
                EA.ObjectType objectType = model.Repository.GetContextItemType();
                object oContext = (object)model.Repository.GetContextObject();
                object[] par = { oContext, objectType,  };
                //Function.Execute(par);

                ScriptUtility.RunScriptFunction(model, Function,objectType, oContext);

            }
            return null;
        }
コード例 #8
0
        /// <summary>
        /// Run function for EA item of arbitrary type<par></par>
        /// - If parameter count = 2 it calls the function with oType, oContext<par></par>
        /// - If parameter count = 3 it calls the function with oType, oContext, Model
        /// </summary>
        /// <param name="model"></param>
        /// <param name="function">Function</param>
        /// <param name="oType">EA Object type</param>
        /// <param name="oContext">EA Object</param>
        /// <returns></returns>
        public static bool RunScriptFunction(Model model, ScriptFunction function, EA.ObjectType oType, object oContext)
        {
            // run script according to parameter count
            switch (function.NumberOfParameters)
            {
                case 2:
                    object[] par2 = { oContext, oType };
                    new ScriptFuntionWrapper(function).Execute(par2);
                    return true;
                case 3:
                    object[] par3 = { oContext, oType, model };
                    return new ScriptFuntionWrapper(function).Execute(par3);
                default:
                    MessageBox.Show($"Script {function.FullName}  has {function.NumberOfParameters} parameter",
                        @"Script function parameter count not 2 or 3, Break!");
                    return false;
            }

        }
コード例 #9
0
		/// <summary>
		/// Gets all suitable Scripts defined in the model.Suitable Scripts have:
		/// <para /> 2 or three parameters
		/// <para /> Tag: EA-Matic 
		/// </summary>
		/// <param name="model"></param>
		/// <returns></returns>
		public static List<Script> GetEaMaticScripts(Model model)
		{			
			if (model != null)
			{
			 XmlDocument xmlScripts = model.SqlQuery(@"select s.ScriptID, s.Notes, s.Script,ps.Script as SCRIPTGROUP, ps.Notes as GROUPNOTES from t_script s
													   inner join t_script ps on s.ScriptAuthor = ps.ScriptName
													   where s.Script like '%EA-Matic%'");
			 //check the hash before continuing
			 int newHash = xmlScripts.InnerXml.GetHashCode();
			 //only create the scripts of the hash is different
			 //otherwise we returned the cached scripts
			 if (newHash != _scriptHash)
			 {
			  //set the new hash code
			  _scriptHash = newHash;
			  //reset scripts
		 	  _allScripts = new List<Script>();
		 	  
		 	  //set flag to reload scripts in includableScripts
		 	  _reloadModelIncludableScripts = true;
		 	  _modelIncludableScripts = new Dictionary<string, string>();
		 	  
		 	  XmlNodeList scriptNodes = xmlScripts.SelectNodes("//Row");
              foreach (XmlNode scriptNode in scriptNodes)
              {
              	//get the <notes> node. If it contains "Group Type=" then it is a group. Else we need to find "Language=" 
              	XmlNode notesNode = scriptNode.SelectSingleNode(model.FormatXPath("Notes"));
              	if (notesNode.InnerText.Contains(_scriptLanguageIndicator))
          	    {
          	    	//we have an actual script.
          	    	//the name of the script
          	    	string scriptName = GetValueByName(notesNode.InnerText, _scriptNameIndicator);
					//now figure out the language
					string language = GetValueByName(notesNode.InnerText, _scriptLanguageIndicator);
					//get the ID
					XmlNode idNode = scriptNode.SelectSingleNode(model.FormatXPath("ScriptID"));
					string scriptId = idNode.InnerText;
					//get the group
					XmlNode groupNode = scriptNode.SelectSingleNode(model.FormatXPath("SCRIPTGROUP"));
					string groupName = groupNode.InnerText;
					//then get the code
					XmlNode codeNode = scriptNode.SelectSingleNode(model.FormatXPath("Script"));	
					if (codeNode != null && language != string.Empty)
					{
						//if the script is still empty EA returns NULL
						string scriptCode = codeNode.InnerText;
						if (scriptCode.Equals("NULL",StringComparison.InvariantCultureIgnoreCase))
						{
							scriptCode = string.Empty;
						}
						var script = new Script(scriptId,scriptName,groupName,scriptCode, language,model); 
						//and create the script if both code and language are found
						_allScripts.Add(script);
						//also add the script to the include dictionary
						_modelIncludableScripts.Add("!INC "+ script.GroupName + "." + script.Name,script.Code);
					}
          	    }
              }
              //Add the static EA-Matic scripts to allScripts
              foreach (Script staticScript in StaticEaMaticScripts)
              {
              	//add the model to the static script first
              	staticScript._model = model;
              	//then add the static scrip to all scripts
              	_allScripts.Add(staticScript);
			  }              
			  //load the code of the scripts (because a script can include another script we can only load the code after all scripts have been created)
			  foreach (Script script in _allScripts) 
			  {
			  	script.ReloadCode();
			  }			  
			 }
			}
			return _allScripts;
		}
コード例 #10
0
 // ReSharper disable once UnusedMember.Global
 public EaScript(Model model, string name, string type, string language, string code)
 {
     Init(model, name, type, language, "", code);
 }
コード例 #11
0
 public EaScript(Model model, string name, string type, string language, string groupGuid, string code)
 {
     Init(model, name, type, language, groupGuid, code);
 }
コード例 #12
0
 /// <summary>
 /// Initialize ScriptGroup
 /// </summary>
 /// <param name="model"></param>
 /// <param name="groupName"></param>
 /// <param name="groupType"></param>
 private void Init(Model model, string groupName, EaScriptGroupType groupType)
 {
     _model = model;
     _name = groupName;
     _groupType = groupType;
 }
コード例 #13
0
 public EaScriptGroup(Model model, string name, EaScriptGroupType groupType)
 {
     Init(model, name, groupType);
 }
コード例 #14
0
        /// <summary>
        /// Constructor to Initialize TabControl, create ToolStripItems (New Tab from, Recent Files) with file history. 
        /// </summary>
        /// <param name="model"></param>
        /// <param name="settings"></param>
        /// <param name="components"></param>
        /// <param name="tabControl"></param>
        /// <param name="sqlTextBoxSearchTerm"></param>
        /// <param name="fileNewTabAndLoadRecentFileMenuItem">File, New Tab from recent files</param>
        /// <param name="fileLoadTabRecentFileMenuItem">File, Load Tab from recent files</param>
        /// <param name="addinTabName"></param>
        public SqlTabPagesCntrl(Model model, AddinSettings settings,
            System.ComponentModel.IContainer components,
            TabControl tabControl, TextBox sqlTextBoxSearchTerm,
            ToolStripMenuItem fileNewTabAndLoadRecentFileMenuItem,
            ToolStripMenuItem fileLoadTabRecentFileMenuItem, 
            string addinTabName)
        {
            Settings = settings;
            _model = model;
            _tabControl = tabControl;
            _components = components;
            _sqlTextBoxSearchTerm = sqlTextBoxSearchTerm;



            // Recent MenuItems to complete with items of recent files
            _fileNewTabAndLoadRecentFileMenuItem = fileNewTabAndLoadRecentFileMenuItem;
            _fileLoadTabRecentFileMenuItem = fileLoadTabRecentFileMenuItem;

            // Update text and tooltip for menu item
            _tabLoadTabFromRecentFileMenuItem.Text = MenuLoadTabFromRecentFileText;
            _tabLoadTabFromRecentFileMenuItem.ToolTipText = MenuLoadTabFromRecentFileTooltip;



            _tabNewTabFromRecentFileMenuItem.Text = MenuNewTabFromRecentText;
            _tabNewTabFromRecentFileMenuItem.ToolTipText = MenuNewTabFromRecentTooltip;

            
            LoadOpenedTabsFromLastSession();
            

            // Load recent files into ToolStripMenu
            LoadRecentFilesIntoToolStripItems();
            _addinTabName = addinTabName;

        }
コード例 #15
0
		/// <summary>
		/// creates a new script
		/// </summary>
		/// <param name="scriptId">the id of the script</param>
		/// <param name="scriptName">the name of the script</param>
		/// <param name="groupName">the name of the script group</param>
		/// <param name="code">the code</param>
		/// <param name="language">the language the code is written in</param>
		/// <param name="model">the model this script resides in</param>
		public Script(string scriptId,string scriptName,string groupName, string code, string language, Model model):this(scriptId, scriptName, groupName, code, language, false)
		{
			_model = model;
		}
コード例 #16
0
        /// <summary>
        /// Initialize Setting (not Keys). Be sure Repository is loaded! Also don't change the sequence of hide/visible.
        /// </summary>
        public void InitializeSettings()
        {
            // get global settings
            _model = new Model(Repository);

            _txtSearchName.Text = AddinSettings.QuickSearchName;
            IntializeSearches();

            ParameterizeMenusAndButtons();
            // parameterize 5 Buttons to quickly run search
            ParameterizeToolbarSearchButton();
            // parameterize 5 Buttons to quickly run services
            ParameterizeToolbarServiceButton();
            //
            //_txtSearchName.DataSource = _globalCfg.getListFileCompleteName();

            //
            ResizeRtfListOfChanges();

            _rtfListOfSearches.Text = Search.GetRtf();



        }
コード例 #17
0
        /// <summary>
        /// Update settings with model specific features like: Scripts
        /// </summary>
        /// <param name="model"></param>
        public void UpdateModel(Model model)
        {
            _model = model;

            // get all services of type Call and Script which are available 
            GetAllServices();
            // update Services of type Call and Script
            UpdateKeysAndToolbarsServices();


        }