private void button_OK_Click(object sender, RoutedEventArgs e) { // return; // Click to save the note //none of URI or note is available, there is nothing to save if (newNoteText.Length == 0 && newInfoItem == null) { return; } bNoteModified = false; bSkipModifyConfirmation = false; //use the title as note, if only URI is available if (newInfoItem != null && newNoteText.Length == 0) { newNoteText = newInfoItem.Title; } ComboBoxItem cbi_sel = (ComboBoxItem)comboBox_SaveLoc.SelectedItem; string xmlFileFullPath = cbi_sel.Tag.ToString(); Element parentElement = new Element { ParentElement = null, HeadImageSource = String.Empty, TailImageSource = String.Empty, NoteText = String.Empty, IsExpanded = true, Path = xmlFileFullPath, Type = ElementType.Heading, }; Element newElement = new Element { ParentElement = parentElement, HeadImageSource = String.Empty, TailImageSource = String.Empty, NoteText = newNoteText, IsExpanded = false, Path = xmlFileFullPath, Type = ElementType.Note, FontColor = ElementColor.Blue.ToString(), Status = ElementStatus.New, }; newElement.ParentElement = parentElement; newElement.Position = 0; if ((newInfoItem != null) && (bool)checkBox_URI.IsChecked) { ElementAssociationType newType; switch (newInfoItem.Type) { case InfoItemType.Email: newType = ElementAssociationType.Email; break; case InfoItemType.File: newType = ElementAssociationType.FileShortcut; break; case InfoItemType.Web: newType = ElementAssociationType.Web; break; default: newType = ElementAssociationType.None; break; } newElement.AssociationType = newType; } try { newElement.ParentElement.Elements.Insert(0, newElement); DatabaseControl temp_dbControl = new DatabaseControl(newElement.ParentElement.Path); temp_dbControl.OpenConnection(); temp_dbControl.InsertElementIntoXML(newElement); temp_dbControl.CloseConnection(); ElementControl elementControl = new ElementControl(newElement.ParentElement.Path); elementControl.CurrentElement = newElement; //if URI is available and selected, association will be added together with the note if ((newInfoItem != null) && (bool)checkBox_URI.IsChecked) { elementControl.AddAssociation(newElement, newInfoItem.Uri, newElement.AssociationType, newNoteText); } string eventInfo = LogEventInfo.NoteText + LogControl.COMMA + newElement.NoteText; if ((bool)checkBox_URI.IsChecked) { eventInfo += LogControl.DELIMITER + LogEventInfo.LinkStatus + LogControl.COMMA + "check"; } else { eventInfo += LogControl.DELIMITER + LogEventInfo.LinkStatus + LogControl.COMMA + "unCheck"; } if (newInfoItem != null && newInfoItem.Uri != null) { eventInfo += LogControl.DELIMITER + LogEventInfo.LinkedFile + LogControl.COMMA + newInfoItem.Uri; } eventInfo += LogControl.DELIMITER + LogEventInfo.PutUnder + LogControl.COMMA + newElement.Path; LogControl.Write( elementControl.CurrentElement, LogEventAccess.QuickCapture, LogEventType.CreateNewNote, LogEventStatus.NULL, eventInfo); newInfoItem = null; } catch (Exception ex) { System.Windows.MessageBox.Show("QuickCapture_button_OK_Click\n" + ex.Message); LogControl.Write( newElement, LogEventAccess.QuickCapture, LogEventType.CreateNewNote, LogEventStatus.Error, LogEventInfo.ErrorMessage + LogControl.COMMA + ex.Message); } ReInitilize(); this.Visibility = Visibility.Hidden; this.ShowInTaskbar = true; }
public bool CreateFolder(Element element) { bool isFolderCreated = false; if (element.ParentElement.Path != root.Path) { DatabaseControl temp_dbControl = new DatabaseControl(element.ParentElement.Path); temp_dbControl.OpenConnection(); isFolderCreated = temp_dbControl.CreateFolder(element); temp_dbControl.CloseConnection(); } else { isFolderCreated = dbControl.CreateFolder(element); } return isFolderCreated; }
private void button_OK_Click(object sender, RoutedEventArgs e) { // return; // Click to save the note //none of URI or note is available, there is nothing to save if (newNoteText.Length == 0 && newInfoItem == null) return; bNoteModified = false; bSkipModifyConfirmation = false; //use the title as note, if only URI is available if (newInfoItem!=null && newNoteText.Length == 0 ) newNoteText = newInfoItem.Title; ComboBoxItem cbi_sel = (ComboBoxItem) comboBox_SaveLoc.SelectedItem; string xmlFileFullPath = cbi_sel.Tag.ToString(); Element parentElement = new Element { ParentElement = null, HeadImageSource = String.Empty, TailImageSource = String.Empty, NoteText = String.Empty, IsExpanded = true, Path = xmlFileFullPath, Type = ElementType.Heading, }; Element newElement = new Element { ParentElement = parentElement, HeadImageSource = String.Empty, TailImageSource = String.Empty, NoteText = newNoteText, IsExpanded = false, Path = xmlFileFullPath, Type = ElementType.Note, FontColor = ElementColor.Blue.ToString(), Status = ElementStatus.New, }; newElement.ParentElement = parentElement; newElement.Position = 0; if ((newInfoItem != null) && (bool)checkBox_URI.IsChecked) { ElementAssociationType newType; switch (newInfoItem.Type) { case InfoItemType.Email: newType = ElementAssociationType.Email; break; case InfoItemType.File: newType = ElementAssociationType.FileShortcut; break; case InfoItemType.Web: newType = ElementAssociationType.Web; break; default: newType = ElementAssociationType.None; break; } newElement.AssociationType = newType; } try { newElement.ParentElement.Elements.Insert(0, newElement); DatabaseControl temp_dbControl = new DatabaseControl(newElement.ParentElement.Path); temp_dbControl.OpenConnection(); temp_dbControl.InsertElementIntoXML(newElement); temp_dbControl.CloseConnection(); ElementControl elementControl = new ElementControl(newElement.ParentElement.Path); elementControl.CurrentElement = newElement; //if URI is available and selected, association will be added together with the note if ((newInfoItem!= null) && (bool)checkBox_URI.IsChecked) { elementControl.AddAssociation(newElement, newInfoItem.Uri, newElement.AssociationType, newNoteText); } string eventInfo = LogEventInfo.NoteText + LogControl.COMMA + newElement.NoteText; if ((bool)checkBox_URI.IsChecked) eventInfo += LogControl.DELIMITER + LogEventInfo.LinkStatus + LogControl.COMMA + "check"; else eventInfo += LogControl.DELIMITER + LogEventInfo.LinkStatus + LogControl.COMMA + "unCheck"; if(newInfoItem!=null && newInfoItem.Uri!=null) eventInfo += LogControl.DELIMITER + LogEventInfo.LinkedFile + LogControl.COMMA + newInfoItem.Uri; eventInfo += LogControl.DELIMITER + LogEventInfo.PutUnder + LogControl.COMMA + newElement.Path; LogControl.Write( elementControl.CurrentElement, LogEventAccess.QuickCapture, LogEventType.CreateNewNote, LogEventStatus.NULL, eventInfo); newInfoItem = null; } catch (Exception ex) { System.Windows.MessageBox.Show("QuickCapture_button_OK_Click\n" + ex.Message); LogControl.Write( newElement, LogEventAccess.QuickCapture, LogEventType.CreateNewNote, LogEventStatus.Error, LogEventInfo.ErrorMessage + LogControl.COMMA + ex.Message); } ReInitilize(); this.Visibility = Visibility.Hidden; this.ShowInTaskbar = true; }
public void UpdateDaysAhead() { Element today = GetTodayElement(); if (today != null) { Element daysahead = null; DatabaseControl tmp_dbControl = new DatabaseControl(today.Path); List<Element> eleList = new List<Element>(); if (today.IsExpanded == true) { foreach (Element ele in today.Elements) { if (ele.NoteText == StartProcess.DAYS_AHEAD) { daysahead = ele; break; } } } else { tmp_dbControl.OpenConnection(); eleList = tmp_dbControl.GetAllElementFromXML(); tmp_dbControl.CloseConnection(); foreach (Element ele in eleList) { if (ele.NoteText == StartProcess.DAYS_AHEAD) { daysahead = ele; break; } } } if (daysahead != null) { daysahead.Elements.Clear(); GC.Collect(); System.IO.DirectoryInfo di = new DirectoryInfo(daysahead.Path); try { FileInfo[] fi = di.GetFiles(); for (int i = 0; i < fi.Length; i++) { Regex regex = new Regex(@"\d{4}-\d{2}-\d{2},\w*"); string filename = fi[i].Name; if (filename == "XooML.xml" || regex.Match(filename).Success) { fi[i].Delete(); } } DatabaseControl temp_dbControl = new DatabaseControl(daysahead.Path); temp_dbControl.OpenConnection(); temp_dbControl.CloseConnection(); } catch (Exception) { return; } } else { daysahead = CreateNewElement(ElementType.Heading, String.Empty); daysahead.Status = ElementStatus.Special; InsertElement(daysahead, today, today.Elements.Count); daysahead.NoteText = StartProcess.DAYS_AHEAD; UpdateElement(daysahead); } const int num_daysahead = 7; List<string> journalPath = JournalControl.GetJournalPathDaysAhead(DateTime.Now, num_daysahead); for (int i = 0; i < num_daysahead; i++) { string dayPath = journalPath[i]; string dayName = System.IO.Path.GetFileName(dayPath); int period = dayName.IndexOf(','); string part1 = dayName.Substring(0, period); string part2 = dayName.Substring(period + 2); Element dayElement = CreateNewElement(ElementType.Note, System.IO.Path.GetFileName(dayPath)); if (i == 0) { part2 = "Today"; } else if (i == 1) { part2 = "Tomorrow"; } dayElement.NoteText = part2 + ", " + part1; InsertElement(dayElement, daysahead, daysahead.Elements.Count); AddAssociation(dayElement, dayPath, ElementAssociationType.FolderShortcut, null); Promote(dayElement); } } }
// Includes XML IO public void UpdateElement(Element element) { if (element == root) { dbControl.UpdateFragmentElementIntoXML(element); return; } if (element.IsCommandNote) { return; } if (element.ParentElement == null) { return; } if (element.IsLocalHeading) { string previousName = System.IO.Directory.GetParent(element.Path).Name; string currentName = HeadingNameConverter.ConvertFromHeadingNameToFolderName(element); if (previousName != currentName) { if (CheckOpenFiles(element) == true) { return; } } } if (element.ParentElement.Path != root.Path) { DatabaseControl temp_dbControl = new DatabaseControl(element.ParentElement.Path); temp_dbControl.newXooMLCreate += new NewXooMLCreateDelegate(dbControl_newXooMLCreate); temp_dbControl.OpenConnection(); temp_dbControl.elementStatusChangedDelegate += new ElementStatusChangedDelegate(dbControl_elementStatusChanged); temp_dbControl.UpdateElementIntoXML(element); temp_dbControl.CloseConnection(); } else { dbControl.UpdateElementIntoXML(element); } switch (element.Type) { case ElementType.Heading: if (element.IsLocalHeading) { string previousPath = element.Path; element.Path = element.ParentElement.Path + HeadingNameConverter.ConvertFromHeadingNameToFolderName(element) + System.IO.Path.DirectorySeparatorChar; try { RenameFolder(element, previousPath); } catch (Exception) { element.Path = previousPath; element.NoteText = System.IO.Directory.GetParent(element.Path).Name; MessageBox.Show("The heading name is too long, please shorten the name and try again."); return; } } DatabaseControl temp_dbControl = new DatabaseControl(element.Path); temp_dbControl.newXooMLCreate +=new NewXooMLCreateDelegate(dbControl_newXooMLCreate); temp_dbControl.OpenConnection(); temp_dbControl.UpdateFragmentElementIntoXML(element); temp_dbControl.CloseConnection(); break; case ElementType.Note: break; }; }
// Includes UI change and XML IO public void RemoveElement(Element element, Element parentElement) { string previousText = element.NoteText; parentElement.Elements.Remove(element); element.NoteText = previousText; if (element.ParentElement.Path != root.Path) { DatabaseControl temp_dbControl = new DatabaseControl(element.ParentElement.Path); temp_dbControl.OpenConnection(); temp_dbControl.RemoveElementFromXML(element); temp_dbControl.CloseConnection(); } else { dbControl.RemoveElementFromXML(element); } }
public void SyncNavigationItem(NavigationItem ni_root) { List<NavigationItem> ni_list; if (ni_root.Path != root.Path) { DatabaseControl temp_dbControl = new DatabaseControl(ni_root.Path); temp_dbControl.OpenConnection(); ni_list = temp_dbControl.GetAllHeadingElementFromXML(); temp_dbControl.CloseConnection(); } else { ni_list = dbControl.GetAllHeadingElementFromXML(); } ni_root.Items.Clear(); foreach (NavigationItem ni in ni_list) { ni.Parent = ni_root; ni.Items.Add(new NavigationItem()); ni_root.Items.Add(ni); } }
public void PowerDDelete(Element element, PowerDDeleteType pddt) { switch (pddt) { case PowerDDeleteType.Delete: DeleteMessageType dmt = DeleteMessageType.Default; switch (element.Type) { case ElementType.Heading: if (element.IsRemoteHeading) { dmt = DeleteMessageType.InplaceExpansionHeading; } else { if (HasChildOrContent(element)) { dmt = DeleteMessageType.HeadingWithChildren; } else { dmt = DeleteMessageType.HeadingWithoutChildren; } } break; case ElementType.Note: if (element.HasAssociation) { switch (element.AssociationType) { case ElementAssociationType.File: dmt = DeleteMessageType.NoteWithFileAssociation; break; case ElementAssociationType.FileShortcut: case ElementAssociationType.Web: case ElementAssociationType.Email: dmt = DeleteMessageType.NoteWithShortcutAssociation; break; }; } else { dmt = DeleteMessageType.NoteWithoutAssociation; } break; }; if (dmt == DeleteMessageType.HeadingWithoutChildren || dmt == DeleteMessageType.NoteWithoutAssociation) { } else { DeleteWindow dw = new DeleteWindow(dmt); if (dw.ShowDialog().Value == true) { } else { return; } } DeleteElement(element); break; case PowerDDeleteType.Undo: string folderPath = String.Empty; string oldGuid = String.Empty; Element oldElement = null; if (element.PowerDStatus == PowerDStatus.Done && element.TempData != String.Empty) { folderPath = element.TempData.Split('|')[0]; oldGuid = element.TempData.Split('|')[1]; DatabaseControl temp_dbControl = new DatabaseControl(folderPath); temp_dbControl.OpenConnection(); foreach (Element ele in temp_dbControl.GetAllElementFromXML()) { if (ele.ID.ToString() == oldGuid) { oldElement = ele; break; } } temp_dbControl.RemoveElementFromXML(oldElement); temp_dbControl.CloseConnection(); if (oldElement != null && oldElement.AssociationURI != String.Empty) { if (oldElement.AssociationType == ElementAssociationType.File) { System.IO.File.Delete(element.AssociationURIFullPath); System.IO.File.Move(folderPath + oldElement.AssociationURI, element.Path + oldElement.AssociationURI); element.AssociationType = ElementAssociationType.File; AssignICCInfo(element, element.Path + oldElement.AssociationURI); } else { System.IO.File.Delete(folderPath + oldElement.AssociationURI); } } } element.FontColor = ElementColor.Black.ToString(); element.TempData = String.Empty; element.PowerDStatus = PowerDStatus.None; element.IsVisible = Visibility.Visible; break; }; UpdateElement(element); }
public void PowerDDone(Element element, DateTime dt) { if (element == null) { return; } string dateFolderPath = JournalControl.GetJournalPath(dt) + System.IO.Path.DirectorySeparatorChar; Guid lastID = element.ID; Guid newID = Guid.NewGuid(); element.ID = newID; element.PowerDStatus = PowerDStatus.Done; element.PowerDTimeStamp = dt; element.FontColor = ElementColor.SeaGreen.ToString(); DatabaseControl temp_dbControl = new DatabaseControl(dateFolderPath); temp_dbControl.OpenConnection(); bool isLocalFile = false; bool isLocalFolder = false; string targetFileName = element.AssociationURI; if (element.AssociationType == ElementAssociationType.File) { isLocalFile = true; } if (element.AssociationType == ElementAssociationType.Folder) { isLocalFolder = true; } if (isLocalFile || isLocalFolder) { string shortcutName = ShortcutNameConverter.GenerateShortcutNameFromFileName(element.AssociationURI, dateFolderPath); string shortcutPath = dateFolderPath + shortcutName; if (isLocalFile) { element.AssociationType = ElementAssociationType.FileShortcut; } else { element.AssociationType = ElementAssociationType.FolderShortcut; } element.AssociationURI = shortcutName; CreateShortcut(element, element.ParentElement.Path + targetFileName, shortcutPath); } Element parent = element.ParentElement; element.ParentElement = null; element.Position = -1; temp_dbControl.InsertElementIntoXML(element); element.ParentElement = parent; temp_dbControl.CloseConnection(); if (isLocalFile) { element.AssociationType = ElementAssociationType.File; element.AssociationURI = targetFileName; } if (isLocalFolder) { element.AssociationType = ElementAssociationType.Folder; element.AssociationURI = targetFileName; } if (element.AssociationType != ElementAssociationType.None && !isLocalFile && !isLocalFolder) { System.IO.File.Copy(element.AssociationURIFullPath, dateFolderPath + element.AssociationURI); } element.ID = lastID; element.IsVisible = Visibility.Visible; element.TempData = dateFolderPath + "|" + newID.ToString(); element.PowerDStatus = PowerDStatus.Done; element.PowerDTimeStamp = dt; element.FontColor = ElementColor.SpringGreen.ToString(); UpdateElement(element); if (element.FlagStatus == FlagStatus.Flag) { Check(element); } }
public void PowerDDelegate(Element element, string folderPath) { if (Directory.Exists(folderPath) == false) { return; } if (MessageBox.Show("This association and its file or shortcut (if any) will be moved to \r\n" + folderPath, "Delegate", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel) { return; } if (CheckOpenFiles(element) == true) { return; } element.PowerDStatus = PowerDStatus.Delegated; element.PowerDTimeStamp = DateTime.Now; Element parent = element.ParentElement; Guid id = element.ID; element.ID = Guid.NewGuid(); element.Status = ElementStatus.New; element.FontColor = ElementColor.Blue.ToString(); DatabaseControl temp_dbControl = new DatabaseControl(folderPath); temp_dbControl.OpenConnection(); element.ParentElement = null; element.Position = -1; temp_dbControl.InsertElementIntoXML(element); temp_dbControl.CloseConnection(); element.ParentElement = parent; element.ID = id; if (element.HasAssociation) { if (element.AssociationType == ElementAssociationType.Folder) { System.IO.Directory.Move(element.AssociationURIFullPath, folderPath + element.AssociationURI); } else { System.IO.File.Move(element.AssociationURIFullPath, folderPath + element.AssociationURI); } } string folderName = System.IO.Directory.GetParent(folderPath).Name; element.NoteText = "\"" + element.NoteText + "\" has been moved to: " + folderName; element.Status = ElementStatus.Normal; element.PowerDStatus = PowerDStatus.Done; element.PowerDTimeStamp = DateTime.Now; element.FontColor = ElementColor.SpringGreen.ToString(); element.AssociationType = ElementAssociationType.FolderShortcut; string shortcutName = ShortcutNameConverter.GenerateShortcutNameFromFileName(folderName, parent.Path); string shortcutPath = parent.Path + shortcutName; element.AssociationURI = shortcutName; CreateShortcut(element, folderPath, shortcutPath); element.TailImageSource = FileTypeHandler.GetIcon(ElementAssociationType.FolderShortcut, element.AssociationURIFullPath); UpdateElement(element); }
public void AddAppointments(Element element, DateTime dt) { Outlook.Application outlookApp = new Outlook.Application(); // Get the NameSpace and Logon information. Outlook.NameSpace outlookNS = outlookApp.GetNamespace("mapi"); //Log on by using a dialog box to choose the profile. outlookNS.Logon(Missing.Value, Missing.Value, true, true); // Lets Get The Calendar folder. Outlook.MAPIFolder outlookCal = outlookNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar); // Get the Items (Appointments) collection from the Calendar folder. Outlook.Items appointItems = outlookCal.Items; // Set start value DateTime startDt = new DateTime(dt.Year, dt.Month, dt.Day, 0, 0, 0); // Set end value DateTime endDt = new DateTime(dt.Year, dt.Month, dt.Day, 23, 59, 59); // Initial restriction is Jet query for date range string sCriteria = "[Start] >= '" + startDt.ToString("g") + "' AND [End] <= '" + endDt.ToString("g") + "'"; //Use the Restrict method to reduce the number of items to process. Outlook.Items restrictedItems = appointItems.Restrict(sCriteria); restrictedItems.Sort("[Start]", Type.Missing); restrictedItems.IncludeRecurrences = true; //Get each item until item null. Outlook.AppointmentItem appointItem; //Preferably the first Item appointItem = (Outlook.AppointmentItem) restrictedItems.GetFirst(); if (appointItem == null) { MessageBox.Show("There are no meetings or appointments in the Outlook calendar to import for this date."); } int count =0; foreach (Element ele in element.Elements) { if (ele.IsCommandNote == false) break; count++; } while (appointItem != null) { //create heading for each appoints string newNoteText = appointItem.Start.ToShortTimeString() + " " + appointItem.Subject.ToString(); if(newNoteText.Length > StartProcess.MAX_EXTRACTNAME_LENGTH) newNoteText = newNoteText.Substring(0, StartProcess.MAX_EXTRACTNAME_LENGTH); bool bDuplicate = false; Element dupEle = element.FirstChild; bool bOverwrite = false; int index = 2; //Check whether there is duplicate appointments with same heading foreach (Element ele in FindAllHeadingElements(element)) { if (newNoteText == ele.NoteText) { //System.Windows.MessageBox.Show("Duplicate appointments found!\n"); dupEle = ele; bDuplicate = true; break; } } System.Windows.MessageBoxButton buttons = System.Windows.MessageBoxButton.YesNo; string message = "The appointment has already existed,do you want to overwrite it?"; string caption = newNoteText; //if duplicate appointment exists and user don't want to merge them, skip it if ((bDuplicate == true) && (System.Windows.MessageBox.Show(message, caption, buttons, System.Windows.MessageBoxImage.Warning, System.Windows.MessageBoxResult.Yes) == System.Windows.MessageBoxResult.No)) { appointItem = (Outlook.AppointmentItem)restrictedItems.GetNext(); continue; } Element appointEle = dupEle; if( bDuplicate== true) { if (dupEle.IsExpanded) { //overwrite the current appointments int remain = 0; while (dupEle.Elements.Count > remain) { if (dupEle.FirstChild.AssociationType == ElementAssociationType.File) { remain++; dupEle.Elements.Move(0, dupEle.Elements.Count - 1); continue; } DeleteElement(dupEle.FirstChild); } } else { DatabaseControl temp_dbControl = new DatabaseControl(dupEle.Path); temp_dbControl.OpenConnection(); List<Element> eleList = temp_dbControl.GetAllElementFromXML(); foreach (Element ele in eleList) { if (ele.AssociationType != ElementAssociationType.File) { ele.ParentElement = dupEle; dupEle.Elements.Add(ele); DeleteElement(ele); } } temp_dbControl.CloseConnection(); } UpdateElement(dupEle); appointEle = dupEle; appointEle.Status = ElementStatus.New; appointEle.FontColor = ElementColor.Blue.ToString(); appointEle.Position = count++; UpdateElement(appointEle); }else { //create new appointment appointEle = CreateNewElement(ElementType.Heading, newNoteText); appointEle.Status = ElementStatus.New; appointEle.FontColor = ElementColor.Blue.ToString(); InsertElement(appointEle, element, count++); UpdateElement(element); } //add subject Element subEle = CreateNewElement(ElementType.Note, string.Empty); subEle.FontColor = ElementColor.Blue.ToString(); subEle.Status = ElementStatus.New; subEle.NoteText = "<no subject>"; if (appointItem.Subject != null) subEle.NoteText = "Subject: " + appointItem.Subject.ToString(); if (subEle.NoteText.Length > StartProcess.MAX_EXTRACTTEXT_LENGTH) subEle.NoteText = subEle.NoteText.Substring(0, StartProcess.MAX_EXTRACTTEXT_LENGTH) + "..."; InsertElement(subEle, appointEle, appointEle.Elements.Count); //add location Element locEle = CreateNewElement(ElementType.Note, string.Empty); locEle.Status = ElementStatus.New; locEle.FontColor = ElementColor.Blue.ToString(); locEle.NoteText = "<no location>"; if (appointItem.Location != null) locEle.NoteText = "Location: " + appointItem.Location.Trim().ToString(); InsertElement(locEle, appointEle, appointEle.Elements.Count); //add start time Element startEle = CreateNewElement(ElementType.Note, string.Empty); startEle.FontColor = ElementColor.Blue.ToString(); startEle.Status = ElementStatus.New; startEle.NoteText = "<no start time>"; if (appointItem.Start != null) startEle.NoteText = "Start time: " + appointItem.Start.ToShortTimeString(); InsertElement(startEle, appointEle, appointEle.Elements.Count); //add end time Element endEle = CreateNewElement(ElementType.Note, string.Empty); endEle.Status = ElementStatus.New; endEle.FontColor = ElementColor.Blue.ToString(); endEle.NoteText = "<no end time>"; if (appointItem.End != null) endEle.NoteText = "End Time: " + appointItem.End.ToShortTimeString(); InsertElement(endEle, appointEle, appointEle.Elements.Count); //add attachments foreach (Outlook.Attachment attachment in appointItem.Attachments) { string attachmentFileName = attachment.FileName; Regex byproduct = new Regex("att[0-9]+[.txt|.c]"); if (!byproduct.IsMatch(attachmentFileName.ToLower())) { string fileNameWithoutExt = System.IO.Path.GetFileNameWithoutExtension(attachmentFileName); string fileNameExt = System.IO.Path.GetExtension(attachmentFileName); string copyPath = appointEle.Path + attachmentFileName; message = "The attachment has already existed,do you want to overwriet it?"; bOverwrite = true; index = 2; while (FileNameChecker.Exist(copyPath)) { caption = attachmentFileName; if (System.Windows.MessageBox.Show(message, caption, buttons, System.Windows.MessageBoxImage.Warning, System.Windows.MessageBoxResult.Yes) == System.Windows.MessageBoxResult.Yes) { bOverwrite = true; break; } copyPath = appointEle.Path + fileNameWithoutExt + " (" + index.ToString() + ")" + fileNameExt; attachmentFileName = fileNameWithoutExt + " (" + index.ToString() + ")" + fileNameExt; index++; } attachment.SaveAsFile(copyPath); if (bOverwrite == false) { Element attachmentElement = CreateNewElement(ElementType.Note, " --- " + fileNameWithoutExt); attachmentElement.FontColor = ElementColor.Blue.ToString(); attachmentElement.Status = ElementStatus.New; attachmentElement.AssociationType = ElementAssociationType.File; attachmentElement.AssociationURI = System.IO.Path.GetFileName(copyPath); attachmentElement.TailImageSource = FileTypeHandler.GetIcon((ElementAssociationType)attachmentElement.AssociationType, copyPath); InsertElement(attachmentElement, appointEle, appointEle.Elements.Count); } else appointEle.Elements.Move(0, appointEle.Elements.Count - 1); } } //add body text Element bodyEle = CreateNewElement(ElementType.Note, string.Empty); bodyEle.Status = ElementStatus.New; bodyEle.FontColor = ElementColor.Blue.ToString(); bodyEle.NoteText = "<no message>"; if ((appointItem.Body != null) && (appointItem.Body.Trim() != string.Empty)) { bodyEle.NoteText = appointItem.Body.Replace("\r\n", " ").Replace("\t"," ").Trim(); if(bodyEle.NoteText.Length>StartProcess.MAX_EXTRACTTEXT_LENGTH) bodyEle.NoteText = bodyEle.NoteText.Substring(0, StartProcess.MAX_EXTRACTTEXT_LENGTH) + "..."; } //add the uri to appoint item in outlook InsertElement(bodyEle, appointEle, appointEle.Elements.Count); string fileFullName = appointItem.EntryID; ElementAssociationType type = ElementAssociationType.Appointment; string folderPath = appointEle.Path; string fileName = "<no subject>"; if (appointItem.Subject != null) { fileName = appointItem.Subject.ToString(); if (appointItem.Subject.Length > StartProcess.MAX_EXTRACTNAME_LENGTH) fileName = appointItem.Subject.Substring(0, StartProcess.MAX_EXTRACTNAME_LENGTH); } string shortcutName = ShortcutNameConverter.GenerateShortcutNameFromAppointmentSubject(fileName, folderPath); AssignAssociationInfo(bodyEle, fileFullName, shortcutName, type); //appointEle.IsExpanded = true; UpdateElement(appointEle); appointItem = (Outlook.AppointmentItem)restrictedItems.GetNext(); } // Log off outlookNS.Logoff(); // Clean up appointItem = null; restrictedItems = null; appointItems = null; outlookCal = null; outlookNS = null; outlookApp = null; }
public void LabelWith(Element element, string path) { ElementControl temp_eleControl = new ElementControl(path); Element ele = new Element { ID = Guid.NewGuid(), ParentElement = temp_eleControl.Root, HeadImageSource = String.Empty, TailImageSource = String.Empty, NoteText = element.NoteText, Path = path, Type = ElementType.Note, Status = ElementStatus.New, FontColor = ElementColor.Blue.ToString(), Position = 0, }; string shortcutName = ShortcutNameConverter.GenerateShortcutNameFromFileName(element.AssociationURI, path); string shortcutPath = path + shortcutName; ele.AssociationType = ElementAssociationType.FolderShortcut; ele.AssociationURI = shortcutName; CreateShortcut(ele, element.Path, shortcutPath); temp_eleControl.Root.Elements.Insert(0, ele); DatabaseControl temp_dbControl = new DatabaseControl(path); temp_dbControl.OpenConnection(); temp_dbControl.InsertElementIntoXML(ele); temp_dbControl.CloseConnection(); temp_eleControl.UpdateElement(ele); string folderName, parentName, tempPath; int pos; char[] ds = { '\\' }; tempPath = path.TrimEnd(ds); pos = tempPath.LastIndexOfAny(ds); folderName = tempPath.Substring(pos + 1); tempPath = tempPath.Remove(pos); pos = tempPath.LastIndexOfAny(ds); parentName = tempPath.Substring(pos + 1); //string notifyText = "Labeled with \"" + System.IO.Path.GetFileName(targetPath) + "\" under \"" + System.IO.Path.Path.GetFileName(parent) + "\""; string notifyText = "Labeled with \"" + folderName + "\" under \"" + parentName + "\""; //add an note for notification Element notifyEle = new Element { ID = Guid.NewGuid(), ParentElement = element, NoteText = notifyText, Path = element.Path, Type = ElementType.Note, Status = ElementStatus.New, FontColor = ElementColor.SpringGreen.ToString(), Position = 0, }; /* shortcutName = ShortcutNameConverter.GenerateShortcutNameFromFileName(folderName, element.Path); shortcutPath = element.Path + shortcutName; notifyEle.AssociationType = ElementAssociationType.FolderShortcut; notifyEle.AssociationURI = shortcutName; CreateShortcut(notifyEle, path, shortcutPath); notifyEle.TailImageSource = FileTypeHandler.GetIcon(ElementAssociationType.FolderShortcut, notifyEle.AssociationURIFullPath); */ notifyEle.PowerDStatus = PowerDStatus.Done; notifyEle.PowerDTimeStamp = DateTime.Now; InsertElement(notifyEle, element, 0); UpdateElement(element); }
// Includes UI change and XML IO public void InsertElement(Element newElement, Element parentElement, int index) { newElement.ParentElement = parentElement; parentElement.Elements.Insert(index, newElement); if (newElement.IsCommandNote) { return; } if (newElement.ParentElement.Path != root.Path) { DatabaseControl temp_dbControl = new DatabaseControl(newElement.ParentElement.Path); temp_dbControl.OpenConnection(); temp_dbControl.InsertElementIntoXML(newElement); temp_dbControl.CloseConnection(); } else { dbControl.InsertElementIntoXML(newElement); } }
public void HideElement(Element element) { if (element.IsCommandNote) { return; } if (element.ElementAboveUnderSameParent != null && element.ElementAboveUnderSameParent.IsCommandNote && element.ElementAboveUnderSameParent.Command == ElementCommand.DisplayMoreAssociations) { int hiddenAssociationCount = Int32.Parse(element.ElementAboveUnderSameParent.NoteText.Split(' ')[10]); element.ElementAboveUnderSameParent.NoteText = String.Format("Click the icon on the right to show the next {0} association(s)", ++hiddenAssociationCount); } else if (element.ElementBelowUnderSameParent != null && element.ElementBelowUnderSameParent.IsCommandNote && element.ElementBelowUnderSameParent.Command == ElementCommand.DisplayMoreAssociations) { int hiddenAssociationCount = Int32.Parse(element.ElementBelowUnderSameParent.NoteText.Split(' ')[10]); element.ElementBelowUnderSameParent.NoteText = String.Format("Click the icon on the right to show the next {0} association(s)", ++hiddenAssociationCount); } else { int hiddenAssociationCount = 0; Element commandNote = new Element(); commandNote.Type = ElementType.Note; commandNote.Command = ElementCommand.DisplayMoreAssociations; commandNote.Status = ElementStatus.Special; commandNote.TailImageSource = String.Format("pack://application:,,,/{0};component/{1}", "Planz", "Images/command.png"); commandNote.HasAssociation = true; commandNote.CanOpen = false; commandNote.CanExplore = false; commandNote.CanRename = false; commandNote.CanDelete = false; commandNote.NoteText = String.Format("Click the icon on the right to show the next {0} association(s)", ++hiddenAssociationCount); InsertElement(commandNote, element.ParentElement, element.Position); } element.IsVisible = Visibility.Collapsed; DatabaseControl temp_dbControl = new DatabaseControl(element.ParentElement.Path); temp_dbControl.OpenConnection(); temp_dbControl.UpdateElementIntoXML(element); temp_dbControl.CloseConnection(); }
public bool HasChildOrContent(Element element) { if (element.IsNote) { return false; } else if (element.HasChildren) { return true; } else { System.IO.DirectoryInfo di = new DirectoryInfo(element.Path); DatabaseControl temp_dbControl = new DatabaseControl(element.Path); temp_dbControl.OpenConnection(); bool noContent = false; if (temp_dbControl.GetAllElementFromXML().Count == 0) { if (di.GetFiles().Length == 1 && di.GetFiles()[0].Name == StartProcess.XOOML_XML_FILENAME) { noContent = true; } } temp_dbControl.CloseConnection(); return !noContent; } }
public void DisplayMoreAssociations(Element element) { try { Queue<Element> displayElements = new Queue<Element>(); DatabaseControl temp_dbControl = new DatabaseControl(element.ParentElement.Path); temp_dbControl.OpenConnection(); temp_dbControl.SHOW_ME_ALL = true; List<Element> eleList = temp_dbControl.GetAllElementFromXML(); temp_dbControl.CloseConnection(); Element eleAbove = element.ElementAboveUnderSameParent; int pos = 0; int j = 0; bool more = false; if (eleAbove != null) { pos = eleAbove.Position; for (j = 0; j < eleList.Count; j++) { if (eleList[j].ID == eleAbove.ID) { j++; break; } } } for (; j < eleList.Count; j++) { if (eleList[j].IsVisible == Visibility.Collapsed) { displayElements.Enqueue(eleList[j]); if (displayElements.Count == MAX_NEWASSOCIATION_VISIBLE) { more = true; break; } } else { break; } } while (displayElements.Count > 0) { Element ele = displayElements.Dequeue(); ele.ParentElement = element.ParentElement; ele.IsVisible = Visibility.Visible; element.ParentElement.Elements.Insert(++pos, ele); UpdateElement(ele); } if (!more) { element.ParentElement.Elements.Remove(element); } } catch (Exception ex) { } }