Beispiel #1
0
        public void UpdateRootPath(string newRootPath)
        {
            root.Path = newRootPath;
            root.Elements.Clear();

            ni_root.Path = newRootPath;
            ni_root.Items.Clear();
            ni_root.Items.Clear();
            selectedElements.Clear();
            updateStatusList.Clear();
            tobeDeletedElements.Clear();

            GC.Collect();

            dbControl = new DatabaseControl(newRootPath);
            dbControl.newXooMLCreate += new NewXooMLCreateDelegate(dbControl_newXooMLCreate);
            dbControl.OpenConnection();
            dbControl.newDBControlHighP += new NewDatabaseControlHandler(dbControl_newDBControlHighP);
            dbControl.newDBControlLowP += new NewDatabaseControlHandler(dbControl_newDBControlLowP);
            dbControl.elementUpdate += new ElementUpdateDelegate(dbControl_elementUpdate);
            dbControl.elementStatusChangedDelegate += new ElementStatusChangedDelegate(dbControl_elementStatusChanged);
            dbControl.elementDelete += new ElementDeleteDelegate(dbControl_elementDelete);

            foreach (Element element in dbControl.GetAllElementFromXML())
            {
                AddElement(element, root);

                if (element.IsHeading)
                {
                    NavigationItem ni = new NavigationItem
                    {
                        Name = element.NoteText,
                        Path = element.Path,
                        Parent = ni_root,
                    };
                    ni.Items.Add(new NavigationItem());
                    ni_root.Items.Add(ni);
                }
            }

            currentElement = root;

            RunXMLBackgroundWorker();
        }
Beispiel #2
0
        public void ShowOrHidePowerDElement(Element parent, PowerDStatus status, bool show)
        {
            try
            {
                DatabaseControl temp_dbControl;
                List<Element> allElements = new List<Element>();

                if (parent.Path != root.Path)
                {
                    temp_dbControl = new DatabaseControl(parent.Path);
                    temp_dbControl.OpenConnection();
                    temp_dbControl.DO_NOT_UPDATE_POWERDREGION = true;
                    allElements = temp_dbControl.GetAllElementFromXML();

                }
                else
                {
                    temp_dbControl = dbControl;
                    temp_dbControl.DO_NOT_UPDATE_POWERDREGION = true;
                    allElements = temp_dbControl.GetAllElementFromXML();
                    temp_dbControl.DO_NOT_UPDATE_POWERDREGION = false;
                }

                for (int i = allElements.Count - 1; i >= 0; i--)
                {
                    if (allElements[i].PowerDStatus == status)
                    {
                        //allElements[i].ParentElement = parent;
                        if (show)
                        {
                            allElements[i].IsVisible = Visibility.Visible;
                        }
                        else
                        {
                            allElements[i].IsVisible = Visibility.Collapsed;
                            for (int j = parent.Elements.Count - 1; j >= 0 ; j--)
                            {
                                if (parent.Elements[j].ID == allElements[i].ID)
                                {
                                    parent.Elements.RemoveAt(j);
                                    break;
                                }
                            }
                        }
                        UpdateElement(allElements[i]);
                    }
                    else
                    {
                        continue;
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }
Beispiel #3
0
        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);
                }
            }
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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;
        }
Beispiel #6
0
        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;
            }
        }
Beispiel #7
0
        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)
            {

            }
        }
Beispiel #8
0
        // Note: param "rootElementPath" should be ending with System.IO.Path.DirectorySeparatorChar
        public ElementControl(string rootElementPath)
        {
            root = new Element
            {
                ParentElement = null,
                HeadImageSource = String.Empty,
                TailImageSource = String.Empty,
                NoteText = String.Empty,
                IsExpanded = true,
                Path = rootElementPath,
                Type = ElementType.Heading,
            };

            ni_root = new NavigationItem
            {
                Name = String.Empty,
                Path = rootElementPath,
                Parent = null,
            };

            dbControl = new DatabaseControl(rootElementPath);
            dbControl.newXooMLCreate += new NewXooMLCreateDelegate(dbControl_newXooMLCreate);
            dbControl.OpenConnection();
            dbControl.newDBControlHighP += new NewDatabaseControlHandler(dbControl_newDBControlHighP);
            dbControl.newDBControlLowP += new NewDatabaseControlHandler(dbControl_newDBControlLowP);
            dbControl.elementUpdate += new ElementUpdateDelegate(dbControl_elementUpdate);
            dbControl.elementStatusChangedDelegate += new ElementStatusChangedDelegate(dbControl_elementStatusChanged);
            dbControl.elementDelete += new ElementDeleteDelegate(dbControl_elementDelete);

            root.ShowAssociationMarkedDone = dbControl.GetFragmentElementFromXML().ShowAssociationMarkedDone;
            root.ShowAssociationMarkedDefer = dbControl.GetFragmentElementFromXML().ShowAssociationMarkedDefer;

            foreach (Element element in dbControl.GetAllElementFromXML())
            {
                if (element.IsVisible == Visibility.Collapsed)
                {
                    continue;
                }

                AddElement(element, root);

                if (element.IsHeading)
                {
                    NavigationItem ni = new NavigationItem
                    {
                        Name = element.NoteText,
                        Path = element.Path,
                        Parent = ni_root,
                    };
                    ni.Items.Add(new NavigationItem());
                    ni_root.Items.Add(ni);
                }
            }

            currentElement = root;

            RunXMLBackgroundWorker();
        }