/// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.</summary>
        public override string ToString()
        {
            string result;

            using (IO.StringWriter stringWriter = new IO.StringWriter(Globalization.CultureInfo.InvariantCulture))
            {
                this._action(stringWriter);
                result = stringWriter.ToString();
            }
            return(result);
        }
Ejemplo n.º 2
0
        private CodeCompileUnit GenerateCodeFromServiceMapFile(string mapFilePath)
        {
            try
            {
                string           generatedNamespace = GetGeneratedNamespace();
                SvcMapFileLoader loader             = new SvcMapFileLoader(mapFilePath);
                SvcMapFile       mapFile            = loader.LoadMapFile() as SvcMapFile;

                HandleProxyGenerationErrors(mapFile.LoadErrors);

                // We always use C# for the generated proxy
                CodeDomProvider provider = System.CodeDom.Compiler.CodeDomProvider.CreateProvider("c#");

                //Note: with the current implementation of the generator, it does all of its
                //  work in the constructor.  This may change in the future.
                VSWCFServiceContractGenerator generator = VSWCFServiceContractGenerator.GenerateCodeAndConfiguration(
                    mapFile,
                    GetToolConfig(mapFile, mapFilePath),
                    provider,
                    generatedNamespace,
                    null, //targetConfiguration
                    null, //configurationNamespace
                    new ImportExtensionServiceProvider(),
                    new TypeResolver(),
                    FRAMEWORK_VERSION_35,
                    typeof(System.Data.Design.TypedDataSetSchemaImporterExtensionFx35)  //Always we are above framework version 3.5
                    );

                // Determine what "name" to display to users for the service if there are any exceptions
                // If generatedNamespace is empty, then we display the name of the .svcmap file.
                string referenceDisplayName = String.IsNullOrEmpty(generatedNamespace) ?
                                              System.IO.Path.GetFileName(mapFilePath) : generatedNamespace;

                VerifyGeneratedCodeAndHandleErrors(referenceDisplayName, mapFile, generator.TargetCompileUnit, generator.ImportErrors, generator.ProxyGenerationErrors);
#if DEBUG
#if false
                IO.TextWriter        writer  = new IO.StringWriter();
                CodeGeneratorOptions options = new CodeGeneratorOptions();
                options.BlankLinesBetweenMembers = true;
                provider.GenerateCodeFromCompileUnit(generator.TargetCompileUnit, writer, options);
                Debug.WriteLine("Generated proxy code:\r\n" + writer.ToString());
#endif
#endif
                return(generator.TargetCompileUnit);
            }
            catch (Exception ex)
            {
                string errorMessage = ex.Message;
                errorMessage = String.Format(CultureInfo.CurrentCulture, "{0}: {1}", IO.Path.GetFileName(mapFilePath), errorMessage);
                throw new InvalidOperationException(errorMessage, ex);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 返回数据库实体类对应的json对象(对时间进行了数字处理)
 /// </summary>
 /// <param name="model">数据库实体类</param>
 public string GetModelJson <TModel>(TModel model)
 {
     if (model == null)
     {
         return(Constant.nullString);
     }
     else
     {
         NFinal.IO.StringWriter sw = new IO.StringWriter();
         NFinal.Json.JsonHelper.WriteJson(model, sw, Json.DateTimeFormat.LocalTimeNumber);
         return(sw.ToString());
     }
 }
Ejemplo n.º 4
0
            /// <summary>
            /// 创建一个模拟的 MVC 控制器。
            /// </summary>
            /// <typeparam name="TController">控制的数据类型。</typeparam>
            /// <param name="user">当前已授权的登录用户。</param>
            /// <param name="mockFactoryCallback">模拟的执行器工厂回调函数。</param>
            /// <returns>返回一个控制器的实例。</returns>
            public static TController Create <TController>(object user, Action <MockExecutorFactory> mockFactoryCallback = null)
                where TController : Web.Mvc.Controller, new()
            {
                var httpRequest  = new HttpRequest(string.Empty, "http://www.aoite.com/", string.Empty);
                var stringWriter = new IO.StringWriter();
                var httpResponce = new HttpResponse(stringWriter);
                var httpContext  = new HttpContext(httpRequest, httpResponce);

                var sessionContainer = new SessionState.HttpSessionStateContainer("id", new SessionState.SessionStateItemCollection(),
                                                                                  new HttpStaticObjectsCollection(), 10, true,
                                                                                  HttpCookieMode.AutoDetect,
                                                                                  SessionState.SessionStateMode.InProc, false);

                httpContext.Items["AspSession"] = typeof(SessionState.HttpSessionState).GetConstructor(
                    BindingFlags.NonPublic | BindingFlags.Instance,
                    null, CallingConventions.Standard,
                    new[] { typeof(SessionState.HttpSessionStateContainer) },
                    null)
                                                  .Invoke(new object[] { sessionContainer });
                HttpContext.Current = httpContext;

                var appFactoryType = typeof(HttpContext).Assembly.GetType("System.Web.HttpApplicationFactory");

                object appFactory = DynamicFactory.CreateFieldGetter(appFactoryType.GetField("_theApplicationFactory", BindingFlags.NonPublic | BindingFlags.Static))(null);

                DynamicFactory.CreateFieldSetter(appFactoryType.GetField("_state", BindingFlags.NonPublic | BindingFlags.Instance))(appFactory, HttpContext.Current.Application);

                var identityStore = new MockSessionIdentityStore(user);
                var container     = ServiceFactory.CreateContainer(identityStore, mockFactoryCallback);

                container.Add <IIdentityStore>(identityStore);
                Webx.Container = container;
                TController c = new TController();

                c.ControllerContext = new Web.Mvc.ControllerContext(new Routing.RequestContext(new HttpContextWrapper(httpContext), new Routing.RouteData()), c);
                return(c);
            }