public void Execute(IDataContext context, DelegateExecute nextExecute) { ISolution solution; IAssemblyFile existingAssemblyFile = TryGetExistingAssemblyFile(context, out solution); if (existingAssemblyFile == null) { return; } var deobfuscator = solution.TryGetComponent <IAssemblyDeobfuscatorManager>(); if (deobfuscator == null) { return; } string newFileName = AskUser(existingAssemblyFile); if (newFileName == null) { return; } FileSystemPath newAssembly = null; Shell.Instance.GetComponent <UITaskExecutor>().FreeThreaded.ExecuteTask("Deobfuscating...", TaskCancelable.Yes, progressIndicator => { using (ReadLockCookie.Create()) newAssembly = deobfuscator.Execute(existingAssemblyFile, newFileName, progressIndicator); }); if (newAssembly != null) { if (MessageBox.ShowYesNo("Deobfuscation complete!\nWould you like to open the deobfuscated assembly?")) { AddToAssemblyExplorer(newAssembly, solution); } } }
void MainWindow_Loaded(object sender, RoutedEventArgs e) { var agentManager = new AgentManager(lifetime, this); agentManager.Initialise(); // Note, using this lifetime means we get alerts for ALL balloons, // not just the current one (i.e. other classes could also create // a balloon, and we'd get those clicks, too) agent = new Agent(lifetime, agentManager); agent.BalloonOptionClicked.Advise(lifetime, tag => MessageBox.ShowExclamation(string.Format("Clicked: {0}", tag))); agent.ButtonClicked.Advise(lifetime, button => MessageBox.ShowExclamation(string.Format("Clicked button: {0}", button))); var character = agent.AgentCharacter.Character; Animations.ItemsSource = character.Animations.OrderBy(); Animations.SelectedIndex = 0; firstTime = true; }
/// <summary> /// Export all features for documentation /// </summary> private void ExportFeaturesForDocumentation() { MessageBox.ShowInfo("latest"); var brwsr = new FolderBrowserDialog() { Description = "Choose where to save the ResharperFeatures.xml file." }; if (brwsr.ShowDialog() == DialogResult.Cancel) { return; } string saveDirectoryPath = brwsr.SelectedPath; string fileName = Path.Combine(saveDirectoryPath, "ResharperFeatures.xml"); var xDoc = new XDocument(); var xDocRoot = new XElement("Features"); // var productVersion = new ReSharperApplicationDescriptor().ProductVersion; // version = String.Format("{0}.{1}", productVersion.Major, productVersion.Minor); this.version = "9.0"; this.myTestAssemblies = new List <Assembly>(); foreach (var testAssemblyName in this.myTestAssemblyNames) { var testAssembly = Assembly.Load(testAssemblyName); this.myTestAssemblies.Add(testAssembly); } var cache = this.GetTestsForFeatures(); // Context actions int cAnumber = 0; // var contextActionTable = Shell.Instance.GetComponent<ContextActionTable>(); // foreach (var ca in contextActionTable.AllActions) // { // AddFeature(xDocRoot, ca.MergeKey.Split('.').Last(), ca.Type, // "ContextAction", version, ca.Name, ca.Description, String.Empty, cache, null); // cAnumber++; // } // Quick fixes and Inspections int qFnumber = 0; int insTypeNumber = 0; var quickFixTable = Shell.Instance.GetComponent <QuickFixTable>(); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { Type[] types = null; try { types = assembly.GetTypes(); } catch (Exception e) { MessageBox.ShowError("Cannot load assembly!!!!" + e.ToString()); continue; } if (types == null) { continue; } foreach (var type in types) { string name = "Unknown"; string description = "Unknown"; string lang = String.Empty; var attrs = Attribute.GetCustomAttributes(type); // Quick fixes if (typeof(IQuickFix).IsAssignableFrom(type) && !type.IsInterface && !type.IsAbstract) { // foreach (var attr in attrs) // { // if (attr is FeatureDescAttribute) // { // var a = (FeatureDescAttribute)attr; // name = a.Title; // description = a.Description; // } // } this.AddFeature(xDocRoot, type.Name, type, "QuickFix", this.version, name, description, lang, cache, null); qFnumber++; } // Inspections if (typeof(IHighlighting).IsAssignableFrom(type) && !type.IsInterface && !type.IsAbstract) { string id = string.Empty; string severity = string.Empty; string group = string.Empty; string solutionWide = string.Empty; string allQuickFixes = string.Empty; string configurable = string.Empty; string compoundName = string.Empty; /// TODO: Make GetHighlightingQuickFixesInfo public // var quickFixes = quickFixTable.GetHighlightingQuickFixesInfo(type); // foreach (var quickFix in quickFixes) // allQuickFixes += quickFix.QuickFixType.Name + ","; if (!string.IsNullOrEmpty(allQuickFixes)) { allQuickFixes = allQuickFixes.TrimEnd(','); } foreach (var attr in attrs) { if (attr is ConfigurableSeverityHighlightingAttribute) { var a = (ConfigurableSeverityHighlightingAttribute)attr; id = a.ConfigurableSeverityId; var inpectionInstance = HighlightingSettingsManager.Instance.GetSeverityItem(id); lang = this.GetLangsForInspection(id); if (inpectionInstance != null) { name = inpectionInstance.FullTitle; description = inpectionInstance.HTMLDescriptionBody; severity = inpectionInstance.DefaultSeverity.ToString(); solutionWide = inpectionInstance.SolutionAnalysisRequired ? "yes" : "no"; group = inpectionInstance.GroupId; compoundName = inpectionInstance.CompoundItemName; configurable = "yes"; break; } } if (attr is StaticSeverityHighlightingAttribute) { id = type.Name; var a = (StaticSeverityHighlightingAttribute)attr; name = a.ToolTipFormatString; group = a.GroupId; severity = a.Severity.ToString(); solutionWide = "no"; configurable = "no"; } } if (name != "Unknown") { var details = new XElement("Details", new XAttribute("DefaultSeverity", severity), new XAttribute("Group", group), new XAttribute("SolutionWide", solutionWide), new XAttribute("Configurable", configurable), new XAttribute("CompoundName", compoundName ?? ""), new XAttribute("QuickFixes", allQuickFixes) ); if (string.IsNullOrEmpty(name) && description == "Unknown") { name = RsDocExportFeatures.SplitCamelCase(type.Name); } if (string.IsNullOrEmpty(name)) { name = description; } this.AddFeature(xDocRoot, id, type, "Inspection", this.version, name, description, lang, cache, details); insTypeNumber++; } } } } xDocRoot.Add(new XAttribute("TotalContextActions", cAnumber), new XAttribute("TotalQuickFixes", qFnumber), new XAttribute("TotalInspections", insTypeNumber)); foreach (var ins in HighlightingSettingsManager.Instance.SeverityConfigurations) { var inspection = (from nodes in xDocRoot.Elements() let xAttribute = nodes.Attribute("Id") where xAttribute != null && xAttribute.Value == ins.Id select nodes).FirstOrDefault(); if (inspection == null) { var details = new XElement("Details", new XAttribute("DefaultSeverity", ins.DefaultSeverity), new XAttribute("Group", ins.GroupId), new XAttribute("SolutionWide", ins.SolutionAnalysisRequired ? "yes" : "no"), new XAttribute("Configurable", "yes"), new XAttribute("CompoundName", ins.CompoundItemName ?? ""), new XAttribute("QuickFixes", "") ); this.AddFeature(xDocRoot, ins.Id, ins.GetType(), "Inspection", this.version, ins.FullTitle, ins.HTMLDescriptionBody, this.GetLangsForInspection(ins.Id), null, details); } insTypeNumber++; } xDoc.Add(xDocRoot); this.SynchronizeWithStaticDesciription(xDoc); xDoc.Save(fileName); MessageBox.ShowInfo("ReSharper features exported successfully."); }
/// <summary> /// Builds a dictionary (feature type, test object) /// </summary> /// <returns></returns> private List <KeyValuePair <Type, Object> > GetTestsForFeatures() { var cache = new List <KeyValuePair <Type, Object> >(); foreach (var assembly in this.myTestAssemblies) { foreach (var testType in assembly.GetTypes()) { if (testType.IsAbstract || testType.IsInterface || testType.Name.Contains("Availability")) { continue; } var matchFound = false; var ignore = false; foreach (var attribute in testType.GetCustomAttributes(false)) { if (attribute.GetType().Name == "IgnoreAttribute") { ignore = true; } } if (ignore) { continue; } foreach (Type genericTypeArgument in testType.BaseType.GetGenericArguments()) { if (genericTypeArgument != null && !testType.ContainsGenericParameters) { cache.Add(new KeyValuePair <Type, Object>(genericTypeArgument, Activator.CreateInstance(testType))); matchFound = true; } } var methods = testType.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic); foreach (var methodInfo in methods) { if (methodInfo.Name == "CreateContextAction") { if (methodInfo.GetParameters().Length == 1) { var parametersArray = new object[] { null }; var testTypeInstance = Activator.CreateInstance(testType); try { object result = methodInfo.Invoke(testTypeInstance, parametersArray); cache.Add(new KeyValuePair <Type, Object>(result.GetType(), testTypeInstance)); } catch (Exception e) { MessageBox.ShowError(e.ToString()); } matchFound = true; } } } if (!matchFound && testType.Name.EndsWith("Test")) { this.myUnmatchedTests.Add(testType); } } } return(cache); }
private void SynchronizeWithStaticDesciription(XDocument xDoc) { var staticDescriptionXml = new XDocument(); var file = Assembly.GetExecutingAssembly().GetPath().Directory.Directory.Combine("lib/FeatureDescriptionStitic.xml"); if (!file.ExistsFile) { staticDescriptionXml.Add(new XElement("Features")); foreach (var featureNode in xDoc.Root.Elements()) { staticDescriptionXml.Root.Add(new XElement("Feature", new XAttribute("Id", featureNode.Attribute("Id").Value), new XAttribute("SinceVersion", featureNode.Attribute("SinceVersion").Value))); } } else { try { staticDescriptionXml = XDocument.Load(file.FullPath); } catch (XmlException exception) { MessageBox.ShowInfo("FeatureDescriptionStitic.xml is corrupted... /n" + exception); } } foreach (var featureNode in xDoc.Root.Elements()) { var staticFeatureNode = (from nodes in staticDescriptionXml.Root.Elements() where nodes.Attribute("Id").Value == featureNode.Attribute("Id").Value select nodes).FirstOrDefault(); if (staticFeatureNode == null) { staticDescriptionXml.Root.Add(new XElement("Feature", new XAttribute("Id", featureNode.Attribute("Id").Value), new XAttribute("SinceVersion", featureNode.Attribute("SinceVersion").Value))); } else { foreach (var childElement in staticFeatureNode.Elements()) { if (featureNode.Element(childElement.Name) != null) { featureNode.Element(childElement.Name).Remove(); } featureNode.Add(childElement); } foreach (var attribute in staticFeatureNode.Attributes()) { if (featureNode.Attribute(attribute.Name) != null) { featureNode.Attribute(attribute.Name).Remove(); } featureNode.Add(attribute); } } } foreach (var staticFeature in staticDescriptionXml.Root.Elements()) { var dynamicFeatureNode = (from nodes in xDoc.Root.Elements() where nodes.Attribute("Id").Value == staticFeature.Attribute("Id").Value select nodes).FirstOrDefault(); if (dynamicFeatureNode == null && staticFeature.Attribute("DeprecatedSince") == null) { staticFeature.Add(new XAttribute("DeprecatedSince", this.version)); } } staticDescriptionXml.Save(file.FullPath); }
private static void HandleElement(ITextControl editor, ITreeNode element, int offset) { string stringToInsert = Clipboard.GetText(); if (string.IsNullOrEmpty(stringToInsert)) { return; } IDocCommentNode docCommentNode = element as IDocCommentNode; if (docCommentNode != null) { JetBrains.Util.dataStructures.TypedIntrinsics.Int32 <DocLine> currentLineNumber = editor.Document.GetCoordsByOffset(editor.Caret.Offset()).Line; string currentLine = editor.Document.GetLineText(currentLineNumber); int index = currentLine.IndexOf("///", StringComparison.Ordinal); if (index < 0) { return; } string prefix = currentLine.Substring(0, index); if (ShallEscape(docCommentNode, editor.Caret.Offset()) && JetBrains.UI.RichText.RichTextBlockToHtml.HtmlEncode(stringToInsert) != stringToInsert && MessageBox.ShowYesNo("Do you want the text to be escaped?")) { stringToInsert = JetBrains.UI.RichText.RichTextBlockToHtml.HtmlEncode(stringToInsert); } stringToInsert = stringToInsert.Replace("\n", "\n" + prefix + "///"); } ITokenNode token = element as ITokenNode; if (token != null) { if (token.GetTokenType() == CSharpTokenType.STRING_LITERAL && offset < token.GetTreeTextRange().EndOffset.Offset) { string text = token.GetText(); if (text.StartsWith("@") && offset > token.GetTreeTextRange().StartOffset.Offset + 1) { stringToInsert = stringToInsert.Replace("\"", "\"\""); } else if (!text.StartsWith("@")) { stringToInsert = stringToInsert. Replace("\\", "\\\\"). Replace("\a", "\\a"). Replace("\b", "\\b"). Replace("\f", "\\f"). Replace("\n", "\\n"). Replace("\r", "\\r"). Replace("\t", "\\t"). Replace("\v", "\\v"). Replace("\'", "\\'"). Replace("\"", "\\\""); } } } editor.Document.InsertText(editor.Caret.Offset(), stringToInsert); }
private void CreateXml(TemplateApplicability applicability, IContextBoundSettingsStore bound, string saveDirectoryPath, string version, IDataContext context) { string type; ScopeFilter scopeFilter = ScopeFilter.Language; switch (applicability) { case TemplateApplicability.Live: type = "Live"; break; case TemplateApplicability.Surround: type = "Surround"; break; case TemplateApplicability.File: type = "File"; scopeFilter = ScopeFilter.Project; break; default: return; } var topicId = "Reference__Templates_Explorer__" + type + "_Templates"; var fileName = Path.Combine(saveDirectoryPath, topicId + ".xml"); var topic = XmlHelpers.CreateHmTopic(topicId); var topicRoot = topic.Root; topicRoot.Add(new XElement("p", new XElement("menupath", "ReSharper | Templates Explorer | " + type + " Templates"))); topicRoot.Add(new XElement("p", "This section lists all predefined " + type + " templates in ReSharper " + version + ".")); topicRoot.Add(new XElement("p", XmlHelpers.CreateInclude("Templates__Template_Basics__Template_Types", type))); var summaryTable = XmlHelpers.CreateTable(new[] { "Template", "Description" }, new[] { "20%", "80%" }); var summaryItems = new List <Tuple <string, XElement> >(); var tables = new Dictionary <string, XElement>(); var defaultTemplates = context.GetComponent <StoredTemplatesProvider>() .EnumerateTemplates(bound, applicability, false); var myScopeCategoryManager = context.GetComponent <ScopeCategoryManager>(); foreach (var template in defaultTemplates) { var templateIdPresentable = !template.Shortcut.IsNullOrEmpty() ? template.Shortcut : template.Description; templateIdPresentable = Regex.Replace(templateIdPresentable, "&Enum", "Enum"); var currentTemplateLangs = new List <string>(); var imported = String.Empty; var scopeString = String.Empty; var cat = String.Empty; foreach (var category in template.Categories) { if (category.Contains("Imported")) { imported = category; break; } if (category.Contains("C#")) { cat = "C#"; } if (category.Contains("VB.NET")) { cat = "VB.NET"; } } foreach (var point in template.ScopePoints) { foreach (var provider in myScopeCategoryManager.GetCoveredProviders(scopeFilter, point)) { var lang = provider.CategoryCaption; if (lang == "ASP.NET" && type == "Surround" && !cat.IsNullOrEmpty()) { lang = lang + "(" + cat + ")"; } if (!lang.IsNullOrEmpty()) { currentTemplateLangs.Add(lang); if (!tables.ContainsKey(lang)) { tables.Add(lang, XmlHelpers.CreateTable(new[] { "Template", "Details" }, new[] { "20%", "80%" })); } } } if (currentTemplateLangs.Count == 0) { MessageBox.ShowExclamation(String.Format("The '{0}' template has no associated languages", templateIdPresentable)); } scopeString += " " + point.PresentableShortName + ","; } scopeString = scopeString.TrimEnd(','); var paramElement = new XElement("list"); foreach (var param in template.Fields) { var expr = param.Expression as MacroCallExpressionNew; var paramItemElement = new XElement("li", new XElement("code", param.Name)); if (expr != null) { var macro = MacroDescriptionFormatter.GetMacroAttribute(expr.Definition); paramItemElement.Add(" - " + macro.LongDescription + " (", XmlHelpers.CreateHyperlink(macro.Name, "Template_Macros", macro.Name), ")"); } else { paramItemElement.Add(" - " + "no macro"); } paramElement.Add(paramItemElement); } if (template.Text.Contains("$SELECTION$")) { paramElement.Add(new XElement("li", new XElement("code", "SELECTION"), " - The text selected by the user before invoking the template.")); } if (template.Text.Contains("$END$")) { paramElement.Add(new XElement("li", new XElement("code", "END"), " - The caret position after the template is applied.")); } var processedLangs = new List <string>(); foreach (var lang in currentTemplateLangs) { if (!processedLangs.Contains(lang)) { AddTemplateRow(tables, summaryItems, lang, templateIdPresentable, template, scopeString, paramElement, type, imported); processedLangs.Add(lang); } } } foreach (var table in tables) { summaryTable.Add(new XElement("tr", new XElement("td", new XAttribute("colspan", "2"), new XElement("b", table.Key)))); foreach (var item in summaryItems) { if (item.Item1 == table.Key) { summaryTable.Add(item.Item2); } } var langForHeading = table.Key; if (langForHeading == "Global") { langForHeading = "Global Usage"; } CreateTopicForLang(langForHeading, type, table.Value, saveDirectoryPath, version); } var indexChapter = XmlHelpers.CreateChapter(String.Format("Index of {0} Templates", type)); topicRoot.Add(new XComment("Total " + type + " templates: " + summaryItems.Count)); indexChapter.Add(summaryTable); topicRoot.Add(indexChapter); topic.Save(fileName); }