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);
     }
 }
Exemplo n.º 2
0
 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.Spec.FullName), e);
     }
 }
        public void GetCollectionNakedObjectFromId()
        {
            IList <Claim> claims = NakedObjectsFramework.GetService <ClaimRepository>().FindMyClaims(null, "");
            INakedObject  no     = NakedObjectsFramework.NakedObjectManager.CreateAdapter(claims, null, null);

            INakedObject service = NakedObjectsFramework.ServicesManager.GetService("ClaimRepository");
            IActionSpec  action  = service.Spec.GetObjectActions().Single(a => a.Id == "FindMyClaims");

            INakedObject[] parms = new[] { null, "" }.Select(o => NakedObjectsFramework.NakedObjectManager.CreateAdapter(o, null, null)).ToArray();

            var cm = new CollectionMemento(NakedObjectsFramework.LifecycleManager, NakedObjectsFramework.NakedObjectManager, NakedObjectsFramework.MetamodelManager, service, action, parms);

            no.SetATransientOid(cm);

            string id = NakedObjectsFramework.GetObjectId(no);

            INakedObject no2 = NakedObjectsFramework.GetNakedObjectFromId(id);

            List <Claim> claims2 = no2.GetDomainObject <IEnumerable <Claim> >().ToList();

            Assert.AreEqual(claims.Count(), claims2.Count());

            int index = 0;
            Dictionary <Claim, Claim> dict = claims.ToDictionary(x => x, y => claims2.Skip(index++).First());

            dict.ForEach(kvp => Assert.AreSame(kvp.Key, kvp.Value));
        }
        public void TestGetPropertyChoicesOtherValue()
        {
            INakedObject choicesRepo   = NakedObjectsFramework.GetAdaptedService("ChoicesRepository");
            object       choicesObject = choicesRepo.GetDomainObject <ChoicesRepository>().GetChoicesObject();


            string id = NakedObjectsFramework.GetObjectId(choicesObject);

            const string parm1Id = "ChoicesObject-Name-Input0";
            const string parm2Id = "ChoicesObject-AProperty-Input0";

            mocks.Request.Setup(x => x.Params).Returns(new NameValueCollection {
                { parm1Id, "AName" }, { parm2Id, "" }
            });

            JsonResult result = controller.GetPropertyChoices(id);

            Assert.IsInstanceOf <IDictionary <string, string[][]> >(result.Data);

            var dict = result.Data as IDictionary <string, string[][]>;

            Assert.AreEqual(1, dict.Count);
            Assert.IsTrue(dict.ContainsKey("ChoicesObject-AProperty-Input"));

            Assert.IsTrue(dict["ChoicesObject-AProperty-Input"][0].SequenceEqual(new[] { "AName-A", "AName-B" }));
            Assert.IsTrue(dict["ChoicesObject-AProperty-Input"][1].SequenceEqual(new[] { "AName-A", "AName-B" }));
        }
        public void TestGetPropertyAutoComplete()
        {
            INakedObject autoCompleteRepo   = NakedObjectsFramework.GetAdaptedService("AutoCompleteRepository");
            object       autoCompleteObject = autoCompleteRepo.GetDomainObject <AutoCompleteRepository>().GetAutoCompleteObject();

            string id = NakedObjectsFramework.GetObjectId(autoCompleteObject);

            const string parm1Id = "AutoCompleteObject-Name-Input";

            mocks.Request.Setup(x => x.Params).Returns(new NameValueCollection {
                { parm1Id, "" }
            });

            JsonResult result = controller.GetPropertyCompletions(id, "AProperty", "");

            var list = result.Data as IList <object>;

            Assert.AreEqual(2, list.Count);

            var nv1 = new RouteValueDictionary(list[0]);
            var nv2 = new RouteValueDictionary(list[1]);

            Assert.AreEqual("value5", nv1["label"]);
            Assert.AreEqual("value5", nv1["value"]);
            Assert.AreEqual("value5", nv1["link"]);
            Assert.AreEqual("/Images/Default.png", nv1["src"]);
            Assert.AreEqual("String", nv1["alt"]);

            Assert.AreEqual("value6", nv2["label"]);
            Assert.AreEqual("value6", nv2["value"]);
            Assert.AreEqual("value6", nv2["link"]);
            Assert.AreEqual("/Images/Default.png", nv2["src"]);
            Assert.AreEqual("String", nv1["alt"]);
        }
        private ViewResult InvokeAction(INakedObject nakedObject, string actionName, FormCollection parameters, String viewNameForFailure, string viewNameForSuccess = null)
        {
            bool valid;
            var  result = InvokeAction <object>(nakedObject.Object, actionName, parameters, out valid);

            return(View(valid ? viewNameForSuccess : viewNameForFailure, result ?? nakedObject.GetDomainObject()));
        }
 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);
     }
 }
Exemplo n.º 8
0
 public bool IsSet(INakedObject nakedObject)
 {
     if (!nakedObject.Exists())
     {
         return(false);
     }
     return(nakedObject.GetDomainObject <bool>());
 }
Exemplo n.º 9
0
 public override void SetProperty(INakedObject nakedObject, INakedObject value, ITransactionManager transactionManager)
 {
     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);
        }
        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 override object GetProperty(INakedObject nakedObject) {
     try {
         return propertyMethod.GetValue(nakedObject.GetDomainObject(), null);
     }
     catch (TargetInvocationException e) {
         InvokeUtils.InvocationException("Exception executing " + propertyMethod, e);
         return null;
     }
 }
 public void InitProperty(INakedObject nakedObject, INakedObject value)
 {
     try {
         property.SetValue(nakedObject.GetDomainObject(), value.GetDomainObject(), null);
     }
     catch (TargetInvocationException e) {
         InvokeUtils.InvocationException("Exception executing " + property, e);
     }
 }
 public object GetProperty(INakedObject nakedObject)
 {
     try {
         return(propertyMethod.GetValue(nakedObject.GetDomainObject(), null));
     }
     catch (TargetInvocationException e) {
         InvokeUtils.InvocationException("Exception executing " + propertyMethod, e);
         return(null);
     }
 }
Exemplo n.º 15
0
        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);
        }
        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());
            }
        }
        /// <summary>
        ///     Whether the provided argument exceeds the <see cref="SingleIntValueFacetAbstract.Value" /> maximum length}.
        /// </summary>
        public virtual bool Exceeds(INakedObject nakedObject)
        {
            var str = nakedObject.GetDomainObject() as string;

            if (str == null)
            {
                return(false);
            }
            int maxLength = Value;

            return(maxLength != 0 && str.Length > maxLength);
        }
        public void Persist <T>(ref T transientObject)
        {
            INakedObject adapter = framework.NakedObjectManager.GetAdapterFor(transientObject);

            if (IsPersistent(transientObject))
            {
                throw new PersistFailedException(string.Format(Resources.NakedObjects.AlreadyPersistentMessage, adapter));
            }
            Validate(adapter);
            framework.LifecycleManager.MakePersistent(adapter);
            transientObject = adapter.GetDomainObject <T>();
        }
 public override object[] GetCompletions(INakedObject inObject, string autoCompleteParm) {
     try {
         object autoComplete = InvokeUtils.Invoke(method, inObject.GetDomainObject(), new object[] {autoCompleteParm});
         if (autoComplete is IQueryable) {
             return ((IQueryable) autoComplete).Take(PageSize).ToArray();
         }
         throw new NakedObjectDomainException("Must return IQueryable 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);
     }
 }
Exemplo n.º 20
0
        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 INakedObject RecoverCollection()
        {
            INakedObject nakedObject = Action.Execute(Target, Parameters);

            if (selectedObjects != null)
            {
                IEnumerable <object> selected = nakedObject.GetDomainObject <IEnumerable>().Cast <object>().Where(x => selectedObjects.Contains(x));
                IList newResult = CollectionUtils.CloneCollectionAndPopulate(nakedObject.Object, selected);
                nakedObject = nakedObjectManager.CreateAdapter(newResult, null, null);
            }

            nakedObject.SetATransientOid(this);
            return(nakedObject);
        }
 public object[] GetCompletions(INakedObject inObject, string autoCompleteParm)
 {
     try {
         object autoComplete = InvokeUtils.Invoke(method, inObject.GetDomainObject(), new object[] { autoCompleteParm });
         var    complete     = autoComplete as IQueryable;
         if (complete != null)
         {
             return(complete.Take(PageSize).ToArray());
         }
         throw new NakedObjectDomainException("Must return IQueryable 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);
     }
 }
Exemplo n.º 23
0
        // validate all the passed in types to fail at reflection time as far as possible

        #region IAuditManager Members

        public void Invoke(INakedObject nakedObject, INakedObject[] parameters, bool queryOnly, IIdentifier identifier, ISession session, ILifecycleManager lifecycleManager, IMetamodelManager manager)
        {
            IAuditor auditor = GetAuditor(nakedObject, lifecycleManager, manager);

            IPrincipal byPrincipal = session.Principal;
            string     memberName  = identifier.MemberName;

            if (nakedObject.Spec is IServiceSpec)
            {
                string serviceName = nakedObject.Spec.GetTitle(nakedObject);
                auditor.ActionInvoked(byPrincipal, memberName, serviceName, queryOnly, parameters.Select(no => no.GetDomainObject()).ToArray());
            }
            else
            {
                auditor.ActionInvoked(byPrincipal, memberName, nakedObject.GetDomainObject(), queryOnly, parameters.Select(no => no.GetDomainObject()).ToArray());
            }
        }
        /// <summary>
        ///     Apply changes from form and attempt to save
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="form"></param>
        /// <param name="obj"></param>
        /// <returns>true if changes in form are valid and object saved</returns>
        protected bool SaveObject <T>(FormCollection form, ref T obj)
        {
            INakedObject naked  = NakedObjectsContext.GetNakedObject(obj);
            bool         result = false;

            if (ValidateChanges(naked, new ObjectAndControlData()
            {
                Form = form
            }))
            {
                if (ApplyChanges(naked, new ObjectAndControlData()
                {
                    Form = form
                }))
                {
                    result = true;
                }
            }
            obj = naked.GetDomainObject <T>();
            return(result);
        }
        private T InvokeAction <T>(INakedObject nakedObject, IActionSpec action, FormCollection parameters, out bool valid)
        {
            if (ActionExecutingAsContributed(action, nakedObject))
            {
                if (action.ParameterCount == 1)
                {
                    // contributed action being invoked with a single parm that is the current target
                    // no dialog - go straight through
                    INakedObject result = action.Execute(nakedObject, new[] { nakedObject });
                    valid = true;
                    return(result.GetDomainObject <T>());
                }
                if (action.ParameterCount > 1)
                {
                    // contributed action being invoked with multiple parms - populate first that match the target
                    IActionParameterSpec parmToPopulate = action.Parameters.FirstOrDefault(p => nakedObject.Spec.IsOfType(p.Spec));
                    if (parmToPopulate != null)
                    {
                        ViewData[IdHelper.GetParameterInputId(action, parmToPopulate)] = NakedObjectsContext.GetObjectId(nakedObject.Object);
                    }
                }
            }

            if (ValidateParameters(nakedObject, action, new ObjectAndControlData {
                Form = parameters
            }))
            {
                IEnumerable <INakedObject> parms = GetParameterValues(action, new ObjectAndControlData {
                    Form = parameters
                });
                INakedObject result = action.Execute(nakedObject, parms.ToArray());
                valid = true;
                return(result.GetDomainObject <T>());
            }

            valid = false;
            return(default(T));
        }
Exemplo n.º 26
0
        public string InvariantString(INakedObject nakedObject)
        {
            var context = nakedObject.GetDomainObject <T>();

            return(parser.InvariantString(context));
        }
 public override void Populate(string[] keys, INakedObject nakedObject)
 {
     nakedObject.GetDomainObject <IViewModel>().PopulateUsingKeys(keys);
 }
 public override string[] Derive(INakedObject nakedObject)
 {
     return(nakedObject.GetDomainObject <IViewModel>().DeriveKeys());
 }
Exemplo n.º 29
0
 public uint UnsignedIntegerValue(INakedObject nakedObject)
 {
     return(nakedObject.GetDomainObject <uint>());
 }
Exemplo n.º 30
0
 public static object Invoke(MethodInfo method, INakedObject nakedObject) {
     var parameters = new object[method.GetParameters().Length];
     return Invoke(method, nakedObject.GetDomainObject(), parameters);
 }
 public ushort UnsignedShortValue(INakedObject nakedObject)
 {
     return(nakedObject.GetDomainObject <ushort>());
 }
 public TimeSpan TimeValue(INakedObject nakedObject)
 {
     return(nakedObject.GetDomainObject <TimeSpan>());
 }
Exemplo n.º 33
0
 public Guid GuidValue(INakedObject nakedObject)
 {
     return(nakedObject.GetDomainObject <Guid>());
 }
 /// <summary>
 ///     For convenience of subclass facets that implement
 ///     <see cref="IValidatingInteractionAdvisor" />, <see cref="IHidingInteractionAdvisor" /> or
 ///     <see cref="IDisablingInteractionAdvisor" />
 /// </summary>
 protected internal virtual string UnwrapString(INakedObject nakedObject) {
     object obj = nakedObject.GetDomainObject();
     if (obj == null) {
         return null;
     }
     if (!(obj is string)) {
         return null;
     }
     return (string) obj;
 }
 public void Persisted(INakedObject nakedObject) {
     Init();
     IAuditor auditor = GetNamespaceAuthorizerFor(nakedObject) ?? defaultAuditor;
     auditor.ObjectPersisted(NakedObjectsContext.Session.Principal, nakedObject.GetDomainObject());
 }
Exemplo n.º 36
0
        public static object Invoke(MethodInfo method, INakedObject nakedObject)
        {
            var parameters = new object[method.GetParameters().Length];

            return(Invoke(method, nakedObject.GetDomainObject(), parameters));
        }
 public float FloatValue(INakedObject nakedObject)
 {
     return(nakedObject.GetDomainObject <float>());
 }
Exemplo n.º 38
0
        public void Persisted(INakedObject nakedObject, ISession session, ILifecycleManager lifecycleManager, IMetamodelManager manager)
        {
            IAuditor auditor = GetAuditor(nakedObject, lifecycleManager, manager);

            auditor.ObjectPersisted(session.Principal, nakedObject.GetDomainObject());
        }
Exemplo n.º 39
0
        public string ParseableTitle(INakedObject nakedObject)
        {
            var context = nakedObject.GetDomainObject <T>();

            return(parser.EditableTitleOf(context));
        }
Exemplo n.º 40
0
 public static object[] GetKey(this EntityObjectStore.LocalContext context, INakedObject nakedObject)
 {
     return(context.GetIdMembers(nakedObject.GetDomainObject().GetEntityProxiedType()).Select(x => x.GetValue(nakedObject.GetDomainObject(), null)).ToArray());
 }
Exemplo n.º 41
0
        private static string GetBooleanFieldValue(this HtmlHelper html, INakedObject valueNakedObject) {
            var state = valueNakedObject.GetDomainObject<bool?>();
            string src = "Images/unset.png";
            string alt = MvcUi.TriState_NotSet;

            if (state.HasValue) {
                if (state.Value) {
                    src = "Images/checked.png";
                    alt = MvcUi.TriState_True;
                }
                else {
                    src = "Images/unchecked.png";
                    alt = MvcUi.TriState_False;
                }
            }

            var tag = new TagBuilder("img");
            tag.MergeAttribute("src", src);
            tag.MergeAttribute("alt", alt);

            return tag.ToString();
        }