protected override object GetValue(object obj) { IObjectInstance objectInsance = obj as IObjectInstance; ObjectProperty property = objectInsance.LookupProperty(this); return(property.Value); }
public virtual void CopyAttributesFrom(IObjectInstance instance) { foreach (IAttributeModel attributeModel in instance.Attributes.Values) { this.Attributes.Add(attributeModel.Name, attributeModel); } }
public ObjectPropertyAtom(IObjectInstance objectInstance, ClassProperty classProperty) : base(objectInstance, classProperty) { if (ClassProperty.CanRead) { // When the property is out of date, update it from the wrapped object. _depProperty = new Dependent(delegate { object value = ClassProperty.GetObjectValue(ObjectInstance.WrappedObject); value = TranslateOutgoingValue(value); if (!Object.Equals(_value, value)) { _value = value; } if (_firePropertyChanged) { ObjectInstance.FirePropertyChanged(ClassProperty.Name); } _firePropertyChanged = true; }); // When the property becomes out of date, trigger an update. // The update should have lower priority than user input & drawing, // to ensure that the app doesn't lock up in case a large model is // being updated outside the UI (e.g. via timers or the network). _depProperty.Invalidated += () => UpdateScheduler.ScheduleUpdate(this); } }
public static IObjectInstance CreateInstance(string modelName) { IObjectInstance newInstance = ObjectModelsHolder.Current.Holder.CreateInstance(modelName); newInstance.IsNew = true; return(newInstance); }
public ObjectPropertyAtom(IObjectInstance objectInstance, ClassProperty classProperty) : base(objectInstance, classProperty) { if (ClassProperty.CanRead) { // When the property is out of date, update it from the wrapped object. _depProperty = new Dependent(delegate { object value = ClassProperty.GetObjectValue(ObjectInstance.Model, ObjectInstance.ViewModel); object translatedValue = TranslateOutgoingValue(value); bool changed = !Object.Equals(_value, translatedValue); _value = translatedValue; if (changed && _firePropertyChanged) ObjectInstance.FirePropertyChanged(ClassProperty.Name); _firePropertyChanged = true; }); // When the property becomes out of date, trigger an update. Action triggerUpdate = new Action(delegate { ObjectInstance.Dispatcher.BeginInvoke(new Action(delegate { using (NotificationGate.BeginOutbound()) { _depProperty.OnGet(); } })); }); _depProperty.Invalidated += triggerUpdate; } }
/// <summary> /// Creates instance with valid type /// </summary> /// <param name="modelName">Model name of required instance</param> /// <returns>Instance with type set in <see cref="IObjectModel.InstanceTypeQualifiedName"/> (or default type <see cref="Constants.DefaultInstanceType"/>)</returns> public IObjectInstance CreateInstance(string modelName) { if (!cachedModels.ContainsKey(modelName)) { throw new ModelNotFoundException(modelName); } IObjectModel model = cachedModels[modelName]; if (string.IsNullOrEmpty(model.InstanceTypeQualifiedName)) { model.InstanceTypeQualifiedName = Constants.DefaultInstanceType; } IObjectInstance instance = null; try { instance = (IObjectInstance)Activator.CreateInstance(Type.GetType(model.InstanceTypeQualifiedName), model); } catch (Exception ex) { throw ex; } return(instance); }
public ExceptionThrowingTest(TimeSpan runningTime, MethodBase method, Exception thrownException, IObjectInstance instance = null, IEnumerable<IObjectInstance> arguments = null) : base(runningTime, method, instance, arguments) { if (thrownException == null) throw new ArgumentNullException("thrownException"); Exception = thrownException; }
public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance) { IObjectInstance objectInstance = instance as IObjectInstance; if (objectInstance != null) { return(objectInstance.ClassInstance); } if (objectType.IsGenericType) { var genericRoot = objectType.GetGenericTypeDefinition(); if (genericRoot == typeof(ObjectInstance <>)) { var field = objectType.GetField("_classInstance", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly); var value = field.GetValue(null); return(value as ICustomTypeDescriptor); } } return(new ClassInstance(objectType, typeof(ObjectInstance <>).MakeGenericType(objectType))); }
private TabItem CreateTabItem(object item) { IObjectInstance wrapper = item as IObjectInstance; CloudTabViewModel tabViewModel = wrapper.WrappedObject as CloudTabViewModel; return(new CloudTabItem(tabViewModel)); }
protected override void SetValue(object obj, object value) { IObjectInstance objectInsance = obj as IObjectInstance; ObjectProperty property = objectInsance.LookupProperty(this); property.OnUserInput(value); }
public void NavigateTo(object rawViewModel) { IObjectInstance viewModel = ForView.Wrap(rawViewModel); _viewModel = viewModel; DisplayView(viewModel); }
private ObjectProperty GetObjectProperty(object component) { // Find the object property. IObjectInstance objectInstance = ((IObjectInstance)component); ObjectProperty objectProperty = objectInstance.LookupProperty(this); return(objectProperty); }
//public AStep() public IAttributeModel ProcessElement(IObjectInstance objectInstance) { if (objectInstance == null) { objectInstance = this.OwnerInstance; } return(objectInstance.GetAttribute(this.Name)); }
public MethodTest(TimeSpan runningTime, MethodInfo method, Object result = null, IEnumerable<IObjectInstance> arguments = null, IObjectInstance instance = null) : base(runningTime, method, instance, arguments, result) { if(instance != null && method.IsStatic) throw new ArgumentException("method is static so no instance should be specified"); if(instance == null && !method.IsStatic) throw new ArgumentNullException("instance", "non-static method needs instance to be called on"); if (instance != null) if (instance.Instance.GetType() != method.ReflectedType) throw new ArgumentException("instance type does not match method reflected type"); }
public IAttributeModel ProcessElement(IObjectInstance objectInstance) { if (objectInstance == null) { objectInstance = this.OwnerInstance; } return(PathProcessor.ProcessPath(this, objectInstance)); }
public static TWrappedObjectType Unwrap <TWrappedObjectType>(object dataContext) where TWrappedObjectType : class { IObjectInstance wrapper = dataContext as IObjectInstance; return (wrapper == null ? default(TWrappedObjectType) : wrapper.WrappedObject as TWrappedObjectType); }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, System.Type destinationType) { if (destinationType == typeof(System.String) && value is IObjectInstance) { IObjectInstance instanceObject = (IObjectInstance)value; return(instanceObject.Name); } return(base.ConvertTo(context, culture, value, destinationType)); }
public ObjectPropertyCollection(IObjectInstance objectInstance, ClassMember classProperty) : base(objectInstance, classProperty) { if (ClassProperty.CanRead) { // When the collection is out of date, update it from the wrapped object. _depCollection = new Dependent(() => BindingInterceptor.Current.UpdateValue(this)); // When the property becomes out of date, trigger an update. _depCollection.Invalidated += TriggerUpdate; } }
public ObjectPropertyCollection(IObjectInstance objectInstance, ClassProperty classProperty) : base(objectInstance, classProperty) { if (ClassProperty.CanRead) { // When the collection is out of date, update it from the wrapped object. _depCollection = new Computed(OnUpdateCollection); // When the property becomes out of date, trigger an update. _depCollection.Invalidated += TriggerUpdate; } }
public ObjectPropertyCollection(IObjectInstance objectInstance, ClassProperty classProperty) : base(objectInstance, classProperty) { if (ClassProperty.CanRead) { // When the collection is out of date, update it from the wrapped object. _depCollection = new Dependent(OnUpdateCollection); // When the property becomes out of date, trigger an update. _depCollection.Invalidated += TriggerUpdate; } }
public ObjectPropertyAtom(IObjectInstance objectInstance, ClassMember classProperty) : base(objectInstance, classProperty) { if (ClassProperty.CanRead) { // When the property is out of date, update it from the wrapped object. _depProperty = new Dependent(() => BindingInterceptor.Current.UpdateValue(this)); // When the property becomes out of date, trigger an update. // The update should have lower priority than user input & drawing, // to ensure that the app doesn't lock up in case a large model is // being updated outside the UI (e.g. via timers or the network). _depProperty.Invalidated += () => UpdateScheduler.ScheduleUpdate(this); } }
public ObjectPropertyCollection(IObjectInstance objectInstance, ClassProperty classProperty, bool hasChildObjects) : base(objectInstance, classProperty) { _hasChildObjects = hasChildObjects; if (ClassProperty.CanRead) { // Bind to the observable collection. ClassProperty.SetUserOutput(ObjectInstance, _collection); // When the collection is out of date, update it from the wrapped object. _depCollection = new Computed(OnUpdateCollection); } }
private void DisplayView(IObjectInstance viewModel) { if (_mainPage != null) { UserControl view = CreateView(viewModel.WrappedObject.GetType()); view.DataContext = viewModel; // TODO: Begin exit animation. Remove the child when animation completes. _mainPage.LayoutRoot.Children.Clear(); _mainPage.LayoutRoot.Children.Add(view); // TODO: Begin enter animation. } }
// Called when the user edits the property. Sets the property in the wrapped object. private void OnPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) { // Get the wrapped object. IObjectInstance objectInstance = (IObjectInstance)obj; object wrappedObject = objectInstance.WrappedObject; ObjectProperty objectProperty = objectInstance.LookupProperty(this); if (objectProperty != null) { // Set the property in the wrapped object. object value = obj.GetValue(_dependencyProperty); objectProperty.OnUserInput(value); } }
public ObjectPropertyAtom(IObjectInstance objectInstance, ClassProperty classProperty, bool hasChildObject) : base(objectInstance, classProperty) { _hasChildObject = hasChildObject; if (ClassProperty.CanRead) { // When the property is out of date, update it from the wrapped object. _depProperty = new Computed(delegate { object value = ClassProperty.GetObjectValue(ObjectInstance.WrappedObject); if (_hasChildObject) { IObjectInstance oldChild = _child; object oldValue = oldChild == null ? null : oldChild.WrappedObject; _child = null; IObjectInstance wrapper; if (value == null) { wrapper = null; } else if (value == oldValue) { wrapper = oldChild; _child = wrapper; } else { if (WrapObject(value, out wrapper)) { _child = wrapper; } } ClassProperty.SetUserOutput(ObjectInstance, wrapper); if (oldChild != _child && oldChild != null) { ObjectInstance.Tree.RemoveKey(oldValue); oldChild.Dispose(); } } else { ClassProperty.SetUserOutput(ObjectInstance, value); } }); } }
public bool WrapObject(object value, out IObjectInstance wrapper) { if (!_wrapperByObject.TryGetValue(value, out wrapper)) { wrapper = (IObjectInstance)typeof(ObjectInstance<>) .MakeGenericType(value.GetType()) .GetConstructors() .Single() .Invoke(new object[] { value, this }); _wrapperByObject.Add(value, wrapper); return true; } else return false; }
/// <summary> /// Wrap an object to be used as the DataContext of a view. /// All of the properties of the object are available for /// data binding with automatic updates. /// </summary> /// <param name="wrappedObject">The object to wrap for the view.</param> /// <returns>An object suitable for data binding.</returns> public static IObjectInstance Wrap(object wrappedObject) { Initialize(); if (wrappedObject == null) { return(null); } IObjectInstance root = (IObjectInstance)typeof(ObjectInstance <>) .MakeGenericType(wrappedObject.GetType()) .GetConstructors() .Single() .Invoke(new object[] { wrappedObject, Deployment.Current.Dispatcher }); return(root); }
public bool WrapObject(object value, out IObjectInstance wrapper) { if (!_wrapperByObject.TryGetValue(value, out wrapper)) { wrapper = (IObjectInstance)typeof(ObjectInstance <>) .MakeGenericType(value.GetType()) .GetConstructors() .Single() .Invoke(new object[] { value, this }); _wrapperByObject.Add(value, wrapper); return(true); } else { return(false); } }
/// <summary> /// Wrap an object to be used as the DataContext of a view. /// All of the properties of the object are available for /// data binding with automatic updates. /// </summary> /// <param name="wrappedObject">The object to wrap for the view.</param> /// <returns>An object suitable for data binding.</returns> public static IObjectInstance Wrap(object wrappedObject) { Initialize(); if (wrappedObject == null) { return(null); } Tree tree = new Tree(); IObjectInstance root = (IObjectInstance)typeof(ObjectInstance <>) .MakeGenericType(wrappedObject.GetType()) .GetConstructors() .Single() .Invoke(new object[] { wrappedObject, tree }); tree.SetRoot(root); return(root); }
public ObjectProperty(IObjectInstance wrapper, object wrappedObject, PropertyInfo propertyInfo, CustomMemberProvider provider) { _wrapper = wrapper; _wrappedObject = wrappedObject; _propertyInfo = propertyInfo; _provider = provider; if (_provider.IsCollection) { _collection = new ObservableCollection <object>(); _value = _collection; } _depValue = new Dependent(UpdateValue); _depValue.Invalidated += ValueInvalidated; UpdateNow(); }
public ObjectPropertyAtom(IObjectInstance objectInstance, ClassProperty classProperty, bool hasChildObject) : base(objectInstance, classProperty) { _hasChildObject = hasChildObject; if (ClassProperty.CanRead) { // When the property is out of date, update it from the wrapped object. _depProperty = new Computed(delegate { object value = ClassProperty.GetObjectValue(ObjectInstance.WrappedObject); if (_hasChildObject) { IObjectInstance oldChild = _child; object oldValue = oldChild == null ? null : oldChild.WrappedObject; _child = null; IObjectInstance wrapper; if (value == null) wrapper = null; else if (value == oldValue) { wrapper = oldChild; _child = wrapper; } else { if (WrapObject(value, out wrapper)) _child = wrapper; } ClassProperty.SetUserOutput(ObjectInstance, wrapper); if (oldChild != _child && oldChild != null) { ObjectInstance.Tree.RemoveKey(oldValue); oldChild.Dispose(); } } else { ClassProperty.SetUserOutput(ObjectInstance, value); } }); } }
public object GetValue(object instance) { IObjectInstance obj = instance as IObjectInstance; if (obj == null) { return(null); } ObjectProperty property = obj.LookupProperty(this); if (property == null) { return(null); } return(property.GetValue()); }
public IObjectInstance GetInstance(string modelName, object primaryKey) { IObjectInstance instance = this.CreateInstance(modelName); ObjectQuery query = new ObjectQuery(modelName) { Criteria = new Criteria(new ValueCondition(instance.PrimaryKey, primaryKey)), Top = 2 }; List <IObjectInstance> queryResult = query.Execute(); if (queryResult.Count > 1) { throw new Exception("В выборке более одного объекта"); } return((IObjectInstance)queryResult[0]); }
public void SetValue(object instance, object value) { IObjectInstance obj = instance as IObjectInstance; if (obj == null) { return; } ObjectProperty property = obj.LookupProperty(this); if (property == null) { return; } property.SetValue(value); }
public ObjectPropertyAtom(IObjectInstance objectInstance, ClassProperty classProperty) : base(objectInstance, classProperty) { if (ClassProperty.CanRead) { // When the property is out of date, update it from the wrapped object. _depProperty = new Dependent(delegate { object value = ClassProperty.GetObjectValue(ObjectInstance.WrappedObject); value = TranslateOutgoingValue(value); if (!Object.Equals(_value, value)) _value = value; if (_firePropertyChanged) ObjectInstance.FirePropertyChanged(ClassProperty.Name); _firePropertyChanged = true; }); // When the property becomes out of date, trigger an update. _depProperty.Invalidated += () => UpdateScheduler.ScheduleUpdate(this); } }
private static string GetInvokeMethodCode(MethodBase method, IObjectInstance instance = null, IEnumerable<IObjectInstance> arguments = null, bool methodHasReturnValue = false) { StringBuilder testCode = new StringBuilder(); if(method.IsConstructor) { testCode.Append(CodeWritingUtils.GetVariableInstantiationStatement(method as ConstructorInfo, arguments)); return testCode.ToString(); } if (!method.IsStatic) { testCode.AppendLine(CodeWritingUtils.GetVariableInstantiationStatement(instance, INSTANCE_NAME)); } testCode.AppendFormat("{0}{1}", methodHasReturnValue ? "var " + RESULT_NAME + " = " : String.Empty, CodeWritingUtils.GetMethodInvocationStatement( method.IsStatic? method.ReflectedType.Name : INSTANCE_NAME, method, arguments)); return testCode.ToString(); }
public static String GetObjectCreationExpression(IObjectInstance instance) { if (instance == null) return "null"; StringBuilder code = new StringBuilder(); if (instance.InstanceNeedsConstructor) { code.AppendFormat("new {0}(", instance.Instance.GetType().Name); var args = instance.CreationData.Arguments; for (int i = 0; i < args.Count; ++i ) { code.AppendFormat("{0}{1}", GetObjectCreationExpression(args[i]), i != args.Count-1? ", " : String.Empty); } code.AppendFormat(")"); } else { if (instance.Instance is String) return "\"" + instance.Instance + "\""; else if (instance.Instance is char) return "'" + instance.Instance + "'"; else if (instance.Instance is Enum) return instance.Instance.GetType().Name + "." + instance.Instance.ToString(); else if (instance is NullObjectInstance) return "null"; else if (instance.Instance is bool) return instance.ToString().ToLower(); else if (instance.Instance is Decimal) return instance.Instance.ToString() + "M"; else return instance.Instance.ToString(); } return code.ToString(); }
public new List <IObjectInstance> Execute() { this.ParseQuery(); List <IObjectInstance> objectInstances = new List <IObjectInstance>(); ExecutionResult executionResult = (ExecutionResult)base.Execute(); foreach (RowResult row in executionResult.Rows) { IObjectInstance objectInstance = ObjectModelsHolder.Current.Holder.CreateInstance(this.ownerInstance.Model.Name); foreach (string columnName in row.Keys) { objectInstance.Attributes[objectInstance.GetAttributeByMappingColumn(columnName).Name].Field.ForceSet(row[columnName]); } objectInstances.Add(objectInstance); } return(objectInstances); }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { IObjectInstance objectBeingSelected; try { string selectedObjectsName = (string)value; if (selectedObjectsName.Length == 0) { return(null); } if (context.Instance is IObjectInstance) { IObjectInstance objectBeingEditted = (IObjectInstance)context.Instance; objectBeingSelected = LookupObject(objectBeingEditted.TestExecution(), selectedObjectsName); } else { throw new ArgumentException("alksdjalksdlkajlkaj"); } } catch (ArgumentException e) { throw e; } catch (Exception e) { throw new ArgumentException("Problem finding object '" + (string)value + "'"); } return(objectBeingSelected); } return(base.ConvertFrom(context, culture, value)); }
protected UnitTest(TimeSpan runningTime, MethodBase method, IObjectInstance instance = null, IEnumerable<IObjectInstance> arguments = null, Object result = null) { RunningTime = runningTime; if (method == null) throw new ArgumentNullException("method"); Method = method; if (arguments == null) Arguments = new List<IObjectInstance>(); else Arguments = new List<IObjectInstance>(arguments); var parameterList = new List<ParameterInfo>(method.GetParameters()); if (parameterList.Count != Arguments.Count) throw new ArgumentException("argument count does not match parameter count"); for (int i = 0; i < parameterList.Count; ++i) { if (!(Arguments[i] is NullObjectInstance) && !parameterList[i].ParameterType.IsAssignableFrom(Arguments[i].Instance.GetType())) throw new ArgumentException("argument types do not match parameter types"); } if (!method.IsConstructor) { if (!method.IsStatic && instance == null) throw new ArgumentException("non-static method must have an instance to be invoked on"); if (method.IsStatic && instance != null) throw new ArgumentException("static method cannot have an instance"); } Result = result; Instance = instance; m_id = Interlocked.Increment(ref m_GlobalId); }
public void SetRoot(IObjectInstance root) { _root = root; _depNodes.Touch(); }
public ObjectProperty(IObjectInstance objectInstance, ClassProperty classProperty) { ObjectInstance = objectInstance; ClassProperty = classProperty; }
protected bool WrapObject(object value, out IObjectInstance wrapper) { return ObjectInstance.Tree.WrapObject(value, out wrapper); }
protected void AddChild(IObjectInstance child) { _children.Add(child); }
public ObjectPropertyCommand(IObjectInstance objectInstance, ClassMemberCommand classCommand) : base(objectInstance, classCommand) { ClassCommand = classCommand; }
public void SetUserOutput(IObjectInstance objectInstance, object value) { // Set the value into the dependency property. objectInstance.SetValue(_dependencyProperty, value); }
public static ObjectProperty From(IObjectInstance objectInstance, ClassProperty classProperty) { return classProperty.MakeObjectProperty(objectInstance); }
public ObjectPropertyCollectionNative(IObjectInstance objectInstance, ClassProperty classProperty) : base(objectInstance, classProperty) { }
public ObjectPropertyCollectionObject(IObjectInstance objectInstance, ClassMember classProperty) : base(objectInstance, classProperty) { }
public ObjectProperty MakeObjectProperty(IObjectInstance objectInstance) { return _makeObjectProperty(objectInstance); }
public ObjectPropertyAtomObject(IObjectInstance objectInstance, ClassMember classProperty) : base(objectInstance, classProperty) { }
public ObjectPropertyAtomNative(IObjectInstance objectInstance, ClassProperty classProperty) : base(objectInstance, classProperty) { }
public static String GetVariableInstantiationStatement(IObjectInstance instance, String variableName = "instance") { StringBuilder code = new StringBuilder(); code.AppendFormat("var {0} = ", variableName ); code.Append(GetObjectCreationExpression(instance)); code.Append(";"); return code.ToString(); }