void TextArea_MouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { try { var pos = e.GetPosition(Editor.TextArea); var pt = new Point((int)pos.X, (int)pos.Y); conMenu.Show(this.PointToScreen(pt)); while (conMenu.Items.Count > 9) { conMenu.Items.RemoveAt(conMenu.Items.Count - 1); } if (Helper != null) { EditorScript.BuildMenu(conMenu.Items , Helper.GetScripts(Document, Editor.CaretOffset, Editor.IsReadOnly) , (script) => { var ide = this.FindForm() as EditorWindow; if (ide != null) { return(ide.Execute(script)); } return(Task.FromResult(false)); }); } OnMouseDown(new MouseEventArgs(MouseButtons.Right, e.ClickCount, pt.X, pt.Y, 0)); } catch (Exception ex) { Utils.HandleError(ex); } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); EditorScript editorScript = (EditorScript)target; editorScript.UpdateHotkeys(); }
void OnValidate() { Mesh mesh = Instantiate(meshFilter.sharedMesh); mesh.MarkDynamic(); Ray ray = EditorScript.GetMouseRay(); }
public void ButtonClicked(int code) { if (curr != null) { curr.Release(); } editors[code].OnClick(); curr = editors[code]; }
public override void OnInspectorGUI() { base.OnInspectorGUI(); EditorScript myScript = (EditorScript)target; GUILayout.BeginHorizontal(); GUILayout.Label("Checking Type "); defaultChoice = EditorGUILayout.Popup(defaultChoice, checkingType); GUILayout.EndHorizontal(); if (defaultChoice == 1) // choose None { if (GUILayout.Button("Add TextFields")) { ArrayUtility.Add(ref textValues, ""); } for (int i = 0; i < textValues.Length; i++) { GUILayout.BeginHorizontal(); GUILayout.Label("String"); textValues [i] = GUILayout.TextField(textValues [i], GUILayout.Width(200)); if (GUILayout.Button("Remove")) { //ArrayUtility.Remove (ref textValues,textValues[i]); xoa dl cua phan tu thu i (trung nhau se sai) ArrayUtility.RemoveAt(ref textValues, i); // xoa phan tu thu i theo index } if (GUILayout.Button("Check")) { string[] inputCloned = textValues [i].Split('\n'); foreach (string subStrCloned in inputCloned) { myScript.CheckRegexAndExist(subStrCloned); } } GUILayout.EndHorizontal(); } } else if (defaultChoice == 0) { GUILayout.Label("String"); input = GUILayout.TextArea(input, GUILayout.Height(100)); if (GUILayout.Button("Check")) { //string[] inputArray = Regex.Split (input, "\n"); string[] inputArray = input.Split('\n'); foreach (string subStr in inputArray) { myScript.CheckRegexAndExist(subStr); } } } }
static EditorSystemsBase() { START(); DEBUGS("cool Init"); EditorScript.Init(); EditorApplication.update += delegate() { DEBUGS("cool Update"); UPDATE(); EditorScript.Updates(); }; }
private void AddRefMenuItems(ContextMenuStrip conMenu, IEnumerable <ItemReference> refs) { var gen = new Editor.ScriptMenuGenerator(); gen.SetItems(refs); gen.Conn = _wizard.Connection; gen.ConnData = _wizard.ConnectionInfo.First(); conReferenceOptions.Items.Clear(); EditorScript.BuildMenu(conMenu.Items, gen.GetScripts(), async s => { var win = new EditorWindow(); var result = win.SetConnection(_wizard.ConnectionInfo.First()); win.Show(); await result; win.Execute(s); }); }
/// <inheritdoc/> public void Execute(string code) { ScriptState <object> state = null; var options = ScriptOptions.Default .WithImports("System"); var globals = new EditorScript { Editor = _serviceProvider.GetService <IProjectEditor>() }; try { state = CSharpScript.RunAsync(code, options, globals).Result; } catch (CompilationErrorException e) { Console.WriteLine(string.Join(Environment.NewLine, e.Diagnostics)); } }
/// <inheritdoc/> public object Execute(string code, object state) { ScriptState <object> next = null; if (state is ScriptState <object> previous) { try { next = previous.ContinueWithAsync(code).Result; } catch (CompilationErrorException ex) { var log = _serviceProvider.GetService <ILog>(); log?.LogException(ex); log?.LogError($"{Environment.NewLine}{ex.Diagnostics}"); } return(next); } var options = ScriptOptions.Default .WithImports("System"); var globals = new EditorScript { Editor = _serviceProvider.GetService <IProjectEditor>() }; try { next = CSharpScript.RunAsync(code, options, globals).Result; } catch (CompilationErrorException ex) { var log = _serviceProvider.GetService <ILog>(); log?.LogException(ex); log?.LogError($"{Environment.NewLine}{ex.Diagnostics}"); } return(next); }
/// <inheritdoc/> public void Execute(string code) { ScriptState <object> state = null; var options = ScriptOptions.Default .WithImports("System"); var globals = new EditorScript { Editor = _serviceProvider.GetService <IProjectEditor>() }; try { state = CSharpScript.RunAsync(code, options, globals).Result; } catch (CompilationErrorException ex) { var log = _serviceProvider.GetService <ILog>(); log?.LogException(ex); log?.LogError($"{Environment.NewLine}{ex.Diagnostics}"); } }
// ビルド前処理 public void OnPreprocessBuild(BuildTarget t, string p) { EditorSystemsBase.DEBUGS("cool BeforeBuildScript"); EditorScript.BeforeBuildScript(EditorUserBuildSettings.development); }
private void Awake() { StackField.text = "1"; editor = EditorScript.MyInstance; MyIndex = 1; }
public static IEnumerable<IEditorScript> GetScripts(IAsyncConnection conn, string type, string id , string relatedId = null, DataRow row = null) { if (!string.IsNullOrEmpty(id)) { ArasMetadataProvider metadata = null; ItemType itemType = null; if (conn != null) { metadata = ArasMetadataProvider.Cached(conn); itemType = metadata.ItemTypeByName(type); } if (metadata != null) { yield return new EditorScript() { Name = "View \"" + (itemType.Label ?? itemType.Name) + "\"", Action = "ApplyItem", Script = string.Format("<Item type='{0}' id='{1}' action='get' levels='1'></Item>", type, id), AutoRun = true, PreferredOutput = OutputType.Table }; if (!string.IsNullOrEmpty(relatedId) && itemType.Related != null) { yield return new EditorScript() { Name = "View \"" + (itemType.Related.Label ?? itemType.Related.Name) + "\"", Action = "ApplyItem", Script = string.Format("<Item type='{0}' id='{1}' action='get' levels='1'></Item>", itemType.Related.Name, relatedId), AutoRun = true, PreferredOutput = OutputType.Table }; } } yield return new EditorScript() { Name = "------" }; if (conn != null) { yield return ArasEditorProxy.ItemTypeAddScript(conn, itemType); } if (row == null) { yield return new EditorScript() { Name = "Edit", Action = "ApplyItem", Script = string.Format("<Item type='{0}' id='{1}' action='edit'></Item>", type, id) }; yield return new EditorScript() { Name = "Delete", Action = "ApplyItem", Script = string.Format("<Item type='{0}' id='{1}' action='delete'></Item>", type, id) }; } else { yield return new EditorScriptExecute() { Name = "Delete", Execute = () => row.Delete() }; } yield return new EditorScript() { Name = "------" }; if (metadata != null) { var actions = new EditorScript() { Name = "Actions" }; var serverActions = metadata.ServerItemActions(type) .OrderBy(l => l.Label ?? l.Value, StringComparer.CurrentCultureIgnoreCase) .ToArray(); foreach (var action in serverActions) { actions.Add(new EditorScript() { Name = (action.Label ?? action.Value), Action = "ApplyItem", Script = string.Format("<Item type='{0}' id='{1}' action='{2}'></Item>", type, id, action.Value), AutoRun = true }); } if (serverActions.Any()) yield return actions; var reports = new EditorScript() { Name = "Reports" }; var serverReports = metadata.ServerReports(type) .OrderBy(l => l.Label ?? l.Value, StringComparer.CurrentCultureIgnoreCase) .ToArray(); foreach (var report in serverReports) { reports.Add(new EditorScript() { Name = (report.Label ?? report.Value), Action = "ApplyItem", Script = @"<Item type='Method' action='Run Report'> <report_name>" + report.Value + @"</report_name> <AML> <Item type='" + itemType.Name + "' typeId='" + itemType.Id + "' id='" + id + @"' /> </AML> </Item>", AutoRun = true }); } if (serverReports.Any()) yield return reports; } yield return new EditorScriptExecute() { Name = "Copy ID", Execute = () => { if (string.IsNullOrEmpty(id)) { System.Windows.Clipboard.Clear(); } else { System.Windows.Clipboard.SetText(id); } } }; } }
public virtual void OnSceneGUI() { EditorScript editorScript = (EditorScript)target; editorScript.UpdateHotkeys(); }
public IEnumerable<IEditorScript> GetScripts() { var items = (Items ?? Enumerable.Empty<IItemData>()) .Where(i => !string.IsNullOrEmpty(i.Id) && !string.IsNullOrEmpty(i.Type)) .ToArray(); if (!items.Any()) yield break; if (items.Skip(1).Any()) // There is more than one { if (items.OfType<DataRowItemData>().Any()) { yield return new EditorScriptExecute() { Name = "Delete", Execute = () => { foreach (var row in items.OfType<DataRowItemData>()) { row.Delete(); } } }; } else { var builder = new StringBuilder("<AML>"); foreach (var item in items) { builder.AppendLine().AppendFormat(" <Item type='{0}' id='{1}' action='delete'></Item>", item.Type, item.Id); } builder.AppendLine().Append("</AML>"); yield return new EditorScript() { Name = "Delete", Action = "ApplyAML", Script = builder.ToString() }; } yield return new EditorScript() { Name = "------" }; yield return new EditorScriptExecute() { Name = "Export", Execute = () => { var refs = items.Select(i => new ItemReference(i.Type, i.Id)); StartExport(refs); } }; } else { var item = items.Single(); var rowItem = item as DataRowItemData; ArasMetadataProvider metadata = null; ItemType itemType = null; if (Conn != null) { metadata = ArasMetadataProvider.Cached(Conn); if (!metadata.ItemTypeByName(item.Type, out itemType)) metadata = null; } if (metadata != null) { yield return new EditorScript() { Name = "View \"" + (itemType.Label ?? itemType.Name) + "\"", Action = "ApplyItem", Script = string.Format("<Item type='{0}' id='{1}' action='get' levels='1'></Item>", item.Type, item.Id), AutoRun = true, PreferredOutput = OutputType.Table }; if (item.Property("related_id") != null && itemType.Related != null) { yield return new EditorScript() { Name = "View \"" + (itemType.Related.Label ?? itemType.Related.Name) + "\"", Action = "ApplyItem", Script = string.Format("<Item type='{0}' id='{1}' action='get' levels='1'></Item>", itemType.Related.Name, item.Property("related_id")), AutoRun = true, PreferredOutput = OutputType.Table }; } } yield return new EditorScript() { Name = "------" }; if (Conn != null) { yield return ArasEditorProxy.ItemTypeAddScript(Conn, itemType); } if (rowItem == null) { yield return new EditorScript() { Name = "Edit", Action = "ApplyItem", Script = string.Format("<Item type='{0}' id='{1}' action='edit'></Item>", item.Type, item.Id) }; yield return new EditorScript() { Name = "Delete", Action = "ApplyItem", Script = string.Format("<Item type='{0}' id='{1}' action='delete'></Item>", item.Type, item.Id) }; } else { if (!string.IsNullOrEmpty(Column)) { var prop = metadata.GetProperty(itemType, Column.Split('/')[0]).Wait(); switch (prop.Type) { case PropertyType.item: // TODO: Handle getting items via the EditorWindow //yield return new EditorScriptExecute() //{ // Name = "Edit Value", // Execute = () => // { // var query = string.Format("<Item type='{0}' action='get'><keyed_name condition='like'>**</keyed_name></Item>", prop.Restrictions.First()); // var values = EditorWindow.GetItems(Conn, query, query.Length - 21); // var results = values.Where(i => prop.Restrictions.Contains(i.Type)).ToArray(); // if (results.Length == 1) // { // rowItem.SetProperty(prop.Name, results[0].Unique); // rowItem.SetProperty(prop.Name + "/keyed_name", results[0].KeyedName); // rowItem.SetProperty(prop.Name + "/type", results[0].Type); // } // } //}; break; } } yield return new EditorScriptExecute() { Name = "Delete", Execute = () => rowItem.Delete() }; } yield return new EditorScript() { Name = "------" }; yield return new EditorScriptExecute() { Name = "Export", Execute = () => { var refs = new[] { new ItemReference(item.Type, item.Id) }; StartExport(refs); } }; if (metadata != null) { var actions = new EditorScript() { Name = "Actions" }; var serverActions = metadata.ServerItemActions(item.Type) .OrderBy(l => l.Label ?? l.Value, StringComparer.CurrentCultureIgnoreCase) .ToArray(); foreach (var action in serverActions) { actions.Add(new EditorScript() { Name = (action.Label ?? action.Value), Action = "ApplyItem", Script = string.Format("<Item type='{0}' id='{1}' action='{2}'></Item>", item.Type, item.Id, action.Value), AutoRun = true }); } if (serverActions.Any()) yield return actions; var reports = new EditorScript() { Name = "Reports" }; var serverReports = metadata.ServerReports(item.Type) .OrderBy(l => l.Label ?? l.Value, StringComparer.CurrentCultureIgnoreCase) .ToArray(); foreach (var report in serverReports) { reports.Add(new EditorScript() { Name = (report.Label ?? report.Value), Action = "ApplyItem", Script = @"<Item type='Method' action='Run Report'> <report_name>" + report.Value + @"</report_name> <AML> <Item type='" + itemType.Name + "' typeId='" + itemType.Id + "' id='" + item.Id + @"' /> </AML> </Item>", AutoRun = true }); } if (serverReports.Any()) yield return reports; } yield return new EditorScriptExecute() { Name = "Copy ID", Execute = () => { System.Windows.Clipboard.SetText(item.Id); } }; } }
public IEnumerable <IEditorScript> GetScripts() { var items = (Items ?? Enumerable.Empty <IItemData>()) .Where(i => !string.IsNullOrEmpty(i.Id) && !string.IsNullOrEmpty(i.Type)) .ToArray(); if (!items.Any()) { yield break; } if (items.Skip(1).Any()) // There is more than one { if (items.OfType <DataRowItemData>().Any()) { yield return(new EditorScriptExecute() { Name = "Delete", Execute = () => { foreach (var row in items.OfType <DataRowItemData>()) { row.Delete(); } return Task.FromResult(true); } }); } else { var builder = new StringBuilder("<AML>"); foreach (var item in items) { builder.AppendLine().AppendFormat(" <Item type='{0}' {1} action='delete'></Item>", item.Type, GetCriteria(item.Id)); } builder.AppendLine().Append("</AML>"); yield return(new EditorScript() { Name = "Delete", Action = "ApplyAML", Script = builder.ToString() }); } var dataRows = items.OfType <DataRowItemData>() .OrderBy(r => r.Property("generation")).ThenBy(r => r.Id) .ToArray(); if (dataRows.Length == 2) // There are exactly two items { yield return(new EditorScript() { Name = "------" }); yield return(new EditorScriptExecute() { Name = "Compare", Execute = async() => { try { await Settings.Current.PerformDiff(dataRows[0].Id, dataRows[0].ToAml , dataRows[1].Id, dataRows[1].ToAml); } catch (Exception ex) { Utils.HandleError(ex); } } }); } yield return(new EditorScript() { Name = "------" }); yield return(new EditorScriptExecute() { Name = "Export", Execute = () => { var refs = items.OfType <ItemRefData>().Select(i => i.Ref); if (!refs.Any()) { refs = items.Select(i => new ItemReference(i.Type, i.Id)); } StartExport(refs); return Task.FromResult(true); } }); } else { var item = items.Single(); var rowItem = item as DataRowItemData; ArasMetadataProvider metadata = null; ItemType itemType = null; if (Conn != null) { metadata = ArasMetadataProvider.Cached(Conn); if (!metadata.ItemTypeByName(item.Type, out itemType)) { metadata = null; } } if (Conn != null) { yield return(ArasEditorProxy.ItemTypeAddScript(Conn, itemType)); } if (item is EditorItemData data) { yield return(new EditorScript() { Name = "Clone as New", Action = "ApplyItem", ScriptGetter = () => { var aml = data.ToItem(Conn.AmlContext).CloneAsNew().ToAml(); return Task.FromResult(XElement.Parse(aml).ToString()); } }); } yield return(new EditorScript() { Name = "------" }); if (rowItem == null) { var script = string.Format("<Item type='{0}' {1} action='edit'></Item>", item.Type, GetCriteria(item.Id)); if (item.Property("config_id") != null && itemType != null && itemType.IsVersionable) { script = string.Format("<Item type='{0}' where=\"[{1}].[config_id] = '{2}'\" action='edit'></Item>" , item.Type, item.Type.Replace(' ', '_'), item.Property("config_id")); } yield return(new EditorScript() { Name = "Edit", Action = "ApplyItem", Script = script }); } else { if (!string.IsNullOrEmpty(Column)) { var prop = metadata.GetProperty(itemType, Column.Split('/')[0]).Wait(); switch (prop.Type) { case PropertyType.item: yield return(new EditorScriptExecute() { Name = "Edit Value", Execute = () => { var query = string.Format("<Item type='{0}' action='get'><keyed_name condition='like'>**</keyed_name></Item>", prop.Restrictions.First()); var values = EditorWindow.GetItems(Conn, query, query.Length - 21); var results = values.Where(i => prop.Restrictions.Contains(i.Type)).ToArray(); if (results.Length == 1) { rowItem.SetProperty(prop.Name, results[0].Unique); rowItem.SetProperty(prop.Name + "/keyed_name", results[0].KeyedName); rowItem.SetProperty(prop.Name + "/type", results[0].Type); } return Task.FromResult(true); } }); break; } } } if (metadata != null) { yield return(new EditorScript() { Name = "View \"" + (itemType.Label ?? itemType.Name) + "\"", Action = "ApplyItem", Script = string.Format("<Item type='{0}' {1} action='get' levels='1'></Item>", item.Type, GetCriteria(item.Id)), AutoRun = true, PreferredOutput = OutputType.Table }); if (item.Property("related_id") != null && itemType.Related != null) { yield return(new EditorScript() { Name = "View \"" + (itemType.Related.Label ?? itemType.Related.Name) + "\"", Action = "ApplyItem", Script = string.Format("<Item type='{0}' id='{1}' action='get' levels='1'></Item>", itemType.Related.Name, item.Property("related_id")), AutoRun = true, PreferredOutput = OutputType.Table }); } } yield return(new EditorScript() { Name = "------" }); if (rowItem == null) { yield return(new EditorScript() { Name = "Delete", Action = "ApplyItem", Script = string.Format("<Item type='{0}' {1} action='delete'></Item>", item.Type, GetCriteria(item.Id)) }); } else { yield return(new EditorScriptExecute() { Name = "Delete", Execute = () => { rowItem.Delete(); return Task.FromResult(true); } }); } if (item.Id.IsGuid()) { yield return(new EditorScript() { Name = "Replace Item", Action = "ApplySql", ScriptGetter = async() => { var aml = string.Format("<Item type='{0}' action='get'><keyed_name condition='like'>**</keyed_name></Item>", item.Type); var replace = EditorWindow.GetItems(Conn, aml, aml.Length - 21); if (replace.Count() == 1) { var sqlItem = Conn.AmlContext.FromXml(_whereUsedSqlAml).AssertItem(); var export = new ExportProcessor(Conn); var script = new InstallScript(); var itemRef = ItemReference.FromFullItem(sqlItem, true); await export.Export(script, new[] { itemRef }); var existing = script.Lines.FirstOrDefault(i => i.Reference.Equals(itemRef)); var needsSql = true; if (existing != null) { var merge = AmlDiff.GetMergeScript(XmlReader.Create(new StringReader(_whereUsedSqlAml)), new XmlNodeReader(existing.Script)); needsSql = merge.Elements().Any(); } if (needsSql) { if (Dialog.MessageDialog.Show("To run this action, InnovatorAdmin needs to install the SQL WhereUsed_General into the database. Do you want to install this?", "Install SQL", "Install", "Cancel") == System.Windows.Forms.DialogResult.OK) { await Conn.ApplyAsync(_whereUsedSqlAml, true, false).ToTask(); } else { return null; } } var result = await Conn.ApplyAsync(@"<AML> <Item type='SQL' action='SQL PROCESS'> <name>WhereUsed_General</name> <PROCESS>CALL</PROCESS> <ARG1>@0</ARG1> <ARG2>@1</ARG2> </Item> </AML>", true, false, item.Type, item.Id).ToTask(); var sql = new StringBuilder("<sql>"); var whereUsed = result.Items().Where(i => !i.Property("type").HasValue() || i.Property("type").Value == i.Property("parent_type").Value); var replaceId = replace.First().Unique; sql.AppendLine(); foreach (var i in whereUsed) { var props = (from p in i.Elements().OfType <IReadOnlyProperty>() where p.Name.Length == 2 && p.Name[0] == 'p' && char.IsNumber(p.Name[1]) select p.Value).GroupConcat(" = '" + replaceId + "',"); sql.Append("update innovator.[").Append(i.Property("main_type").Value.Replace(' ', '_')).Append("] set "); sql.Append(props).Append(" = '").Append(replaceId).Append("'"); sql.Append(" where id ='").Append(i.Property("main_id").Value).Append("';"); sql.AppendLine(); } sql.Append("</sql>"); return sql.ToString(); } return null; } }); } yield return(new EditorScript() { Name = "------" }); yield return(new EditorScriptExecute() { Name = "Export", Execute = () => { var refs = new[] { new ItemReference(item.Type, item.Id) }; StartExport(refs); return Task.FromResult(true); } }); yield return(new EditorScript() { Name = "------" }); yield return(new EditorScript() { Name = "Lock", Action = "ApplyItem", Script = string.Format("<Item type='{0}' {1} action='lock'></Item>", item.Type, GetCriteria(item.Id)) }); yield return(new EditorScript() { Name = "------" }); if (itemType != null && itemType.IsVersionable) { var whereClause = "id='" + item.Id + "'"; if (!item.Id.IsGuid()) { whereClause = item.Id; } yield return(new EditorScript() { Name = "Revisions", AutoRun = true, Action = "ApplyItem", PreferredOutput = OutputType.Table, Script = string.Format(@"<Item type='{0}' action='get' orderBy='generation'> <config_id condition='in'>(select config_id from innovator.[{1}] where {2})</config_id> <generation condition='gt'>0</generation> </Item>", item.Type, item.Type.Replace(' ', '_'), whereClause) }); yield return(new EditorScript() { Name = "------" }); } yield return(new EditorScript() { Name = "Promote", Action = "ApplyItem", Script = string.Format("<Item type='{0}' {1} action='promoteItem'></Item>", item.Type, GetCriteria(item.Id)) }); yield return(new EditorScript() { Name = "------" }); yield return(new EditorScript() { Name = "Where Used", AutoRun = true, Action = "ApplyItem", Script = string.Format("<Item type='{0}' {1} action='getItemWhereUsed'></Item>", item.Type, GetCriteria(item.Id)) }); yield return(new EditorScript() { Name = "Structure Browser", Action = "ApplyItem", AutoRun = true, Script = string.Format(@"<Item type='Method' action='GetItemsForStructureBrowser'> <Item type='{0}' {1} action='GetItemsForStructureBrowser' levels='2' /> </Item>", item.Type, GetCriteria(item.Id)) }); yield return(new EditorScript() { Name = "------" }); if (metadata != null) { var actions = new EditorScript() { Name = "Actions" }; var serverActions = metadata.ServerItemActions(item.Type) .OrderBy(l => l.Label ?? l.Value, StringComparer.CurrentCultureIgnoreCase) .ToArray(); foreach (var action in serverActions) { actions.Add(new EditorScript() { Name = (action.Label ?? action.Value), Action = "ApplyItem", Script = string.Format("<Item type='{0}' {1} action='{2}'></Item>", item.Type, GetCriteria(item.Id), action.Value), AutoRun = true }); } if (serverActions.Any()) { yield return(actions); } var reports = new EditorScript() { Name = "Reports" }; var serverReports = metadata.ServerReports(item.Type) .OrderBy(l => l.Label ?? l.Value, StringComparer.CurrentCultureIgnoreCase) .ToArray(); foreach (var report in serverReports) { reports.Add(new EditorScript() { Name = (report.Label ?? report.Value), Action = "ApplyItem", Script = @"<Item type='Method' action='Run Report'> <report_name>" + report.Value + @"</report_name> <AML> <Item type='" + itemType.Name + "' typeId='" + itemType.Id + "' " + GetCriteria(item.Id) + @" /> </AML> </Item>", AutoRun = true }); } if (serverReports.Any()) { yield return(reports); } } if (item.Id.IsGuid()) { yield return(new EditorScriptExecute() { Name = "Copy ID", Execute = () => { System.Windows.Clipboard.SetText(item.Id); return Task.FromResult(true); } }); } } }
public IEnumerable<IEditorScript> GetScripts() { var items = (Items ?? Enumerable.Empty<IItemData>()) .Where(i => !string.IsNullOrEmpty(i.Id) && !string.IsNullOrEmpty(i.Type)) .ToArray(); if (!items.Any()) yield break; if (items.Skip(1).Any()) // There is more than one { if (items.OfType<DataRowItemData>().Any()) { yield return new EditorScriptExecute() { Name = "Delete", Execute = () => { foreach (var row in items.OfType<DataRowItemData>()) { row.Delete(); } return Task.FromResult(true); } }; } else { var builder = new StringBuilder("<AML>"); foreach (var item in items) { builder.AppendLine().AppendFormat(" <Item type='{0}' {1} action='delete'></Item>", item.Type, GetCriteria(item.Id)); } builder.AppendLine().Append("</AML>"); yield return new EditorScript() { Name = "Delete", Action = "ApplyAML", Script = builder.ToString() }; } var dataRows = items.OfType<DataRowItemData>() .OrderBy(r => r.Property("generation")).ThenBy(r => r.Id) .ToArray(); if (dataRows.Length == 2) // There are exactly two items { yield return new EditorScript() { Name = "------" }; yield return new EditorScriptExecute() { Name = "Compare", Execute = async () => { try { await Settings.Current.PerformDiff(dataRows[0].Id, dataRows[0].ToAml , dataRows[1].Id, dataRows[1].ToAml); } catch (Exception ex) { Utils.HandleError(ex); } } }; } yield return new EditorScript() { Name = "------" }; yield return new EditorScriptExecute() { Name = "Export", Execute = () => { var refs = items.OfType<ItemRefData>().Select(i => i.Ref); if (!refs.Any()) refs = items.Select(i => new ItemReference(i.Type, i.Id)); StartExport(refs); return Task.FromResult(true); } }; } else { var item = items.Single(); var rowItem = item as DataRowItemData; ArasMetadataProvider metadata = null; ItemType itemType = null; if (Conn != null) { metadata = ArasMetadataProvider.Cached(Conn); if (!metadata.ItemTypeByName(item.Type, out itemType)) metadata = null; } if (Conn != null) { yield return ArasEditorProxy.ItemTypeAddScript(Conn, itemType); } yield return new EditorScript() { Name = "------" }; if (rowItem == null) { var script = string.Format("<Item type='{0}' {1} action='edit'></Item>", item.Type, GetCriteria(item.Id)); if (item.Property("config_id") != null && itemType != null && itemType.IsVersionable) { script = string.Format("<Item type='{0}' where=\"[{1}].[config_id] = '{2}'\" action='edit'></Item>" , item.Type, item.Type.Replace(' ', '_'), item.Property("config_id")); } yield return new EditorScript() { Name = "Edit", Action = "ApplyItem", Script = script }; } else { if (!string.IsNullOrEmpty(Column)) { var prop = metadata.GetProperty(itemType, Column.Split('/')[0]).Wait(); switch (prop.Type) { case PropertyType.item: yield return new EditorScriptExecute() { Name = "Edit Value", Execute = () => { var query = string.Format("<Item type='{0}' action='get'><keyed_name condition='like'>**</keyed_name></Item>", prop.Restrictions.First()); var values = EditorWindow.GetItems(Conn, query, query.Length - 21); var results = values.Where(i => prop.Restrictions.Contains(i.Type)).ToArray(); if (results.Length == 1) { rowItem.SetProperty(prop.Name, results[0].Unique); rowItem.SetProperty(prop.Name + "/keyed_name", results[0].KeyedName); rowItem.SetProperty(prop.Name + "/type", results[0].Type); } return Task.FromResult(true); } }; break; } } } if (metadata != null) { yield return new EditorScript() { Name = "View \"" + (itemType.Label ?? itemType.Name) + "\"", Action = "ApplyItem", Script = string.Format("<Item type='{0}' {1} action='get' levels='1'></Item>", item.Type, GetCriteria(item.Id)), AutoRun = true, PreferredOutput = OutputType.Table }; if (item.Property("related_id") != null && itemType.Related != null) { yield return new EditorScript() { Name = "View \"" + (itemType.Related.Label ?? itemType.Related.Name) + "\"", Action = "ApplyItem", Script = string.Format("<Item type='{0}' id='{1}' action='get' levels='1'></Item>", itemType.Related.Name, item.Property("related_id")), AutoRun = true, PreferredOutput = OutputType.Table }; } } yield return new EditorScript() { Name = "------" }; if (rowItem == null) { yield return new EditorScript() { Name = "Delete", Action = "ApplyItem", Script = string.Format("<Item type='{0}' {1} action='delete'></Item>", item.Type, GetCriteria(item.Id)) }; } else { yield return new EditorScriptExecute() { Name = "Delete", Execute = () => { rowItem.Delete(); return Task.FromResult(true); } }; } if (item.Id.IsGuid()) { yield return new EditorScript() { Name = "Replace Item", Action = "ApplySql", ScriptGetter = async () => { var aml = string.Format("<Item type='{0}' action='get'><keyed_name condition='like'>**</keyed_name></Item>", item.Type); var replace = EditorWindow.GetItems(Conn, aml, aml.Length - 21); if (replace.Count() == 1) { var sqlItem = Conn.AmlContext.FromXml(_whereUsedSqlAml).AssertItem(); var export = new ExportProcessor(Conn); var script = new InstallScript(); var itemRef = ItemReference.FromFullItem(sqlItem, true); await export.Export(script, new[] { itemRef }); var existing = script.Lines.FirstOrDefault(i => i.Reference.Equals(itemRef)); var needsSql = true; if (existing != null) { var merge = AmlDiff.GetMergeScript(XmlReader.Create(new StringReader(_whereUsedSqlAml)), new XmlNodeReader(existing.Script)); needsSql = merge.Elements().Any(); } if (needsSql) { if (Dialog.MessageDialog.Show("To run this action, InnovatorAdmin needs to install the SQL WhereUsed_General into the database. Do you want to install this?", "Install SQL", "Install", "Cancel") == System.Windows.Forms.DialogResult.OK) { await Conn.ApplyAsync(_whereUsedSqlAml, true, false).ToTask(); } else { return null; } } var result = await Conn.ApplyAsync(@"<AML> <Item type='SQL' action='SQL PROCESS'> <name>WhereUsed_General</name> <PROCESS>CALL</PROCESS> <ARG1>@0</ARG1> <ARG2>@1</ARG2> </Item> </AML>", true, false, item.Type, item.Id).ToTask(); var sql = new StringBuilder("<sql>"); var whereUsed = result.Items().Where(i => !i.Property("type").HasValue() || i.Property("type").Value == i.Property("parent_type").Value); var replaceId = replace.First().Unique; sql.AppendLine(); foreach (var i in whereUsed) { var props = (from p in i.Elements().OfType<IReadOnlyProperty>() where p.Name.Length == 2 && p.Name[0] == 'p' && char.IsNumber(p.Name[1]) select p.Value).GroupConcat(" = '" + replaceId + "',"); sql.Append("update innovator.[").Append(i.Property("main_type").Value.Replace(' ', '_')).Append("] set "); sql.Append(props).Append(" = '").Append(replaceId).Append("'"); sql.Append(" where id ='").Append(i.Property("main_id").Value).Append("';"); sql.AppendLine(); } sql.Append("</sql>"); return sql.ToString(); } return null; } }; } yield return new EditorScript() { Name = "------" }; yield return new EditorScriptExecute() { Name = "Export", Execute = () => { var refs = new[] { new ItemReference(item.Type, item.Id) }; StartExport(refs); return Task.FromResult(true); } }; yield return new EditorScript() { Name = "------" }; yield return new EditorScript() { Name = "Lock", Action = "ApplyItem", Script = string.Format("<Item type='{0}' {1} action='lock'></Item>", item.Type, GetCriteria(item.Id)) }; yield return new EditorScript() { Name = "------" }; if (itemType != null && itemType.IsVersionable) { var whereClause = "id='" + item.Id + "'"; if (!item.Id.IsGuid()) whereClause = item.Id; yield return new EditorScript() { Name = "Revisions", AutoRun = true, Action = "ApplyItem", PreferredOutput = OutputType.Table, Script = string.Format(@"<Item type='{0}' action='get' orderBy='generation'> <config_id condition='in'>(select config_id from innovator.[{1}] where {2})</config_id> <generation condition='gt'>0</generation> </Item>", item.Type, item.Type.Replace(' ', '_'), whereClause) }; yield return new EditorScript() { Name = "------" }; } yield return new EditorScript() { Name = "Promote", Action = "ApplyItem", Script = string.Format("<Item type='{0}' {1} action='promoteItem'></Item>", item.Type, GetCriteria(item.Id)) }; yield return new EditorScript() { Name = "------" }; yield return new EditorScript() { Name = "Where Used", AutoRun = true, Action = "ApplyItem", Script = string.Format("<Item type='{0}' {1} action='getItemWhereUsed'></Item>", item.Type, GetCriteria(item.Id)) }; yield return new EditorScript() { Name = "Structure Browser", Action = "ApplyItem", AutoRun = true, Script = string.Format(@"<Item type='Method' action='GetItemsForStructureBrowser'> <Item type='{0}' {1} action='GetItemsForStructureBrowser' levels='2' /> </Item>", item.Type, GetCriteria(item.Id)) }; yield return new EditorScript() { Name = "------" }; if (metadata != null) { var actions = new EditorScript() { Name = "Actions" }; var serverActions = metadata.ServerItemActions(item.Type) .OrderBy(l => l.Label ?? l.Value, StringComparer.CurrentCultureIgnoreCase) .ToArray(); foreach (var action in serverActions) { actions.Add(new EditorScript() { Name = (action.Label ?? action.Value), Action = "ApplyItem", Script = string.Format("<Item type='{0}' {1} action='{2}'></Item>", item.Type, GetCriteria(item.Id), action.Value), AutoRun = true }); } if (serverActions.Any()) yield return actions; var reports = new EditorScript() { Name = "Reports" }; var serverReports = metadata.ServerReports(item.Type) .OrderBy(l => l.Label ?? l.Value, StringComparer.CurrentCultureIgnoreCase) .ToArray(); foreach (var report in serverReports) { reports.Add(new EditorScript() { Name = (report.Label ?? report.Value), Action = "ApplyItem", Script = @"<Item type='Method' action='Run Report'> <report_name>" + report.Value + @"</report_name> <AML> <Item type='" + itemType.Name + "' typeId='" + itemType.Id + "' " + GetCriteria(item.Id) + @" /> </AML> </Item>", AutoRun = true }); } if (serverReports.Any()) yield return reports; } if (item.Id.IsGuid()) { yield return new EditorScriptExecute() { Name = "Copy ID", Execute = () => { System.Windows.Clipboard.SetText(item.Id); return Task.FromResult(true); } }; } } }