Пример #1
0
        private void processClientCode(NameValueCollection queryString, HttpContext context)
        {
            IProxyGenerator generator = null;
            ResourceManager resMan = new ResourceManager();
            string platform = queryString["platform"];
            if (string.IsNullOrEmpty(platform))
            {
                context.Response.ContentType = "text/plain";
                context.Response.Write("No Platform is Specified");
                return;
            }
            platform = platform.ToLower();
            if (platform == "csharp")
            {
                TypeMap tm = resMan.GetTypeMap("dotnet-csharp.typemap");
                generator = new CSharpGenerator(tm);
            }
            else if (platform == "java")
            {
                TypeMap tm = resMan.GetTypeMap("dotnet-java.typemap");
                generator = new JavaGenerator(tm);
            }
            else if (platform == "js-angularjs")
            {
                generator = new AngularGenerator();
            }
            else if (platform == "js-dojo")
            {
                generator = new JavaScriptGenerator();
            }
            else if (platform == "js-dojo-amd")
            {
                generator = new JavaScriptDojoAMDGenerator();
            }
            else if (platform == "flex")
            {
                generator = new FlexGenerator();
            }
            else if (platform == "objc")
            {
                TypeMap tm = resMan.GetTypeMap("dotnet-objc.typemap");
                generator = new ObjectiveCGenerator(tm);
            }

            if (generator == null)
            {
                context.Response.ContentType = "text/plain";
                context.Response.Write("Unknown Platform");
                return;
            }

            string format = queryString["format"];
            format = format == null ? "zip" : format.ToLower();


            Service svc = createService();
            IDictionary<string, string> files = generator.Generate(svc);

            if (format == "zip")
            {
                byte[] buffer = ZipExporter.Export(files);
                MemoryStream ms = new MemoryStream(buffer);
                //context.Response.ContentType = "application/zip";
                context.Response.ContentType = "application/octet-stream";
                string fileName = string.Format("{0}_{1}.zip", svc.Name, platform);
                context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
                ms.CopyTo(context.Response.OutputStream);
                context.Response.OutputStream.Close();
            }
            else if (format == "json")
            {
                string s = JsonConvert.SerializeObject(files);
                context.Response.ContentType = "text/json";
                context.Response.Write(s);
            }
            else if (format == "xml")
            {

            }
            
        }