Exemplo n.º 1
0
        public static string GenerateShortcutTargetPath()
        {
            string path = OutlookSupportFunction.GetOutlookApplicationPath() + "OUTLOOK.EXE";

            return(path);
        }
Exemplo n.º 2
0
        private static List <Element> ConvertXML(string dirPath, XmlDocument xmlDoc)
        {
            List <Element> elementList = new List <Element>();

            XmlNode xmlRootNode = xmlDoc.GetElementsByTagName(XML_ROOT)[0];

            foreach (XmlNode xmlElement in xmlRootNode.ChildNodes)
            {
                try
                {
                    Element element = new Element();

                    element.ID         = new Guid(xmlElement.Attributes[XML_ELEMENT_GUID].Value);
                    element.NoteText   = xmlElement.Attributes[XML_ELEMENT_NOTETEXT].Value;
                    element.Position   = Int32.Parse(xmlElement.Attributes[XML_ELEMENT_POSITION].Value);
                    element.IsExpanded = !Boolean.Parse(xmlElement.Attributes[XML_ELEMENT_ISCOLLAPSED].Value);
                    element.Status     = ElementStatus.Normal;

                    switch (xmlElement.Name)
                    {
                    case XML_HEADING:
                        element.Type            = ElementType.Heading;
                        element.AssociationURI  = HeadingNameConverter.ConvertFromHeadingNameToFolderName(element);
                        element.AssociationType = ElementAssociationType.Folder;
                        element.FontColor       = ElementColor.DarkBlue.ToString();
                        if (element.IsExpanded)
                        {
                            element.LevelOfSynchronization = 1;
                        }
                        else
                        {
                            element.LevelOfSynchronization = 0;
                        }
                        break;

                    case XML_NOTE:
                    case XML_LINK:
                    case XML_MAIL:
                    case XML_WORD:
                    case XML_EXCEL:
                    case XML_PPT:
                    default:
                        element.Type = ElementType.Note;
                        element.LevelOfSynchronization = 0;
                        break;
                    }
                    ;

                    if (xmlElement.Attributes[XML_ELEMENT_ASSOCIATIONURI] != null)
                    {
                        element.AssociationURI = xmlElement.Attributes[XML_ELEMENT_ASSOCIATIONURI].Value;
                    }

                    if (xmlElement.Attributes[XML_ELEMENT_ASSOCIATIONTYPE] != null)
                    {
                        switch (xmlElement.Attributes[XML_ELEMENT_ASSOCIATIONTYPE].Value)
                        {
                        case XML_ELEMENT_ASSOCIATIONTYPE_FOLDERSHORTCUT:
                            element.AssociationType = ElementAssociationType.FolderShortcut;
                            break;

                        case XML_ELEMENT_ASSOCIATIONTYPE_FILESHORTCUT:
                            element.AssociationType = ElementAssociationType.FileShortcut;
                            break;

                        case XML_ELEMENT_ASSOCIATIONTYPE_WEB:
                            element.AssociationType = ElementAssociationType.Web;
                            break;

                        case XML_ELEMENT_ASSOCIATIONTYPE_FILE:
                        case XML_ELEMENT_ASSOCIATIONTYPE_NONE:
                        default:
                            element.AssociationType = ElementAssociationType.File;
                            break;
                        }
                        ;
                    }
                    else
                    {
                        if (xmlElement.Name == XML_WORD ||
                            xmlElement.Name == XML_EXCEL ||
                            xmlElement.Name == XML_PPT)
                        {
                            element.AssociationType = ElementAssociationType.File;
                        }
                    }

                    // In-place expansion will be converted to Note with folder shortcut
                    if (xmlElement.Attributes[XML_ELEMENT_FOLDERLINK] != null)
                    {
                        element.Type                   = ElementType.Heading;
                        element.AssociationURI         = xmlElement.Attributes[XML_ELEMENT_ASSOCIATIONURI].Value;
                        element.IsExpanded             = false;
                        element.AssociationType        = ElementAssociationType.FolderShortcut;
                        element.LevelOfSynchronization = 1;
                    }

                    // Email
                    if (xmlElement.Name == XML_MAIL)
                    {
                        string shortcutName = ShortcutNameConverter.GenerateShortcutNameFromEmailSubject(element.NoteText, dirPath);
                        string shortcutPath = dirPath + shortcutName;
                        IWshRuntimeLibrary.WshShellClass wshShell = new IWshRuntimeLibrary.WshShellClass();
                        IWshRuntimeLibrary.IWshShortcut  shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(shortcutPath);

                        string targetPath = OutlookSupportFunction.GenerateShortcutTargetPath();
                        shortcut.TargetPath  = targetPath;
                        shortcut.Arguments   = "/select outlook:" + xmlElement.Attributes[XML_MAIL_ENTRYID].Value;
                        shortcut.Description = targetPath;

                        shortcut.Save();

                        element.AssociationType = ElementAssociationType.Email;
                        element.AssociationURI  = shortcutName;
                    }

                    elementList.Add(element);
                }
                catch (Exception ex)
                {
                    continue;
                }
            }

            elementList.Sort(new SortByPosition());

            return(elementList);
        }