public CollectionMemento(ILifecycleManager lifecycleManager, INakedObjectManager nakedObjectManager, IMetamodelManager metamodel, string[] strings)
            : this(lifecycleManager, nakedObjectManager, metamodel)
        {
            var helper = new StringDecoderHelper(metamodel, strings, true);
            // ReSharper disable once UnusedVariable
            string specName  = helper.GetNextString();
            string actionId  = helper.GetNextString();
            var    targetOid = (IOid)helper.GetNextEncodedToStrings();

            Target = RestoreObject(targetOid);
            Action = Target.GetActionLeafNode(actionId);

            var parameters = new List <INakedObjectAdapter>();

            while (helper.HasNext)
            {
                var parmType = helper.GetNextEnum <ParameterType>();

                switch (parmType)
                {
                case ParameterType.Value:
                    object obj = helper.GetNextObject();
                    parameters.Add(nakedObjectManager.CreateAdapter(obj, null, null));
                    break;

                case ParameterType.Object:
                    var oid = (IOid)helper.GetNextEncodedToStrings();
                    INakedObjectAdapter nakedObjectAdapter = RestoreObject(oid);
                    parameters.Add(nakedObjectAdapter);
                    break;

                case ParameterType.ValueCollection:
                    Type           vInstanceType;
                    IList <object> vColl      = helper.GetNextValueCollection(out vInstanceType);
                    IList          typedVColl = CollectionUtils.ToTypedIList(vColl, vInstanceType);
                    parameters.Add(nakedObjectManager.CreateAdapter(typedVColl, null, null));
                    break;

                case ParameterType.ObjectCollection:
                    Type          oInstanceType;
                    List <object> oColl      = helper.GetNextObjectCollection(out oInstanceType).Cast <IOid>().Select(o => RestoreObject(o).Object).ToList();
                    IList         typedOColl = CollectionUtils.ToTypedIList(oColl, oInstanceType);
                    parameters.Add(nakedObjectManager.CreateAdapter(typedOColl, null, null));
                    break;

                default:
                    throw new ArgumentException(Log.LogAndReturn($"Unexpected parameter type value: {parmType}"));
                }
            }

            Parameters = parameters.ToArray();
        }
Example #2
0
 public INakedObjectAdapter FromEncodedString(string encodedData, INakedObjectManager manager)
 {
     if (EncodedNull.Equals(encodedData))
     {
         return(null);
     }
     return(manager.CreateAdapter(encoderDecoder.FromEncodedString(encodedData), null, null));
 }
        public INakedObjectAdapter ParseTextEntry(string entry, INakedObjectManager manager)
        {
            if (entry == null)
            {
                throw new ArgumentException(Resources.NakedObjects.MissingEntryError);
            }
            object parsed = parser.ParseTextEntry(entry);

            return(manager.CreateAdapter(parsed, null, null));
        }
        private static INakedObjectAdapter AdaptResult(INakedObjectManager nakedObjectManager, object result)
        {
            if (CollectionUtils.IsCollection(result.GetType()) ||
                CollectionUtils.IsQueryable(result.GetType()))
            {
                return(nakedObjectManager.CreateAdapter(result, null, null));
            }

            return(nakedObjectManager.CreateAdapterForExistingObject(result));
        }
        public INakedObject PageInternal <T>(int page, int size, INakedObject collection, INakedObjectManager manager, bool forceEnumerable)
        {
            // page = 0 causes empty collection to be returned
            IEnumerable <T> newCollection = page == 0 ? AsGenericIQueryable <T>(collection).Take(0) : AsGenericIQueryable <T>(collection).Skip((page - 1) * size).Take(size);

            if (forceEnumerable)
            {
                newCollection = newCollection.ToList();
            }

            return(manager.CreateAdapter(newCollection, null, null));
        }
Example #6
0
        public override INakedObject Invoke(INakedObject inObject, INakedObject[] parameters, ILifecycleManager lifecycleManager, IMetamodelManager manager, ISession session, INakedObjectManager nakedObjectManager)
        {
            if (parameters.Length != paramCount)
            {
                Log.Error(actionMethod + " requires " + paramCount + " parameters, not " + parameters.Length);
            }

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

            Log.DebugFormat("Action result {0}", adaptedResult);
            return(adaptedResult);
        }
        public INakedObjectAdapter RecoverCollection()
        {
            INakedObjectAdapter nakedObjectAdapter = Action.Execute(Target, Parameters);

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

            nakedObjectAdapter.SetATransientOid(this);
            return(nakedObjectAdapter);
        }
        // Start a snapshot at the root object, using supplied namespace manager.
        public XmlSnapshot(object obj, XmlSchema schema, INakedObjectManager nakedObjectManager, IMetamodelManager metamodelManager) {
            this.nakedObjectManager = nakedObjectManager;
            this.metamodelManager = metamodelManager;

            INakedObjectAdapter rootObjectAdapter = nakedObjectManager.CreateAdapter(obj, null, null);

            Schema = schema;

            try {
                XmlDocument = new XDocument();
                XsdDocument = new XDocument();

                XsdElement = XsMetaModel.CreateXsSchemaElement(XsdDocument);

                rootPlace = AppendXml(rootObjectAdapter);
            }
            catch (ArgumentException e) {
                throw new NakedObjectSystemException(Log.LogAndReturn("Unable to build snapshot"), e);
            }
        }
        public override INakedObjectAdapter Invoke(INakedObjectAdapter inObjectAdapter, INakedObjectAdapter[] parameters, ILifecycleManager lifecycleManager, IMetamodelManager manager, ISession session, INakedObjectManager nakedObjectManager, IMessageBroker messageBroker, ITransactionManager transactionManager)
        {
            if (parameters.Length != paramCount)
            {
                logger.LogError($"{ActionMethod} requires {paramCount} parameters, not {parameters.Length}");
            }

            object result;

            if (ActionDelegate != null)
            {
                result = ActionDelegate(inObjectAdapter.GetDomainObject(), parameters.Select(no => no.GetDomainObject()).ToArray());
            }
            else
            {
                logger.LogWarning($"Invoking action via reflection as no delegate {OnType}.{ActionMethod}");
                result = InvokeUtils.Invoke(ActionMethod, inObjectAdapter, parameters);
            }

            return(nakedObjectManager.CreateAdapter(result, null, null));
        }
        // Start a snapshot at the root object, using supplied namespace manager.
        public XmlSnapshot(object obj, XmlSchema schema, INakedObjectManager nakedObjectManager, IMetamodelManager metamodelManager)
        {
            this.nakedObjectManager = nakedObjectManager;
            this.metamodelManager   = metamodelManager;

            INakedObjectAdapter rootObjectAdapter = nakedObjectManager.CreateAdapter(obj, null, null);

            Schema = schema;

            try {
                XmlDocument = new XDocument();
                XsdDocument = new XDocument();

                XsdElement = XsMetaModel.CreateXsSchemaElement(XsdDocument);

                rootPlace = AppendXml(rootObjectAdapter);
            }
            catch (ArgumentException e) {
                throw new NakedObjectSystemException(Log.LogAndReturn("Unable to build snapshot"), e);
            }
        }
Example #11
0
        private Tuple <INakedObjectAdapter, TypeOfDefaultValue> GetDefaultValueAndType(INakedObjectAdapter nakedObjectAdapter)
        {
            if (parentAction.IsContributedMethod && nakedObjectAdapter != null)
            {
                IActionParameterSpec[] matchingParms = parentAction.Parameters.Where(p => nakedObjectAdapter.Spec.IsOfType(p.Spec)).ToArray();

                if (matchingParms.Any() && matchingParms.First() == this)
                {
                    return(new Tuple <INakedObjectAdapter, TypeOfDefaultValue>(nakedObjectAdapter, TypeOfDefaultValue.Explicit));
                }
            }

            Tuple <object, TypeOfDefaultValue> defaultValue = null;

            // Check Facet on parm, then facet on type finally fall back on type;

            var defaultsFacet = GetFacet <IActionDefaultsFacet>();

            if (defaultsFacet != null && !defaultsFacet.IsNoOp)
            {
                defaultValue = defaultsFacet.GetDefault(parentAction.RealTarget(nakedObjectAdapter));
            }

            if (defaultValue == null)
            {
                var defaultFacet = Spec.GetFacet <IDefaultedFacet>();
                if (defaultFacet != null && !defaultFacet.IsNoOp)
                {
                    defaultValue = new Tuple <object, TypeOfDefaultValue>(defaultFacet.Default, TypeOfDefaultValue.Implicit);
                }
            }

            if (defaultValue == null)
            {
                object rawValue = nakedObjectAdapter == null ? null : nakedObjectAdapter.Object.GetType().IsValueType ? (object)0 : null;
                defaultValue = new Tuple <object, TypeOfDefaultValue>(rawValue, TypeOfDefaultValue.Implicit);
            }

            return(new Tuple <INakedObjectAdapter, TypeOfDefaultValue>(manager.CreateAdapter(defaultValue.Item1, null, null), defaultValue.Item2));
        }
        // Start a snapshot at the root object, using supplied namespace manager.
        public XmlSnapshot(object obj, XmlSchema schema, INakedObjectManager nakedObjectManager, IMetamodelManager metamodelManager) {
            this.nakedObjectManager = nakedObjectManager;
            this.metamodelManager = metamodelManager;

            INakedObjectAdapter rootObjectAdapter = nakedObjectManager.CreateAdapter(obj, null, null);
            Log.Debug(".ctor(" + DoLog("rootObj", rootObjectAdapter) + AndLog("schema", schema) + AndLog("addOids", "" + true) + ")");

            Schema = schema;

            try {
                XmlDocument = new XDocument();
                XsdDocument = new XDocument();

                XsdElement = XsMetaModel.CreateXsSchemaElement(XsdDocument);

                rootPlace = AppendXml(rootObjectAdapter);
            }
            catch (ArgumentException e) {
                Log.Error("unable to build snapshot", e);
                throw new NakedObjectSystemException(e);
            }
        }
        public override INakedObjectAdapter Invoke(INakedObjectAdapter inObjectAdapter, INakedObjectAdapter[] parameters, ILifecycleManager lifecycleManager, IMetamodelManager manager, ISession session, INakedObjectManager nakedObjectManager, IMessageBroker messageBroker, ITransactionManager transactionManager)
        {
            if (parameters.Length != paramCount)
            {
                Log.Error(actionMethod + " requires " + paramCount + " parameters, not " + parameters.Length);
            }

            object result;

            if (actionDelegate != null)
            {
                result = actionDelegate(inObjectAdapter.GetDomainObject(), parameters.Select(no => no.GetDomainObject()).ToArray());
            }
            else
            {
                Log.WarnFormat("Invoking action via reflection as no delegate {0}.{1}", onType, actionMethod);
                result = InvokeUtils.Invoke(actionMethod, inObjectAdapter, parameters);
            }

            INakedObjectAdapter adaptedResult = nakedObjectManager.CreateAdapter(result, null, null);

            return(adaptedResult);
        }
Example #14
0
        // Start a snapshot at the root object, using supplied namespace manager.
        public XmlSnapshot(object obj, XmlSchema schema, INakedObjectManager nakedObjectManager, IMetamodelManager metamodelManager)
        {
            this.nakedObjectManager = nakedObjectManager;
            this.metamodelManager   = metamodelManager;

            INakedObject rootObject = nakedObjectManager.CreateAdapter(obj, null, null);

            Log.Debug(".ctor(" + DoLog("rootObj", rootObject) + AndLog("schema", schema) + AndLog("addOids", "" + true) + ")");

            Schema = schema;

            try {
                XmlDocument = new XDocument();
                XsdDocument = new XDocument();

                XsdElement = XsMetaModel.CreateXsSchemaElement(XsdDocument);

                rootPlace = AppendXml(rootObject);
            }
            catch (ArgumentException e) {
                Log.Error("unable to build snapshot", e);
                throw new NakedObjectSystemException(e);
            }
        }
 public IEnumerable <INakedObjectAdapter> AsEnumerableInternal <T>(INakedObjectAdapter collection, INakedObjectManager manager)
 {
     return(AsGenericIEnumerable <T>(collection).Select(arg => manager.CreateAdapter(arg, null, null)));
 }
 public INakedObjectAdapter PageInternal <T>(int page, int size, INakedObjectAdapter collection, INakedObjectManager manager, bool forceEnumerable)
 {
     return(manager.CreateAdapter(AsGenericIEnumerable <T>(collection).Skip((page - 1) * size).Take(size).ToList(), null, null));
 }
        public override string GetTitle(INakedObjectAdapter nakedObjectAdapter, INakedObjectManager nakedObjectManager)
        {
            object obj = methodDelegate(nakedObjectAdapter.GetDomainObject(), new object[] {});

            return(obj == null ? null : nakedObjectManager.CreateAdapter(obj, null, null).TitleString());
        }
 public override INakedObjectAdapter Page(int page, int size, INakedObjectAdapter collection, INakedObjectManager manager, bool forceEnumerable) {
     return manager.CreateAdapter(PageInternal(page, size, collection, manager), null, null);
 }
 public override IEnumerable<INakedObjectAdapter> AsEnumerable(INakedObjectAdapter collection, INakedObjectManager manager) {
     return AsCollection(collection).Cast<object>().Select(domainObject => manager.CreateAdapter(domainObject, null, null));
 }
        public INakedObjectAdapter ParseInvariant(string text, INakedObjectManager manager)
        {
            object parsed = parser.ParseInvariant(text);

            return(manager.CreateAdapter(parsed, null, null));
        }
 public override IEnumerable <INakedObjectAdapter> AsEnumerable(INakedObjectAdapter collection, INakedObjectManager manager)
 {
     return(AsCollection(collection).Cast <object>().Select(domainObject => manager.CreateAdapter(domainObject, null, null)));
 }
 public override string GetTitle(INakedObjectAdapter nakedObjectAdapter, INakedObjectManager nakedObjectManager) {
     object obj = methodDelegate(nakedObjectAdapter.GetDomainObject(), new object[] {});
     return obj == null ? null : nakedObjectManager.CreateAdapter(obj, null, null).TitleString();
 }
Example #23
0
        public override string GetTitle(INakedObject nakedObject, INakedObjectManager nakedObjectManager)
        {
            object obj = InvokeUtils.Invoke(method, nakedObject);

            return(obj == null ? null : nakedObjectManager.CreateAdapter(obj, null, null).TitleString());
        }
 public override INakedObjectAdapter Page(int page, int size, INakedObjectAdapter collection, INakedObjectManager manager, bool forceEnumerable)
 {
     return(manager.CreateAdapter(PageInternal(page, size, collection, manager), null, null));
 }
Example #25
0
        public INakedObject ParseFromStream(Stream stream, string mimeType, string name, INakedObjectManager manager)
        {
            object obj = fromStream.ParseFromStream(stream, mimeType, name);

            return(manager.CreateAdapter(obj, null, null));
        }
 public INakedObjectAdapter ParseFromStream(Stream stream, string mimeType, string name, INakedObjectManager manager) {
     object obj = fromStream.ParseFromStream(stream, mimeType, name);
     return manager.CreateAdapter(obj, null, null);
 }
        public override INakedObjectAdapter Invoke(INakedObjectAdapter inObjectAdapter, INakedObjectAdapter[] parameters, ILifecycleManager lifecycleManager, IMetamodelManager manager, ISession session, INakedObjectManager nakedObjectManager, IMessageBroker messageBroker, ITransactionManager transactionManager) {
            if (parameters.Length != paramCount) {
                Log.Error(actionMethod + " requires " + paramCount + " parameters, not " + parameters.Length);
            }

            object result;
            if (actionDelegate != null) {
                result = actionDelegate(inObjectAdapter.GetDomainObject(), parameters.Select(no => no.GetDomainObject()).ToArray());
            }
            else {
                Log.WarnFormat("Invoking action via reflection as no delegate {0}.{1}", onType, actionMethod);
                result = InvokeUtils.Invoke(actionMethod, inObjectAdapter, parameters);
            }

            INakedObjectAdapter adaptedResult = nakedObjectManager.CreateAdapter(result, null, null);

            return adaptedResult;
        }
        public CollectionMemento(ILifecycleManager lifecycleManager, INakedObjectManager nakedObjectManager, IMetamodelManager metamodel, string[] strings)
            : this(lifecycleManager, nakedObjectManager, metamodel) {
            var helper = new StringDecoderHelper(metamodel, strings, true);
            // ReSharper disable once UnusedVariable
            string specName = helper.GetNextString();
            string actionId = helper.GetNextString();
            var targetOid = (IOid) helper.GetNextEncodedToStrings();

            Target = RestoreObject(targetOid);
            Action = Target.GetActionLeafNode(actionId);

            var parameters = new List<INakedObjectAdapter>();

            while (helper.HasNext) {
                var parmType = helper.GetNextEnum<ParameterType>();

                switch (parmType) {
                    case ParameterType.Value:
                        object obj = helper.GetNextObject();
                        parameters.Add(nakedObjectManager.CreateAdapter(obj, null, null));
                        break;
                    case ParameterType.Object:
                        var oid = (IOid) helper.GetNextEncodedToStrings();
                        INakedObjectAdapter nakedObjectAdapter = RestoreObject(oid);
                        parameters.Add(nakedObjectAdapter);
                        break;
                    case ParameterType.ValueCollection:
                        Type vInstanceType;
                        IList<object> vColl = helper.GetNextValueCollection(out vInstanceType);
                        IList typedVColl = CollectionUtils.ToTypedIList(vColl, vInstanceType);
                        parameters.Add(nakedObjectManager.CreateAdapter(typedVColl, null, null));
                        break;
                    case ParameterType.ObjectCollection:
                        Type oInstanceType;
                        List<object> oColl = helper.GetNextObjectCollection(out oInstanceType).Cast<IOid>().Select(o => RestoreObject(o).Object).ToList();
                        IList typedOColl = CollectionUtils.ToTypedIList(oColl, oInstanceType);
                        parameters.Add(nakedObjectManager.CreateAdapter(typedOColl, null, null));
                        break;
                    default:
                        throw new ArgumentException(string.Format("Unexpected parameter type value: {0}", parmType));
                }
            }

            Parameters = parameters.ToArray();
        }