Ejemplo n.º 1
0
        /// <summary>
        /// Private helper function (formerly in SaveSnapshotZip) to make it easier to call with different inputs
        /// </summary>
        private static void SaveSnapshotFromElement(int?focusedElementId, A11yFileMode mode, Dictionary <SnapshotMetaPropertyName, object> otherProperties, CompletenessMode completenessMode, Contexts.ElementContext ec, Package package, A11yElement root)
        {
            var json = JsonConvert.SerializeObject(root, Formatting.Indented);

            using (MemoryStream mStrm = new MemoryStream(Encoding.UTF8.GetBytes(json)))
            {
                AddStream(package, mStrm, elementFileName);
            }

            if (completenessMode == CompletenessMode.Full && ec.DataContext.Screenshot != null)
            {
                using (MemoryStream mStrm = new MemoryStream())
                {
                    ec.DataContext.Screenshot.Save(mStrm, System.Drawing.Imaging.ImageFormat.Png);
                    mStrm.Seek(0, SeekOrigin.Begin);

                    AddStream(package, mStrm, screenshotFileName);
                }
            }

            var meta     = new SnapshotMetaInfo(mode, RuleRunner.GetRuleVersion(), focusedElementId, ec.DataContext.ScreenshotElementId, otherProperties);
            var jsonMeta = JsonConvert.SerializeObject(meta, Formatting.Indented);

            using (MemoryStream mStrm = new MemoryStream(Encoding.UTF8.GetBytes(jsonMeta)))
            {
                AddStream(package, mStrm, metatdataFileName);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Save snapshot zip
        /// </summary>
        /// <param name="ecId">ElementContext Id</param>
        /// <param name="path">The output file</param>
        /// <param name="bmp">The screenshot</param>
        /// <param name="focusedElementId">The ID of the element with the current focus</param>
        /// <param name="mode">The type of file being saved</param>
        /// <param name="otherProperties">Properties to add to the snapshot metadata</param>
        /// <param name="completenessMode">Mode to control selective removal of data from the output</param>
        public static void SaveSnapshotZip(string path, Guid ecId, int?focusedElementId, A11yFileMode mode, Dictionary <SnapshotMetaPropertyName, object> otherProperties = null, CompletenessMode completenessMode = CompletenessMode.Full)
        {
            var ec = DataManager.GetDefaultInstance().GetElementContext(ecId);

            using (FileStream str = File.Open(path, FileMode.Create))
                using (Package package = ZipPackage.Open(str, FileMode.Create))
                {
                    if (completenessMode == CompletenessMode.Full)
                    {
                        SaveSnapshotFromElement(focusedElementId, mode, otherProperties, completenessMode, ec, package, ec.DataContext.RootElment);
                    }
                    else
                    {
                        using (A11yElement reducedRoot = SelectAction.GetDefaultInstance().POIElementContext.Element.GetScrubbedElementTree())
                        {
                            SaveSnapshotFromElement(focusedElementId, mode, otherProperties, completenessMode, ec, package, reducedRoot);
                        }
                    }
                }
        }