Esempio n. 1
0
        public override bool Execute()
        {
            foreach (ITaskItem taskItem in this.SourceDirectories)
            {
                this.Log.LogMessage(MessageImportance.Low, "Building {0}", taskItem.ItemSpec);

                string inputPath = Path.ChangeExtension(taskItem.ItemSpec, ".doodad");
                Builder builder = new Builder(inputPath)
                {
                    DebugOutput = this.DebugMode
                };

                string outputPath;
                if (string.IsNullOrEmpty(this.OutputDirectory))
                {
                    outputPath = inputPath;
                }
                else
                {
                    outputPath = Path.Combine(this.OutputDirectory, Path.GetFileName(inputPath));
                }

                using (FileStream fs = new FileStream(outputPath, FileMode.Create))
                {
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        sw.Write(builder.Render());
                    }
                }
            }

            return true;
        }
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                Builder builder = new Builder(HttpContext.Current.Server.MapPath(context.Request.Path));
            #if DEBUG
                builder.DebugOutput = true;
            #endif

                string output = builder.Render();
            #if DEBUG
                output += string.Format("\n//@ sourceURL={0}\n", context.Request.Url.AbsoluteUri);
            #endif

                if (!string.IsNullOrEmpty(builder.DoodadDescriptor.Behaviour)) {
                    context.Response.AddFileDependency(builder.DoodadDescriptor.Behaviour);
                }

                context.Response.AddFileDependencies(builder.DoodadDescriptor.Stylesheets.ToArray());

                foreach (KeyValuePair<string, string> pair in builder.DoodadDescriptor.Templates) {
                    context.Response.AddFileDependency(pair.Value);
                }

                context.Response.Cache.SetCacheability(HttpCacheability.Public);
                context.Response.Cache.SetETagFromFileDependencies();
                context.Response.Cache.SetLastModifiedFromFileDependencies();
                context.Response.ContentType = "text/javascript";
                context.Response.Write(output);
            }
            catch (DirectoryNotFoundException e)
            {
                context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                context.Response.Output.WriteLine("No doodad exists at the specified URL \"{0}\".", e.Message);
            #if DEBUG
                throw e;
            #endif
            }
            catch (Exception e)
            {
                context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                context.Response.Output.WriteLine(string.Format("Exception of type \"{0}\" was thrown processing the request.", e.GetType().ToString()));
            #if DEBUG
                throw e;
            #endif
            }
        }