Пример #1
0
        public static void Compile(string xic)
        {
            var checker = new XamlBuildCheck()
            {
                Context = System.Web.HttpContext.Current
            };

            if (checker.NeedsBuilding(xic))
            {
#if Silversite
                var handlerInfo = Services.Lazy.Types.Info("XamlImageConverter.Compiler");
                handlerInfo.Load();
                Compiler = handlerInfo.New();
#else
                var assemblyfile = HostingEnvironment.MapPath("~/Bin/Lazy/XamlImageConverter.dll");
                if (!System.IO.File.Exists(assemblyfile))
                {
                    assemblyfile = HostingEnvironment.MapPath("~/Silversite/BinLazy/XamlImageConverter.dll");
                }
                var aname = new System.Reflection.AssemblyName("XamlImageConverter");
                aname.CodeBase = new Uri(assemblyfile).ToString();
                var a    = System.Reflection.Assembly.Load(aname);
                var type = a.GetType("XamlImageConverter.Compiler");
                compiler = Activator.CreateInstance(type);
#endif

                var ct                = compiler.GetType();
                var projectPath       = ct.GetProperty("ProjectPath");
                var libraryPath       = ct.GetProperty("LibraryPath");
                var sourceFiles       = ct.GetProperty("SourceFiles");
                var separateAppDomain = ct.GetProperty("SeparateAppDomain");
                var rebuildAll        = ct.GetProperty("RebuildAll");
                projectPath.SetValue(compiler, HostingEnvironment.MapPath("~"));
                libraryPath.SetValue(compiler, HostingEnvironment.MapPath("~/bin"));
                var sources = new List <string>()
                {
                    xic
                };
                sourceFiles.SetValue(compiler, sources);
                separateAppDomain.SetValue(compiler, false);
                rebuildAll.SetValue(compiler, xic.Contains('<'));
                var compile = ct.GetMethod("Compile", new Type[0]);
                compile.Invoke(compiler, new object[0]);
            }
        }
Пример #2
0
        public void ProcessRequest(System.Web.HttpContext context)
        {
            var checker = new XamlBuildCheck()
            {
                Context = context
            };

            if (handler != null || checker.NeedsBuilding())
            {
                if (handler == null)
                {
                    try {
#if Silversite
                        var handlerInfo = Services.Lazy.Types.Info("XamlImageConverter.XamlImageHandler");
                        handlerInfo.Load();
                        handler = handlerInfo.New <IHttpHandler>();
#else
                        //AppDomain.CurrentDomain.AppendPrivatePath("Lazy\\Awesomium");
                        lock (Lock) {
                            if (!AssemblyResolverInitialized)
                            {
                                int resolving = 0;
                                AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => {
                                    try {
                                        lock (Lock) {
                                            resolving++;
                                            if (resolving > 1)
                                            {
                                                return(null);
                                            }
                                            var aname = new AssemblyName(args.Name);
                                            aname.CodeBase = context.Request.MapPath("~/Bin/Lazy/" + aname.Name + ".dll");
                                            var n = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(l => l.GetName().Name == args.Name) ?? System.Reflection.Assembly.Load(aname);
                                            return(n);
                                        }
                                    } catch {
                                        return(null);
                                    } finally {
                                        resolving--;
                                    }
                                };
                                AssemblyResolverInitialized = true;
                            }
                        }
                        var aname2 = new AssemblyName("XamlImageConverter");
                        var a      = Assembly.Load(aname2);
                        var type   = a.GetType("XamlImageConverter.XamlImageHandler");

                        handler = (System.Web.IHttpHandler)Activator.CreateInstance(type);
#endif
                    } catch {
                        context.Response.StatusCode = 500;
                        context.ApplicationInstance.CompleteRequest();
                    }
                }
#if Silversite
                context.Application.Lock();
                context.Application["XamlImageConverter.Configuration.UseService"]     = Configuration.UseService;
                context.Application["XamlImageConverter.Configuration.Log"]            = Configuration.Log;
                context.Application["XamlImageConverter.Configuration.Cache"]          = Configuration.Cache;
                context.Application["XamlImageConverter.Configuration.SeparateDomain"] = Configuration.SeparateDomain;
                context.Application["XamlImageConverter.Configuration.GCLevel"]        = Configuration.GCLevel;
                context.Application.UnLock();
#endif
                handler.ProcessRequest(context);
            }
            else
            {
                var filename = context.Request.AppRelativeCurrentExecutionFilePath;
                var image    = context.Request.QueryString["Image"] ?? context.Request.QueryString["File"] ?? context.Request.QueryString["Filename"];
                var ext      = Path.GetExtension(filename).ToLower();
                if (ext == ".xaml" || ext == ".psd" || ext == ".svg" || ext == ".svgz")
                {
                    var exts = context.Request.QueryString.GetValues(null);
                    if (exts != null && exts.Length > 0)
                    {
                        ext   = exts[0];
                        image = image ?? filename + "." + ext;
                    }
                }
                var name = System.IO.Path.GetFileName(image);
                image = context.Server.MapPath(image);
                ext   = System.IO.Path.GetExtension(image);
                if (!string.IsNullOrEmpty(ext))
                {
                    ext = ext.Substring(1).ToLower();
                }

                switch (ext)
                {
                case "bmp": context.Response.ContentType = "image/bmp"; break;

                case "png": context.Response.ContentType = "image/png"; break;

                case "jpg":
                case "jpeg":    context.Response.ContentType = "image/jpeg"; break;

                case "tif":
                case "tiff": context.Response.ContentType = "image/tiff"; break;

                case "gif": context.Response.ContentType = "image/gif"; break;

                case "wdp": context.Response.ContentType = "image/vnd.ms-photo"; break;

                case "pdf":
                    context.Response.AppendHeader("content-disposition", "attachment; filename=" + name);
                    context.Response.ContentType = "application/pdf"; break;

                case "xps":
                    context.Response.AppendHeader("content-disposition", "attachment; filename=" + name);
                    context.Response.ContentType = "application/vnd.ms-xpsdocument"; break;

                case "eps":
                case "ps":
                    context.Response.AppendHeader("content-disposition", "attachment; filename=" + name);
                    context.Response.ContentType = "application/postscript"; break;

                case "psd":
                    context.Response.AppendHeader("content-disposition", "attachment; filename=" + name);
                    context.Response.ContentType = "image/photoshop"; break;

                case "svg":
                case "svgz": context.Response.ContentType = "image/svg+xml"; break;

                case "xaml": context.Response.ContentType = "application/xaml+xml"; break;

                default: break;
                }

                if (System.IO.File.Exists(image))
                {
                    context.Response.WriteFile(image);
                }
                else
                {
                    context.Response.StatusCode = 404;
                }
                context.ApplicationInstance.CompleteRequest();
            }
        }
Пример #3
0
 public Group(XamlBuildCheck fbc, string culture)
 {
     FBC         = fbc;
     OldCulture  = fbc.Culture;
     fbc.Culture = culture;
 }