void DeleteJiraTemplateItemFromRegistry(JiraTemplate jiraTemplate) { if (jiraTemplate == null) { return; } RegistryOperation.DeleteRegistrySubKey(RegistryOperation.szAppRegPathTemplates, jiraTemplate.Name); }
public DataModel() { JiraEmail = RegistryOperation.GetBinaryKeyValueInString(RegistryOperation.szAppRegPathGeneral, RegistryOperation.szKeyNameJiraEmail); bToEmail = RegistryOperation.GetBinaryKeyValueInBool(RegistryOperation.szAppRegPathGeneral, RegistryOperation.szKeyNamebToEmail); bCcEmail = RegistryOperation.GetBinaryKeyValueInBool(RegistryOperation.szAppRegPathGeneral, RegistryOperation.szKeyNamebCcEmail); bRemoveRecipients = RegistryOperation.GetBinaryKeyValueInBool(RegistryOperation.szAppRegPathGeneral, RegistryOperation.szKeyNamebRemoveRecipients); // if we create using public property then it will crash at setter because of null reference. _DefaultTemplate = new JiraTemplate(); if (bToEmail == false && bCcEmail == false) { bToEmail = true; // create registry for next time as well RegistryOperation.CreateBinaryKeyValue(RegistryOperation.szAppRegPathGeneral, RegistryOperation.szKeyNamebToEmail, "1"); } JiraTemplates = new List <JiraTemplate>(); string[] TemplateSubKeys = RegistryOperation.GetAppSubKeys(RegistryOperation.szAppRegPathTemplates); if (TemplateSubKeys != null && TemplateSubKeys.Length > 0) { string DefaultTemp = RegistryOperation.GetBinaryKeyValueInString(RegistryOperation.szAppRegPathTemplates, RegistryOperation.szKeyNameTemplateDefault); foreach (string keyName in TemplateSubKeys) { string data = RegistryOperation.GetBinaryKeyValueInString(RegistryOperation.szAppRegPathTemplates + "\\" + keyName, RegistryOperation.szKeyNameTemplateContent); if (data != null && data.Length > 0) { JiraTemplate jt = new JiraTemplate(); jt.Name = keyName; jt.Content = data; JiraTemplates.Add(jt); if (0 == String.Compare(keyName, DefaultTemp, true)) { DefaultTemplate = jt; } } } } else { // create default template and update the registry for next time. string szDefaultTemplate = JiraTemplate.GetDefaultTemplateContent(); RegistryOperation.CreateSubKey(RegistryOperation.szAppRegPathTemplates, RegistryOperation.szSubKeyNameTemplateDefault); RegistryOperation.CreateBinaryKeyValue(RegistryOperation.szAppRegPathTemplates + "\\" + RegistryOperation.szSubKeyNameTemplateDefault, RegistryOperation.szKeyNameTemplateContent, szDefaultTemplate); JiraTemplate jt = new JiraTemplate(); jt.Name = RegistryOperation.szSubKeyNameTemplateDefault; jt.Content = szDefaultTemplate; JiraTemplates.Add(jt); DefaultTemplate = jt; } }
void bInsertTemplate_Click(object sender, RibbonControlEventArgs e) { RibbonButton rb = sender as RibbonButton; if (rb != null) { JiraTemplate jt = Globals.ThisAddIn.dataModel.GetJiraTemplateFromTemplateName(rb.Label); Globals.ThisAddIn.InsertDefaultTemplateInReply(jt); } }
void rbReplyWithTemplate_Click(object sender, RibbonControlEventArgs e) { RibbonButton rb = sender as RibbonButton; if (rb != null) { JiraTemplate jt = Globals.ThisAddIn.dataModel.GetJiraTemplateFromTemplateName(rb.Label); Globals.ThisAddIn.HandleReplyWithTemplate(jt); } }
public void AddJiraTemplateToDataModel(JiraTemplate jiraTemplate) { if (jiraTemplate == null) { return; } this.JiraTemplates.Add(jiraTemplate); WriteJiraTemplateItemToRegistry(jiraTemplate); }
void WriteJiraTemplateItemToRegistry(JiraTemplate jiraTemplate) { if (jiraTemplate == null) { return; } RegistryOperation.CreateSubKey(RegistryOperation.szAppRegPathTemplates, jiraTemplate.Name); RegistryOperation.CreateBinaryKeyValue(RegistryOperation.szAppRegPathTemplates + "\\" + jiraTemplate.Name, RegistryOperation.szKeyNameTemplateContent, jiraTemplate.Content); }
public void AddJiraTemplateToDataModel(string Name, string Content) { if (Name == null || Content == null) { return; } JiraTemplate jiraTemplate = new JiraTemplate(Name, Content); AddJiraTemplateToDataModel(jiraTemplate); }
public void HandleReplyWithTemplate(JiraTemplate jiraTemplate) { if (dataModel.JiraEmail == null || dataModel.JiraEmail.Length < 1) { MessageBox.Show("Invalid Jira Email.\nPlease update email address in Jira Tab.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (jiraTemplate == null) { // fallback to default jiraTemplate = dataModel.DefaultTemplate; } try { Outlook._Explorer exp = Globals.ThisAddIn.Application.ActiveExplorer(); if (exp != null && exp.Selection != null && exp.Selection.Count > 0) { foreach (Object item in exp.Selection) { if (item is Outlook._MailItem) { Outlook._MailItem mailItem = (item as Outlook._MailItem); Outlook._MailItem reply = mailItem.ReplyAll(); AddTemplateDataToMailItem(reply, jiraTemplate); reply.Display(); } } } } catch (Exception Ex) { // To see this exception: Click on the email folders tree's top node i.e. the one which shows like a startup page // and contains Calendar information, tasks and messages overview. After that from ribbon click on the reply button. // http://stackoverflow.com/questions/17211827/how-to-check-if-a-vsto-outlook-explorer-object-has-been-closed // Ex.Message = "The Explorer has been closed and cannot be used for further operations. Review your code and restart Outlook." // Outlook gives valid explorer but selection paramter generates exception. //MessageBox.Show(Ex.Message + "\n" + Ex.StackTrace, "Error!!!"); RegistryOperation.CreateBinaryKeyValue(RegistryOperation.szAppRegPathGeneral, RegistryOperation.szKeyNameLastError, Ex.Message.ToString() + "\n" + Ex.StackTrace.ToString()); } }
private void bSave_Click(object sender, EventArgs e) { string Name = tbName.Text; string Content = rbContent.Text; bool bIsDefault = false; if ( Name == null || Name.Length < 1 || Content == null || Content.Length < 1 ) { MessageBox.Show("Invalid Name/Content.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } JiraTemplate jt = new JiraTemplate(Name, Content); if (editTemplateName == null || editTemplateName.Length < 1) { // this means it is new template Globals.ThisAddIn.dataModel.AddJiraTemplateToDataModel(jt); } else { if (0 == String.Compare(editTemplateName, Globals.ThisAddIn.dataModel.DefaultTemplate.Name)) { bIsDefault = true; } // remove the old registry and add new one. // This ensures there are no duplicate entries in the datamodel. Globals.ThisAddIn.dataModel.RemoveJiraTemplateFromDataModel(editTemplateName); Globals.ThisAddIn.dataModel.AddJiraTemplateToDataModel(jt); // since we remove the current item, we need to set the default again if (bIsDefault) { Globals.ThisAddIn.dataModel.DefaultTemplate = jt; } } this.Close(); }
public void InsertDefaultTemplateInReply(JiraTemplate jiraTemplate) { if (dataModel.JiraEmail == null || dataModel.JiraEmail.Length < 1) { MessageBox.Show("Invalid Jira Email.\nPlease update email address in Jira Tab.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Outlook.Inspector Inspector = Globals.ThisAddIn.Application.ActiveInspector(); if (Inspector != null) { if (jiraTemplate == null) { jiraTemplate = dataModel.DefaultTemplate; } Outlook._MailItem reply = Inspector.CurrentItem as Outlook._MailItem; if (reply != null) { AddTemplateDataToMailItem(reply, jiraTemplate); } } }
public void AddTemplateDataToMailItem(Outlook._MailItem mailItem, JiraTemplate jiraTemplate) { /* https://msdn.microsoft.com/EN-US/library/office/ff863703.aspx * Depending on the type of recipient, this property returns or sets a Long corresponding to the numeric equivalent of one of the following constants: * JournalItem recipient: the OlJournalRecipientType constant olAssociatedContact. * MailItem recipient: one of the following OlMailRecipientType constants: olBCC, olCC, olOriginator, or olTo. * MeetingItem recipient: one of the following OlMeetingRecipientType constants: olOptional, olOrganizer, olRequired, or olResource. * TaskItem recipient: either of the following OlTaskRecipientType constants: olFinalStatus, or olUpdate. * Name Value Description * olBCC 3 The recipient is specified in the BCC property of the Item. * olCC 2 The recipient is specified in the CC property of the Item. * olOriginator 0 Originator (sender) of the Item. * olTo 1 The recipient is specified in the To property of the Item. * * https://msdn.microsoft.com/en-us/library/office/ff184598.aspx * */ if (dataModel.bRemoveRecipients) { // Dont use the for loop because the index changes every time item is // deleted. The below loop ensures all objects are removed without // keeping track of the index. it removes the first item in the list // Also Remove(i) where remove expects the array index to be 1-based // instead of 0. while (mailItem.Recipients.Count > 0) { mailItem.Recipients.Remove(1); } } if (dataModel.bToEmail) { //mailItem.To = mailItem.To + ";" + dataModel.JiraEmail; Outlook.Recipient rcTo = mailItem.Recipients.Add(dataModel.JiraEmail); rcTo.Type = (int)Outlook.OlMailRecipientType.olTo; mailItem.Recipients.ResolveAll(); } if (dataModel.bCcEmail) { //mailItem.CC = mailItem.CC + ";" + dataModel.JiraEmail; Outlook.Recipient rcCc = mailItem.Recipients.Add(dataModel.JiraEmail); rcCc.Type = (int)Outlook.OlMailRecipientType.olCC; mailItem.Recipients.ResolveAll(); } try { Word.Document word = mailItem.GetInspector.WordEditor; Word.Range range = word.Range(0, 0); range.InsertAfter(jiraTemplate.Content); } catch (Exception) { // Don't do anything. } // tried below options but seems like only way to keep formatting in both html and rich text is to // use the word editor option to insert text and keep fonts correct. //switch(mailItem.BodyFormat) //{ // //case Outlook.OlBodyFormat.olFormatHTML: // // mailItem.HTMLBody = JiraTemplate.ConvertTextToHTML(dataModel.JiraTemplates[0].Content) + mailItem.HTMLBody; // // break; // default: // { // Word.Document word = mailItem.GetInspector.WordEditor; // Word.Range range = word.Range(0, 0); // range.InsertAfter(dataModel.JiraTemplates[0].Content); // //word.Content.SetRange(0, 0); // //word.Content.Text = dataModel.JiraTemplates[0].Content + word.Content.Text; // } // break; // //case Outlook.OlBodyFormat.olFormatRichText: // // { // // //http://stackoverflow.com/questions/415291/best-way-to-combine-two-or-more-byte-arrays-in-c-sharp // // byte[] template = RegistryOperation.ToBinaryData(dataModel.JiraTemplates[0].Content); // // byte[] rtfBody = mailItem.RTFBody; // // byte[] result = new byte[template.Length + rtfBody.Length]; // // System.Buffer.BlockCopy(template, 0, result, 0, template.Length); // // System.Buffer.BlockCopy(rtfBody, 0, result, template.Length, rtfBody.Length); // // mailItem.RTFBody = result; // // } // // break; // //default: // // mailItem.Body = dataModel.JiraTemplates[0].Content + mailItem.Body; // // break; //} }
public JiraTemplate(JiraTemplate jiraTemplate) { this.Name = jiraTemplate.Name; this.Content = jiraTemplate.Content; }