//-------------------------------------------------------------------------------------------------------------------------------------- #endregion #region Functions #region Private Functions //-------------------------------------------------------------------------------------------------------------------------------------- static void __exec <T>(object sender, T ev, EvInfo evInfo, EvHandler evhandle) { //use Dynamic callback if derived type; use known type otherwise if (evInfo.IsDerivedMatch) { ((dynamic)evhandle.Cb)(sender, evInfo, ev); } else { ((EventCb <T>)evhandle.Cb)(sender, evInfo, ev); } }
internal static bool IsEvInfoModified(CameraStatus status, EvInfo latest) { if (latest == null) { return false; } var previous = status.EvInfo; status.EvInfo = latest; return previous == null || previous.CurrentIndex != latest.CurrentIndex || previous.MaxIndex != latest.MaxIndex || previous.MinIndex != latest.MinIndex || previous.StepDefinition != latest.StepDefinition; }
//-------------------------------------------------------------------------------------------------------------------------------------- private void _ExecuteHandler <T>(object sender, T ev, object priv, bool forceAsync) { //declares SortedSetTS <EvHandler> allRoutesForType = null; var evType = typeof(T); //null check if (ev == null) { return; } //create event info var evInfo = new EvInfo() { Priv = priv, IsDerivedMatch = false, }; //Execute var executedCallbacks = new HashSet <object>(); while (evType != null && evType != typeof(object)) { //get routes for type allRoutesForType = _ActiveRoutes.TryGetOrDefault(evType); if (allRoutesForType != null) { //Broadcast event foreach (var evhandle in allRoutesForType) { if (!evInfo.IsDerivedMatch || evhandle.ReceiveDerivedTypeEvents) { try { //check that we haven't already run this callback if (!executedCallbacks.Contains(evhandle.Cb)) { //run synchronously or asynchronously? if (evhandle.RunAsync) { //proper async mode; callbacks will be executed in series EventQueue.Enqueue(new EventDescriptor() { Ev = ev, EvHandle = evhandle, EvInfo = evInfo, Sender = sender }); } else if (forceAsync) { //caller did TriggerEventAsync() and callback expects strong type TaskEx.RunSafe(() => __exec(sender, ev, evInfo, evhandle)); } else { __exec(sender, ev, evInfo, evhandle); } //add to hashset so that it's not executed again executedCallbacks.Add(evhandle.Cb); } } catch (Exception ex) { DebugEx.TraceErrorException(ex); } } } } //now moving up the inheritance tree (toward object) #if NETFX evType = evType.BaseType; #elif UNIVERSAL evType = evType.GetTypeInfo().BaseType; #endif evInfo.IsDerivedMatch = true; } }
//-------------------------------------------------------------------------------------------------------------------------------------- private void _ExecuteHandler <T>(object sender, T ev) { //declares SortedSetTS <EvHandler> allRoutesForType = null; var evType = typeof(T); //null check if (ev == null) { return; } //create event info var evInfo = new EvInfo() { priv = null, IsDerivedMatch = false, }; //Execute var executedCallbacks = new HashSet <object>(); while (evType != null && evType != typeof(object)) { //get routes for type allRoutesForType = _ActiveRoutes.TryGetOrDefault(evType); if (allRoutesForType != null) { //Broadcast event foreach (var evhandle in allRoutesForType) { if (!evInfo.IsDerivedMatch || evhandle.ReceiveDerivedTypeEvents) { try { //check that we haven't already run this callback if (!executedCallbacks.Contains(evhandle.Cb)) { //use Dynamic callback if derived type; use known type otherwise if (evInfo.IsDerivedMatch) { ((dynamic)evhandle.Cb)(sender, evInfo, ev); } else { ((EventCb <T>)evhandle.Cb)(sender, evInfo, ev); } //add to hashset so that it's not executed again executedCallbacks.Add(evhandle.Cb); } } catch (Exception ex) { DebugEx.TraceErrorException(ex); } } } } //now moving up the inheritance tree (toward object) #if NETFX evType = evType.BaseType; #elif UNIVERSAL evType = evType.GetTypeInfo().BaseType; #endif evInfo.IsDerivedMatch = true; } }
internal static void GetEvent(string jString, Action<int> error, GetEventHandler result) { var json = JObject.Parse(jString); if (BasicResultHandler.HandleError(json, error)) { return; } var jResult = json["result"]; var jApi = jResult[0]; string[] apis = null; if (jApi.HasValues) { var apilist = new List<string>(); foreach (var str in jApi["names"].Values<string>()) { apilist.Add(str); } apis = apilist.ToArray(); } var jStatus = jResult[1]; string status = null; if (jStatus.HasValues) { status = jStatus.Value<string>("cameraStatus"); } var jZoom = jResult[2]; ZoomInfo zoom = null; if (jZoom.HasValues) { zoom = new ZoomInfo { position = jZoom.Value<int>("zoomPosition"), number_of_boxes = jZoom.Value<int>("zoomNumberBox"), current_box_index = jZoom.Value<int>("zoomIndexCurrentBox"), position_in_current_box = jZoom.Value<int>("zoomPositionCurrentBox") }; } var jLiveview = jResult[3]; bool liveview_status = false; if (jLiveview.HasValues) { jLiveview.Value<bool>("liveviewStatus"); } var jExposureMode = jResult[18]; BasicInfo<string> exposure = null; if (jExposureMode.HasValues) { var modecandidates = new List<string>(); foreach (var str in jExposureMode["exposureModeCandidates"].Values<string>()) { modecandidates.Add(str); } exposure = new BasicInfo<string> { current = jExposureMode.Value<string>("currentExposureMode"), candidates = modecandidates.ToArray() }; } var jPostView = jResult[19]; BasicInfo<string> postview = null; if (jPostView.HasValues) { var pvcandidates = new List<string>(); foreach (var str in jPostView["postviewImageSizeCandidates"].Values<string>()) { pvcandidates.Add(str); } postview = new BasicInfo<string> { current = jPostView.Value<string>("currentPostviewImageSize"), candidates = pvcandidates.ToArray() }; } var jSelfTimer = jResult[20]; BasicInfo<int> selftimer = null; if (jSelfTimer.HasValues) { var stcandidates = new List<int>(); foreach (var str in jSelfTimer["selfTimerCandidates"].Values<int>()) { stcandidates.Add(str); } selftimer = new BasicInfo<int> { current = jSelfTimer.Value<int>("currentSelfTimer"), candidates = stcandidates.ToArray() }; } var jShootMode = jResult[21]; BasicInfo<string> shootmode = null; if (jShootMode.HasValues) { var smcandidates = new List<string>(); foreach (var str in jShootMode["shootModeCandidates"].Values<string>()) { smcandidates.Add(str); } shootmode = new BasicInfo<string> { current = jShootMode.Value<string>("currentShootMode"), candidates = smcandidates.ToArray() }; } var jEV = jResult[25]; EvInfo ev = null; if (jEV.HasValues) { ev = new EvInfo { MaxIndex = jEV.Value<int>("maxExposureCompensation"), MinIndex = jEV.Value<int>("minExposureCompensation"), CurrentIndex = jEV.Value<int>("currentExposureCompensation"), StepDefinition = jEV.Value<int>("stepIndexOfExposureCompensation") }; } var jFN = jResult[27]; BasicInfo<string> fn = null; if (jFN.HasValues) { var fncandidates = new List<string>(); foreach (var str in jFN["fNumberCandidates"].Values<string>()) { fncandidates.Add(str); } fn = new BasicInfo<string> { current = jFN.Value<string>("currentFNumber"), candidates = fncandidates.ToArray() }; } var jIso = jResult[29]; BasicInfo<string> iso = null; if (jIso.HasValues) { var isocandidates = new List<string>(); foreach (var str in jIso["isoSpeedRateCandidates"].Values<string>()) { isocandidates.Add(str); } iso = new BasicInfo<string> { current = jIso.Value<string>("currentIsoSpeedRate"), candidates = isocandidates.ToArray() }; } var jPS = jResult[31]; bool? ps = null; if (jPS.HasValues) { ps = jPS.Value<bool>("isShifted"); } var jSS = jResult[32]; BasicInfo<string> ss = null; if (jSS.HasValues) { var sscandidates = new List<string>(); foreach (var str in jSS["shutterSpeedCandidates"].Values<string>()) { sscandidates.Add(str); } ss = new BasicInfo<string> { current = jSS.Value<string>("currentShutterSpeed"), candidates = sscandidates.ToArray() }; } result.Invoke(new Event() { AvailableApis = apis, CameraStatus = status, ZoomInfo = zoom, LiveviewAvailable = liveview_status, PostviewSizeInfo = postview, SelfTimerInfo = selftimer, ShootModeInfo = shootmode, FNumber = fn, ISOSpeedRate = iso, ShutterSpeed = ss, EvInfo = ev, ExposureMode = exposure, ProgramShiftActivated = ps }); }