Esempio n. 1
0
        private ViewResult InvokeAction(IObjectFacade nakedObject, string actionName, FormCollection parameters, String viewNameForFailure, string viewNameForSuccess = null)
        {
            bool valid;
            var  result = InvokeAction <object>(nakedObject.GetDomainObject(), actionName, parameters, out valid);

            return(View(valid ? viewNameForSuccess : viewNameForFailure, result ?? nakedObject.GetDomainObject()));
        }
 private static IEnumerable GetResultAsEnumerable(IObjectFacade result, IActionFacade contextAction, string propertyName)
 {
     if (result != null)
     {
         if (result.Specification.IsCollection && !ContextParameterIsCollection(contextAction, propertyName))
         {
             return(result.GetDomainObject <IEnumerable>());
         }
         return(new List <object> {
             result.GetDomainObject()
         });
     }
     return(new List <object>());
 }
        private ActionResult SelectSingleItem(IObjectFacade nakedObject, IActionFacade action, ObjectAndControlData controlData, IDictionary <string, string> selectedItem)
        {
            var property = DisplaySingleProperty(controlData, selectedItem);

            if (action == null)
            {
                SetSelectedReferences(nakedObject, selectedItem);
                return(property == null?View("ObjectEdit", nakedObject.GetDomainObject()) : View("PropertyEdit", new PropertyViewModel(nakedObject.GetDomainObject(), property)));
            }
            SetSelectedParameters(nakedObject, action, selectedItem);

            return(View(property == null ? "ActionDialog" : "PropertyEdit", new FindViewModel {
                ContextObject = nakedObject.GetDomainObject(), ContextAction = action, PropertyName = property
            }));
        }
Esempio n. 4
0
        public static ParameterRepresentation Create(IOidStrategy oidStrategy, HttpRequestMessage req, IObjectFacade objectFacade, IActionParameterFacade parameter, RestControlFlags flags)
        {
            var optionals = new List <OptionalProperty>();

            if (parameter.IsChoicesEnabled != Choices.NotEnabled && !parameter.GetChoicesParameters().Any())
            {
                IObjectFacade[] choices      = parameter.GetChoices(objectFacade, null);
                object[]        choicesArray = choices.Select(c => RestUtils.GetChoiceValue(oidStrategy, req, c, parameter, flags)).ToArray();
                optionals.Add(new OptionalProperty(JsonPropertyNames.Choices, choicesArray));
            }

            if (parameter.DefaultTypeIsExplicit(objectFacade))
            {
                IObjectFacade defaultNakedObject = parameter.GetDefault(objectFacade);
                if (defaultNakedObject != null)
                {
                    string title        = defaultNakedObject.TitleString;
                    object value        = RestUtils.ObjectToPredefinedType(defaultNakedObject.GetDomainObject());
                    var    isValue      = defaultNakedObject.Specification.IsParseable || (defaultNakedObject.Specification.IsCollection && defaultNakedObject.ElementSpecification.IsParseable);
                    object defaultValue = isValue ? value : CreateDefaultLinks(oidStrategy, req, parameter, defaultNakedObject, title, flags);

                    optionals.Add(new OptionalProperty(JsonPropertyNames.Default, defaultValue));
                }
            }

            if (optionals.Count == 0)
            {
                return(new ParameterRepresentation(oidStrategy, req, objectFacade, parameter, flags));
            }
            return(CreateWithOptionals <ParameterRepresentation>(new object[] { oidStrategy, req, objectFacade, parameter, flags }, optionals));
        }
        protected static object GetPropertyValue(IOidStrategy oidStrategy, HttpRequestMessage req, IAssociationFacade property, IObjectFacade target, RestControlFlags flags, bool valueOnly = false)
        {
            IObjectFacade valueNakedObject = property.GetValue(target);
            string        title            = RestUtils.SafeGetTitle(property, valueNakedObject);

            if (valueNakedObject == null)
            {
                return(null);
            }
            if (property.Specification.IsParseable || property.Specification.IsCollection)
            {
                return(RestUtils.ObjectToPredefinedType(valueNakedObject.GetDomainObject()));
            }

            if (valueOnly)
            {
                return(RefValueRepresentation.Create(oidStrategy, new ValueRelType(property, new UriMtHelper(oidStrategy, req, valueNakedObject)), flags));
            }

            var helper    = new UriMtHelper(oidStrategy, req, property.IsInline ? target : valueNakedObject);
            var optionals = new List <OptionalProperty> {
                new OptionalProperty(JsonPropertyNames.Title, title)
            };

            if (property.IsEager(target))
            {
                optionals.Add(new OptionalProperty(JsonPropertyNames.Value, ObjectRepresentation.Create(oidStrategy, valueNakedObject, req, flags)));
            }

            return(LinkRepresentation.Create(oidStrategy, new ValueRelType(property, helper), flags, optionals.ToArray()));
        }
Esempio n. 6
0
        public static object GetChoiceValue(IOidStrategy oidStrategy, IObjectFacade item, ChoiceRelType relType, RestControlFlags flags)
        {
            string title = SafeGetTitle(item);
            object value = ObjectToPredefinedType(item.GetDomainObject());

            return(item.Specification.IsParseable ? value : LinkRepresentation.Create(oidStrategy, relType, flags, new OptionalProperty(JsonPropertyNames.Title, title)));
        }
Esempio n. 7
0
        protected FileContentResult AsFile(IObjectFacade domainObject)
        {
            var fileAttachment = domainObject.GetAttachment();

            if (fileAttachment != null)
            {
                bool addHeader = !string.IsNullOrWhiteSpace(fileAttachment.ContentDisposition);

                if (addHeader)
                {
                    string dispositionValue = string.Format("{0}; filename={1}", fileAttachment.ContentDisposition, fileAttachment.FileName);
                    Response.AddHeader("Content-Disposition", dispositionValue);
                }

                Stream stream = fileAttachment.Content;
                using (var br = new BinaryReader(stream)) {
                    byte[] bytes    = br.ReadBytes((int)stream.Length);
                    var    mimeType = fileAttachment.MimeType ?? "image/bmp";

                    // need to use different File overloads or will end up with two content-disposition headers
                    return(addHeader ? File(bytes, mimeType) : File(bytes, mimeType, fileAttachment.FileName));
                }
            }
            var byteArray = domainObject.GetDomainObject <object>() as byte[];

            return(File(byteArray, AttachmentContextFacade.DefaultMimeType));
        }
Esempio n. 8
0
        public static ActionResultModel Create(IFrameworkFacade facade, IActionFacade action, IObjectFacade nakedObject, int page, int pageSize, string format)
        {
            var  result         = nakedObject.GetDomainObject <IEnumerable>();
            Type genericType    = result.GetType().IsGenericType ? result.GetType().GetGenericArguments().First() : typeof(object);
            Type armGenericType = result is IQueryable ? typeof(ActionResultModelQ <>) : typeof(ActionResultModel <>);
            Type armType        = armGenericType.MakeGenericType(genericType);
            var  arm            = (ActionResultModel)Activator.CreateInstance(armType, action, result);

            arm.Page     = page;
            arm.PageSize = pageSize;
            arm.Format   = format;

            return(facade.Wrap(arm, nakedObject) as ActionResultModel);
        }
        private ActionResult ExecuteAction(ObjectAndControlData controlData, IObjectFacade nakedObject, IActionFacade action)
        {
            if (ActionExecutingAsContributed(action, nakedObject) && action.ParameterCount == 1)
            {
                // contributed action being invoked with a single parm that is the current target
                // no dialog - go straight through

                var ac = new ArgumentsContextFacade {
                    Values = new Dictionary <string, object>(), ValidateOnly = false
                };

                if (nakedObject.Specification.IsCollection && !nakedObject.Specification.IsParseable)
                {
                    var oids = nakedObject.ToEnumerable().Select(no => Facade.OidTranslator.GetOidTranslation(no)).ToArray();
                    var spec = nakedObject.ElementSpecification;

                    var ar = Facade.ExecuteListAction(oids, spec, action.Id, ac);
                    return(AppropriateView(controlData, GetResult(ar), action));
                }
                else
                {
                    var oid = Facade.OidTranslator.GetOidTranslation(nakedObject);
                    var ar  = Facade.ExecuteObjectAction(oid, action.Id, ac);

                    return(AppropriateView(controlData, GetResult(ar), action));
                }
            }

            if (!action.Parameters.Any())
            {
                var ac = new ArgumentsContextFacade {
                    Values = new Dictionary <string, object>(), ValidateOnly = false
                };
                var oid    = Facade.OidTranslator.GetOidTranslation(nakedObject);
                var result = Facade.ExecuteObjectAction(oid, action.Id, ac);

                return(AppropriateView(controlData, GetResult(result), action));
            }

            SetDefaults(nakedObject, action);
            // do after any parameters set by contributed action so this takes priority
            SetSelectedParameters(action);
            SetPagingValues(controlData, nakedObject);
            var property = DisplaySingleProperty(controlData, controlData.DataDict);

            return(View(property == null ? "ActionDialog" : "PropertyEdit", new FindViewModel {
                ContextObject = nakedObject.GetDomainObject(), ContextAction = action, PropertyName = property
            }));
        }
Esempio n. 10
0
 public static T GetDomainObject <T>(this IObjectFacade objectFacade)
 {
     return((T)objectFacade.GetDomainObject());
 }
        private static string GetBooleanFieldValue(this HtmlHelper html, IObjectFacade valueNakedObject) {
            var state = valueNakedObject.GetDomainObject<bool?>();

            string img = "unset.png";
            string alt = MvcUi.TriState_NotSet;

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

            var url = new UrlHelper(html.ViewContext.RequestContext);
            var tag = new TagBuilder("img");
            tag.MergeAttribute("src", url.Content("~/Images/" + img));
            tag.MergeAttribute("alt", alt);

            return tag.ToString();
        }
        private static MvcHtmlString GetStandalone(HtmlHelper html, IObjectFacade collectionNakedObject, Func<IAssociationFacade, bool> filter, Func<IAssociationFacade, int> order, TagBuilder tag, bool withTitle) {
            Func<IObjectFacade, string> linkFunc = item => html.Object(html.ObjectTitle(item).ToString(), IdConstants.ViewAction, item.Object).ToString();

            string menu = collectionNakedObject.Specification.IsQueryable ? html.MenuOnTransient(collectionNakedObject.GetDomainObject()).ToString() : "";
            string id = collectionNakedObject.Oid == null ? "" : Encode(html.Facade().OidTranslator.GetOidTranslation(collectionNakedObject));

            // can only be standalone and hence page if we have an id 
            tag.InnerHtml += html.CollectionTable(collectionNakedObject, linkFunc, filter, order, !String.IsNullOrEmpty(id), collectionNakedObject.Specification.IsQueryable, withTitle);

            return html.WrapInForm(IdConstants.EditObjectAction,
                html.Facade().GetObjectTypeShortName(collectionNakedObject.GetDomainObject()),
                menu + tag,
                IdConstants.ActionName,
                new RouteValueDictionary(new { id }));
        }
 private static IEnumerable GetResultAsEnumerable(IObjectFacade result, IActionFacade contextAction, string propertyName) {
     if (result != null) {
         if (result.Specification.IsCollection && !ContextParameterIsCollection(contextAction, propertyName)) {
             return result.GetDomainObject<IEnumerable>();
         }
         return new List<object> {result.GetDomainObject()};
     }
     return new List<object>();
 }
        protected FileContentResult AsFile(IObjectFacade domainObject) {
            var fileAttachment = domainObject.GetAttachment();

            if (fileAttachment != null) {
                bool addHeader = !string.IsNullOrWhiteSpace(fileAttachment.ContentDisposition);

                if (addHeader) {
                    string dispositionValue = string.Format("{0}; filename={1}", fileAttachment.ContentDisposition, fileAttachment.FileName);
                    Response.AddHeader("Content-Disposition", dispositionValue);
                }

                Stream stream = fileAttachment.Content;
                using (var br = new BinaryReader(stream)) {
                    byte[] bytes = br.ReadBytes((int) stream.Length);
                    var mimeType = fileAttachment.MimeType ?? "image/bmp";

                    // need to use different File overloads or will end up with two content-disposition headers 
                    return addHeader ? File(bytes, mimeType) : File(bytes, mimeType, fileAttachment.FileName);
                }
            }
            var byteArray = domainObject.GetDomainObject<object>() as byte[];
            return File(byteArray, AttachmentContextFacade.DefaultMimeType);
        }
        private ActionResult ExecuteAction(ObjectAndControlData controlData, IObjectFacade nakedObject, IActionFacade action) {
            if (ActionExecutingAsContributed(action, nakedObject) && action.ParameterCount == 1) {
                // contributed action being invoked with a single parm that is the current target
                // no dialog - go straight through 

                var ac = new ArgumentsContextFacade {Values = new Dictionary<string, object>(), ValidateOnly = false};

                if (nakedObject.Specification.IsCollection && !nakedObject.Specification.IsParseable) {
                    var oids = nakedObject.ToEnumerable().Select(no => Facade.OidTranslator.GetOidTranslation(no)).ToArray();
                    var spec = nakedObject.ElementSpecification;

                    var ar = Facade.ExecuteListAction(oids, spec, action.Id, ac);
                    return AppropriateView(controlData, GetResult(ar), action);
                }
                else {
                    var oid = Facade.OidTranslator.GetOidTranslation(nakedObject);
                    var ar = Facade.ExecuteObjectAction(oid, action.Id, ac);

                    return AppropriateView(controlData, GetResult(ar), action);
                }
            }

            if (!action.Parameters.Any()) {
                var ac = new ArgumentsContextFacade {Values = new Dictionary<string, object>(), ValidateOnly = false};
                var oid = Facade.OidTranslator.GetOidTranslation(nakedObject);
                var result = Facade.ExecuteObjectAction(oid, action.Id, ac);

                return AppropriateView(controlData, GetResult(result), action);
            }

            SetDefaults(nakedObject, action);
            // do after any parameters set by contributed action so this takes priority
            SetSelectedParameters(action);
            SetPagingValues(controlData, nakedObject);
            var property = DisplaySingleProperty(controlData, controlData.DataDict);

            return View(property == null ? "ActionDialog" : "PropertyEdit", new FindViewModel {ContextObject = nakedObject.GetDomainObject(), ContextAction = action, PropertyName = property});
        }
        private ActionResult SelectSingleItem(IObjectFacade nakedObject, IActionFacade action, ObjectAndControlData controlData, IDictionary<string, string> selectedItem) {
            var property = DisplaySingleProperty(controlData, selectedItem);

            if (action == null) {
                SetSelectedReferences(nakedObject, selectedItem);
                return property == null ? View("ObjectEdit", nakedObject.GetDomainObject()) : View("PropertyEdit", new PropertyViewModel(nakedObject.GetDomainObject(), property));
            }
            SetSelectedParameters(nakedObject, action, selectedItem);

            return View(property == null ? "ActionDialog" : "PropertyEdit", new FindViewModel {ContextObject = nakedObject.GetDomainObject(), ContextAction = action, PropertyName = property});
        }
Esempio n. 17
0
 public static object GetChoiceValue(IOidStrategy oidStrategy, IObjectFacade item, ChoiceRelType relType, RestControlFlags flags) {
     string title = SafeGetTitle(item);
     object value = ObjectToPredefinedType(item.GetDomainObject());
     return item.Specification.IsParseable ? value : LinkRepresentation.Create(oidStrategy, relType, flags, new OptionalProperty(JsonPropertyNames.Title, title));
 }
        internal ActionResult AppropriateView(ObjectAndControlData controlData, IObjectFacade nakedObject, IActionFacade action = null, string propertyName = null) {
            if (nakedObject == null) {
                // no object to go to 
                // if action on object go to that object. 
                // if action on collection go to collection 
                // if action on service go to last object 

                nakedObject = controlData.GetNakedObject(Facade);

                if (nakedObject.Specification.IsService) {
                    object lastObject = Session.LastObject(Facade, ObjectCache.ObjectFlag.BreadCrumb);
                    if (lastObject == null) {
                        return RedirectHome();
                    }

                    nakedObject = Facade.GetObject(lastObject);                  
                }

                if (nakedObject.IsCollectionMemento) {
                    // if we have returned null and existing object is collection memento need to make 
                    // sure action remains action from original collectionMemento.
                    action = nakedObject.MementoAction;
                }

            }

            if (nakedObject.Specification.IsCollection && !nakedObject.Specification.IsParseable) {
                int collectionSize = nakedObject.Count();
                if (collectionSize == 1) {
                    // remove any paging data - to catch case where custom page has embedded standalone collection as paging data will confuse rendering 
                    ViewData.Remove(IdConstants.PagingData);
                    // is this safe TODO !!
                    return View("ObjectView", nakedObject.ToEnumerable().First().GetDomainObject());
                }

                nakedObject = Page(nakedObject, collectionSize, controlData);
                // todo is there a better way to do this ?
                action = action ?? nakedObject.MementoAction;
                int page, pageSize;
                CurrentlyPaging(controlData, collectionSize, out page, out pageSize);
                var format = ViewData["NofCollectionFormat"] as string;
                return View("StandaloneTable", ActionResultModel.Create(Facade, action, nakedObject, page, pageSize, format));
            }
            // remove any paging data - to catch case where custom page has embedded standalone collection as paging data will confuse rendering   
            ViewData.Remove(IdConstants.PagingData);

            if (controlData.DataDict.Values.Contains("max")) {
                // maximizing an inline object - do not update history
                ViewData.Add("updateHistory", false);
            }

            return propertyName == null ? View(nakedObject.IsNotPersistent ? "ObjectView" : "ViewNameSetAfterTransaction", nakedObject.GetDomainObject()) :
                View(nakedObject.IsNotPersistent ? "PropertyView" : "ViewNameSetAfterTransaction", new PropertyViewModel(nakedObject.GetDomainObject(), propertyName));
        }
 private ActionResult View(IObjectFacade nakedObject) {
     string viewName = nakedObject.IsViewModelEditView ? "ViewModel" : "ObjectView";
     return View(viewName, nakedObject.GetDomainObject());
 }
Esempio n. 20
0
        internal ActionResult AppropriateView(ObjectAndControlData controlData, IObjectFacade nakedObject, IActionFacade action = null, string propertyName = null)
        {
            if (nakedObject == null)
            {
                // no object to go to
                // if action on object go to that object.
                // if action on collection go to collection
                // if action on service go to last object

                nakedObject = controlData.GetNakedObject(Facade);

                if (nakedObject.Specification.IsService)
                {
                    object lastObject = Session.LastObject(Facade, ObjectCache.ObjectFlag.BreadCrumb);
                    if (lastObject == null)
                    {
                        return(RedirectHome());
                    }

                    nakedObject = Facade.GetObject(lastObject);
                }

                if (nakedObject.IsCollectionMemento)
                {
                    // if we have returned null and existing object is collection memento need to make
                    // sure action remains action from original collectionMemento.
                    action = nakedObject.MementoAction;
                }
            }

            if (nakedObject.Specification.IsCollection && !nakedObject.Specification.IsParseable)
            {
                int collectionSize = nakedObject.Count();
                if (collectionSize == 1)
                {
                    // remove any paging data - to catch case where custom page has embedded standalone collection as paging data will confuse rendering
                    ViewData.Remove(IdConstants.PagingData);
                    // is this safe TODO !!
                    return(View("ObjectView", nakedObject.ToEnumerable().First().GetDomainObject()));
                }

                nakedObject = Page(nakedObject, collectionSize, controlData);
                // todo is there a better way to do this ?
                action = action ?? nakedObject.MementoAction;
                int page, pageSize;
                CurrentlyPaging(controlData, collectionSize, out page, out pageSize);
                var format = ViewData["NofCollectionFormat"] as string;
                return(View("StandaloneTable", ActionResultModel.Create(Facade, action, nakedObject, page, pageSize, format)));
            }
            // remove any paging data - to catch case where custom page has embedded standalone collection as paging data will confuse rendering
            ViewData.Remove(IdConstants.PagingData);

            if (controlData.DataDict.Values.Contains("max"))
            {
                // maximizing an inline object - do not update history
                ViewData.Add("updateHistory", false);
            }

            return(propertyName == null?View(nakedObject.IsNotPersistent? "ObjectView" : "ViewNameSetAfterTransaction", nakedObject.GetDomainObject()) :
                       View(nakedObject.IsNotPersistent ? "PropertyView" : "ViewNameSetAfterTransaction", new PropertyViewModel(nakedObject.GetDomainObject(), propertyName)));
        }
Esempio n. 21
0
        private ActionResult View(IObjectFacade nakedObject)
        {
            string viewName = nakedObject.IsViewModelEditView ? "ViewModel" : "ObjectView";

            return(View(viewName, nakedObject.GetDomainObject()));
        }