Exemplo n.º 1
0
        /// <summary>
        /// Intanciate an instance of informations on action method.
        /// </summary>
        /// <param name="type_controller"></param>
        /// <param name="areaName"></param>
        /// <param name="methodInfo">differents signatures of one method</param>
        /// <param name="JSNamespace"></param>
        /// <param name="modelInfo"></param>
        public ActionInfo(Type type_controller, string areaName, MethodInfo methodInfo, ConfigJS.JSNamespace JSNamespace, ModelInfo modelInfo)
        {
            _JSNamespace = JSNamespace;

            this._type_controller = type_controller;
            this.Controller       = this._type_controller.Name.Replace("Controller", "");
            this.Area             = areaName;
            this.Url        = "";
            this.MethodInfo = methodInfo;
            this.ModelInfo  = modelInfo;

            if (AspMvcInfo.TypesOfAspNetSetWebApi != null)
            {
                this._IsApiController      = AspMvcInfo.TypesOfAspNetSetWebApi.TWebHttp.IsApiConstroller(this._type_controller);
                this.IsHttpResponseMessage = AspMvcInfo.TypesOfAspNetSetWebApi.TNetHttp.Type_HttpResponseMessage.IsAssignableFrom(this.MethodInfo.ReturnType);
            }
            else
            {
                this._IsApiController      = false;
                this.IsHttpResponseMessage = false;
            }

            this.IsJsonResult   = AspMvcInfo.TypesOfAspNetSetMvc.TMvc.Type_JsonResult.IsAssignableFrom(this.MethodInfo.ReturnType);
            this.IsActionResult = AspMvcInfo.TypesOfAspNetSetMvc.TMvc.Type_ActionResult.IsAssignableFrom(this.MethodInfo.ReturnType);
            this.IsViewResult   = AspMvcInfo.TypesOfAspNetSetMvc.TMvc.Type_ViewResult.IsAssignableFrom(this.MethodInfo.ReturnType);
            this.IsIEnumerable  = TypeHelper.IsCollection(this.MethodInfo.ReturnType);

            this.Action        = this._TypesOfAspNetSet.GetActionName(methodInfo);
            this.RouteTemplate = this._TypesOfAspNetSet.GetRouteTemplate(methodInfo);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Intanciate an instance of informations on action method.
        /// </summary>
        /// <param name="action"></param>
        /// <param name="type_controller"></param>
        /// <param name="areaName"></param>
        /// <param name="miGroup">differents signatures of one method</param>
        /// <param name="JSNamespace"></param>
        /// <param name="modelInfo"></param>
        public ActionInfoGroup(string action, Type type_controller, string areaName, IGrouping <string, MethodInfo> miGroup, ConfigJS.JSNamespace JSNamespace, ModelInfo modelInfo)
        {
            _JSNamespace          = JSNamespace;
            this.MethodName       = action;
            this._type_controller = type_controller;
            this.Controller       = this._type_controller.Name.Replace("Controller", "");
            this.Area             = areaName;
            this.Url             = "";
            this.MethodInfoGroup = miGroup;

            if (AspMvcInfo.TypesOfAspNetSetWebApi != null)
            {
                this._IsApiController = AspMvcInfo.TypesOfAspNetSetWebApi.TWebHttp.IsApiConstroller(this._type_controller);
            }
            else
            {
                this._IsApiController = false;
            }

            this.Signatures = miGroup.Select(x => new ActionInfo(this._type_controller, this.Area, x, JSNamespace, modelInfo)).ToArray();

            //-- set idx.
            for (int ii = 0; ii < this.Signatures.Length; ii++)
            {
                this.Signatures[ii].Idx = ii;
            }
        }
Exemplo n.º 3
0
 public EnumInfo_JS(Type tobj_, IList <DataInfo> jsObjCol_, ConfigJS.JSNamespace JSNamespace, bool flagGetFactory_ = true)
     : base(tobj_, jsObjCol_, JSNamespace, flagGetFactory_)
 {
     if (tobj_.IsEnum == false)
     {
         throw new Exception("It must be 'Enum'");
     }
 }
Exemplo n.º 4
0
        private void InitializeCore(Assembly asp_net, IList <AssemblySet> typeSetList, AssemblyResolver ar, bool isAspNetCoreWindows)
        {
            this.IsAspNetCoreWindows = isAspNetCoreWindows;

            _JSNamespace = new ConfigJS.JSNamespace();

            if (isAspNetCoreWindows)
            {
                //-- AspNetCore.

                AspMvcInfo.TypesOfAspNetSetMvc = new TypesOfAspNetSetBaseMvc(
                    new AssemblyInfoWrapperCoreMvc(ar, new AssemblyInfoWrapperBaseMvc_FormattersJson(ar), new AssemblyInfoWrapperBaseMvc_ViewFeatures(ar)));
                AspMvcInfo.TypesOfAspNetSetWebApi = new TypesOfAspNetSetBaseWebApi(new AssemblyInfoWrapperCoreWebApi_NetHttp() /* is useless */,
                                                                                   new AssemblyInfoWrapperCoreWebApi_WebHttp(AspMvcInfo.TypesOfAspNetSetMvc.TMvc /*the same assembly*/, new AssemblyInfoWrapperBaseWebApi_Abstractions(ar)));
            }
            else
            {
                //-- AspNet.

                AspMvcInfo.TypesOfAspNetSetMvc = new TypesOfAspNetSetBaseMvc(new AssemblyInfoWrapperMvc(ar));

                try
                {
                    var TNetHttp = new AssemblyInfoWrapperWebApi_NetHttp(ar);
                    AspMvcInfo.TypesOfAspNetSetWebApi = new TypesOfAspNetSetBaseWebApi(TNetHttp, new AssemblyInfoWrapperWebApi_WebHttp(ar, TNetHttp));
                }
                catch (SystemNetHttp_Or_SystemWebHttp_NotFoundException ex)
                {
                    //-- not System.Net.Http(not WebApi).
                    //-- do nothing because issue is managed.
                    AspMvcInfo.TypesOfAspNetSetWebApi = null;
                }
            }


            InitiliazeForAspNetObjects(asp_net);

            foreach (var f in typeSetList)
            {
                foreach (var t in f.Types_Model)
                {
                    if (this.Types_Model.Contains(t) == false)
                    {
                        this.Types_Model.Add(t);
                    }
                }

                foreach (var t in f.Types_Enum)
                {
                    if (this.Types_Enum.Contains(t) == false)
                    {
                        this.Types_Enum.Add(t);
                    }
                }
            }
        }
Exemplo n.º 5
0
        protected DataInfo(Type tobj_, IList <DataInfo> objInfoCol_, ConfigJS.JSNamespace JSNamespace, bool flagGetFactory_ = true)
        {
            if ((JSNamespace != null) == false)
            {
                throw new ArgumentNullException("JSNamespace");
            }

            this.TObj           = tobj_;
            this.ObjInfoCol     = objInfoCol_;
            this.flagGetFactory = flagGetFactory_;
            this._JSNamespace   = JSNamespace;
        }
Exemplo n.º 6
0
        protected override DataInfo Factory(EnumScript choice, Type tobj, ConfigJS.JSNamespace JSNamespac)
        {
            switch (choice)
            {
            case EnumScript.JS:
                return(new EnumInfo_JS(tobj, this.JsObjCol, JSNamespac, this.flagGetFactory));

            case EnumScript.TS:
                return(new EnumInfo_TS(tobj, this.JsObjCol, JSNamespac, this.flagGetFactory));

            default:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 7
0
        static internal List <string> GetJS_Enums(IList <ParameterInfo> piArray, ConfigJS.JSNamespace _JSNamespace)
        {
            List <string> jsParams = new List <string>();

            foreach (var pi in piArray)
            {
                string paramName = pi.Name;

                string jsValue;

                jsValue = GetScript_EmptyValue_WithFactory_forEnum(TypeHelper.GetUnderlyingTypeOrDefault(pi.ParameterType), true, _JSNamespace, EnumScript.JS);

                jsParams.Add(string.Format("\"{0}\":{1}", paramName, jsValue));
            }
            return(jsParams);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Get parameters of action in JS in string.
        /// </summary>
        /// <param name="piArray"></param>
        /// <param name="_JSNamespace"></param>
        /// <param name="choice"></param>
        /// <param name="jsParams"></param>
        /// <param name="nsAlias"></param>
        /// <param name="separator"></param>
        /// <returns>true => appending, false => nothing </returns>
        static internal bool GetScript_Params(ParameterInfo[] piArray, ConfigJS.JSNamespace _JSNamespace, EnumScript choice, StringBuilder jsParams, bool nsAlias, ModelInfo modelInfo, char separator = ',')
        {
            for (var ii = 0; ii < piArray.Length; ii++)
            {
                var    pi        = piArray[ii];
                string paramName = pi.Name;

                string scriptValue = GetScript_EmptyValue_WithFactory(pi.ParameterType, nsAlias, _JSNamespace, choice, modelInfo.found_complex_types);

                if (ii >= 1)
                {
                    jsParams.Append(separator);
                }

                jsParams.Append(ScriptHelper.GetInstance(choice).GetKeyValue(paramName, scriptValue));
            }

            return(piArray.Length > 0);
        }
Exemplo n.º 9
0
 public ModelInfo(string appAspNetPath, IList <string> whiteNamespaces, IList <string> blackNamespaces, ConfigJS.JSNamespace JSNamespace)
     : this(TypeHelper.GetTypesOfClass(appAspNetPath, whiteNamespaces, blackNamespaces), JSNamespace)
 {
 }
Exemplo n.º 10
0
 public ModelInfo(ConfigJS.JSNamespace JSNamespace, params Type[] allTypes)
     : this(allTypes.ToList(), JSNamespace)
 {
 }
Exemplo n.º 11
0
        private static List <ActionInfoGroup> ExtractUrlFromAspNetMvcApplication(IList <Type> types_contoller, ConfigJS.JSNamespace JSNamespace, ModelInfo modelInfo)
        {
            List <ActionInfoGroup> urlList = new List <ActionInfoGroup>();

            for (int ii = 0; ii < types_contoller.Count; ii++)
            {
                List <ActionInfoGroup> urlListTemp = ExtractUrlFromController(types_contoller[ii], JSNamespace, modelInfo);

                urlList.AddRange(urlListTemp);
            }


            return(urlList);
        }
Exemplo n.º 12
0
 public EnumColInfo(string appAspNetPath, ConfigJS.JSNamespace JSNamespace)
     : base(TypeHelper.GetTypesOfEnum(appAspNetPath, new string[] { }, new string[] { }), JSNamespace)
 {
 }
Exemplo n.º 13
0
        /// <summary>
        /// Get instance.
        /// </summary>
        /// <param name="choice"></param>
        /// <param name="tobj"></param>
        /// <param name="JSNamespace"></param>
        /// <returns></returns>
        internal static TypeSorter_Script GetInstance(EnumScript choice, TypeSorter_ tobj, ConfigJS.JSNamespace JSNamespace)
        {
            switch (choice)
            {
            case EnumScript.JS:
                return(new TypeSorter_JS(tobj, JSNamespace));

            case EnumScript.TS:
                return(new TypeSorter_TS(tobj, JSNamespace));

            default:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 14
0
 abstract protected DataInfo Factory(EnumScript choice, Type tobj, ConfigJS.JSNamespace JSNamespace);
Exemplo n.º 15
0
        internal static string GetScript_EmptyValue_WithFactory(Type t, bool nsAlias, ConfigJS.JSNamespace _JSNamespace, EnumScript choice, HashSet <Type> found_complex_types)
        {
            string jsValue;

            if (!ScriptHelper.GetInstance(choice).GetPrimitiveEmptyValue(t, out jsValue))
            {
                bool isCollection;

                //-- it's class so, we use functionReference.
                Type telem_work = TypeHelper.FindCustomTypeOrDefault(t, out isCollection);

                if (telem_work != null)
                {
                    if (isCollection)
                    {
                        //-- telem_work  is collection.
                        jsValue = ScriptHelper.GetInstance(choice).GetObjectFactoryName(telem_work, isCollection, false, _JSNamespace.GetObjectFullName(telem_work, nsAlias));
                    }
                    else
                    {
                        if (AspMvcInfo.TypesOfAspNetSetWebApi != null)
                        {
                            if (
                                AspMvcInfo.TypesOfAspNetSetMvc.TMvc.Type_ActionResult.IsAssignableFrom(telem_work) == false &&
                                AspMvcInfo.TypesOfAspNetSetWebApi.TNetHttp.Type_HttpResponseMessage.IsAssignableFrom(telem_work) == false &&

                                (
                                    AspMvcInfo.TypesOfAspNetSetWebApi.TWebHttp.Type_IHttpActionResult == null ||

                                    (AspMvcInfo.TypesOfAspNetSetWebApi.TWebHttp.Type_IHttpActionResult != null &&
                                     AspMvcInfo.TypesOfAspNetSetWebApi.TWebHttp.Type_IHttpActionResult.IsAssignableFrom(telem_work) == false)
                                )
                                )
                            {
                                jsValue = GetObjectFactoryName_wrapper_with_found_complex_types(telem_work, isCollection, nsAlias, _JSNamespace, choice, found_complex_types);
                            }
                            else
                            {
                                jsValue = "{}";
                            }
                        }
                        else
                        {
                            //-- no web api.
                            if (AspMvcInfo.TypesOfAspNetSetMvc.TMvc.Type_ActionResult.IsAssignableFrom(telem_work) == false)
                            {
                                jsValue = GetObjectFactoryName_wrapper_with_found_complex_types(telem_work, isCollection, nsAlias, _JSNamespace, choice, found_complex_types);
                            }
                            else
                            {
                                jsValue = "{}";
                            }
                        }
                    }
                }
                else
                {
                    jsValue = "{}";
                }
            }

            return(jsValue);
        }
Exemplo n.º 16
0
        private static string GetObjectFactoryName_wrapper_with_found_complex_types(Type telem_work, bool isCollection, bool nsAlias, ConfigJS.JSNamespace _JSNamespace, EnumScript choice, HashSet <Type> found_complex_types)
        {
            string jsValue_;

            System.Diagnostics.Debug.Assert(ScriptHelper.GetCategoryType(telem_work) == ScriptHelper.EnumType.tcomplex, "it must be complex type");

            //-- complex type
            if (found_complex_types != null && found_complex_types.Contains(telem_work) == false)
            {
                telem_work = typeof(System.Object);
            }

            jsValue_ = ScriptHelper.GetInstance(choice).GetObjectFactoryName(telem_work, isCollection, false, _JSNamespace.GetObjectFullName(telem_work, nsAlias));

            return(jsValue_);
        }
Exemplo n.º 17
0
        private static List <ActionInfoGroup> ExtractUrlFromController(Type type_controller_current, ConfigJS.JSNamespace JSNamespace, ModelInfo modelInfo)
        {
            List <ActionInfoGroup> urlListTemp = new List <ActionInfoGroup>();

            IGrouping <string, MethodInfo>[] miGroups;
            {
                MethodInfo[] miArray = type_controller_current.GetMethods(BindingFlags.Public |
                                                                          BindingFlags.Instance | BindingFlags.DeclaredOnly);

                miGroups = miArray
                           .Where(x => x.Name.IndexOf("get_") < 0)
                           .GroupBy(x => x.Name).ToArray();
            }


            for (int jj = 0; jj < miGroups.Length; jj++)
            {
                IGrouping <string, MethodInfo> mig_current = miGroups[jj];

                //-- TODO: passer à ActionInfo, plusieurs signatures d'une méthode.
                ActionInfoGroup url = CreateUrl(type_controller_current, mig_current, JSNamespace, modelInfo);
                if (url != null)
                {
                    urlListTemp.Add(url);
                }
            }

            return(urlListTemp);
        }
Exemplo n.º 18
0
 public ModelInfo(string appAspNetPath, ConfigJS.JSNamespace JSNamespace)
 {
     this.Types_In     = TypeHelper.GetTypesOfClass(appAspNetPath, new string[] { }, new string[] { });
     this._JSNamespace = JSNamespace;
 }
Exemplo n.º 19
0
 /// <summary>
 /// Indicates if the type has members with complex or somple type.
 /// </summary>
 /// <param name="ts"></param>
 /// <param name="JSNamespace"></param>
 internal TypeSorter_TS(TypeSorter_ ts, ConfigJS.JSNamespace JSNamespace) : base(ts)
 {
     this._JSNamespace = JSNamespace;
 }
Exemplo n.º 20
0
        internal static string GetScript_EmptyValue_WithFactory_forEnum(Type t, bool nsAlias, ConfigJS.JSNamespace _JSNamespace, EnumScript choice)
        {
            if (t.IsEnum == false)
            {
                throw new Exception("t must be Enum");
            }

            string jsValue;
            Type   telem_work;
            bool   isCollection = TypeHelper.GetElementTypeOfCollection(t, out telem_work);

            if (isCollection == false)
            {
                telem_work = t;
            }

            //-- telem_work  is collection.
            jsValue = ScriptHelper.GetInstance(choice).GetObjectFactoryName(telem_work, isCollection, true, _JSNamespace.GetObjectFullName(telem_work, nsAlias));

            return(jsValue);
        }
Exemplo n.º 21
0
 public DataInfoCol(IList <Type> Types_Net, ConfigJS.JSNamespace JSNamespace)
 {
     _JSNamespace = JSNamespace;
     this.Init(Types_Net);
 }
Exemplo n.º 22
0
 public EnumColInfo(IList <Type> Types_Net, ConfigJS.JSNamespace JSNamespace)
     : base(Types_Net, JSNamespace)
 {
 }
Exemplo n.º 23
0
 public EnumColInfo(Assembly ass, ConfigJS.JSNamespace JSNamespace)
     : base(TypeHelper.GetTypesOfEnum(ass, new string[] { }, new string[] { }), JSNamespace)
 {
 }
Exemplo n.º 24
0
        /// <summary>
        /// Creates instance of ActionInfo.
        /// </summary>
        /// <param name="type_controller_current"></param>
        /// <param name="miGroup">differents signatures of one method</param>
        /// <param name="JSNamespace"></param>
        /// <param name="modelInfo"></param>
        /// <returns></returns>
        private static ActionInfoGroup CreateUrl(Type type_controller_current, IGrouping <string, MethodInfo> miGroup, ConfigJS.JSNamespace JSNamespace, ModelInfo modelInfo)
        {
            ActionInfoGroup url = null;

            string area = TryGetArea(type_controller_current);

            url = new ActionInfoGroup(miGroup.Key,
                                      type_controller_current,
                                      area,
                                      miGroup, JSNamespace, modelInfo);


            return(url);
        }
Exemplo n.º 25
0
 public EnumColInfo(Assembly ass, IList <string> whiteNamespaces, IList <string> blackNamespaces, ConfigJS.JSNamespace JSNamespace)
     : base(TypeHelper.GetTypesOfEnum(ass, whiteNamespaces, blackNamespaces), JSNamespace)
 {
 }
Exemplo n.º 26
0
        /// <summary>
        /// Creates oldClasses from Types. Memorise all [RecursiveTypeSorter] in list.
        /// </summary>
        /// <param name="tobjArray_In"></param>
        /// <param name="JSNamespace"></param>
        /// <param name="rTypeSorters"></param>
        /// <param name="classes"></param>
        /// <returns></returns>
        static private List <Type> ExecuteCore(List <Type> tobjArray_In, List <Dictionary <Type, TypeSorter_> > classes, ConfigJS.JSNamespace JSNamespace, ref List <RecursiveTypeDependanceSorter> rTypeSorters)
        {
            do
            {
                //-- create each class.
            }while (AddClass(tobjArray_In, classes, JSNamespace, ref rTypeSorters));

            #region "unresolvedTypes"
            List <Type> unresolvedTypes;
            {
                Type[] resolvedTypes = classes.SelectMany(x => x.Keys).ToArray();
                Type[] allTypes      = rTypeSorters.SelectMany(r => r.OccurencesOfDependanceType_All.Keys).ToArray();
                unresolvedTypes = allTypes.Except(resolvedTypes).ToList();
            }
            #endregion

            return(unresolvedTypes);
        }
Exemplo n.º 27
0
 public EnumColInfo(string appAspNetPath, IList <string> whiteNamespaces, IList <string> blackNamespaces, ConfigJS.JSNamespace JSNamespace)
     : base(TypeHelper.GetTypesOfEnum(appAspNetPath, whiteNamespaces, blackNamespaces), JSNamespace)
 {
 }
Exemplo n.º 28
0
        /// <summary>
        /// Add a new class for unresolved types, in old classes. Memorize all [RecursiveTypeSorter] in list.
        /// </summary>
        /// <param name="allTypes_In"></param>
        /// <param name="oldClasses"></param>
        /// <param name="JSNamespace"></param>
        /// <param name="serializeTypes"></param>
        /// <returns></returns>
        private static bool AddClass(List <Type> allTypes_In, List <Dictionary <Type, TypeSorter_> > oldClasses, ConfigJS.JSNamespace JSNamespace, ref List <RecursiveTypeDependanceSorter> serializeTypes)
        {
            var typesToIgnore_temp = oldClasses.SelectMany(kv => kv.Keys).ToArray();
            var types_toResolve_In = allTypes_In.Where(t => typesToIgnore_temp.Contains(t) == false).ToArray();

            if (types_toResolve_In.Length > 0)
            {
                RecursiveTypeDependanceSorter st = new RecursiveTypeDependanceSorter();
                serializeTypes.Add(st);
                st.TypesToIgnore.AddRange(typesToIgnore_temp);

                foreach (Type t_in in types_toResolve_In)
                {
                    //-- sorts dependances.
                    st.Execute(t_in, true, JSNamespace);
                }

                var cl = st.ResolvedTypes.ToDictionary(kv => kv.Key, kv => kv.Value);

                if (cl.Count > 0)
                {
                    oldClasses.Add(cl);
                }

                return(cl.Count > 0);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 29
0
 public ModelInfo(List <Type> allTypes, ConfigJS.JSNamespace JSNamespace)
 {
     this.Types_In     = allTypes;
     this._JSNamespace = JSNamespace;
 }
Exemplo n.º 30
0
 /// <summary>
 /// Generates Url
 /// </summary>
 /// <param name="types_contoller"></param>
 /// <param name="modelInfo"></param>
 /// <param name="JSNamespace"></param>
 public UrlInfo(IList <Type> types_contoller, ModelInfo modelInfo, ConfigJS.JSNamespace JSNamespace)
 {
     this.AreaInfoList = GetAreaInfoList(types_contoller, modelInfo, JSNamespace);
 }