/// <summary> /// Specialized replay for WrappedObject ctor /// </summary> /// <param name="currentInstance"></param> /// <param name="currentReplayInstanceIndex"></param> private void ReplayWrappedObjectCtor(BindingInstance currentInstance, int currentReplayInstanceIndex) { Type type = System.Reflection.Assembly.GetExecutingAssembly().GetType((string)currentInstance.Parameters[1]); if (type != null) { //Using reflection to call the correct DOMWrapper object Type[] cArgTypes = { typeof(IntPtr) }; ConstructorInfo cInfo = type.GetConstructor(cArgTypes); DOM.WrappedObject wobj = null; if (cInfo != null) { IntPtr intPtr = new IntPtr(0); object[] cArgs = { intPtr }; wobj = cInfo.Invoke(cArgs) as DOM.WrappedObject; if (wobj != null) { _recordReplayWrapperPtrMap.Add((long)currentInstance.Parameters[0], wobj); } } } else { string exceptionString = "Replaying binding instance " + currentReplayInstanceIndex + " error : type of recorded WrapperObject ctor is unknown"; ReplayStateConsistent = false; throw new RRException(exceptionString); } }
/// <summary> /// Specialized replay for SetParent /// </summary> /// <param name="currentInstance"></param> /// <param name="currentReplayInstanceIndex"></param> private void ReplayWrappedObjectSetParent(BindingInstance currentInstance, int currentReplayInstanceIndex) { if (currentInstance.Parameters.Length >= 1) { DOM.WrappedObject wobj = currentInstance.Parameters[0] as DOM.WrappedObject; DOM.WrappedObject parentWobj; if (currentInstance.Parameters.Length == 2) { parentWobj = currentInstance.Parameters[1] as DOM.WrappedObject; } else { parentWobj = null; } if (parentWobj != null) { wobj.SetParent(parentWobj); } } else { string exceptionString = "Replaying binding instance " + currentReplayInstanceIndex + " error : SetParent requies at least two arguments!"; ReplayStateConsistent = false; throw new RRException(exceptionString); } }
public MyScheduleItemView(Context context, ViewItemSchedule s) : base(context) { Schedule = s; base.Orientation = Orientation.Vertical; base.SetPaddingRelative(ThemeHelper.AsPx(context, 5), ThemeHelper.AsPx(context, 5), 0, 0); m_classColorBindingInstance = Binding.SetBinding(s.Class, nameof(s.Class.Color), (c) => { base.Background = new ColorDrawable(ColorTools.GetColor(c.Color)); }); // Can't figure out how to let both class name and room wrap while giving more importance // to room like I did on UWP, so just limiting name to 2 lines for now till someone complains. var textViewName = CreateTextView(""); m_classNameBindingInstance = Binding.SetBinding(s.Class, nameof(s.Class.Name), (c) => { textViewName.Text = c.Name; }); textViewName.SetMaxLines(2); base.AddView(textViewName); base.AddView(CreateTextView(GetStringTimeToTime(s))); if (!string.IsNullOrWhiteSpace(s.Room)) { base.AddView(CreateTextView(s.Room)); } }
/// <summary> /// Initializes a new instance of the <see cref="Adic.Binding.BindingInfo"/> class. /// </summary> /// <param name="type">Type from which the binding is bound to.</param> /// <param name="value">Value to which the binding is bound to.</param> /// <param name="instanceType">Binding instance type.</param> /// <param name="originalBinding">Original binding.</param> public BindingInfo(Type type, object value, BindingInstance instanceType, BindingInfo originalBinding) { this.type = type; this.value = value; this.instanceType = instanceType; this.originalBinding = originalBinding; }
/// <summary> /// Specialized replay for Runtime ctor /// </summary> /// <param name="currentInstance"></param> private void ReplayHTMLRuntimeCtor(BindingInstance currentInstance) { _replayParams = new string[currentInstance.Parameters.Length]; for (int i = 0; i < currentInstance.Parameters.Length; i++) { if (currentInstance.Parameters[i].Equals("--record")) { _replayParams[i] = "--replay"; } else if (currentInstance.Parameters[i].Equals("--record+")) { _replayParams[i] = "--replay+"; } else { _replayParams[i] = (string)currentInstance.Parameters[i]; } } HTMLRuntimeConfiguration htmlconfig = new HTMLRuntimeConfiguration(ReplayParams); //Loading the runtime _runtime = new mwr.HTMLRuntime(htmlconfig); if (_runtime != null) { _runtime.Configuration.EnableReplay = true; } }
private void UpdateActionBarTitle() { if (_selectedClassNameBinding != null) { _selectedClassNameBinding.Dispose(); _selectedClassNameBinding = null; } if (ViewModel.SelectedItem == NavigationManager.MainMenuSelections.Classes) { if (ViewModel.SelectedClass != null) { _selectedClassNameBinding = ViewModel.SelectedClass.SetBinding(nameof(ViewItemClass.Name), (c) => { Toolbar.Title = c.Name; }); } else { Toolbar.Title = PowerPlannerResources.GetStringMenuItem(NavigationManager.MainMenuSelections.Classes); } } else { Toolbar.Title = PowerPlannerResources.GetStringMenuItem(ViewModel.SelectedItem.GetValueOrDefault()); } }
/// <summary> /// Adds a binding. /// </summary> /// <param name="value">Binding value.</param> /// <param name="instanceType">Binding instance type.</param> /// <returns>The binding condition factory.</returns> public IBindingConditionFactory AddBinding(object value, BindingInstance instanceType) { var binding = new BindingInfo(this.bindingType, value, instanceType); this.binder.AddBinding(binding); return(this.CreateBindingConditionFactoryProvider(binding)); }
/// <summary> /// Binds the key type to all assignable types in a given <paramref name="namespaceName"/> /// as singleton bindings. /// </summary> /// <param name="namespaceName">Namespace name.</param> /// <param name="bindingInstance">Binding instance type.</param>. /// <param name="includeChildren">Indicates whether child namespaces should be included.</param> /// <returns>The binding condition object related to this binding.</returns> protected IBindingConditionFactory ToNamespace(string namespaceName, BindingInstance bindingInstance, bool includeChildren) { var types = TypeUtils.GetAssignableTypes(this.bindingType, namespaceName, includeChildren); IBindingConditionFactory[] bindingConditionFactories = new IBindingConditionFactory[types.Length]; for (int typeIndex = 0; typeIndex < types.Length; typeIndex++) { bindingConditionFactories[typeIndex] = this.AddBinding(types[typeIndex], bindingInstance); } return(this.CreateBindingConditionFactoryProvider(bindingConditionFactories)); }
private void FilterReplayReturnParams(BindingInstance instance) { instance.RetVal = FilterReplayObject(instance.RetVal); if (instance.Parameters != null) { for (int j = 0; j < instance.Parameters.Length; j++) { object obj = instance.Parameters[j]; if (obj != null) { instance.Parameters[j] = FilterReplayObject(obj); } } } }
public void StatInstance(BindingInstance instance) { _bindingInstances++; if (instance.Outgoing) { _outgoingInstances++; } else { _incomingInstances++; } string key = instance.ClassInfo + ":" + instance.FuncName + " [" + ((instance.Outgoing) ? "out" : "in") + "]"; int count; if (_bindingCallsStats.TryGetValue(key, out count)) { count++; _bindingCallsStats[key] = count; } else { _bindingCallsStats.Add(key, 1); } }
/// <summary> /// The loop for handling incoming bindings /// </summary> public void InputBindingsReplayLoop() { Console.WriteLine("Starting the input binding replay loop"); while (CurrentReplayInstanceIndex < ReplaySession.Instances.Count && !ReplaySession.Instances[CurrentReplayInstanceIndex].Outgoing) { BindingInstance currentInstance = ReplaySession.Instances[CurrentReplayInstanceIndex]; string classInfo = currentInstance.ClassInfo; string funcName = currentInstance.FuncName; int currentReplayInstanceIndex = CurrentReplayInstanceIndex; Console.WriteLine("Replaying instance {0}", currentReplayInstanceIndex); FilterReplayReturnParams(currentInstance); CurrentReplayInstanceIndex++; if (classInfo == "HTMLRuntime" && funcName == "ctor") { ReplayHTMLRuntimeCtor(currentInstance); } else if (classInfo == "WrappedObject" && funcName == "ctor") { ReplayWrappedObjectCtor(currentInstance, currentReplayInstanceIndex); } else if (classInfo == "WrappedObject" && funcName == "SetParent") { ReplayWrappedObjectSetParent(currentInstance, currentReplayInstanceIndex); } else if (classInfo == "HTMLRuntime" && funcName == "SetTopGlobalContext") { mwr.HTMLRuntime.Instance.SetTopGlobalContext(currentInstance.Parameters[0] as mdr.DObject); } else if (classInfo == "HTMLRuntime" && funcName == "ProcessEvents") { HTMLRuntime.Instance.ProcessEvents(new IntPtr(0)); } else if (classInfo == "Element" && funcName == "SetEventHandlerAttr") { DOM.Element.SetEventHandlerAttr((mdr.DObject)currentInstance.Parameters[0], (string)currentInstance.Parameters[1], (string)currentInstance.Parameters[2]); } else if (classInfo == "Element" && funcName == "GetEventHandlerAttr") { DOM.Element.GetEventHandlerAttr((mdr.DObject)currentInstance.Parameters[0], (EventTypes)currentInstance.Parameters[1], (string)currentInstance.Parameters[2]); } else if (classInfo == "HTMLRuntime" && funcName == "RunHTMLScriptString") { HTMLRuntime.Instance.RunHTMLScriptString((mdr.DObject)currentInstance.Parameters[0], (string)currentInstance.Parameters[1], (string)currentInstance.Parameters[2]); } else if (classInfo == "HTMLRuntime" && funcName == "ShutDown") { ReplayHTMLRuntimeShutdown(); } else { string exceptionString = "Replaying binding instance " + currentReplayInstanceIndex + " error : unknown binding: " + classInfo + " : " + funcName; ReplayStateConsistent = false; throw new RRException(exceptionString); } } }
/// <summary> /// Specialized replay for WrappedObject ctor /// </summary> /// <param name="currentInstance"></param> /// <param name="currentReplayInstanceIndex"></param> private void ReplayWrappedObjectCtor(BindingInstance currentInstance, int currentReplayInstanceIndex) { Type type = System.Reflection.Assembly.GetExecutingAssembly().GetType((string)currentInstance.Parameters[1]); if (type != null) { //Using reflection to call the correct DOMWrapper object Type[] cArgTypes = { typeof(IntPtr) }; ConstructorInfo cInfo = type.GetConstructor(cArgTypes); DOM.WrappedObject wobj = null; if (cInfo != null) { IntPtr intPtr = new IntPtr(0); object[] cArgs = { intPtr }; wobj = cInfo.Invoke(cArgs) as DOM.WrappedObject; if (wobj != null) _recordReplayWrapperPtrMap.Add((long)currentInstance.Parameters[0], wobj); } } else { string exceptionString = "Replaying binding instance " + currentReplayInstanceIndex + " error : type of recorded WrapperObject ctor is unknown"; ReplayStateConsistent = false; throw new RRException(exceptionString); } }
/// <summary> /// Initializes a new instance of the <see cref="Adic.Binding.BindingInfo"/> class. /// </summary> /// <param name="type">Type from which the binding is bound to.</param> /// <param name="value">Value to which the binding is bound to.</param> /// <param name="instanceType">Binding instance type.</param> public BindingInfo(Type type, object value, BindingInstance instanceType) : this(type, value, instanceType, null) { }
/// <summary> /// Initializes a new instance of the <see cref="Adic.Binding.BindingInfo"/> class. /// </summary> /// <param name="type">The type from which the binding is bound to.</param> /// <param name="value">The value to which the binding is bound to.</param> /// <param name="instanceType">The binding instance type.</param> public BindingInfo(Type type, object value, BindingInstance instanceType) { this.type = type; this.value = value; this.instanceType = instanceType; }
/// <summary> /// Specialized replay for SetParent /// </summary> /// <param name="currentInstance"></param> /// <param name="currentReplayInstanceIndex"></param> private void ReplayWrappedObjectSetParent(BindingInstance currentInstance, int currentReplayInstanceIndex) { if (currentInstance.Parameters.Length >= 1) { DOM.WrappedObject wobj = currentInstance.Parameters[0] as DOM.WrappedObject; DOM.WrappedObject parentWobj; if (currentInstance.Parameters.Length == 2) parentWobj = currentInstance.Parameters[1] as DOM.WrappedObject; else parentWobj = null; if (parentWobj != null) wobj.SetParent(parentWobj); } else { string exceptionString = "Replaying binding instance " + currentReplayInstanceIndex + " error : SetParent requies at least two arguments!"; ReplayStateConsistent = false; throw new RRException(exceptionString); } }
public void AddBindingInstance(BindingInstance sessionEvent) { Instances.Add(sessionEvent); }
public void StatInstance(BindingInstance instance) { _bindingInstances++; if (instance.Outgoing) _outgoingInstances++; else _incomingInstances++; string key = instance.ClassInfo + ":" + instance.FuncName + " [" + ((instance.Outgoing) ? "out" : "in") + "]"; int count; if (_bindingCallsStats.TryGetValue(key, out count)) { count++; _bindingCallsStats[key] = count; } else _bindingCallsStats.Add(key, 1); }
/// <summary> /// Function for Replaying all outgoing bindings, gets classInfo, function name and params for checking the consisency if the caller state /// It returns the recorded return value of the binding if the state is consistence (the func/class name and param count match the recorded ones) /// </summary> /// <param name="classInfo"></param> /// <param name="funcName"></param> /// <param name="parameters"></param> /// <returns></returns> public object OutputBindingReplay(string classInfo, string funcName, params object[] parameters) { //Going through all the incoming messages firsts InputBindingsReplayLoop(); if (CurrentReplayInstanceIndex >= ReplaySession.Instances.Count) { Console.WriteLine("Warning: Replaying {0} in class {1} after replay file ended!", funcName, classInfo); CurrentReplayInstanceIndex++; return(null); } BindingInstance currentInstance = ReplaySession.Instances[CurrentReplayInstanceIndex]; Console.WriteLine("Replaying instance {0}", CurrentReplayInstanceIndex); FilterReplayReturnParams(currentInstance); if (!currentInstance.FuncName.Equals(funcName)) { if (funcName == "gcDestroy" && classInfo == "WrappedObject") { Console.WriteLine("Warning: By passing unmatching gcDestroy calls!"); return(null); } else if (currentInstance.FuncName == "gcDestroy" && currentInstance.ClassInfo == "WrappedObject") { while (currentInstance.FuncName == "gcDestroy" && currentInstance.ClassInfo == "WrappedObject") { Console.WriteLine("Warning: By passing unmatching gcDestroy replay calls!"); CurrentReplayInstanceIndex++; InputBindingsReplayLoop(); currentInstance = ReplaySession.Instances[CurrentReplayInstanceIndex]; FilterReplayReturnParams(currentInstance); } } else { string exceptionString = "Replaying binding instance " + CurrentReplayInstanceIndex + " error : function name mismtach: CALLED " + funcName + " while REPLAYED " + currentInstance.FuncName; throw new RRException(exceptionString); } } if (!currentInstance.FuncName.Equals(funcName)) { string exceptionString = "Replaying binding instance " + CurrentReplayInstanceIndex + " error : function name mismtach: CALLED " + funcName + " while REPLAYED " + currentInstance.FuncName; throw new RRException(exceptionString); } if (parameters.Length != currentInstance.Parameters.Length) { string exceptionString = "Replaying binding instance " + CurrentReplayInstanceIndex + " error : function " + funcName + " param length mismtach: CALLED " + parameters.Length + " while REPLAYED " + currentInstance.Parameters.Length; throw new RRException(exceptionString); } if (classInfo == "HTMLDocument" && funcName == "write") { Console.WriteLine("---> Document.write {0}", parameters[1]); } //Commented for now /* * for (int i = 0; i < parameters.Length; i++) * { * if (!currentEvent.Parameters[i].Equals(parameters[i])) * { * string exceptionString = "Replaying binding event " + CurrentReplayEvent + " error : function " + funcName + * " param " + i + " value mismtach: CALLED " + parameters[i].ToString() + " while REPLAYED " + currentEvent.Parameters[i].ToString(); * throw new Exception(exceptionString); * } * } */ CurrentReplayInstanceIndex++; return(currentInstance.RetVal); }