Esempio n. 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 e) // Gets thrown if screenshot doesn't exist in file
                    {
                        e.ReportException();
                        bmp = null;
                    }

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

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

                    return(new LoadActionParts(element, bmp, selectedElement.SynthesizeBitmapFromElements(), meta));
                }
        }
Esempio n. 2
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 e) // Gets thrown if screenshot doesn't exist in file
                    {
                        e.ReportException();
                        bmp = null;
                    }

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

                    IReadOnlyDictionary <int, CustomProperty> CustomProperties;
                    try
                    {
                        var customPropertiesPart = (from p in parts where p.Uri.OriginalString == "/" + SaveAction.customPropsFileName select p.GetStream()).First();
                        CustomProperties = LoadCustomProperties(customPropertiesPart);
                        customPropertiesPart.Close();
                    }
#pragma warning disable CA1031                                 // Do not catch general exception types: specific handlers placed in conditional below
                    catch (Exception e)
#pragma warning restore CA1031                                 // Do not catch general exception types: specific handlers placed in conditional below
                    {
                        if (!(e is InvalidOperationException)) // An expected exception thrown when file does not exist, such as in old a11ytest files
                        {
                            e.ReportException();
                        }
                        CustomProperties = null;
                    }

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

                    return(new LoadActionParts(element, bmp, selectedElement.SynthesizeBitmapFromElements(), meta));
                }
        }