/// <summary> /// Returns string of id of it selected and has a supported type (Package, Diagram, Element, Attribute, Operation).It also copies the id to Clipboard. /// </summary> /// <param name="template"></param> /// <param name="templateText"></param> /// <returns></returns> private string IdConstant(SqlTemplate template, string templateText) { // #Branch={...guid...}# if ( template == SqlTemplates.GetTemplate(SqlTemplates.SqlTemplateId.DesignId)) { // get design ID ObjectType objectType = _model.Repository.GetContextItemType(); int id; switch (objectType) { case ObjectType.otElement: id = ((Element)_model.Repository.GetContextObject()).ElementID; break; case ObjectType.otPackage: id = ((Package)_model.Repository.GetContextObject()).PackageID; break; case ObjectType.otDiagram: id = ((Diagram)_model.Repository.GetContextObject()).DiagramID; break; case ObjectType.otAttribute: id = ((EA.Attribute)_model.Repository.GetContextObject()).AttributeID; break; case ObjectType.otMethod: id = ((Method)_model.Repository.GetContextObject()).MethodID; break; default: return templateText; } string sId = $"{id}"; Clipboard.SetText(sId); return sId; } return templateText; }
/// <summary> /// Returns guid of it selected and has a supported type (Package, Diagram, Element, Attribute, Operation) /// </summary> /// <param name="template"></param> /// <param name="templateText"></param> /// <returns></returns> private string GuidConstant(SqlTemplate template, string templateText) { // #Branch={...guid...}# if (template == SqlTemplates.GetTemplate(SqlTemplates.SqlTemplateId.DesignGuid)) { // get design Id ObjectType objectType = _model.Repository.GetContextItemType(); string guid; switch (objectType) { case ObjectType.otElement: guid = ((Element)_model.Repository.GetContextObject()).ElementGUID; break; case ObjectType.otPackage: guid = ((Package)_model.Repository.GetContextObject()).PackageGUID; break; case ObjectType.otDiagram: guid = ((Diagram)_model.Repository.GetContextObject()).DiagramGUID; break; case ObjectType.otAttribute: guid = ((EA.Attribute)_model.Repository.GetContextObject()).AttributeGUID; break; case ObjectType.otMethod: guid = ((Method)_model.Repository.GetContextObject()).MethodGUID; break; default: return templateText; } Clipboard.SetText(guid); return guid; } return templateText; }
/// <summary> /// Insert Branch for a constant package like: '#Branch={.....guid...}'. If the context Element is a package it inserts the Package Id. /// </summary> /// <param name="template"></param> /// <param name="templateText"></param> /// <returns></returns> private string BranchConstantPackageTemplateText(SqlTemplate template, string templateText) { ObjectType objectType = _model.Repository.GetContextItemType(); // #Branch={...guid...}# if (objectType == ObjectType.otPackage && template == SqlTemplates.GetTemplate(SqlTemplates.SqlTemplateId.BranchIdsConstantPackage)) { // get package Id string guid = ((Package) _model.Repository.GetContextObject()).PackageGUID; // replace {.....} by guid Regex pattern = new Regex(@"={[^}]*}"); templateText = pattern.Replace(templateText, $"={guid}"); } return templateText; }