public UriMtHelper(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyTypeContextFacade propertyContext)
     : this(oidStrategy ,req) {
     assoc = propertyContext.Property;
     spec = propertyContext.OwningSpecification;
     cachedId = "";
     CachedType = spec.DomainTypeName(oidStrategy);
 }
Example #2
0
        public ActionResult SearchTypeList(TypeSearchFilter searchFilter)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Search Type").ToInputLogString());

            try
            {
                if (ModelState.IsValid)
                {
                    _typeFacade = new TypeFacade();
                    TypeViewModel typeVm = new TypeViewModel();
                    typeVm.SearchFilter = searchFilter;

                    typeVm.TypeList  = _typeFacade.GetTypeList(typeVm.SearchFilter);
                    ViewBag.PageSize = typeVm.SearchFilter.PageSize;

                    return(PartialView("~/Views/Type/_TypeList.cshtml", typeVm));
                }

                return(Json(new
                {
                    Valid = false,
                    Error = string.Empty
                }));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Search Type").Add("Error Message", ex.Message).ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }
 public UriMtHelper(IOidStrategy oidStrategy, HttpRequestMessage req, ITypeFacade spec)
     : this(oidStrategy, req)
 {
     this.spec  = spec;
     cachedId   = "";
     CachedType = RestUtils.SpecToPredefinedTypeString(spec, oidStrategy);
 }
 public UriMtHelper(IOidStrategy oidStrategy, HttpRequestMessage req, IObjectFacade objectFacade) : this(oidStrategy ,req) {
     this.objectFacade = objectFacade;
     spec = objectFacade.Specification;
     IOidTranslation oid = oidStrategy.FrameworkFacade.OidTranslator.GetOidTranslation(objectFacade);
     cachedId = oid.InstanceId;
     CachedType = oid.DomainType;
 }
Example #5
0
        public static Tuple <string, string> SpecToTypeAndFormatString(ITypeFacade spec, IOidStrategy oidStrategy)
        {
            PredefinedType?pdt = SpecToPredefinedType(spec);

            if (pdt.HasValue)
            {
                switch (pdt.Value)
                {
                case PredefinedType.Number:
                    return(new Tuple <string, string>(pdt.Value.ToRoString(), PredefinedType.Decimal.ToRoString()));

                case PredefinedType.Integer:
                    return(new Tuple <string, string>(PredefinedType.Number.ToRoString(), pdt.Value.ToRoString()));

                case PredefinedType.Boolean:
                    return(new Tuple <string, string>(pdt.Value.ToRoString(), null));

                case PredefinedType.List:
                    return(new Tuple <string, string>(PredefinedType.List.ToRoString(), null));

                case PredefinedType.Set:
                    return(new Tuple <string, string>(PredefinedType.Set.ToRoString(), null));

                case PredefinedType.String:
                    return(new Tuple <string, string>(pdt.Value.ToRoString(), pdt.Value.ToRoString()));

                case PredefinedType.Void:
                    return(new Tuple <string, string>(null, null));

                default:
                    return(new Tuple <string, string>(PredefinedType.String.ToRoString(), pdt.Value.ToRoString()));
                }
            }
            return(new Tuple <string, string>(spec.DomainTypeName(oidStrategy), null));
        }
        private void SetLinks(HttpRequestMessage req, ITypeFacade spec, RelType parentRelType) {
            var tempLinks = new List<LinkRepresentation> {
                LinkRepresentation.Create(OidStrategy, parentRelType, Flags),
                LinkRepresentation.Create(OidStrategy, SelfRelType, Flags)
            };

            Links = tempLinks.ToArray();
        }
 public UriMtHelper(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyTypeContextFacade propertyContext)
     : this(oidStrategy, req)
 {
     assoc      = propertyContext.Property;
     spec       = propertyContext.OwningSpecification;
     cachedId   = "";
     CachedType = spec.DomainTypeName(oidStrategy);
 }
 public UriMtHelper(IOidStrategy oidStrategy, HttpRequestMessage req, ActionTypeContextFacade actionTypeContext)
     : this(oidStrategy, req)
 {
     action     = actionTypeContext.ActionContext.Action;
     spec       = actionTypeContext.OwningSpecification;
     cachedId   = "";
     CachedType = spec.DomainTypeName(oidStrategy);
 }
 private ListRepresentation(IOidStrategy oidStrategy, ITypeFacade[] specs, HttpRequestMessage req, RestControlFlags flags)
     : base(oidStrategy, flags) {
     Value = specs.Select(s => CreateDomainLink(oidStrategy, req, s)).ToArray();
     SelfRelType = new TypesRelType(RelValues.Self, new UriMtHelper(oidStrategy, req));
     SetLinks(req);
     SetExtensions();
     SetHeader(true);
 }
        public void AddListRepresentationParameter(MediaTypeHeaderValue mediaType, RestControlFlags flags)
        {
            ITypeFacade specToUse      = param == null ? spec : param.Specification;
            string      typeName       = specToUse == null ? typeof(object).FullName : specToUse.DomainTypeName(oidStrategy);
            string      parameterValue = GetParameterValue(flags, typeName);

            mediaType.Parameters.Add(new NameValueHeaderValue(RestControlFlags.ElementTypeReserved, string.Format("\"{0}\"", parameterValue)));
        }
 private void SetScalars(ITypeFacade spec) {
     Name = spec.FullName;
     DomainType = spec.DomainTypeName(OidStrategy);
     FriendlyName = spec.SingularName;
     PluralName = spec.PluralName;
     Description = spec.Description;
     IsService = spec.IsService;
 }
 public UriMtHelper(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyContextFacade propertyContext)
     : this(oidStrategy ,req) {
     assoc = propertyContext.Property;
     objectFacade = propertyContext.Target;
     spec = objectFacade.Specification;
     IOidTranslation oid = oidStrategy.FrameworkFacade.OidTranslator.GetOidTranslation(objectFacade);
     cachedId = oid.InstanceId;
     CachedType = oid.DomainType;
 }
Example #13
0
 public static string SpecToPredefinedTypeString(ITypeFacade spec, IOidStrategy oidStrategy, bool useDateOverDateTime = false)
 {
     if (!spec.IsVoid)
     {
         var pdt = SpecToPredefinedTypes(spec);
         return(pdt != null?pdt.Item1.ToRoString() : spec.DomainTypeName(oidStrategy));
     }
     return(null);
 }
 private void SetScalars(ITypeFacade spec)
 {
     Name         = spec.FullName;
     DomainType   = spec.DomainTypeName(OidStrategy);
     FriendlyName = spec.SingularName;
     PluralName   = spec.PluralName;
     Description  = spec.Description;
     IsService    = spec.IsService;
 }
Example #15
0
        private void SetLinks(HttpRequestMessage req, ITypeFacade spec, RelType parentRelType)
        {
            var tempLinks = new List <LinkRepresentation> {
                LinkRepresentation.Create(OidStrategy, parentRelType, Flags),
                LinkRepresentation.Create(OidStrategy, SelfRelType, Flags)
            };

            Links = tempLinks.ToArray();
        }
        public UriMtHelper(IOidStrategy oidStrategy, HttpRequestMessage req, IObjectFacade objectFacade) : this(oidStrategy, req)
        {
            this.objectFacade = objectFacade;
            spec = objectFacade.Specification;
            IOidTranslation oid = oidStrategy.FrameworkFacade.OidTranslator.GetOidTranslation(objectFacade);

            cachedId   = oid.InstanceId;
            CachedType = oid.DomainType;
        }
        private void SetLinks(HttpRequestMessage req, ITypeFacade spec) {
            var tempLinks = new List<LinkRepresentation>();

            if (Flags.FormalDomainModel) {
                tempLinks.Add(LinkRepresentation.Create(OidStrategy, new DomainTypeRelType(RelValues.ElementType, new UriMtHelper(OidStrategy, req, spec)), Flags));
            }

            Links = tempLinks.ToArray();
        }
Example #18
0
 public static bool IsBlobOrClob(ITypeFacade spec)
 {
     if (spec.IsParseable || spec.IsCollection)
     {
         Type underlyingType      = spec.GetUnderlyingType();
         PredefinedFormatType?pdt = TypeToPredefinedFormatType(underlyingType);
         return(pdt == PredefinedFormatType.Blob || pdt == PredefinedFormatType.Clob);
     }
     return(false);
 }
 public UriMtHelper(IOidStrategy oidStrategy, HttpRequestMessage req, IObjectFacade objectFacade, string instanceId) : this(oidStrategy, req) {
     this.objectFacade = objectFacade;
     spec = objectFacade.Specification;
     if (objectFacade.Specification.IsParseable) {
         throw new ArgumentException($"Cannot build URI  for parseable specification : {objectFacade.Specification.FullName}");
     }
     IOidTranslation oid = oidStrategy.FrameworkFacade.OidTranslator.GetOidTranslation(objectFacade);
     cachedId = instanceId;
     CachedType = oid.DomainType;
 }
Example #20
0
        public IActionFacade[] GetLocallyContributedActions(ITypeFacade typeFacade, string id)
        {
            var objectSpec = WrappedValue as IObjectSpec;

            if (objectSpec != null)
            {
                return(objectSpec.GetLocallyContributedActions(((TypeFacade)typeFacade).WrappedValue, id).Select(a => new ActionFacade(a, FrameworkFacade, framework, "")).Cast <IActionFacade>().ToArray());
            }
            return(new IActionFacade[] { });
        }
Example #21
0
        private object GetCompletionData(IObjectFacade nakedObject, ITypeFacade spec)
        {
            string label = nakedObject.TitleString;
            string value = nakedObject.TitleString;
            string link  = spec.IsParseable ? label : Facade.OidTranslator.GetOidTranslation(nakedObject).ToString();
            string src   = GetIconSrc(nakedObject);
            string alt   = GetIconAlt(nakedObject);

            return(new { label, value, link, src, alt });
        }
Example #22
0
        public JsonResult SaveType(TypeSaveViewModel typeSaveVM)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Type Save").ToInputLogString());
            try
            {
                if (ModelState.IsValid)
                {
                    TypeItemEntity typeEntity = new TypeItemEntity
                    {
                        TypeId     = typeSaveVM.TypeId,
                        TypeName   = typeSaveVM.TypeName,
                        TypeCode   = typeSaveVM.TypeCode,
                        Status     = typeSaveVM.Status,
                        UserId     = UserInfo.UserId,
                        CreateUser = typeSaveVM.CreateUser,
                        CreateDate = typeSaveVM.CreateDate
                    };

                    _typeFacade = new TypeFacade();

                    if (typeEntity.TypeName.Length <= 100 && typeEntity.TypeName.Length > 0)
                    {
                        var checkType = _typeFacade.CheckTypeName(typeEntity);

                        if (checkType == false)
                        {
                            return(Json(new { is_success = false, message = "ชื่อ Type ซ้ำ" }));
                        }
                        else
                        {
                            var isSuccess = _typeFacade.SaveType(typeEntity);
                            return(isSuccess
                                ? Json(new { is_success = true, message = "บันทึก Type สำเร็จ" })
                                : Json(new { is_success = false, message = "บันทึก Type ไม่สำเร็จ" }));
                        }
                    }
                    else
                    {
                        return(Json(new { is_success = false, message = "ชื่อ Type ต้องมากกว่าหรือเท่ากับ 1 ตัวอักษร และไม่เกิน 100 ตัวอักษร" }));
                    }
                }

                return(Json(new
                {
                    is_success = false,
                    message = string.Empty
                }));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Type Save").Add("Error Message", ex.Message).ToFailLogString());
                return(Json(new { is_success = false, message = string.Format(CultureInfo.InvariantCulture, "Error : {0}", ex.Message) }));
            }
        }
        public UriMtHelper(IOidStrategy oidStrategy, HttpRequestMessage req, ActionContextFacade actionContext)
            : this(oidStrategy, req)
        {
            action       = actionContext.Action;
            objectFacade = actionContext.Target;
            spec         = objectFacade.Specification;
            IOidTranslation oid = oidStrategy.FrameworkFacade.OidTranslator.GetOidTranslation(objectFacade);

            cachedId   = oid.InstanceId;
            CachedType = oid.DomainType;
        }
Example #24
0
        public RestSnapshot(IOidStrategy oidStrategy, ITypeFacade spec, HttpRequestMessage req, RestControlFlags flags)
            : this(oidStrategy, req, true)
        {
            logger.DebugFormat("RestSnapshot:DomainType");


            populator = () => {
                representation = DomainTypeRepresentation.Create(oidStrategy, req, spec, flags);
                SetHeaders();
            };
        }
Example #25
0
        private void SetLinks(HttpRequestMessage req, ITypeFacade spec)
        {
            var tempLinks = new List <LinkRepresentation>();

            if (Flags.FormalDomainModel)
            {
                tempLinks.Add(LinkRepresentation.Create(OidStrategy, new DomainTypeRelType(RelValues.ElementType, new UriMtHelper(OidStrategy, req, spec)), Flags));
            }

            Links = tempLinks.ToArray();
        }
 protected DomainTypeRepresentation(IOidStrategy oidStrategy, HttpRequestMessage req, ITypeFacade spec, RestControlFlags flags)
     : base(oidStrategy, flags) {
     var helper = new UriMtHelper(oidStrategy, req, spec);
     SelfRelType = new DomainTypeRelType(RelValues.Self, helper);
     SetScalars(spec);
     SetLinks(helper);
     SetMembers(spec, req);
     SetTypeActions(spec, req);
     SetExtensions();
     SetHeader();
 }
 private string GetParameterValue(RestControlFlags flags, ITypeFacade parameterValueSpec)
 {
     if (flags.SimpleDomainModel)
     {
         return(RestUtils.SpecToTypeAndFormatString(parameterValueSpec, oidStrategy).Item1);
     }
     if (flags.FormalDomainModel)
     {
         return(BuildDomainTypeUri(RestUtils.SpecToPredefinedTypeString(parameterValueSpec, oidStrategy)).ToString());
     }
     return(null);
 }
 public UriMtHelper(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyContextFacade propertyContext)
     : this(oidStrategy, req) {
     assoc = propertyContext.Property;
     objectFacade = propertyContext.Target;
     spec = objectFacade.Specification;
     if (objectFacade.Specification.IsParseable) {
         throw new ArgumentException($"Cannot build URI  for parseable specification : {objectFacade.Specification.FullName}");
     }
     IOidTranslation oid = oidStrategy.FrameworkFacade.OidTranslator.GetOidTranslation(objectFacade);
     cachedId = propertyContext.Target.IsTransient ? "" : oid.InstanceId;
     CachedType = oid.DomainType;
 }
Example #29
0
        public UriMtHelper(IOidStrategy oidStrategy, HttpRequestMessage req, IObjectFacade objectFacade, string instanceId) : this(oidStrategy, req)
        {
            this.objectFacade = objectFacade;
            spec = objectFacade.Specification;
            if (objectFacade.Specification.IsParseable)
            {
                throw new ArgumentException($"Cannot build URI  for parseable specification : {objectFacade.Specification.FullName}");
            }
            IOidTranslation oid = oidStrategy.FrameworkFacade.OidTranslator.GetOidTranslation(objectFacade);

            cachedId   = instanceId;
            CachedType = oid.DomainType;
        }
        public void AddActionResultRepresentationParameter(MediaTypeHeaderValue mediaType, RestControlFlags flags)
        {
            ITypeFacade resultSpec         = action.ReturnType;
            bool        isCollection       = resultSpec.IsCollection && !resultSpec.IsParseable;
            ITypeFacade parameterValueSpec = isCollection ? action.ElementType : resultSpec;
            string      parameterValue     = GetParameterValue(flags, parameterValueSpec);

            if (parameterValue != null)
            {
                string parameterType = isCollection ? RestControlFlags.ElementTypeReserved : RestControlFlags.DomainTypeReserved;
                mediaType.Parameters.Add(new NameValueHeaderValue(parameterType, string.Format("\"{0}\"", parameterValue)));
            }
        }
Example #31
0
        public static Tuple <string, string> SpecToTypeAndFormatString(ITypeFacade spec, IOidStrategy oidStrategy, bool useDateOverDateTime)
        {
            var types = SpecToPredefinedTypes(spec, useDateOverDateTime);

            if (types != null)
            {
                var pdtString = types.Item1.ToRoString();
                var pftString = types.Item2.HasValue ? types.Item2.Value.ToRoString() : null;

                return(new Tuple <string, string>(pdtString, pftString));
            }
            return(new Tuple <string, string>(spec.DomainTypeName(oidStrategy), null));
        }
Example #32
0
        public static PredefinedType?SpecToPredefinedType(ITypeFacade spec)
        {
            if (spec.IsFileAttachment || spec.IsImage)
            {
                return(PredefinedType.Blob);
            }

            if (spec.IsParseable || spec.IsCollection || spec.IsVoid)
            {
                Type underlyingType = spec.GetUnderlyingType();
                return(TypeToPredefinedType(underlyingType));
            }
            return(null);
        }
Example #33
0
        public UriMtHelper(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyContextFacade propertyContext)
            : this(oidStrategy, req)
        {
            assoc        = propertyContext.Property;
            objectFacade = propertyContext.Target;
            spec         = objectFacade.Specification;
            if (objectFacade.Specification.IsParseable)
            {
                throw new ArgumentException($"Cannot build URI  for parseable specification : {objectFacade.Specification.FullName}");
            }
            IOidTranslation oid = oidStrategy.FrameworkFacade.OidTranslator.GetOidTranslation(objectFacade);

            cachedId   = propertyContext.Target.IsTransient ? "" : oid.InstanceId;
            CachedType = oid.DomainType;
        }
 private void SetTypeActions(ITypeFacade spec, HttpRequestMessage req) {
     TypeActions = new[] {
         LinkRepresentation.Create(OidStrategy, new TypeActionRelType(new UriMtHelper(OidStrategy, req, spec), WellKnownIds.IsSubtypeOf), Flags,
             new OptionalProperty(JsonPropertyNames.Id, WellKnownIds.IsSubtypeOf),
             new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.SuperType, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Href, null, typeof (object))))))),
         LinkRepresentation.Create(OidStrategy, new TypeActionRelType(new UriMtHelper(OidStrategy, req, spec), WellKnownIds.IsSupertypeOf), Flags,
             new OptionalProperty(JsonPropertyNames.Id, WellKnownIds.IsSupertypeOf),
             new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.SubType, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Href, null, typeof (object))))))),
         
         // extensions to 1.1 spec    
         LinkRepresentation.Create(OidStrategy, new TypeActionRelType(new UriMtHelper(OidStrategy, req, spec), WellKnownIds.FilterSubtypesFrom), Flags,
             new OptionalProperty(JsonPropertyNames.Id, WellKnownIds.FilterSubtypesFrom),
             new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.SubTypes, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Href, null, typeof (object))))))),
         LinkRepresentation.Create(OidStrategy, new TypeActionRelType(new UriMtHelper(OidStrategy, req, spec), WellKnownIds.FilterSupertypesFrom), Flags,
             new OptionalProperty(JsonPropertyNames.Id, WellKnownIds.FilterSupertypesFrom),
             new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.SuperTypes, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Href, null, typeof (object)))))))
     };
 }
        private void SetTypeActions(ITypeFacade spec, HttpRequestMessage req)
        {
            TypeActions = new[] {
                LinkRepresentation.Create(OidStrategy, new TypeActionRelType(new UriMtHelper(OidStrategy, req, spec), WellKnownIds.IsSubtypeOf), Flags,
                                          new OptionalProperty(JsonPropertyNames.Id, WellKnownIds.IsSubtypeOf),
                                          new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.SuperType, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Href, null, typeof(object))))))),
                LinkRepresentation.Create(OidStrategy, new TypeActionRelType(new UriMtHelper(OidStrategy, req, spec), WellKnownIds.IsSupertypeOf), Flags,
                                          new OptionalProperty(JsonPropertyNames.Id, WellKnownIds.IsSupertypeOf),
                                          new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.SubType, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Href, null, typeof(object))))))),

                // extensions to 1.1 spec
                LinkRepresentation.Create(OidStrategy, new TypeActionRelType(new UriMtHelper(OidStrategy, req, spec), WellKnownIds.FilterSubtypesFrom), Flags,
                                          new OptionalProperty(JsonPropertyNames.Id, WellKnownIds.FilterSubtypesFrom),
                                          new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.SubTypes, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Href, null, typeof(object))))))),
                LinkRepresentation.Create(OidStrategy, new TypeActionRelType(new UriMtHelper(OidStrategy, req, spec), WellKnownIds.FilterSupertypesFrom), Flags,
                                          new OptionalProperty(JsonPropertyNames.Id, WellKnownIds.FilterSupertypesFrom),
                                          new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.SuperTypes, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Href, null, typeof(object)))))))
            };
        }
        private void SetMembers(ITypeFacade spec, HttpRequestMessage req)
        {
            IAssociationFacade[] properties  = spec.Properties.Where(p => !p.IsCollection).ToArray();
            IAssociationFacade[] collections = spec.Properties.Where(p => p.IsCollection).ToArray();
            IActionFacade[]      actions     = spec.GetActionLeafNodes();

            IEnumerable <LinkRepresentation> propertyMembers = properties.Select(p => LinkRepresentation.Create(OidStrategy, new TypeMemberRelType(RelValues.Property, new UriMtHelper(OidStrategy, req, new PropertyTypeContextFacade {
                Property = p, OwningSpecification = spec
            })), Flags));
            IEnumerable <LinkRepresentation> collectionMembers = collections.Select(c => LinkRepresentation.Create(OidStrategy, new TypeMemberRelType(RelValues.Collection, new UriMtHelper(OidStrategy, req, new PropertyTypeContextFacade {
                Property = c, OwningSpecification = spec
            })), Flags));
            IEnumerable <LinkRepresentation> actionMembers = actions.Select(a => LinkRepresentation.Create(OidStrategy, new TypeMemberRelType(RelValues.Action, new UriMtHelper(OidStrategy, req, new ActionTypeContextFacade {
                ActionContext = new ActionContextFacade {
                    Action = a
                }, OwningSpecification = spec
            })), Flags));

            Members = propertyMembers.Union(collectionMembers).Union(actionMembers).ToArray();
        }
        protected static void AddStringProperties(ITypeFacade spec, int?maxLength, string pattern, Dictionary <string, object> exts)
        {
            if (spec.IsParseable)
            {
                if (maxLength != null)
                {
                    exts.Add(JsonPropertyNames.MaxLength, maxLength);
                }

                if (!string.IsNullOrEmpty(pattern))
                {
                    exts.Add(JsonPropertyNames.Pattern, pattern);
                }

                if (spec.IsDateTime)
                {
                    exts.Add(JsonPropertyNames.Format, PredefinedType.Date_time.ToRoString());
                }
            }
        }
Example #38
0
 private bool GetValue(string[] values, ITypeFacade spec, bool nullEmpty, out object domainObject)
 {
     if (!values.Any())
     {
         domainObject = null;
         return(true);
     }
     if (spec.IsParseable)
     {
         var v = values.First();
         domainObject = nullEmpty && string.IsNullOrEmpty(v) ? null : v;
         return(true);
     }
     if (!spec.IsCollection)
     {
         domainObject = GetNakedObjectFromId(values.First()).GetDomainObject <object>();
         return(true);
     }
     domainObject = null;
     return(false);
 }
Example #39
0
        public ActionResult Edit(int TypeId)
        {
            var list = new TypeViewModel();

            list.TypeIsActiveList = new List <SelectListItem>();
            list.TypeIsActiveList.Add(new SelectListItem()
            {
                Text = "Active", Value = "true"
            });
            list.TypeIsActiveList.Add(new SelectListItem()
            {
                Text = "Inactive", Value = "false"
            });

            var typeVM = new TypeViewModel();

            _typeFacade = new TypeFacade();

            if (TypeId != null && TypeId != 0)
            {
                var typeItemEntity = _typeFacade.GetTypeById(TypeId);

                typeVM.TypeId   = typeItemEntity.TypeId;
                typeVM.TypeName = typeItemEntity.TypeName;
                typeVM.TypeCode = typeItemEntity.TypeCode;
                typeVM.Status   = typeItemEntity.Status;

                typeVM.CreateDate = DateUtil.ToStringAsDateTime(typeItemEntity.CreateDate);
                typeVM.UpdateDate = DateUtil.ToStringAsDateTime(typeItemEntity.UpdateDate);

                typeVM.CreateUserName   = typeItemEntity.CreateUserName;
                typeVM.UpdateUserName   = typeItemEntity.UpdateUserName;
                typeVM.TypeIsActiveList = list.TypeIsActiveList;
                typeVM.CreateUser       = typeItemEntity.CreateUser;
                typeVM.UpdateUser       = typeItemEntity.UpdateUser;
            }

            return(View(typeVM));
        }
 private object GetValue(string[] values, IAssociationFacade propertySpec, ITypeFacade spec) {
     object domainObject;
     return GetValue(values, spec, false, out domainObject) ? domainObject : Facade.GetTypedCollection(propertySpec, values);
 }
 private static string GetCode(ITypeFacade spec) {
     return GetCode(FacadeUtils.GetType(spec.FullName));
 }
        private static object GetTypedCollection(IFrameworkFacade surface, IEnumerable collectionValue, ITypeFacade collectionitemSpec)
        {
            string[] rawCollection = collectionValue.Cast <string>().ToArray();

            Type instanceType    = collectionitemSpec.GetUnderlyingType();
            var  typedCollection = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(instanceType));

            if (collectionitemSpec.IsParseable)
            {
                return(rawCollection.Select(s => string.IsNullOrEmpty(s) ? null : s).ToArray());
            }

            // need to check if collection is actually a collection memento
            if (rawCollection.Count() == 1)
            {
                var firstObj = GetNakedObjectFromId(surface, rawCollection.First());

                if (firstObj != null && firstObj.IsCollectionMemento)
                {
                    return(firstObj.Object);
                }
            }

            var objCollection = rawCollection.Select(s => GetNakedObjectFromId(surface, s).Object).ToArray();

            objCollection.Where(o => o != null).ForEach(o => typedCollection.Add(o));

            return(typedCollection.AsQueryable());
        }
 private IEnumerable<IObjectFacade> GetRecentlyViewed(ITypeFacade type, string autoCompleteParm) {
     var allcached = Session.CachedObjectsOfType(Facade,type).Select(o => Facade.GetObject(o));
     return string.IsNullOrWhiteSpace(autoCompleteParm) ? allcached : allcached.Where(of => of.TitleString.ToUpper().Contains(autoCompleteParm.Trim().ToUpper()));
 }
        public static Tuple<PredefinedJsonType, PredefinedFormatType?> SpecToPredefinedTypes(ITypeFacade spec, bool useDateOverDateTime = false) {
            if (spec.IsFileAttachment || spec.IsImage) {
                return new Tuple<PredefinedJsonType, PredefinedFormatType?>(PredefinedJsonType.String, PredefinedFormatType.Blob);
            }

            if (spec.IsParseable || spec.IsCollection || spec.IsVoid) {
                Type underlyingType = spec.GetUnderlyingType();
                return TypeToPredefinedTypes(underlyingType, useDateOverDateTime);
            }
            return null;
        }
 public ChoiceContextFacade(string id, ITypeFacade spec) {
     this.id = id;
     this.spec = spec;
 }
        public RestSnapshot(IOidStrategy oidStrategy, ITypeFacade spec, HttpRequestMessage req, RestControlFlags flags)
            : this(oidStrategy,req, true) {
            logger.DebugFormat("RestSnapshot:DomainType");


            populator = () => {
                representation = DomainTypeRepresentation.Create(oidStrategy ,req, spec, flags);
                SetHeaders();
            };
        }
 public static DomainTypeRepresentation Create(IOidStrategy oidStrategy, HttpRequestMessage req, ITypeFacade spec, RestControlFlags flags) {
     return new DomainTypeRepresentation(oidStrategy ,req, spec, flags);
 }
 private bool GetValue(string[] values, ITypeFacade spec, bool nullEmpty, out object domainObject) {
     if (!values.Any()) {
         domainObject = null;
         return true;
     }
     if (spec.IsParseable) {
         var v = values.First();
         domainObject = nullEmpty && string.IsNullOrEmpty(v) ? null : v;
         return true;
     }
     if (!spec.IsCollection) {
         domainObject = GetNakedObjectFromId(values.First()).GetDomainObject<object>();
         return true;
     }
     domainObject = null;
     return false;
 }
 private object GetCompletionData(IObjectFacade nakedObject, ITypeFacade spec) {
     string label = nakedObject.TitleString;
     string value = nakedObject.TitleString;
     string link = spec.IsParseable ? label : Facade.OidTranslator.GetOidTranslation(nakedObject).ToString();
     string src = GetIconSrc(nakedObject);
     string alt = GetIconAlt(nakedObject);
     return new {label, value, link, src, alt};
 }
 public static string SpecToPredefinedTypeString(ITypeFacade spec, IOidStrategy oidStrategy, bool useDateOverDateTime = false) {
     if (!spec.IsVoid) {
         var pdt = SpecToPredefinedTypes(spec);
         return pdt != null ? pdt.Item1.ToRoString() : spec.DomainTypeName(oidStrategy);
     }
     return null;
 }
 private object GetValue(string[] values, IActionParameterFacade parameterSpec, ITypeFacade spec) {
     object domainObject;
     return GetValue(values, spec, true, out domainObject) ? domainObject : Facade.GetTypedCollection(parameterSpec, values);
 }
 public static bool IsPredefined(ITypeFacade spec) {
     var pdts = SpecToPredefinedTypes(spec);
     return pdts != null;
 }
 private LinkRepresentation CreateDomainLink(IOidStrategy oidStrategy, HttpRequestMessage req, ITypeFacade spec) {
     return LinkRepresentation.Create(oidStrategy, new DomainTypeRelType(new UriMtHelper(oidStrategy, req, spec)), Flags);
 }
        public static Tuple<string, string> SpecToTypeAndFormatString(ITypeFacade spec, IOidStrategy oidStrategy, bool useDateOverDateTime) {
            var types = SpecToPredefinedTypes(spec, useDateOverDateTime);

            if (types != null) {
                var pdtString = types.Item1.ToRoString();
                var pftString = types.Item2.HasValue ? types.Item2.Value.ToRoString() : null;

                return new Tuple<string, string>(pdtString, pftString);
            }
            return new Tuple<string, string>(spec.DomainTypeName(oidStrategy), null);
        }
 public bool Equals(ITypeFacade other)
 {
     return(Equals((object)other));
 }
 public static bool IsBlobOrClob(ITypeFacade spec) {
     if (spec.IsParseable || spec.IsCollection) {
         Type underlyingType = spec.GetUnderlyingType();
         PredefinedFormatType? pdt = TypeToPredefinedFormatType(underlyingType);
         return pdt == PredefinedFormatType.Blob || pdt == PredefinedFormatType.Clob;
     }
     return false;
 }
 public string GetLinkDomainTypeBySpecification(ITypeFacade spec) {
     throw new NotImplementedException();
 }
 public static bool IsAttachment(ITypeFacade spec) {
     return (spec.IsImage || spec.IsFileAttachment);
 }
 public string GetLinkDomainTypeBySpecification(ITypeFacade spec) {
     return GetCode(spec);
 }
        public static MapRepresentation GetExtensions(string friendlyname,
                                                      string description,
                                                      string pluralName,
                                                      string domainType,
                                                      bool? isService,
                                                      bool? hasParams,
                                                      bool? optional,
                                                      int? maxLength,
                                                      string pattern,
                                                      int? memberOrder,
                                                      DataType? dataType,
                                                      string presentationHint,
                                                      IDictionary<string, object> customExtensions,
                                                      ITypeFacade returnType,
                                                      ITypeFacade elementType,
                                                      IOidStrategy oidStrategy,
                                                      bool useDateOverDateTime) {
            var exts = new Dictionary<string, object> {
                {JsonPropertyNames.FriendlyName, friendlyname},
                {JsonPropertyNames.Description, description}
            };

            if (pluralName != null) {
                exts.Add(JsonPropertyNames.PluralName, pluralName);
            }

            if (domainType != null) {
                exts.Add(JsonPropertyNames.DomainType, domainType);
            }

            if (hasParams != null) {
                exts.Add(JsonPropertyNames.HasParams, hasParams);
            }

            if (isService != null) {
                exts.Add(JsonPropertyNames.IsService, isService);
            }

            if (optional != null) {
                exts.Add(JsonPropertyNames.Optional, optional);
            }

            if (memberOrder != null) {
                exts.Add(JsonPropertyNames.MemberOrder, memberOrder);
            }

            if (dataType != null) {
                exts.Add(JsonPropertyNames.CustomDataType, dataType.ToString().ToLower());
            }

            if (!string.IsNullOrEmpty(presentationHint)) {
                exts.Add(JsonPropertyNames.PresentationHint, presentationHint);
            }


            if (returnType != null && !returnType.IsVoid) {
                Tuple<string, string> jsonDataType = SpecToTypeAndFormatString(returnType, oidStrategy, useDateOverDateTime);
                exts.Add(JsonPropertyNames.ReturnType, jsonDataType.Item1);

                if (jsonDataType.Item2 != null) {
                    exts.Add(JsonPropertyNames.Format, jsonDataType.Item2);
                }

                if (jsonDataType.Item1 == PredefinedJsonType.String.ToRoString()) {
                    exts.Add(JsonPropertyNames.MaxLength, maxLength ?? 0);
                    exts.Add(JsonPropertyNames.Pattern, pattern ?? "");
                }
                // blob and clobs are arrays hence additional checks
                else if (returnType.IsCollection && (jsonDataType.Item1 == PredefinedJsonType.List.ToRoString() || jsonDataType.Item1 == PredefinedJsonType.Set.ToRoString())) {
                    exts.Add(JsonPropertyNames.ElementType, SpecToTypeAndFormatString(elementType, oidStrategy, useDateOverDateTime).Item1);
                    exts.Add(JsonPropertyNames.PluralName, elementType.PluralName);
                }
            }

            if (customExtensions != null) {
                foreach (var kvp in customExtensions) {
                    exts.Add(kvp.Key, kvp.Value);
                }
            }

            return CreateMap(exts);
        }