Beispiel #1
0
        /// <summary>
        /// Extract snapshot file
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        internal static LoadActionParts LoadSnapshotZip(string path)
        {
            using (FileStream str = File.Open(path, FileMode.Open, FileAccess.Read))
                using (Package package = ZipPackage.Open(str, FileMode.Open, FileAccess.Read))
                {
                    var parts = package.GetParts();

                    var         elementPart = (from p in parts where p.Uri.OriginalString == "/" + SaveAction.elementFileName select p.GetStream()).First();
                    A11yElement element     = A11yElement.FromStream(elementPart);
                    elementPart.Close();

                    Bitmap bmp;
                    try
                    {
                        var bmpPart = (from p in parts where p.Uri.OriginalString == "/" + SaveAction.screenshotFileName select p.GetStream()).First();
                        bmp = LoadBmp(bmpPart);
                        bmpPart.Close();
                    }
                    catch (InvalidOperationException) // Gets thrown if screenshot doesn't exist in file
                    {
                        bmp = null;
                    }

                    var metadataPart      = (from p in parts where p.Uri.OriginalString == "/" + SaveAction.metatdataFileName select p.GetStream()).First();
                    SnapshotMetaInfo meta = SnapshotMetaInfo.DeserializeFromStream(metadataPart);
                    metadataPart.Close();

                    var selectedElement = element.FindDescendent(k => k.UniqueId == meta.ScreenshotElementId);

                    return(new LoadActionParts(element, bmp, selectedElement.SynthesizeBitmapFromElements(), meta));
                }
        }
        public void FindDescendent_SimpleCondition_ReturnsNull()
        {
            A11yElement child = new A11yElement()
            {
                UniqueId = 5,
            };
            A11yElement parent = new A11yElement()
            {
                Children = new List <A11yElement>()
                {
                    child
                },
            };
            var result = parent.FindDescendent(ke => ke.UniqueId == 0);

            Assert.IsNull(result);
        }
        public void FindDescendent_SimpleCondition_ReturnsChild()
        {
            A11yElement child = new A11yElement()
            {
                UniqueId = 0
            };
            A11yElement parent = new A11yElement()
            {
                Children = new List <A11yElement>()
                {
                    child
                }
            };
            var result = parent.FindDescendent(ke => ke.UniqueId == 0);

            Assert.AreEqual(result, child);
        }