public void Open(INamedElement element) { var member = element as IUnresolvedEntity; if (member == null) { var entity = element as IMember; if (entity != null) { member = entity.UnresolvedMember; } } if (member == null) { var entity = element as IType; if (entity != null) { member = entity.GetDefinition().Parts [0]; } } if (member == null) { return; } var url = AssemblyBrowserWidget.GetIdString(member); try { widget.Open(url); } catch (Exception e) { LoggingService.LogError("Error while navigating to " + url, e); MessageService.ShowException(e, GettextCatalog.GetString("{0} could not be opened", url), GettextCatalog.GetString("Error while opening assembly")); } }
public void Open(INamedElement element) { var member = element as IUnresolvedEntity; if (member == null) { var entity = element as IMember; if (entity != null) { member = entity.UnresolvedMember; } } if (member == null) { var entity = element as IType; if (entity != null) { member = entity.GetDefinition().Parts [0]; } } if (member == null) { return; } var url = AssemblyBrowserWidget.GetIdString(member); widget.Open(url); }
internal static void AddSubElement(XmlNode sectionNode, INamedElement parent) { var name = sectionNode.Name; switch (sectionNode.Name) { case "add": if (sectionNode.Attributes != null) { addAsNamedElement(sectionNode, parent); } break; case "remove": if (sectionNode.Attributes != null) { removeNamedElement(sectionNode, parent); } break; case "clear": parent.Children.Clear(); // clear all named children break; default: AddChildElement(sectionNode, parent, name); break; } }
/// <summary> /// Default constructor /// </summary> public CacheProviderElement(INamedElement config) { Attributes = config.Attributes; Children = config.Children; _assembly = Attributes[Constants.ASSEMBLY]; _typeName = Attributes[Constants.TYPE]; }
public void generateNamedElement(INamedElement el) { do { generatedNamedElementNumber++; } while (NamedElements.ContainsKey("element_" + generatedNamedElementNumber)); el.Name = "element_" + generatedNamedElementNumber; }
/// <summary> /// Default constructor /// </summary> public AuditProviderElement(INamedElement config, AuditConfig auditConfig) { Attributes = config.Attributes; Children = config.Children; _assembly = Attributes[Constants.ASSEMBLY]; _typeName = Attributes[Constants.TYPE]; _modules = Attributes.ContainsKey(Constants.MODULES) ? new List <string>(Attributes[Constants.MODULES].ToUpperInvariant().Split(',')) : new List <string>(); _useLocalTime = Attributes.ContainsKey(USE_LOCAL_TIME) ? bool.Parse(Attributes[USE_LOCAL_TIME]) : auditConfig.UseLocalTime; }
internal static void AddChildElement(XmlNode sectionNode, INamedElement parent, string name) { var element = new NamedConfigurationElement { Name = name }; if (parent.Children.ContainsKey(name)) { throw new ConfigurationErrorsException(string.Format(ADDS_REQUIRES_UNIQUE_NAME, sectionNode)); } parent.Children.Add(name, element); PopulateNode(sectionNode, element); }
/// <summary> /// Creates a CacheProviderElement from a ICacheProvider /// </summary> /// <param name="provider">the provider to create the configuration entry from</param> /// <param name="config">the configuration for the provider</param> public CacheProviderElement(ICacheProvider provider, INamedElement config) { Attributes = config.Attributes; Children = config.Children; _provider = provider; if (Name.EndsWith("Provider")) { Name = Name.Substring(0, Name.Length - 8); } Assembly = provider.GetType().Assembly.FullName; Type = provider.GetType().FullName; }
/// <summary> /// Creates a AuditProviderElement from a IAuditProvider /// </summary> /// <param name="provider">the provider to create the configuration entry from</param> /// <param name="config">the configuration for the provider</param> public AuditProviderElement(IAuditProvider provider, INamedElement config) { Attributes = config.Attributes; Children = config.Children; _provider = provider; if (Name.EndsWith("Provider")) { Name = Name.Substring(0, Name.Length - 8); } Assembly = provider.GetType().Assembly.FullName; Type = provider.GetType().FullName; _useLocalTime = !Attributes.ContainsKey(USE_LOCAL_TIME) || bool.Parse(Attributes[USE_LOCAL_TIME]); }
public DataConfig(INamedElement element) { if (element == null) { element = new NamedConfigurationElement() { Name = SectionName } } ; Children = element.Children; Attributes = element.Attributes; Name = element.Name; if (Attributes.ContainsKey(DEFAULT_CONNECTION_STRING)) { _default = Attributes[DEFAULT_CONNECTION_STRING]; } }
public static void DeserializeConfigElement(XmlReader reader, INamedElement section) { reader.MoveToContent(); var doc = new XmlDocument(); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { var sectionNode = doc.ReadNode(reader); if (sectionNode == null) { continue; } AddSubElement(sectionNode, section); } } }
private static void addAsNamedElement(XmlNode sectionNode, INamedElement parent) { if (sectionNode.Attributes == null) { throw new ConfigurationErrorsException(string.Format(ADDS_REQUIRES_NAME, sectionNode)); } var nameAttr = sectionNode.Attributes["name"]; if (nameAttr == null) { throw new ConfigurationErrorsException(string.Format(ADDS_REQUIRES_NAME, sectionNode)); } string name = nameAttr.Value; if (string.IsNullOrEmpty(name)) { throw new ConfigurationErrorsException(string.Format(ADDS_REQUIRES_NAME, sectionNode)); } AddChildElement(sectionNode, parent, name); }
private static void removeNamedElement(XmlNode sectionNode, INamedElement parent) { if (sectionNode.Attributes == null) { throw new ConfigurationErrorsException(string.Format(REMOVE_REQUIRES_NAME, sectionNode)); } var nameAttr = sectionNode.Attributes["name"]; if (nameAttr == null) { throw new ConfigurationErrorsException(string.Format(REMOVE_REQUIRES_NAME, sectionNode)); } string name = nameAttr.Value; if (string.IsNullOrEmpty(name)) { throw new ConfigurationErrorsException(string.Format(REMOVE_REQUIRES_NAME, sectionNode)); } if (parent.Children.ContainsKey(name)) { parent.Children.Remove(name); } }
void JumpToDeclaration (INamedElement element) { IEntity entity = element as IEntity; if (entity == null && element is IType) entity = ((IType)element).GetDefinition (); if (entity == null) { LoggingService.LogError ("Unknown element:" + element); return; } string fileName; bool isCecilProjectContent = entity.Region.IsEmpty; if (isCecilProjectContent) { fileName = entity.ParentAssembly.UnresolvedAssembly.Location; } else { fileName = entity.Region.FileName; } var doc = IdeApp.Workbench.OpenDocument (fileName, entity.Region.BeginLine, entity.Region.BeginColumn); if (isCecilProjectContent && doc != null) { doc.RunWhenLoaded (delegate { MonoDevelop.Ide.Gui.Content.IUrlHandler handler = doc.ActiveView as MonoDevelop.Ide.Gui.Content.IUrlHandler; if (handler != null) handler.Open (entity.GetIdString ()); }); } }
public void JumpToDeclaration (INamedElement visitable, bool askIfMultipleLocations = true) { if (askIfMultipleLocations) { var type = visitable as IType; if (type != null && type.GetDefinition () != null && type.GetDefinition ().Parts.Count > 1) { using (var monitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor (true, true)) { foreach (var part in type.GetDefinition ().Parts) monitor.ReportResult (GetJumpTypePartSearchResult (part)); } return; } } JumpToDeclaration (visitable); }
/* string GetDeclaredFile(IMember item) { if (item is IMember) { IMember mem = (IMember) item; if (mem.Region == null) return null; else if (mem.Region.FileName != null) return mem.Region.FileName; else if (mem.DeclaringType != null) { foreach (IType c in mem.DeclaringType.Parts) { if ((mem is IField && c.Fields.Contains((IField)mem)) || (mem is IEvent && c.Events.Contains((IEvent)mem)) || (mem is IProperty && c.Properties.Contains((IProperty)mem)) || (mem is IMethod && c.Methods.Contains((IMethod)mem))) { return GetClassFileName(c); } } } } else if (item is IType) { IType cls = (IType) item; return GetClassFileName (cls); } else if (item is MonoDevelop.Projects.Parser.LocalVariable) { MonoDevelop.Projects.Parser.LocalVariable cls = (MonoDevelop.Projects.Parser.LocalVariable) item; return cls.Region.FileName; } return null; } public bool CanJumpToDeclaration (IMember item) { return (GetDeclaredFile(item) != null); }*/ public bool CanJumpToDeclaration (INamedElement element) { var entity = element as IEntity; if (entity == null && element is IType) entity = ((IType)element).GetDefinition (); if (entity == null) return false; if (entity.Region.IsEmpty) { return !string.IsNullOrEmpty (entity.ParentAssembly.UnresolvedAssembly.Location); } return true; }
public void Open (INamedElement element) { var member = element as IUnresolvedEntity; if (member == null) { var entity = element as IMember; if (entity != null) member = entity.UnresolvedMember; } if (member == null) { var entity = element as IType; if (entity != null) member = entity.GetDefinition ().Parts [0]; } if (member == null) return; var url = AssemblyBrowserWidget.GetIdString (member); try { widget.Open (url); } catch (Exception e) { MessageService.ShowError (GettextCatalog.GetString ("{0} could not be opened", url), e); } }
public void Open (INamedElement element) { var member = element as IUnresolvedEntity; if (member == null) { var entity = element as IMember; if (entity != null) member = entity.UnresolvedMember; } if (member == null) { var entity = element as IType; if (entity != null) member = entity.GetDefinition ().Parts [0]; } if (member == null) return; var url = AssemblyBrowserWidget.GetIdString (member); widget.Open (url); }
public JumpTo (INamedElement el) { this.el = el; }
public void GenerateDoc (IEntity member) { Init (member); this.member = member; this.currentType = GetType (member); DocConfig.Instance.Rules.ForEach (r => r.Run (this, member)); if (member is IParameterizedMember) { this.currentType = "parameter"; foreach (var p in ((IParameterizedMember)member).Parameters) { curName = p.Name; this.member = member; SplitWords (p, p.Name); DocConfig.Instance.Rules.ForEach (r => r.Run (this, p)); } } if (member is IMethod) { IMethod method = (IMethod)member; int count = 1; foreach (var param in method.TypeParameters) { this.currentType = "typeparam"; curName = param.Name; tags["TypeParam"] = param.Name; switch (count) { case 1: tags["TypeParamNumber"] = "1st"; break; case 2: tags["TypeParamNumber"] = "2nd"; break; case 3: tags["TypeParamNumber"] = "3rd"; break; default: tags["TypeParamNumber"] = count + "th"; break; } count++; DocConfig.Instance.Rules.ForEach (r => r.Run (this, param)); } } // ITypeDefinition type; // if (member is ITypeDefinition) { // type = (ITypeDefinition)member; // } else { // type = ((IMember)member).DeclaringTypeDefinition; // } // TODO: Exceptions! // this.currentType = "exception"; // foreach (var exception in visitor.Exceptions) { // var exceptionType = MonoDevelop.Refactoring.HelperMethods.ConvertToReturnType (exception); // // // curName = exceptionType.FullName; // tags["Exception"] = exceptionType.ToInvariantString (); // SplitWords (exceptionType, exceptionType.Name); // // if (type != null) { // IType resolvedType = type.GetProjectContent ().SearchType (type.CompilationUnit, type, type.Location, exceptionType); // string sentence = AmbienceService.GetDocumentationSummary (resolvedType); // if (! string.IsNullOrEmpty(sentence)) { // sentence = sentence.Trim (); // if (sentence.StartsWith ("<para>") && sentence.EndsWith ("</para>")) // sentence = sentence.Substring ("<para>".Length, sentence.Length - "<para>".Length - "</para>".Length).Trim (); // if (sentence.StartsWith ("Represents the error that occurs when")) // sentence = "Is thrown when" + sentence.Substring ("Represents the error that occurs when".Length); // if (!string.IsNullOrEmpty (sentence)) // Set ("exception", curName, sentence); // } // } // // DocConfig.Instance.Rules.ForEach (r => r.Run (this)); // } }
/// <summary> /// Called when user clicks on the add-in menu /// </summary> /// <param name="e">The context of the VS tools and metadata</param> public override void OnClick(AddinDesignerEventArgs e) { try { StringBuilder result; INamedElement namedElement = e.SelectedElement as INamedElement; if (namedElement is TablesAutomation.ITable) { result = this.GenerateFromTable(namedElement as TablesAutomation.ITable, true); } else if (namedElement is TablesAutomation.ITableExtension) { result = this.GenerateFromTableExtension(namedElement as TablesAutomation.ITableExtension, true); } else if (namedElement is TablesAutomation.IRelation) { result = this.GenerateFromTableRelations(e.SelectedElements.OfType <TablesAutomation.IRelation>()); var selectedRelations = e.SelectedElements.OfType <TablesAutomation.IRelation>(); if (selectedRelations.Any()) { result = this.GenerateFromTableRelations(selectedRelations); } } else { throw new NotImplementedException($"Element {e.SelectedElement.ToString()} is not supported."); } if (result != null) { string message = string.Empty; int counter = 0; message += $"Counting for " + tableName; message += "\n\n"; using (SqlConnection conn = new SqlConnection(BusinessDatabaseConnectionString)) { var query = result.ToString(); query = query.Replace("\n", " "); query = query.Replace("\r", " "); query = query.Replace(" GO ", ""); conn.Open(); using (SqlCommand command = new SqlCommand(query, conn)) { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { if (reader.FieldCount == 1) { string counterLocStr = reader["COUNTER"].ToString(); counter += int.Parse(counterLocStr); } else { string dataAreaId = reader["DATAAREAID"].ToString(); string counterLocStr = reader["COUNTER"].ToString(); message += $"{dataAreaId.ToUpper()}: {int.Parse(counterLocStr)}"; counter += int.Parse(counterLocStr); } } } } conn.Close(); } message += "\n\n"; message += $"Total: {counter}"; message += "\n\n"; message += "================== USED QUERY ===================\n"; message += result.ToString(); message += "==============================================="; CoreUtility.DisplayInfo(message); } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
protected bool GetElementList(string filePath, FileType fileType, ref List <T> list, out skinManifest manifest) { if (String.IsNullOrEmpty(filePath) || !File.Exists(filePath)) { manifest = null; return(false); } Exception exception; var skin = XmlSerializerBase <skin> .Read(filePath, out exception); if (exception != null) { if (exception.InnerException != null) { MessageBox.Show(exception.InnerException.Message, Settings.Default.Error, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(exception.Message, Settings.Default.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } list = null; } else if (skin != null) { object[] elements = skin.GetElements(typeof(T)); if (elements != null && elements.Length > 0) { manifest = skin.manifest; list = elements.Cast <T>().OrderBy(s => s.Id).ToList(); XmlNameTable nameTable = skin.RootElement.OwnerDocument.NameTable; var nsmgr = new XmlNamespaceManager(nameTable); nsmgr.AddNamespace("ss", "http://www.PeerProject.com/schemas/Skin.xsd"); XmlElement root = skin.RootElement; string nodeName = skin.GetElementName(typeof(T)); string childName = skin.GetElementChildName(typeof(T)); foreach (var element in list) { if (!(element is INamedElement)) { continue; } INamedElement ne = (INamedElement)element; string xpath = String.Format("/ss:skin/ss:{0}/ss:{1}[@{2}='{3}']", nodeName, childName, element.IdName, element.Id); XmlNodeList nl = root.SelectNodes(xpath, nsmgr); if (nl.Count > 0) { var xe = nl[0] as XmlElement; if (xe != null) { element.NodeList = xe.ChildNodes; } } } if (fileType == FileType.OldEnglish) { _oldFilePath = filePath; } else if (fileType == FileType.NewEnglish) { _newFilePath = filePath; } else if (fileType == FileType.Updated) { _updatedFilePath = filePath; } return(true); } } manifest = null; return(false); }
static DomRegion GetRegion (INamedElement el) { if (el is IEntity) return ((IEntity)el).BodyRegion; return ((IUnresolvedEntity)el).BodyRegion; }