コード例 #1
0
//        public static IApiPage ApiFactory(LGMServiceType service, APRIConfigSettings config)
        public static T ApiFactory <T>(LGMServiceType service, APRIConfigSettings config)
        {
            object returnPage = null;

            try
            {
                apiPage.TryGetValue(service, out var page);

                returnPage = page != null?page(config) : new APIActionsBase(config);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw;
            }

            //IApiPage page = GetPage(service, userUser, password);
            if (returnPage is T)
            {
                return((T)returnPage);
            }

            try
            {
                return((T)Convert.ChangeType(returnPage, typeof(T)));
            }
            catch (InvalidCastException)
            {
                return(default(T));
            }
            //return returnPage;
        }
コード例 #2
0
        //private static IApiPage GetPage(LGMServiceType service, string userName, string passWord)
        //{
        //    APRIConfigSettings config = new APRIConfigSettings
        //    {
        //        UserName = userName,
        //        Password = passWord
        //    };
        //    IApiPage page = null;

        //    switch (service)
        //    {
        //          case LGMServiceType.AssetsService:
        //              page = new LGMAssetsService(config);
        //              break;

        //    }

        //    return page;
        //}

//        public static IApiPage ApiFactory(LGMServiceType service, string userUser, string password)
        public static T ApiFactory <T>(LGMServiceType service, string userUser, string password)
        {
            APRIConfigSettings config = new APRIConfigSettings
            {
                UserName = userUser,
                Password = password
            };

            return(ApiFactory <T>(service, config));
        }