public virtual void Add(IOid oid, INakedObject adapter) {
     lock (adapters) {
         adapters[oid] = adapter;
     }
     // log after so that adapter is in map if required by ToString
     Log.DebugFormat("Add {0} as {1}", oid, adapter);
 }
Example #2
0
 public static object Invoke(MethodInfo method, INakedObject nakedObject, INakedObject[] parameters) {
     object[] parameterPocos = parameters == null ? new object[0] : new object[parameters.Length];
     for (int i = 0; i < parameterPocos.Length; i++) {
         parameterPocos[i] = parameters[i] == null ? null : parameters[i].Object;
     }
     return Invoke(method, nakedObject.Object, parameterPocos);
 }
Example #3
0
        private void Page(ICollectionFacet testArrayFacet, INakedObject collection, object first) {
            INakedObject pagedCollection = testArrayFacet.Page(1, 1, collection, false);
            var pagedCollectionFacet = new DotNetGenericIEnumerableFacet<object>(facetHolder, typeof (object), false);

            Assert.IsTrue(pagedCollectionFacet.AsEnumerable(pagedCollection).Count() == 1);
            Assert.AreSame(pagedCollectionFacet.AsEnumerable(pagedCollection).First().Object, first);
        }
        protected void Persist(INakedObject nakedObject, IPersistedObjectAdder persistor) {
            if (nakedObject.ResolveState.IsAggregated() ||
                (nakedObject.ResolveState.IsTransient() &&
                 nakedObject.Specification.Persistable != Persistable.TRANSIENT)) {
                INakedObjectAssociation[] fields = nakedObject.Specification.Properties;
                if (!nakedObject.Specification.IsEncodeable && fields.Length > 0) {
                    Log.Info("make persistent " + nakedObject);
                    nakedObject.Persisting();
                    if (!nakedObject.Specification.ContainsFacet(typeof (IComplexTypeFacet))) {
                        persistor.MadePersistent(nakedObject);
                    }

                    foreach (INakedObjectAssociation field in fields) {
                        if (!field.IsPersisted) {
                            continue;
                        }
                        if (field is IOneToManyAssociation) {
                            INakedObject collection = field.GetNakedObject(nakedObject);
                            if (collection == null) {
                                throw new NotPersistableException("Collection " + field.Name + " does not exist in " + nakedObject.Specification.FullName);
                            }
                            MakePersistent(collection, persistor);
                        }
                        else {
                            INakedObject fieldValue = field.GetNakedObject(nakedObject);
                            if (fieldValue == null) {
                                continue;
                            }
                            Persist(fieldValue, persistor);
                        }
                    }
                    persistor.AddPersistedObject(nakedObject);
                }
            }
        }
 public virtual void Add(object obj, INakedObject adapter) {
     lock (domainObjects) {
         domainObjects[obj] = adapter;
     }
     // log at end so that if ToString needs adapters they're in maps. 
     Log.DebugFormat("Add instance of {0} as {1}", obj.GetType().FullName, adapter);
 }
Example #6
0
 private static void ClearPreviousTransients(this HttpSessionStateBase session, INakedObject nakedObject, ObjectFlag flag) {
     if (nakedObject.Oid.HasPrevious) {
         if (nakedObject.Oid.Previous.IsTransient) {
             session.GetCache(flag).Remove(FrameworkHelper.GetObjectId(nakedObject.Oid.Previous));
         }
     }
 }
 public override string HiddenReason(INakedObject nakedObject) {
     if (nakedObject == null) {
         return null;
     }
     var isHidden = (bool) InvokeUtils.Invoke(method, nakedObject);
     return isHidden ? Resources.NakedObjects.Hidden : null;
 }
 public void MakePersistent(INakedObject nakedObject, IPersistedObjectAdder persistor) {
     if (nakedObject.Specification.IsCollection) {
         MakeCollectionPersistent(nakedObject, persistor);
     }
     else {
         MakeObjectPersistent(nakedObject, persistor);
     }
 }
 private INamespaceAuditor GetNamespaceAuthorizerFor(INakedObject target) {
     Assert.AssertNotNull(target);
     string fullyQualifiedOfTarget = target.Specification.FullName;
     return namespaceAuditors.
         Where(x => fullyQualifiedOfTarget.StartsWith(x.NamespaceToAudit)).
         OrderByDescending(x => x.NamespaceToAudit.Length).
         FirstOrDefault();
 }
 public virtual void AddDisposedObject(INakedObject nakedObject) {
     lock (disposals) {
         Log.DebugFormat("Mark as disposed {0}", nakedObject);
         if (!disposals.Contains(nakedObject)) {
             disposals.Add(nakedObject);
         }
     }
 }
 /// <summary>
 ///     Whether the provided argument exceeds the <see cref="SingleIntValueFacetAbstract.Value" /> maximum length}.
 /// </summary>
 public virtual bool Exceeds(INakedObject nakedObject) {
     string str = UnwrapString(nakedObject);
     if (str == null) {
         return false;
     }
     int maxLength = Value;
     return maxLength != 0 && str.Length > maxLength;
 }
Example #12
0
        public static void AddOrUpdateInCache(this HttpSessionStateBase session, INakedObject nakedObject, string url, ObjectFlag flag = ObjectFlag.None) {
            // only add transients if we are storing transients in the session 

            if ((!nakedObject.ResolveState.IsTransient() || MvcIdentityAdapterHashMap.StoringTransientsInSession) || nakedObject.Specification.IsCollection) {
                session.ClearPreviousTransients(nakedObject, flag);
                session.GetCache(flag).AddOrUpdateInCache(nakedObject, url, flag);
            }
        }
 public virtual void AddChangedObject(INakedObject nakedObject) {
     lock (changes) {
         Log.DebugFormat("Mark as dirty {0}", nakedObject);
         if (!changes.Contains(nakedObject)) {
             changes.Add(nakedObject);
         }
     }
 }
Example #14
0
        public void SetUp() {
            IFacetHolder holder = null;
            Customer17 customer = new Customer17();
            target = new ProgrammableNakedObject(customer, null);

            MethodInfo method = typeof(Customer17).GetMethod("Validate0SomeAction");
            facet = new ActionParameterValidationFacetViaMethod(method, 0, holder);
        }
Example #15
0
 public override string InvalidReason(INakedObject target, INakedObject proposedValue) {
     if (proposedValue != null) {
         return (string) InvokeUtils.Invoke(method, target, new[] {proposedValue});
     }
     else {
         return null;
     }
 }
 public override void SetProperty(INakedObject nakedObject, INakedObject value) {
     try {
         property.SetValue(nakedObject.GetDomainObject(), value.GetDomainObject(), null);
     }
     catch (TargetInvocationException e) {
         InvokeUtils.InvocationException("Exception executing " + property, e);
     }
 }
        public override bool IsEditView(INakedObject nakedObject) {
            var target = nakedObject.GetDomainObject<IViewModelSwitchable>();

            if (target != null) {
                return target.IsEditView();
            }

            throw new NakedObjectSystemException(nakedObject.Object == null ? "Null domain object" : "Wrong type of domain object: " + nakedObject.Object.GetType().FullName);
        }
 private IEnumerable PageInternal(int page, int size, INakedObject collection) {
     int firstIndex = (page - 1)*size;
     for (int index = firstIndex; index < firstIndex + size; index++) {
         if (index >= AsEnumerable(collection).Count()) {
             yield break;
         }
         yield return AsCollection(collection)[index];
     }
 }
 public override object GetProperty(INakedObject nakedObject) {
     try {
         return propertyMethod.GetValue(nakedObject.GetDomainObject(), null);
     }
     catch (TargetInvocationException e) {
         InvokeUtils.InvocationException("Exception executing " + propertyMethod, e);
         return null;
     }
 }
        public override void Init(INakedObject collection, INakedObject[] 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(INakedObject collection, INakedObject[] initData) {
            Array newCollection = Array.CreateInstance(collection.GetDomainObject().GetType().GetElementType(), initData.Length);
            collection.ReplacePoco(newCollection);

            int i = 0;
            foreach (INakedObject nakedObject in initData) {
                AsCollection(collection)[i++] = nakedObject.Object;
            }
        }
        public CollectionMemento(INakedObject target, INakedObjectAction action, INakedObject[] parameters) {
            Target = target;
            Action = action;
            Parameters = parameters;

            if (Target.Specification.IsViewModel) {
                PersistorUtils.PopulateViewModelKeys(Target);
            }
        }
 public override void AddAdapter(INakedObject nakedObject) {
     base.AddAdapter(nakedObject);
     if (nakedObject.Specification.IsService ||
         nakedObject.Specification.IsViewModel ||
         nakedObject.Specification.ContainsFacet(typeof (IComplexTypeFacet))) {
         return;
     }
     ObjectStore.LoadComplexTypes(nakedObject, nakedObject.ResolveState.IsGhost());
 }
 public static void MakeObjectPersistent(INakedObject nakedObject, IPersistedObjectAdder persistor) {
     if (nakedObject.ResolveState.IsAggregated() ||
         nakedObject.ResolveState.IsPersistent() ||
         nakedObject.Specification.Persistable == Persistable.TRANSIENT ||
         nakedObject.Specification.IsService) {
         return;
     }
     Log.Info("persist " + nakedObject);
     persistor.AddPersistedObject(nakedObject);
 }
        public bool IsVisible(ISession session, INakedObject target, IIdentifier member) {
            var checkViewType = member.IsField ? CheckType.ViewField : CheckType.Action;
            var checkEditType = member.IsField ? CheckType.EditField : CheckType.Action;

            var contextView = new AuthorizationContext((ClaimsPrincipal)session.Principal, member.ToIdentityString(IdentifierDepth.ClassName), ((int)checkViewType).ToString());
            var contextEdit = new AuthorizationContext((ClaimsPrincipal)session.Principal, member.ToIdentityString(IdentifierDepth.ClassName), ((int)checkEditType).ToString());

            // being editable implies visibility 
            return manager.CheckAccess(contextView) || manager.CheckAccess(contextEdit);
        }
 public void Reset(INakedObject inObject) {
     try {
         var collection = (IList) property.GetValue(inObject.GetDomainObject(), null);
         collection.Clear();
         property.SetValue(inObject.GetDomainObject(), collection, null);
     }
     catch (Exception e) {
         throw new ReflectionException(string.Format("Failed to get/set property {0} in {1}", property.Name, inObject.Specification.FullName), e);
     }
 }
        public override INakedObject Invoke(INakedObject inObject, INakedObject[] parameters) {
            if (parameters.Length != paramCount) {
                Log.Error(actionMethod + " requires " + paramCount + " parameters, not " + parameters.Length);
            }

            object result = InvokeUtils.Invoke(actionMethod, inObject, parameters);
            INakedObject adaptedResult = PersistorUtils.CreateAdapter(result);

            Log.DebugFormat("Action result {0}", adaptedResult);
            return adaptedResult;
        }
        public void Invoke(INakedObject nakedObject, INakedObject[] parameters, bool queryOnly, IIdentifier identifier) {
            Init();
            IAuditor auditor = GetNamespaceAuthorizerFor(nakedObject) ?? defaultAuditor;

            if (nakedObject.Specification.IsService) {
                string serviceName = nakedObject.Specification.GetTitle(nakedObject);
                auditor.ActionInvoked(NakedObjectsContext.Session.Principal, identifier.MemberName, serviceName, queryOnly, parameters.Select(no => no.GetDomainObject()).ToArray());
            }
            else {
                auditor.ActionInvoked(NakedObjectsContext.Session.Principal, identifier.MemberName, nakedObject.GetDomainObject(), queryOnly, parameters.Select(no => no.GetDomainObject()).ToArray());
            }
        }
 private void MakeCollectionPersistent(INakedObject collection, IPersistedObjectAdder persistor) {
     if (collection.ResolveState.IsPersistent() || collection.Specification.Persistable == Persistable.TRANSIENT) {
         return;
     }
     Log.Info("persist " + collection);
     if (collection.ResolveState.IsTransient()) {
         collection.ResolveState.Handle(Events.StartResolvingEvent);
         collection.ResolveState.Handle(Events.EndResolvingEvent);
     }
     persistor.MadePersistent(collection);
     collection.GetAsEnumerable().ForEach(no => MakePersistent(no, persistor));
 }
Example #30
0
        private static string GetFieldInputId(INakedObject nakedObject, INakedObjectAssociation property) {
            string fieldId;

            if (nakedObject.Oid is AggregateOid) {
                var aoid = ((AggregateOid) nakedObject.Oid);
                INakedObjectAssociation parent = aoid.ParentOid.Specification.Properties.Where(p => p.Id == aoid.FieldName).SingleOrDefault();
                fieldId = IdHelper.GetInlineFieldInputId(parent, nakedObject, property);
            }
            else {
                fieldId = IdHelper.GetFieldInputId(nakedObject, property);
            }
            return fieldId;
        }