/// <summary> /// Load JSON stored custom property registrations from stream /// </summary> private static IReadOnlyDictionary <int, CustomProperty> LoadCustomProperties(Stream stream) { using (StreamReader reader = new StreamReader(stream)) { string jsonProps = reader.ReadToEnd(); Dictionary <int, CustomProperty> deserializedProperties = JsonConvert.DeserializeObject <Dictionary <int, CustomProperty> >(jsonProps); Registrar.GetDefaultInstance().MergeCustomPropertyRegistrations(deserializedProperties); return(deserializedProperties); } }
public static void RegisterCustomProperties(IEnumerable <CustomProperty> properties) { if (properties == null) { throw new ArgumentNullException(nameof(properties)); } foreach (CustomProperty p in properties) { Registrar.GetDefaultInstance().RegisterCustomProperty(p); } }
/// <summary> /// Update Data context in given ElementContext for Test Mode /// if Data Context is already up to date based on parameters, just skip. /// </summary> /// <param name="ecId">ElementContext Id</param> /// <param name="dm"></param> /// <param name="tvm"></param> /// <param name="force">Force the update</param> /// <returns>boolean</returns> public static bool SetTestModeDataContext(Guid ecId, DataContextMode dm, TreeViewMode tvm, bool force = false) { var ec = GetDataManager().GetElementContext(ecId); // if Data context is set via Live Mode, set it to null. if (ec.DataContext != null && ec.DataContext.Mode == DataContextMode.Live) { ec.DataContext = null; // Re-register user-configured custom UIA data Registrar.GetDefaultInstance().RestoreCustomPropertyRegistrations(); } if (NeedNewDataContext(ec.DataContext, dm, tvm) || force) { ec.DataContext = new ElementDataContext(ec.Element, MaxElements); PopulateData(ec.DataContext, dm, tvm); return(true); } return(false); }
/// <summary> /// Build a cacherequest for properties and patterns /// </summary> /// <param name="uia"></param> /// <param name="pps">Property ids</param> /// <param name="pts">Pattern ids</param> /// <returns></returns> public static IUIAutomationCacheRequest GetPropertiesCache(IUIAutomation uia, IEnumerable <int> pps, IEnumerable <int> pts) { if (uia == null) { throw new ArgumentNullException(nameof(uia)); } var cr = uia.CreateCacheRequest(); if (pps != null) { foreach (var pp in pps) { cr.AddProperty(pp); } } IEnumerable <int> cps = Registrar.GetDefaultInstance().GetCustomPropertyRegistrations().Keys; foreach (var cp in cps) { cr.AddProperty(cp); } if (pts != null) { foreach (var pt in pts) { if (pt != 0) { cr.AddPattern(pt); } } } return(cr); }
/// <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, 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 (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.RuleVersion, focusedElementId, ec.DataContext.ScreenshotElementId); var jsonMeta = JsonConvert.SerializeObject(meta, Formatting.Indented); using (MemoryStream mStrm = new MemoryStream(Encoding.UTF8.GetBytes(jsonMeta))) { AddStream(package, mStrm, metadataFileName); } var customProps = Registrar.GetDefaultInstance().GetCustomPropertyRegistrations(); var jsonCustomProps = JsonConvert.SerializeObject(customProps, Formatting.Indented); using (MemoryStream mStrm = new MemoryStream(Encoding.UTF8.GetBytes(jsonCustomProps))) { AddStream(package, mStrm, customPropsFileName); } }