예제 #1
0
        // This function takes an XmlNode object that represents
        // a <Folder> element and adds a subfolder to the hierarchy
        // based on the values contained in the element.
        public void AddSubFolderFromXml(XmlNode folderNode)
        {
            Folder newFolder = null;

            // Load the name, id, and type.
            XmlNode nameNode = folderNode.SelectSingleNode("./Name");
            XmlNode idNode   = folderNode.SelectSingleNode("./Id");
            XmlNode typeNode = folderNode.SelectSingleNode("./Type");

            if (nameNode != null && nameNode.InnerText != "" &&
                idNode != null && idNode.InnerText != "" &&
                typeNode != null && typeNode.InnerText != "")
            {
                // If the values are all present, add the subfolder.
                newFolder = this.AddSubFolder(nameNode.InnerText, idNode.InnerText,
                                              (FolderType)XmlConvert.ToInt32(typeNode.InnerText));

                // Load the current sync key
                XmlNode syncKeyNode = folderNode.SelectSingleNode("./SyncKey");
                if (syncKeyNode != null && syncKeyNode.InnerText != "")
                {
                    newFolder.SyncKey = syncKeyNode.InnerText;
                }

                // Load the last sync time
                XmlNode lastSyncTimeNode = folderNode.SelectSingleNode("./LastSyncTime");
                if (lastSyncTimeNode != null && lastSyncTimeNode.InnerText != "")
                {
                    newFolder.LastSyncTime = XmlConvert.ToDateTime(lastSyncTimeNode.InnerText,
                                                                   XmlDateTimeSerializationMode.Utc);
                }

                // Load any options
                XmlNode permanentDeleteNode = folderNode.SelectSingleNode("./PermanentDelete");
                if (permanentDeleteNode != null)
                {
                    newFolder.AreDeletesPermanent = true;
                }

                XmlNode ignoreServerChangesNode = folderNode.SelectSingleNode("./IgnoreServerChanges");
                if (ignoreServerChangesNode != null)
                {
                    newFolder.AreChangesIgnored = true;
                }

                XmlNode conversationModeNode = folderNode.SelectSingleNode("./ConversationMode");
                if (conversationModeNode != null)
                {
                    newFolder.UseConversationMode = true;
                }

                XmlNode windowSizeNode = folderNode.SelectSingleNode("./WindowSize");
                if (windowSizeNode != null)
                {
                    newFolder.WindowSize = XmlConvert.ToInt32(windowSizeNode.InnerText);
                }

                XmlNode filterTypeNode = folderNode.SelectSingleNode("./FilterType");
                if (filterTypeNode != null)
                {
                    newFolder.EnsureOptions();
                    newFolder.options.FilterType =
                        (SyncFilterType)XmlConvert.ToInt32(filterTypeNode.InnerText);
                }

                XmlNode conflictHandlingNode = folderNode.SelectSingleNode("./ConflictHandling");
                if (conflictHandlingNode != null)
                {
                    newFolder.EnsureOptions();
                    newFolder.options.ConflictHandling =
                        (ConflictResolution)XmlConvert.ToInt32(conflictHandlingNode.InnerText);
                }

                XmlNode mimeTruncationNode = folderNode.SelectSingleNode("./MimeTruncation");
                if (mimeTruncationNode != null)
                {
                    newFolder.EnsureOptions();
                    newFolder.options.MimeTruncation =
                        (MimeTruncationType)XmlConvert.ToInt32(mimeTruncationNode.InnerText);
                }

                XmlNode classNode = folderNode.SelectSingleNode("./ClassToSync");
                if (classNode != null)
                {
                    newFolder.EnsureOptions();
                    newFolder.options.Class = classNode.InnerText;
                }

                XmlNode maxItemsNode = folderNode.SelectSingleNode("./MaxItems");
                if (maxItemsNode != null)
                {
                    newFolder.EnsureOptions();
                    newFolder.options.MaxItems = XmlConvert.ToInt32(maxItemsNode.InnerText);
                }

                XmlNode bodyPreferencesNode = folderNode.SelectSingleNode("./BodyPreferences");
                if (bodyPreferencesNode != null)
                {
                    newFolder.EnsureOptions();
                    if (newFolder.options.BodyPreference == null)
                    {
                        newFolder.options.BodyPreference    = new BodyPreferences[1];
                        newFolder.options.BodyPreference[0] = new BodyPreferences();
                    }

                    newFolder.options.BodyPreference[0].Type =
                        (BodyType)XmlConvert.ToInt32(bodyPreferencesNode.InnerText);

                    XmlNode truncationSizeAttribute = bodyPreferencesNode.SelectSingleNode("@TruncationSize");
                    if (truncationSizeAttribute != null)
                    {
                        newFolder.options.BodyPreference[0].TruncationSize =
                            XmlConvert.ToUInt32(truncationSizeAttribute.InnerText);
                    }

                    XmlNode allOrNoneAttribute = bodyPreferencesNode.SelectSingleNode("@AllOrNone");
                    if (allOrNoneAttribute != null)
                    {
                        newFolder.options.BodyPreference[0].AllOrNone = true;
                    }

                    XmlNode previewSizeAttribute = bodyPreferencesNode.SelectSingleNode("@PreviewSize");
                    if (previewSizeAttribute != null)
                    {
                        newFolder.options.BodyPreference[0].Preview =
                            XmlConvert.ToInt32(previewSizeAttribute.InnerText);
                    }
                }

                XmlNode bodyPartPreferencesNode = folderNode.SelectSingleNode("./BodyPartPreferences");
                if (bodyPartPreferencesNode != null)
                {
                    newFolder.EnsureOptions();
                    if (newFolder.options.BodyPartPreference == null)
                    {
                        newFolder.options.BodyPartPreference = new BodyPreferences();
                    }

                    newFolder.options.BodyPartPreference.Type =
                        (BodyType)XmlConvert.ToInt32(bodyPartPreferencesNode.InnerText);

                    XmlNode truncationSizeAttribute = bodyPartPreferencesNode.SelectSingleNode("@TruncationSize");
                    if (truncationSizeAttribute != null)
                    {
                        newFolder.options.BodyPartPreference.TruncationSize =
                            XmlConvert.ToUInt32(truncationSizeAttribute.InnerText);
                    }

                    XmlNode allOrNoneAttribute = bodyPartPreferencesNode.SelectSingleNode("@AllOrNone");
                    if (allOrNoneAttribute != null)
                    {
                        newFolder.options.BodyPartPreference.AllOrNone = true;
                    }

                    XmlNode previewSizeAttribute = bodyPartPreferencesNode.SelectSingleNode("@PreviewSize");
                    if (previewSizeAttribute != null)
                    {
                        newFolder.options.BodyPartPreference.Preview =
                            XmlConvert.ToInt32(previewSizeAttribute.InnerText);
                    }
                }

                XmlNode rightsManagementSupportedNode = folderNode.SelectSingleNode("./RightsManagementSupported");
                if (rightsManagementSupportedNode != null)
                {
                    newFolder.EnsureOptions();
                    newFolder.options.IsRightsManagementSupported = true;
                }

                XmlNode mimeSupportNode = folderNode.SelectSingleNode("./MimeSupport");
                if (mimeSupportNode != null)
                {
                    newFolder.EnsureOptions();
                    newFolder.options.MimeSupportLevel =
                        (MimeSupport)XmlConvert.ToInt32(mimeSupportNode.InnerText);
                }

                // If there are any subfolders, load them
                XmlNode subFoldersNode = folderNode.SelectSingleNode("./Folders");
                if (subFoldersNode != null)
                {
                    XmlNodeList subFoldersList = subFoldersNode.SelectNodes("./Folder");

                    foreach (XmlNode subFolderNode in subFoldersList)
                    {
                        newFolder.AddSubFolderFromXml(subFolderNode);
                    }
                }
            }
        }