コード例 #1
0
            public void ReadUploadInfoData(XmlTextReader reader, SupportingFileFactory fileFactory)
            {
                Debug.Assert(reader.LocalName == ATTACHED_FILE_UPLOAD_ELEMENT, "Xml reader is improperly positioned");
                int depth = 0;

                string contextId = reader.GetAttribute(ATTACHED_FILE_UPLOAD_CONTEXT_ATTRIBUTE);
                string uploadUri = reader.GetAttribute(ATTACHED_FILE_UPLOAD_URI_ATTRIBUTE);
                string uploadVersionString = reader.GetAttribute(ATTACHED_FILE_UPLOAD_VERSION_ATTRIBUTE);
                int uploadVersion = -1;
                if (uploadVersionString != null)
                    uploadVersion = Int32.Parse(uploadVersionString, CultureInfo.InvariantCulture);

                //fixup the reference path
                BlogPostSettingsBag settings = new BlogPostSettingsBag();
                if (!reader.IsEmptyElement)
                {
                    depth = 1;
                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            bool isEmptyElement = reader.IsEmptyElement;
                            depth++;
                            if (reader.LocalName == SETTINGS_BAG_ELEMENT)
                            {
                                ReadBlogPostSettingsBag(reader, settings);

                                //this element was completely handled, and the stack was reset to its end element,
                                //so unset the depth and re-start the loop
                                depth--;
                                continue;
                            }
                            if (isEmptyElement)
                                depth--;
                        }
                        else if (reader.NodeType == XmlNodeType.EndElement)
                        {
                            depth--;
                        }

                        if (depth == 0)
                            break;
                    }
                }

                Trace.Assert(uploadUri != null, "Informational: UploadUri is null");

                fileFactory.AddUploadInfo(contextId, uploadVersion, uploadUri == null ? null : new Uri(uploadUri), settings);
                Debug.Assert(depth == 0 && reader.LocalName == ATTACHED_FILE_UPLOAD_ELEMENT, "Xmlreader is unexpectedly positioned (probably read to far!)");
            }