Example #1
0
        /// <summary>
        /// 读取指定的story.
        /// </summary>
        /// <param name="storyName">story名称.</param>
        /// <param name="userStore">如果参数为null, 创建一个新的.</param>
        internal static void ReadStoryFile(string storyName, IsolatedStorageFile userStore = null)
        {
            if (userStore == null)
            {
                userStore = IsolatedStorageFile.GetUserStoreForApplication();
            }
            using (IsolatedStorageFileStream fileStream = userStore.OpenFile(storyName + ".xml", System.IO.FileMode.Open))
            {
                XDocument xdoc            = XDocument.Load(fileStream);
                var       picturesLibrary = new MediaLibrary().Pictures;

                // Load all photos.
                foreach (XElement photoElement in xdoc.Root.Elements())
                {
                    try
                    {
                        Photo photo = new Photo()
                        {
                            Name = photoElement.Attribute("Name").Value,
                        };
                        string photoDurationString = photoElement.Attribute("PhotoDuration").Value;
                        int    photoDuration       = int.Parse(photoDurationString);
                        photo.PhotoDuration = TimeSpan.FromSeconds(photoDuration);
                        XElement transitionElement = photoElement.Element("Transition");
                        if (transitionElement != null)
                        {
                            photo.Transition = TransitionBase.Load(photoElement.Element("Transition"));
                        }
                        Picture picture = picturesLibrary.Where(p => p.Name == photo.Name).FirstOrDefault();
                        if (picture == null)
                        {
                            // 如果找不到原文件,可能已经被删除了
                            // TODO: 我们需要记录错误吗? 我们是继续下一个图片还是抛出异常?
                            continue;
                        }
                        photo.ThumbnailStream = picture.GetThumbnail();
                        App.MediaCollection.Add(photo);
                    }
                    catch
                    {
                        // TODO: 我们需要记录错误吗? 我们是继续下一个图片还是抛出异常?
                        continue;
                    }
                }
            }
        }