static void Main(string[] args) { //Create a SnippetInfo for each code snippet you want to package var Snippet1 = new SnippetInfo(); Snippet1.SnippetFileName = "UnprotectDocument.snippet"; Snippet1.SnippetPath = "C:\\MySnippets"; Snippet1.SnippetLanguage = SnippetInfo.GetSnippetLanguage(Snippet1.SnippetPathName); Snippet1.SnippetDescription = SnippetInfo.GetSnippetDescription(Snippet1.SnippetFileName); //Create a new package var Vsix = new VSIXPackage(); //Populate the collection of snippets Vsix.CodeSnippets.Add(Snippet1); //Set package metadata information Vsix.Tags = "Word"; Vsix.PackageAuthor = "Alessandro Del Sole"; Vsix.PackageDescription = "A test VSIX package with snippets"; Vsix.License = "C:\\temp\\MIT_License.txt"; Vsix.MoreInfoURL = "https://github.com/alessandrodelsole/delsolevsix"; //Assign other properties here... //Go build it! Vsix.Build("C:\\temp\\Sample.vsix"); //Convert an old .vsi file into a .vsix package VsiService.Vsi2Vsix("C:\\temp\\VBWPFSnippets.vsi", "C:\\temp\\VBWPFSnippets.vsix", "VB WPF Snippets", "Alessandro Del Sole", "VB Snippets for WPF", "A common set of WPF Snippets for VB", null, null, "https://github.com/alessandrodelsole/delsolevsix"); Console.WriteLine("Package created. Starting..."); Process.Start("C:\\temp\\VBWPFSnippets.vsix"); Console.ReadLine(); }
//Create 2 examples foreach CodeLanguage from Database public static void CodeSnippedExampleForeachCodeLanguageInDatabase() { int ExamplePerLanguage = 2; for (int l = 0; l < DbCodeLanguage.GetallLanguages().Count; l++) { for (int examples = 0; examples < ExamplePerLanguage; examples++) { SnippetInfo snippetInfo = new SnippetInfo( 9999, UserInfo.Userinformation.ID, 9999, "Name" + examples, "Code" + examples, DateTime.Now, "Usage" + examples, DateTime.Now, "Description" + examples, DateTime.Now, DbCodeLanguage.GetallLanguages()[l].ID,//<------------- DateTime.Now ); System.Threading.Thread.Sleep(1000); DbSnippets.AddNewSnippet(snippetInfo); } } }
public SnippetElement GetElement(SnippetInfo snippetInfo) { if ("Selection".Equals(snippetInfo.Tag, StringComparison.OrdinalIgnoreCase)) { return new SnippetSelectionElement() { Indentation = GetWhitespaceBefore(snippetInfo.SnippetText, snippetInfo.Position).Length } } ; if ("Caret".Equals(snippetInfo.Tag, StringComparison.OrdinalIgnoreCase)) { // If a ${Selection} exists, use the ${Caret} only if there is text selected // (if no text is selected, ${Selection} will set the caret if (snippetInfo.SnippetText.IndexOf("${Selection}", StringComparison.OrdinalIgnoreCase) >= 0) { return(new SnippetCaretElement(setCaretOnlyIfTextIsSelected: true)); } else { return(new SnippetCaretElement()); } } return(null); }
public SnippetElement GetElement(SnippetInfo snippetInfo) { if ("refactoring:ctor".Equals(snippetInfo.Tag, StringComparison.OrdinalIgnoreCase)) return new InlineRefactorSnippetElement(context => CreateDialog(context), "{" + snippetInfo.Tag + "}"); return null; }
private void SaveAsNew() { if (ControlState.Execute(c, ControlStateVisuals.Colored)) { TextRange Coderange = new TextRange(Code.Document.ContentStart, Code.Document.ContentEnd); TextRange Usagerange = new TextRange(Usage.Document.ContentStart, Usage.Document.ContentEnd); TextRange Descriptionrange = new TextRange(Description.Document.ContentStart, Description.Document.ContentEnd); SnippetInfo info = new SnippetInfo( 0, UserInfo.Userinformation.ID, 0, Name.Text, Coderange.Text, DateTime.Now, Usagerange.Text, DateTime.Now, Descriptionrange.Text, DateTime.Now, DbCodeLanguage.ToID(Language.SelectedItem.ToString()), DateTime.Now ); DbSnippets.AddNewSnippet(info); if (Nav != null) { Nav.FilterCodeSnippeds(); } ControlState.Execute(c, ControlStateVisuals.Background); Clear(); } }
private List <SnippetInfo> selectSnippetInfo(string sql, Dictionary <string, object> parameters) { SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection); foreach (KeyValuePair <string, object> kvp in parameters) { command.Parameters.Add(new SQLiteParameter(kvp.Key, kvp.Value)); } SQLiteDataReader dr = command.ExecuteReader(); List <SnippetInfo> snippetInfoList = new List <SnippetInfo>(); while (dr.Read()) { SnippetInfo snippetInfo = new SnippetInfo { Id = (int)dr.GetInt64(0), Titel = dr.GetString(1), Beschreibung = dr.GetString(2), CreationDate = dr.GetDateTime(3), LastEditDate = dr.GetDateTime(4), Favorite = dr.GetBoolean(5), }; snippetInfoList.Add(snippetInfo); } return(snippetInfoList); }
public void GetTagsTest() { IDatabaseDAO db = App.DatabaseInstance; Tag tag = new Tag { Title = "TestTag", Type = TagType.TAG_WITHOUT_TYPE }; SnippetCode snippetCode = new SnippetCode(); List <Tag> tags = new List <Tag> { tag }; SnippetInfo snippetInfo = new SnippetInfo { SnippetCode = snippetCode }; snippetInfo.Tags.AddRange(tags, true); db.saveSnippet(snippetInfo); Tag dbTag = db.GetTags("TestTag", TagType.TAG_WITHOUT_TYPE).First(); Assert.IsNotNull(dbTag); Assert.AreEqual(tag.Title, dbTag.Title); Assert.AreEqual(tag.Type, dbTag.Type); Assert.IsNotNull(dbTag.Id); }
public List <SnippetInfo> GetInfos(string file) { List <SnippetInfo> result = new List <SnippetInfo>(); int count = infos.Count; for (int i = 0; i < count; i++) { SnippetInfo info = infos[i]; string key = Path.GetFileNameWithoutExtension(info.path); Regex[] patterns = info.patterns; bool contains = false; for (int j = 0; j < patterns.Length; j++) { if (patterns[j].IsMatch(file)) { contains = true; break; } } if (contains && !ignoreFiles.ContainsKey(key) || forcedFiles.ContainsKey(key)) { result.Add(info); } } return(result); }
public SnippetElement GetElement(SnippetInfo snippetInfo) { if ("refactoring:switchbody".Equals(snippetInfo.Tag, StringComparison.OrdinalIgnoreCase)) { return(new SwitchBodySnippetElement()); } return(null); }
public SnippetXML(HeaderInfo headerInfo, SnippetInfo snippetInfo) { xml = new XDocument(new XDeclaration("1.0", "utf-8", null)); XElement codeSnippets = new XElement(MicrosoftNs + "CodeSnippets"); codeSnippets.Add(BuildLocDefinition()); codeSnippets.Add(BuildSnippet(headerInfo, snippetInfo)); xml.Add(codeSnippets); }
private void SnippetPage_SnippetSaved(SnippetInfo snippetInfo) { // Relay event to any handler that is interested in changes AnySnippetSaved.Invoke(snippetInfo); // in case it was the title of a new snippet that was changed, refresh the tree view // TODO: Only refresh the new group or sth. like that for performance refreshNodesAsync().ConfigureAwait(false); }
public SnippetElement GetElement(SnippetInfo snippetInfo) { if ("refactoring:ctor".Equals(snippetInfo.Tag, StringComparison.OrdinalIgnoreCase)) { return(new InlineRefactorSnippetElement(context => CreateDialog(context), "{" + snippetInfo.Tag + "}")); } return(null); }
public List <Tag> GetTagsFromSnippetInfo(SnippetInfo snippetInfo) { string sql = "select tag.id, tag.title, tag.type from tag_snippetInfo left join tag on tag_snippetInfo.tagId = tag.id where tag_snippetInfo.snippetInfoId = :snippetId"; Dictionary <string, object> dict = new Dictionary <string, object> { { "snippetId", snippetInfo.Id } }; return(selectTag(sql, dict)); }
private bool shouldNodeShow(SnippetInfo s, String filter = "") { bool negate = filter.IsFirstLetter('^'); if (negate) { filter = filter.Substring(1); } return((filter == "" || s.Titel.Contains(filter) || s.Tags.Any(t => t.Title.Contains(filter)) || s.Beschreibung.Contains(filter)) ^ negate); }
//Main public SnippetItem(SnippetInfo info, SnippetsPage page, NavBarSnippet navbar) { InitializeComponent(); Info = info; Page = page; Name.Content = info._Name; Language.Content = DbCodeLanguage.ToString(info._LanguageID); CreateDate.Content = info._CreateDate; Navbar = navbar; }
private void openMenuItem_Click(object sender, RoutedEventArgs e) { //Open the XML Document, and attempt to populate the GUI with its values try { var dialog = new Microsoft.Win32.OpenFileDialog { Filter = "Code Snippets (.snippet)|*.snippet" }; if (dialog.ShowDialog() == true) { SnippetXML xdoc = new SnippetXML(XDocument.Load(dialog.FileName)); HeaderInfo headerInfo = xdoc.GetHeaderDataFromFile(); titleTextBox.Text = headerInfo.Title; authorTextBox.Text = headerInfo.Author; descriptionTextBox.Text = headerInfo.Description; if (GetSelectedRadioButton() == "Expansion") { expansionRadioButton.IsChecked = true; } else { surroundsWithRadioButton.IsChecked = true; } SnippetInfo snippetInfo = xdoc.GetSnippetInfoFromFile(); foreach (ComboBoxItem item in languageComboBox.Items) { if (item.Tag.ToString() == snippetInfo.Language) { languageComboBox.SelectedItem = item; break; } } codeRichTextBox.Document.Blocks.Clear(); codeRichTextBox.Document.Blocks.Add(new Paragraph(new Run(snippetInfo.Code))); literalsDataGrid.ItemsSource = snippetInfo.Literals; } } catch (System.IO.IOException ex) { MessageBox.Show("Error loading file:" + Environment.NewLine + ex.Message.ToString()); } catch (System.Xml.XmlException ex) { MessageBox.Show("Error parsing XML in file. " + Environment.NewLine + ex.Message.ToString()); } catch (NullReferenceException ex) { MessageBox.Show("There was a problem locating the necessary elements within the XML." + Environment.NewLine + ex.Message.ToString()); } catch (Exception ex) { MessageBox.Show("An Unknown Error occurred." + Environment.NewLine + ex.Message.ToString()); } }
private void saveTagsToSnippetInfo(IEnumerable <Tag> tags, SnippetInfo snippetInfo) { // Delete the existing Tag <-> snippetInfo connections execute("delete from tag_snippetInfo where snippetInfoId = :snippetInfoId", new Dictionary <string, object> { { ":snippetInfoId", snippetInfo.Id } }); execute("BEGIN TRANSACTION"); // Save connection between tags and snippetInfo foreach (Tag tag in tags.ToArray()) { if (tag.IsEmpty || !tag.Id.HasValue) { continue; } Dictionary <string, object> dict; if (!tag.Id.HasValue) { Tag dbTag = doesTagTitleExist(tag); if (dbTag != null) { dict = new Dictionary <string, object> { { ":snippetInfoId", snippetInfo.Id.Value }, { ":tagId", dbTag.Id.Value } }; } else { continue; } } else { dict = new Dictionary <string, object> { { ":snippetInfoId", snippetInfo.Id.Value }, { ":tagId", tag.Id.Value } }; } execute("insert into tag_snippetInfo (snippetInfoId, tagId) values (:snippetInfoId, :tagId)", dict); } execute("COMMIT"); }
public override bool cleanup(SnippetInfo info) { Dictionary<string, object> ex = (info.executable as Dictionary<string, object>); List<string> toDelete = (ex["copiedPaths"] as List<string>); for(int i = 0; i < toDelete.Count; i++) { File.Delete(toDelete[i]); } CompilerResults cr = (ex["results"] as CompilerResults); cr.TempFiles.Delete(); File.Delete(cr.PathToAssembly); return true; }
private void SnippetCategorySelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.AddedItems.Count == 0) { return; } _selectedSnippet = e.AddedItems[0] as SnippetInfo; if (_selectedSnippet == null) { return; } snippetGridView.ItemsSource = _selectedSnippet.Snippets; }
public SnippetCode GetSnippetCode(SnippetInfo parentInfo) { List <SnippetCode> result = selectSnippetCode("select * from snippetCode c inner join snippetInfo i on i.id = c.id where i.id=:id", new Dictionary <string, object> { { "id", parentInfo.Id } }); if (result.Count > 0) { return(result.First()); } else { return(null); } }
public SnippetElement GetElement(SnippetInfo snippetInfo) { int typeSeparator = snippetInfo.Tag.IndexOf(':'); if (typeSeparator > 0) { string type = snippetInfo.Tag.Substring(0, typeSeparator); string name = snippetInfo.Tag.Substring(typeSeparator + 1); if ("anchor".Equals(type, StringComparison.OrdinalIgnoreCase)) { return(new SnippetAnchorElement(name)); } } return(null); }
public override bool cleanup(SnippetInfo info) { Dictionary <string, object> ex = (info.executable as Dictionary <string, object>); List <string> toDelete = (ex["copiedPaths"] as List <string>); for (int i = 0; i < toDelete.Count; i++) { File.Delete(toDelete[i]); } CompilerResults cr = (ex["results"] as CompilerResults); cr.TempFiles.Delete(); File.Delete(cr.PathToAssembly); return(true); }
public SnippetElement GetElement(SnippetInfo snippetInfo) { if ("Selection".Equals(snippetInfo.Tag, StringComparison.OrdinalIgnoreCase)) { return new SnippetSelectionElement() { Indentation = GetWhitespaceBefore(snippetInfo.SnippetText, snippetInfo.Position).Length } } ; if ("Caret".Equals(snippetInfo.Tag, StringComparison.OrdinalIgnoreCase)) { return(new SnippetCaretElement()); } return(null); }
public async Task AddCodeAsync(string name, [Remainder] string code) { var info = new SnippetInfo() { UserId = base.Context.User.Id, Name = name, Code = code }; if (await CodeWithNameExists(name)) { await ReplyAsync("Ein Code mit diesem Namen existiert bereits!"); return; } await AddEntryToDatabase(info); await ReplyAsync($"Der Code wurde unter dem Namen `{name}` gespeichert."); }
//Update new Snippet public static void UpdateSnippet(SnippetInfo snippetInfo) { using (MySqlConnection connection = DbInfo.Connection()) { using (MySqlCommand cmd = new MySqlCommand()) { cmd.Connection = connection; cmd.CommandType = CommandType.Text; cmd.CommandText = "UPDATE `codesnippets` SET " + "`TagCollectionID`= @TagCollectionID," + "`Name`= @Name," + "`Code`= @Code," + "`CodeEditDate`= @CodeEditDate," + "`UsageExample`= @UsageExample," + "`UsageEditDate`= @UsageEditDate," + "`Description`= @Description," + "`DescriptionEditDate`= @DescriptionEditDate," + "`LanguageID`= @LanguageID " + "WHERE `ID`= @ID"; cmd.Parameters.AddWithValue("@ID", snippetInfo._ID); cmd.Parameters.AddWithValue("@TagCollectionID", snippetInfo._TagCollectionID); cmd.Parameters.AddWithValue("@Name", snippetInfo._Name); cmd.Parameters.AddWithValue("@Code", snippetInfo._Code); cmd.Parameters.AddWithValue("@CodeEditDate", snippetInfo._CodeEditDate.ToString()); cmd.Parameters.AddWithValue("@UsageExample", snippetInfo._UsageExample); cmd.Parameters.AddWithValue("@UsageEditDate", snippetInfo._UsageEditDate.ToString()); cmd.Parameters.AddWithValue("@Description", snippetInfo._Description); cmd.Parameters.AddWithValue("@DescriptionEditDate", snippetInfo._DescriptionEditDate.ToString()); cmd.Parameters.AddWithValue("@LanguageID", snippetInfo._LanguageID); try { int recordsAffected = cmd.ExecuteNonQuery(); } finally { connection.Close(); } } } }
private async Task UpdateDb(string name, SnippetInfo info) { var db = await ReadDatabase(); db[name] = info; var filesFolder = _configuration["FileStore:DataFolder"]; if (!Directory.Exists(filesFolder)) { _logger.LogError("FileStore:DataFolder does not refer to an existing directory. Did you configure it in appsettings.json?"); await ReplyAsync("Bot not properly configured. Check logs for details."); return; } var pollModuleDirectory = Directory.CreateDirectory(Path.Combine(filesFolder, "CodeModule")); var serialized = JsonConvert.SerializeObject(db); await File.WriteAllTextAsync(Path.Combine(pollModuleDirectory.FullName, "CodeDb.json"), serialized); }
private void SnippetSelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.AddedItems.Count == 0) { return; } _selectedSnippet = e.AddedItems[0] as SnippetInfo; if (_selectedSnippet == null) { return; } // Open the selected snippet in a web view // Note: At this point I'd like to pass a custom SnippetInfo object. However, if you try to pass no simple types (like ints, strings, etc.) // then when the app suspends you'll find the await SuspensionManager.SaveAsync(); statement fails in App.OnSuspending(). This is a known issue. // The only worksaround is to pass simple types. So, here we pass the (unique) snippet filename (this can be used to lookup additional info // by the snippet page as required): Frame.Navigate(typeof(SnippetPage), _selectedSnippet.SnippetFile); }
public void deleteSnippet(SnippetInfo infoToDelete) { SnippetCode dbSnippetCodeToDelete = GetSnippetCode(infoToDelete); if (dbSnippetCodeToDelete != null) { execute("DELETE FROM snippetCode where snippetCode.id = :snippetCodeId", new Dictionary <string, object> { { "snippetCodeId", dbSnippetCodeToDelete.Id } }); } foreach (Tag tag in infoToDelete.Tags) { if (!existsSnippetToTag(tag)) { execute("DELETE FROM tag WHERE id = :tagId", new Dictionary <string, object> { { "tagId", tag.Id } }); } } }
public void ReadXml_SingleSnippetInfo_CanDeserialize() { SnippetInfo snippetInfo = new SnippetInfo(); string snippetInfoXml = @" <SnippetInfo> <SnippetTemplatePath>/path1</SnippetTemplatePath> <SlotName>Slot1</SlotName> <Data><![CDATA[Data 1]]></Data> </SnippetInfo>"; using (StringReader s = new StringReader(snippetInfoXml)) { XmlSerializer serializer = new XmlSerializer(typeof(SnippetInfo)); snippetInfo = (SnippetInfo)serializer.Deserialize(s); } // Assert Assert.AreEqual <string>("/path1", snippetInfo.SnippetTemplatePath); Assert.AreEqual <string>("Slot1", snippetInfo.SlotName); Assert.AreEqual <string>("Data 1", snippetInfo.Data); }
/// <summary> /// Adds a new tab with the given snippet to the tabs /// </summary> /// <param name="si">Snippet that is to be opened. If this is null, a new one gets created by the SnippetPage</param> /// <param name="switchTo">If true, the new tab gets focused immediately</param> private void addSnippetPage(SnippetInfo si = null, bool switchTo = true) { TabItem tabItem = new TabItem { Header = si?.Titel ?? TITLE_UNNAMED }; SnippetPage snippetPage = new SnippetPage(si); snippetPage.TitleChanged += SnippetPage_TitleChanged; snippetPage.SnippetSaved += SnippetPage_SnippetSaved; tabItem.Content = snippetPage; tbc_pages.Items.Remove(ti_add); tbc_pages.Items.Add(tabItem); tbc_pages.Items.Add(ti_add); if (switchTo) { tbc_pages.SelectedIndex = tbc_pages.Items.Count - 2; } }
public async Task AddCodeAsync(string name, [Remainder] string code) { var info = new SnippetInfo() { UserId = base.Context.User.Id, Name = name, Code = code, Id = Guid.NewGuid().ToString() }; try { await AddEntryToDatabase(info); await ReplyAsync($"Der Code wurde unter dem Namen `{name}` gespeichert."); } catch { await ReplyAsync("Ein Code mit diesem Namen existiert bereits!"); } }
//Get SnippetInfo from ID public static SnippetInfo GetSnippetInfoFromID(int ID) { //Create temp SnippetInfo Temp = null; //create connection and open it MySqlConnection connection = DbInfo.Connection(); //Build Mysql command MySqlCommand cmd = connection.CreateCommand(); //Create and add Commandtext cmd.CommandText = "SELECT `ID`, `UserID`, `TagCollectionID`, `Name`, `Code`, `CodeEditDate`, `UsageExample`, `UsageEditDate`, `Description`, `DescriptionEditDate`, `LanguageID`, `CreateDate` FROM `codesnippets` WHERE `ID` = @ID"; cmd.Parameters.AddWithValue("@ID", ID); //Create reader MySqlDataReader reader = cmd.ExecuteReader(); //if match is found if (reader.Read()) { //Save a new Temporary Snippet return(new SnippetInfo( int.Parse(reader["ID"].ToString()), int.Parse(reader["UserID"].ToString()), int.Parse(reader["TagCollectionID"].ToString()), reader["Name"].ToString(), reader["Code"].ToString(), DateTime.Parse(reader["CodeEditDate"].ToString()), reader["UsageExample"].ToString(), DateTime.Parse(reader["UsageEditDate"].ToString()), reader["Description"].ToString(), DateTime.Parse(reader["DescriptionEditDate"].ToString()), int.Parse(reader["LanguageID"].ToString()), DateTime.Parse(reader["CreateDate"].ToString()) )); } //Return value return(Temp); }