private void SaveAsSnippet(string filePath) { string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePath); XNamespace ns = "http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"; XElement element = new XElement((XName)(ns + "CodeSnippets"), new XElement((XName)(ns + "CodeSnippet"), new object[] { new XAttribute("Format", "1.0.0"), new XElement((XName)(ns + "Header"), new object[] { new XElement((XName)(ns + "Title"), fileNameWithoutExtension + " - assemblies and namespaces"), new XElement((XName)(ns + "Description"), fileNameWithoutExtension + " - assemblies and namespaces"), new XElement((XName)(ns + "Shortcut"), fileNameWithoutExtension.Replace(" ", "")), new XElement((XName)(ns + "SnippetTypes"), new XElement((XName)(ns + "SnippetType"), "Expansion")), this.chkNoShadow.Checked ? new XElement((XName)(ns + "Keywords"), new XElement((XName)(ns + "Keyword"), "LINQPad.NoShadowing")) : null }), new XElement((XName)(ns + "Snippet"), new object[] { new XElement((XName)(ns + "References"), from r in this.GetRefs(false).Concat <string>(this.GetRefs(true)) select new XElement((XName)(ns + "Reference"), new XElement((XName)(ns + "Assembly"), r))), new XElement((XName)(ns + "Imports"), from import in this.GetImports() select new XElement((XName)(ns + "Import"), new XElement((XName)(ns + "Namespace"), import))), new XElement((XName)(ns + "Code"), new object[] { new XAttribute("Language", "csharp"), new XCData("$end$") }) }) })); try { element.Save(filePath); } catch (Exception exception) { MessageBox.Show("Error saving file: " + exception.Message); return; } SnippetManager.ClearSnippetCache(); SnippetManager.set_LINQPadSnippetsFolder(UserOptions.Instance.GetCustomSnippetsFolder(false)); }
private static void Run(string queryToLoad, bool runQuery, string activationCode, bool deactivate, bool noForward, bool noUpdate, string caller) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (Environment.OSVersion.Version.Major >= 6) { try { SetProcessDPIAware(); } catch { } } AutoSaver.Start(); Wheeler.Register(); if (Environment.OSVersion.Version.Major < 6) { ToolStripManager.RenderMode = ToolStripManagerRenderMode.System; } if (!((activationCode != null) || deactivate)) { Splash = new LINQPad.UI.Splash(); Splash.Show(); Splash.Update(); } Log.add_StringWriter(new Action <string>(Log.Write)); Log.add_ExceptionWriter(new Action <Exception>(Log.Write)); TypeResolver.ManyToOne = Resources.ManyToOne; TypeResolver.OneToMany = Resources.OneToMany; TypeResolver.OneToOne = Resources.OneToOne; TypeResolver.ManyToMany = Resources.ManyToMany; TypeResolver.Results = Resources.Results; TypeResolver.Column = Resources.Column; TypeResolver.Key = Resources.Key; TypeResolver.Database = Resources.Database; TypeResolver.GetSameFolderReferences = new Func <string, string[]>(AssemblyProber.GetSameFolderReferences); WSAgent.WebClientFactory = new Func <WebClient>(WebHelper.GetWebClient); WSAgent.FastWebClientFactory = new Func <WebClient>(WebHelper.GetFastWebClient); WSAgent.BackupWebClientFactory = new Func <WebClient>(WebHelper.GetBackupWebClient); WSAgent.CurrentVersionString = VersionString; AutocompletionManager.PassiveAutocompletion = UserOptions.Instance.PassiveAutocompletion; AutocompletionManager.DisableLambdaSnippets = UserOptions.Instance.DisableLambdaSnippets; SnippetManager.set_LINQPadSnippetsFolder(UserOptions.Instance.GetCustomSnippetsFolder(false)); WSAgent.DiagnosticMode = DiagnosticMode; AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Program.CurrentDomain_UnhandledException); if (deactivate) { WSAgent.Remove(true); } else { if (activationCode != null) { using (RegisterForm form = new RegisterForm(activationCode)) { form.ShowDialog(); return; } } if (!noUpdate) { Thread thread = new Thread(new ParameterizedThreadStart(UpdateAgent.RunServerComms)) { Name = "Update Agent", IsBackground = true }; _updateThread = thread; _updateThread.Start(caller); } if (!string.IsNullOrEmpty(caller)) { new Thread(delegate { try { Thread.Sleep(0xbb8); if (File.Exists(caller)) { FileInfo info = new FileInfo(caller); if (((info.Directory == null) || (info.Directory.Parent == null)) || (info.Directory.Parent.Name.ToLowerInvariant() != "updates")) { if (info.IsReadOnly) { info.IsReadOnly = false; } if (!File.Exists(caller + ".config")) { try { File.WriteAllText(caller + ".config", "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n<configuration>\r\n <startup useLegacyV2RuntimeActivationPolicy=\"true\">\r\n <supportedRuntime version=\"v4.0\"/>\r\n </startup>\r\n <runtime>\r\n <legacyUnhandledExceptionPolicy enabled=\"1\" />\r\n </runtime>\r\n</configuration>"); } catch { } } string path = Assembly.GetExecutingAssembly().Location + ".config"; if (!File.Exists(path)) { try { File.WriteAllText(path, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n<configuration>\r\n <startup useLegacyV2RuntimeActivationPolicy=\"true\">\r\n <supportedRuntime version=\"v4.0\"/>\r\n </startup>\r\n <runtime>\r\n <legacyUnhandledExceptionPolicy enabled=\"1\" />\r\n </runtime>\r\n</configuration>"); } catch { } } try { File.Copy(Assembly.GetExecutingAssembly().Location, caller, true); } catch { Thread.Sleep(0x1388); File.Copy(Assembly.GetExecutingAssembly().Location, caller, true); } } } } catch { } }) { Name = "Update patcher" }.Start(); } UnpackDb(); QueryOneToOne(); QueryStudioKeys(noForward); StartSemanticParsingService(); new Thread(delegate { try { Thread.Sleep(0x3e8); if (GacResolver.IsLINQPadGaced()) { MessageBox.Show("Warning: A different revision of LINQPad has been installed to the Global Assembly Cache. This will prevent correct operation.", "LINQPad", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch { } }) { IsBackground = true }.Start(); Application.Run(new MainForm(queryToLoad, runQuery)); TempFileRef.DeleteAll(); } }