public string HiddenReason(INakedObjectAdapter nakedObjectAdapter) { if (nakedObjectAdapter == null) { return null; } var isHidden = (bool) methodDelegate(nakedObjectAdapter.GetDomainObject(), new object[] {}); return isHidden ? Resources.NakedObjects.Hidden : null; }
public override IConsent IsUsable(INakedObjectAdapter target) { bool isPersistent = target.ResolveState.IsPersistent(); IConsent disabledConsent = IsUsableDeclaratively(isPersistent); if (disabledConsent != null) { return disabledConsent; } var immutableFacet = GetFacet<IImmutableFacet>(); if (immutableFacet != null) { WhenTo when = immutableFacet.Value; if (when == WhenTo.UntilPersisted && !isPersistent) { return new Veto(Resources.NakedObjects.FieldDisabledUntil); } if (when == WhenTo.OncePersisted && isPersistent) { return new Veto(Resources.NakedObjects.FieldDisabledOnce); } ITypeSpec tgtSpec = target.Spec; if (tgtSpec.IsAlwaysImmutable() || (tgtSpec.IsImmutableOncePersisted() && isPersistent)) { return new Veto(Resources.NakedObjects.FieldDisabled); } } var f = GetFacet<IDisableForContextFacet>(); string reason = f == null ? null : f.DisabledReason(target); if (reason == null) { var fs = GetFacet<IDisableForSessionFacet>(); reason = fs == null ? null : fs.DisabledReason(Session, target, LifecycleManager, MetamodelManager); } return GetConsent(reason); }
public object[] GetCompletions(INakedObjectAdapter inObjectAdapter, string autoCompleteParm) { try { object autoComplete = methodDelegate(inObjectAdapter.GetDomainObject(), new object[] { autoCompleteParm }); //returning an IQueryable var queryable = autoComplete as IQueryable; if (queryable != null) { return queryable.Take(PageSize).ToArray(); } //returning an IEnumerable (of string only) var strings = autoComplete as IEnumerable<string>; if (strings != null) { return strings.ToArray(); } //return type is a single object if (!CollectionUtils.IsCollection(autoComplete.GetType())) { return new object[] { autoComplete }; } throw new NakedObjectDomainException("Must return IQueryable or a single object from autoComplete method: " + method.Name); } catch (ArgumentException ae) { string msg = string.Format("autoComplete exception: {0} has mismatched parameter type - must be string", method.Name); throw new InvokeException(msg, ae); } }
public TestObject(ILifecycleManager lifecycleManager, IObjectPersistor persistor, INakedObjectAdapter nakedObjectAdapter, ITestObjectFactory factory, ITransactionManager transactionManager) : base(factory) { this.lifecycleManager = lifecycleManager; this.persistor = persistor; this.transactionManager = transactionManager; NakedObject = nakedObjectAdapter; }
private void Persist(INakedObjectAdapter nakedObjectAdapter) { if (nakedObjectAdapter.ResolveState.IsAggregated() || (nakedObjectAdapter.ResolveState.IsTransient() && nakedObjectAdapter.Spec.Persistable != PersistableType.Transient)) { IAssociationSpec[] fields = ((IObjectSpec) nakedObjectAdapter.Spec).Properties; if (!nakedObjectAdapter.Spec.IsEncodeable && fields.Length > 0) { Log.Info("make persistent " + nakedObjectAdapter); nakedObjectAdapter.Persisting(); if (!nakedObjectAdapter.Spec.ContainsFacet(typeof (IComplexTypeFacet))) { manager.MadePersistent(nakedObjectAdapter); } foreach (IAssociationSpec field in fields) { if (!field.IsPersisted) { continue; } if (field is IOneToManyAssociationSpec) { INakedObjectAdapter collection = field.GetNakedObject(nakedObjectAdapter); if (collection == null) { throw new NotPersistableException("Collection " + field.Name + " does not exist in " + nakedObjectAdapter.Spec.FullName); } MakePersistent(collection); } else { INakedObjectAdapter fieldValue = field.GetNakedObject(nakedObjectAdapter); if (fieldValue == null) { continue; } Persist(fieldValue); } } persistor.AddPersistedObject(nakedObjectAdapter); } } }
public void ReplacePoco(INakedObjectAdapter nakedObjectAdapter, object newDomainObject) { Log.DebugFormat("ReplacePoco nakedObjectAdapter: {0} newDomainOject: {1}", nakedObjectAdapter, newDomainObject); RemoveAdapter(nakedObjectAdapter); identityMap.Replaced(nakedObjectAdapter.Object); nakedObjectAdapter.ReplacePoco(newDomainObject); identityMap.AddAdapter(nakedObjectAdapter); }
public void InitProperty(INakedObjectAdapter nakedObjectAdapter, INakedObjectAdapter value) { try { property.SetValue(nakedObjectAdapter.GetDomainObject(), value.GetDomainObject(), null); } catch (TargetInvocationException e) { InvokeUtils.InvocationException("Exception executing " + property, e); } }
public string InvalidReason(INakedObjectAdapter target, INakedObjectAdapter[] proposedArguments) { if (methodDelegate != null) { return (string)methodDelegate(target.GetDomainObject(), proposedArguments.Select(no => no.GetDomainObject()).ToArray()); } //Fall back (e.g. if method has > 6 params) on reflection... Log.WarnFormat("Invoking validate method via reflection as no delegate {0}.{1}", target, method); return (string)InvokeUtils.Invoke(method, target, proposedArguments); }
/// <summary> /// Whether the provided argument exceeds the <see cref="SingleIntValueFacetAbstract.Value" /> maximum length}. /// </summary> public virtual bool Exceeds(INakedObjectAdapter nakedObjectAdapter) { var str = nakedObjectAdapter.GetDomainObject() as string; if (str == null) { return false; } int maxLength = Value; return maxLength != 0 && str.Length > maxLength; }
public override void SetProperty(INakedObjectAdapter nakedObjectAdapter, INakedObjectAdapter value, ITransactionManager transactionManager, ISession session, ILifecycleManager lifecycleManager) { try { property.SetValue(nakedObjectAdapter.GetDomainObject(), value.GetDomainObject(), null); } catch (TargetInvocationException e) { InvokeUtils.InvocationException("Exception executing " + property, e); } }
public void MakePersistent(INakedObjectAdapter nakedObjectAdapter) { if (nakedObjectAdapter.Spec.IsCollection) { MakeCollectionPersistent(nakedObjectAdapter); } else { MakeObjectPersistent(nakedObjectAdapter); } }
public override bool IsEditView(INakedObjectAdapter nakedObjectAdapter) { var target = nakedObjectAdapter.GetDomainObject<IViewModelSwitchable>(); if (target != null) { return target.IsEditView(); } throw new NakedObjectSystemException(nakedObjectAdapter.Object == null ? "Null domain object" : "Wrong type of domain object: " + nakedObjectAdapter.Object.GetType().FullName); }
public override void Invoke(INakedObjectAdapter nakedObjectAdapter, ISession session, ILifecycleManager lifecycleManager, IMetamodelManager metamodelManager) { profileManager.Begin(session, associatedEvent, "", nakedObjectAdapter, lifecycleManager); try { underlyingFacet.Invoke(nakedObjectAdapter, session, lifecycleManager, metamodelManager); } finally { profileManager.End(session, associatedEvent, "", nakedObjectAdapter, lifecycleManager); } }
public void MakeObjectPersistent(INakedObjectAdapter nakedObjectAdapter) { if (nakedObjectAdapter.ResolveState.IsAggregated() || nakedObjectAdapter.ResolveState.IsPersistent() || nakedObjectAdapter.Spec.Persistable == PersistableType.Transient || nakedObjectAdapter.Spec is IServiceSpec) { return; } persistor.AddPersistedObject(nakedObjectAdapter); }
protected ObjectFacade(INakedObjectAdapter nakedObject, IFrameworkFacade frameworkFacade, INakedObjectsFramework framework) { FacadeUtils.AssertNotNull(nakedObject, "NakedObject is null"); FacadeUtils.AssertNotNull(frameworkFacade, "FrameworkFacade is null"); FacadeUtils.AssertNotNull(framework, "framework is null"); WrappedNakedObject = nakedObject; this.framework = framework; FrameworkFacade = frameworkFacade; }
public object GetProperty(INakedObjectAdapter nakedObjectAdapter) { try { return propertyMethod.GetValue(nakedObjectAdapter.GetDomainObject(), null); } catch (TargetInvocationException e) { InvokeUtils.InvocationException("Exception executing " + propertyMethod, e); return null; } }
public override void Init(INakedObjectAdapter collection, INakedObjectAdapter[] initData) { IList wrappedCollection = AsCollection(collection); List<object> toAdd = initData.Select(no => no.Object).Where(obj => !wrappedCollection.Contains(obj)).ToList(); toAdd.ForEach(obj => wrappedCollection.Add(obj)); List<object> toRemove = wrappedCollection.Cast<object>().Where(o => !initData.Select(x => x.Object).Contains(o)).ToList(); toRemove.ForEach(wrappedCollection.Remove); }
public override void Init(INakedObjectAdapter collection, INakedObjectAdapter[] initData) { Array newCollection = Array.CreateInstance(collection.GetDomainObject().GetType().GetElementType(), initData.Length); collection.ReplacePoco(newCollection); int i = 0; foreach (INakedObjectAdapter nakedObject in initData) { AsCollection(collection)[i++] = nakedObject.Object; } }
private IEnumerable PageInternal(int page, int size, INakedObjectAdapter collection, INakedObjectManager manager) { int firstIndex = (page - 1)*size; for (int index = firstIndex; index < firstIndex + size; index++) { if (index >= AsEnumerable(collection, manager).Count()) { yield break; } yield return AsCollection(collection)[index]; } }
public override INakedObjectAdapter Invoke(INakedObjectAdapter nakedObjectAdapter, INakedObjectAdapter[] parameters, int resultPage, ILifecycleManager lifecycleManager, IMetamodelManager manager, ISession session, INakedObjectManager nakedObjectManager, IMessageBroker messageBroker, ITransactionManager transactionManager) { profileManager.Begin(session, ProfileEvent.ActionInvocation, identifier.MemberName, nakedObjectAdapter, lifecycleManager); try { return underlyingFacet.Invoke(nakedObjectAdapter, parameters, resultPage, lifecycleManager, manager, session, nakedObjectManager, messageBroker, transactionManager); } finally { profileManager.End(session, ProfileEvent.ActionInvocation, identifier.MemberName, nakedObjectAdapter, lifecycleManager); } }
public bool IsEditable(ISession session, ILifecycleManager lifecycleManager, INakedObjectAdapter target, IIdentifier identifier) { object authorizer = GetAuthorizer(target, lifecycleManager); Type authType = authorizer.GetType(); if ((typeof(INamespaceAuthorizer)).IsAssignableFrom(authType)) { var nameAuth = (INamespaceAuthorizer) authorizer; return nameAuth.IsEditable(session.Principal, target.Object, identifier.MemberName); } return isEditableDelegates[authType](authorizer, session.Principal, target.GetDomainObject(), identifier.MemberName); }
public CollectionMemento(ILifecycleManager lifecycleManager, INakedObjectManager nakedObjectManager, IMetamodelManager metamodel, INakedObjectAdapter target, IActionSpec actionSpec, INakedObjectAdapter[] parameters) : this(lifecycleManager, nakedObjectManager, metamodel) { Target = target; Action = actionSpec; Parameters = parameters; if (Target.Spec.IsViewModel) { lifecycleManager.PopulateViewModelKeys(Target); } }
public void Reset(INakedObjectAdapter inObjectAdapter) { try { var collection = (IList) property.GetValue(inObjectAdapter.GetDomainObject(), null); collection.Clear(); property.SetValue(inObjectAdapter.GetDomainObject(), collection, null); } catch (Exception e) { throw new ReflectionException(string.Format("Failed to get/set property {0} in {1}", property.Name, inObjectAdapter.Spec.FullName), e); } }
public void Reset(INakedObjectAdapter inObjectAdapter) { try { var collection = (IList) property.GetValue(inObjectAdapter.GetDomainObject(), null); collection.Clear(); property.SetValue(inObjectAdapter.GetDomainObject(), collection, null); } catch (Exception e) { throw new ReflectionException(Log.LogAndReturn($"Failed to get/set property {property.Name} in {inObjectAdapter.Spec.FullName}"), e); } }
private void MakeCollectionPersistent(INakedObjectAdapter collection) { if (collection.ResolveState.IsPersistent() || collection.Spec.Persistable == PersistableType.Transient) { return; } if (collection.ResolveState.IsTransient()) { collection.ResolveState.Handle(Events.StartResolvingEvent); collection.ResolveState.Handle(Events.EndResolvingEvent); } manager.MadePersistent(collection); collection.GetAsEnumerable(manager).ForEach(MakePersistent); }
public override string GetTitleWithMask(string mask, INakedObjectAdapter nakedObjectAdapter, INakedObjectManager nakedObjectManager) { if (maskDelegate != null) { return (string) maskDelegate(nakedObjectAdapter.GetDomainObject(), new object[] {mask}); } if (maskMethod != null) { return (string) maskMethod.Invoke(nakedObjectAdapter.GetDomainObject(), new object[] {mask}); } return GetTitle(nakedObjectAdapter, nakedObjectManager); }
public void SetUp() { ISpecification holder = new Mock<ISpecification>().Object; var customer = new Customer17(); var mock = new Mock<INakedObjectAdapter>(); target = mock.Object; mock.Setup(no => no.Object).Returns(customer); MethodInfo method = typeof (Customer17).GetMethod("Validate0SomeAction"); facet = new ActionParameterValidation(method, holder); }
public void Invoke(INakedObjectAdapter nakedObjectAdapter, INakedObjectAdapter[] parameters, bool queryOnly, IIdentifier identifier, ISession session, ILifecycleManager lifecycleManager) { IAuditor auditor = GetAuditor(nakedObjectAdapter, lifecycleManager); IPrincipal byPrincipal = session.Principal; string memberName = identifier.MemberName; if (nakedObjectAdapter.Spec is IServiceSpec) { string serviceName = nakedObjectAdapter.Spec.GetTitle(nakedObjectAdapter); auditor.ActionInvoked(byPrincipal, memberName, serviceName, queryOnly, parameters.Select(no => no.GetDomainObject()).ToArray()); } else { auditor.ActionInvoked(byPrincipal, memberName, nakedObjectAdapter.GetDomainObject(), queryOnly, parameters.Select(no => no.GetDomainObject()).ToArray()); } }
public override object[] GetChoices(INakedObjectAdapter nakedObjectAdapter, IDictionary<string, INakedObjectAdapter> parameterNameValues) { INakedObjectAdapter[] parms = FacetUtils.MatchParameters(parameterNames, parameterNameValues); try { var options = choicesDelegate(nakedObjectAdapter.GetDomainObject(), parms.Select(p => p.GetDomainObject()).ToArray()) as IEnumerable; if (options != null) { return options.Cast<object>().ToArray(); } throw new NakedObjectDomainException(Log.LogAndReturn($"Must return IEnumerable from choices method: {choicesMethod.Name}")); } catch (ArgumentException ae) { throw new InvokeException(Log.LogAndReturn($"Choices exception: {choicesMethod.Name} has mismatched (ie type of choices parameter does not match type of action parameter) parameter types"), ae); } }
public object[] GetChoices(INakedObjectAdapter inObjectAdapter, IDictionary<string, INakedObjectAdapter> parameterNameValues) { INakedObjectAdapter[] parms = FacetUtils.MatchParameters(parameterNames, parameterNameValues); try { object options = methodDelegate(inObjectAdapter.GetDomainObject(), parms.Select(p => p.GetDomainObject()).ToArray()); var enumerable = options as IEnumerable; if (enumerable != null) { return enumerable.Cast<object>().ToArray(); } throw new NakedObjectDomainException(Log.LogAndReturn($"Must return IEnumerable from choices method: {method.Name}")); } catch (ArgumentException ae) { throw new InvokeException(Log.LogAndReturn($"Choices exception: {method.Name} has mismatched (ie type of parameter does not match type of property) parameter types"), ae); } }
public IObjectFacade GetValue(IObjectFacade target) { INakedObjectAdapter result = assoc.GetNakedObject(((ObjectFacade)target).WrappedNakedObject); return(ObjectFacade.Wrap(result, FrameworkFacade, framework)); }
public string DisabledReason(INakedObjectAdapter nakedObjectAdapter) { return((string)methodDelegate(nakedObjectAdapter.GetDomainObject(), new object[] {})); }
/// <summary> /// Provides a default of <c>null</c> /// </summary> public override object GetDefault(INakedObjectAdapter inObjectAdapter) { return(null); }
public override object GetDefault(INakedObjectAdapter inObjectAdapter) => methodDelegate(inObjectAdapter.GetDomainObject(), new object[] { });
public string DisabledReason(INakedObjectAdapter inObjectAdapter) { return(Resources.NakedObjects.Bounded); }
public static ObjectFacade Wrap(INakedObjectAdapter nakedObject, IFrameworkFacade facade, INakedObjectsFramework framework) => nakedObject == null ? null : new ObjectFacade(nakedObject, facade, framework);
public void LoadComplexTypes(INakedObjectAdapter adapter, bool isGhost) { objectStore.LoadComplexTypesIntoNakedObjectFramework(adapter, isGhost); }
public void Reload(INakedObjectAdapter nakedObjectAdapter) { Log.DebugFormat("Reload nakedObjectAdapter: {0}", nakedObjectAdapter); objectStore.Reload(nakedObjectAdapter); }
public string Disables(IInteractionContext ic) { INakedObjectAdapter target = ic.Target; return(DisabledReason(target)); }
public override INakedObjectAdapter Invoke(INakedObjectAdapter nakedObjectAdapter, INakedObjectAdapter[] parameters, int resultPage, ILifecycleManager lifecycleManager, IMetamodelManager manager, ISession session, INakedObjectManager nakedObjectManager, IMessageBroker messageBroker, ITransactionManager transactionManager) => Invoke(nakedObjectAdapter, parameters, lifecycleManager, manager, session, nakedObjectManager, messageBroker, transactionManager);
public sbyte SByteValue(INakedObjectAdapter nakedObjectAdapter) => nakedObjectAdapter.GetDomainObject <sbyte>();
public override string GetTitle(INakedObjectAdapter nakedObjectAdapter, INakedObjectManager nakedObjectManager, ISession session, IObjectPersistor persistor) { var obj = methodDelegate(nakedObjectAdapter.GetDomainObject(), new object[] { }); return(obj == null ? null : nakedObjectManager.CreateAdapter(obj, null, null).TitleString()); }
public Guid GuidValue(INakedObjectAdapter nakedObjectAdapter) { return(nakedObjectAdapter.GetDomainObject <Guid>()); }
public static bool IsNotPersistent(this INakedObjectAdapter nakedObject) => nakedObject.ResolveState.IsTransient() && nakedObject.Spec.Persistable == PersistableType.ProgramPersistable || nakedObject.Spec.Persistable == PersistableType.Transient;
public static bool IsViewModelEditView(this INakedObjectAdapter target, ISession session, IObjectPersistor persistor) => target.Spec.ContainsFacet <IViewModelFacet>() && target.Spec.GetFacet <IViewModelFacet>().IsEditView(target, session, persistor);
public ulong UnsignedLongValue(INakedObjectAdapter nakedObjectAdapter) => nakedObjectAdapter.GetDomainObject <ulong>();
public void Refresh(INakedObjectAdapter nakedObjectAdapter) { Log.DebugFormat("Refresh nakedObjectAdapter: {0}", nakedObjectAdapter); objectStore.Refresh(nakedObjectAdapter); }
public override void SetProperty(INakedObjectAdapter inObjectAdapter, INakedObjectAdapter value, ITransactionManager transactionManager, ISession session, ILifecycleManager lifecycleManager) { methodDelegate(inObjectAdapter.GetDomainObject(), new[] { value.GetDomainObject() }); }
public ITestNaked GetDefault() { INakedObjectAdapter defaultValue = field.GetDefault(owningObject.NakedObject); return(factory.CreateTestNaked(defaultValue)); }
public abstract void Invoke(INakedObjectAdapter nakedObjectAdapter, ISession session, ILifecycleManager lifecycleManager, IMetamodelManager metamodelManager);
public override Tuple <object, TypeOfDefaultValue> GetDefault(INakedObjectAdapter nakedObjectAdapter) { return(new Tuple <object, TypeOfDefaultValue>(value, TypeOfDefaultValue.Explicit)); }
public virtual object InvokeAndReturn(INakedObjectAdapter nakedObjectAdapter, ISession session, ILifecycleManager lifecycleManager, IMetamodelManager metamodelManager, IObjectPersistor persistor) { Invoke(nakedObjectAdapter, session, lifecycleManager, metamodelManager); return(null); }
private static bool IsNotQueryable(INakedObjectAdapter objectRepresentingCollection) => objectRepresentingCollection.Oid is ICollectionMemento cm && cm.IsNotQueryable;
public override void Invoke(INakedObjectAdapter nakedObjectAdapter, ISession session, ILifecycleManager lifecycleManager, IMetamodelManager metamodelManager) { updatingDelegate(nakedObjectAdapter.GetDomainObject()); }
public override void Invoke(INakedObjectAdapter nakedObjectAdapter, ISession session, ILifecycleManager lifecycleManager, IMetamodelManager metamodelManager) { }
public abstract object[] GetChoices(INakedObjectAdapter nakedObjectAdapter, IDictionary<string, INakedObjectAdapter> parameterNameValues);
public override string Invoke(INakedObjectAdapter nakedObjectAdapter, Exception exception) { return((string)methodDelegate(nakedObjectAdapter.GetDomainObject(), new object[] { exception })); }
public string Execute(INakedObjectAdapter obj, INakedObjectAdapter[] parameters) { return(methodDelegate(obj.GetDomainObject(), parameters.Select(no => no.GetDomainObject()).ToArray()) as string); }
public override string Invoke(INakedObjectAdapter nakedObjectAdapter, Exception exception) => throw exception;
protected ObjectFacade(INakedObjectAdapter nakedObject, IFrameworkFacade frameworkFacade, INakedObjectsFramework framework) { WrappedNakedObject = nakedObject ?? throw new NullReferenceException($"{nameof(nakedObject)} is null"); this.framework = framework ?? throw new NullReferenceException($"{nameof(framework)} is null"); FrameworkFacade = frameworkFacade ?? throw new NullReferenceException($"{nameof(frameworkFacade)} is null"); }