/// <inheritdoc/>
        public bool WriteToStream(
            BaseCompositeFileProcessingProvider provider,
            StreamWriter streamWriter,
            IVirtualFile virtualFile,
            ClientDependencyType type,
            string originalUrl,
            HttpContextBase context)
        {
            StreamReader streamReader = null;

            try
            {
                Stream readStream = virtualFile.Open();
                streamReader = new StreamReader(readStream);
                string output = streamReader.ReadToEnd();

                DefaultFileWriter.WriteContentToStream(provider, streamWriter, output, type, context, originalUrl);

                return(true);
            }
            catch (Exception)
            {
                // The file must have failed to open
                return(false);
            }
            finally
            {
                // readStream is disposed by the streamReader.
                streamReader?.Dispose();
            }
        }
Example #2
0
        public bool WriteToStream(
            BaseCompositeFileProcessingProvider provider,
            StreamWriter sw,
            IVirtualFile vf,
            ClientDependencyType type,
            string origUrl,
            HttpContextBase http)
        {
            try
            {
                using (var readStream = vf.Open())
                    using (var streamReader = new StreamReader(readStream))
                    {
                        var output = streamReader.ReadToEnd();
                        DefaultFileWriter.WriteContentToStream(provider, sw, output, type, http, origUrl);
                        return(true);
                    }
            }
            catch (Exception exception)
            {
                LogHelper.Warn(typeof(EmbeddedResourceVirtualFileWriter), exception.Message);

                return(false);
            }
        }
Example #3
0
        public bool WriteToStream(BaseCompositeFileProcessingProvider provider, StreamWriter sw, FileInfo fi, ClientDependencyType type, string origUrl, HttpContextBase http)
        {
            try
            {
                //if it is a file based dependency then read it
                var fileContents = File.ReadAllText(fi.FullName, Encoding.UTF8); //read as utf 8

                //for our custom file reader to work we just need to put the origUrl into the httpcontext items so
                //we can retreive it in the reader to then figure out the 'real' requested path.
                http.Items["Cdf_LessWriter_origUrl"] = origUrl;
                //get the default less config
                var config = DotlessConfiguration.GetDefaultWeb();
                //set the file reader to our custom file reader
                config.LessSource = typeof(CdfFileReader);
                //disable cache for this engine since we are already caching our own, plus enabling this will cause errors because
                // the import paths aren't resolved properly.
                config.CacheEnabled = false;
                //get the engine based on the custom config with our custom file reader
                var lessEngine = LessWeb.GetEngine(config);

                var output = lessEngine.TransformToCss(fileContents, origUrl);

                DefaultFileWriter.WriteContentToStream(provider, sw, output, type, http, origUrl);

                return(true);
            }
            catch (Exception ex)
            {
                ClientDependencySettings.Instance.Logger.Error(string.Format("Could not write file {0} contents to stream. EXCEPTION: {1}", fi.FullName, ex.Message), ex);
                return(false);
            }
        }
        /// <summary>
        /// Writes the output of an external request to the stream
        /// </summary>
        /// <param name="sw"></param>
        /// <param name="url"></param>
        /// <param name="type"></param>
        /// <param name="http"></param>
        protected virtual CompositeFileDefinition WriteFileToStream(StreamWriter sw, string url, ClientDependencyType type, HttpContextBase http)
        {
            var rVal = RequestHelper.TryReadUri(url, http, BundleDomains, out string requestOutput, out Uri resultUri);

            if (!rVal)
            {
                return(null);
            }

            //write the contents of the external request.
            DefaultFileWriter.WriteContentToStream(this, sw, requestOutput, type, http, url);
            return(new CompositeFileDefinition(url, false));
        }
Example #5
0
        public bool WriteToStream(BaseCompositeFileProcessingProvider provider, StreamWriter sw, FileInfo fi, ClientDependencyType type, string origUrl, HttpContextBase http)
        {
            try
            {
                //NOTE: We don't want this compressed since CDF will do that ourselves
                var output = Compiler.Compile(fi.FullName, false, new List <string>());

                DefaultFileWriter.WriteContentToStream(provider, sw, output, type, http, origUrl);

                return(true);
            }
            catch (Exception ex)
            {
                ClientDependencySettings.Instance.Logger.Error(string.Format("Could not write file {0} contents to stream. EXCEPTION: {1}", fi.FullName, ex.Message), ex);
                return(false);
            }
        }
 public bool WriteToStream(BaseCompositeFileProcessingProvider provider, StreamWriter sw, IVirtualFile vf, ClientDependencyType type, string origUrl, HttpContextBase http)
 {
     try
     {
         using (var readStream = vf.Open())
             using (var streamReader = new StreamReader(readStream))
             {
                 var output = streamReader.ReadToEnd();
                 DefaultFileWriter.WriteContentToStream(provider, sw, output, type, http, origUrl);
                 return(true);
             }
     }
     catch (Exception)
     {
         // the file must have failed to open
         return(false);
     }
 }
Example #7
0
        public void Write(string filename, T objectToWrite)
        {
            foreach (FileWriter <T> writer in FileWriters)
            {
                if (writer.CanWrite(filename))
                {
                    writer.Write(filename, objectToWrite);
                    return;
                }
            }

            if (DefaultFileWriter != null)
            {
                DefaultFileWriter.Write(filename, objectToWrite);
                return;
            }

            throw new Exception("Could not write to file.  No file reader exists for the given file name, and no default file writer is defined.");
        }
Example #8
0
        public bool WriteToStream(BaseCompositeFileProcessingProvider provider, StreamWriter sw, FileInfo fi, ClientDependencyType type, string origUrl, HttpContextBase http)
        {
            //if it is a file based dependency then read it
            var fileContents = File.ReadAllText(fi.FullName, Encoding.UTF8); //read as utf 8

            var engine = GetEngine();

            try
            {
                var output = CompileTypeScript(engine, fileContents);
                DefaultFileWriter.WriteContentToStream(provider, sw, output, type, http, origUrl);
                return(true);
            }
            catch (System.Exception ex)
            {
                ClientDependencySettings.Instance.Logger.Error(string.Format("Could not write file {0} contents to stream. EXCEPTION: {1}", fi.FullName, ex.Message), ex);
                return(false);
            }
        }
Example #9
0
        public bool WriteToStream(BaseCompositeFileProcessingProvider provider, StreamWriter sw, FileInfo fi, ClientDependencyType type, string origUrl, HttpContextBase http)
        {
            try
            {
                //if it is a file based dependency then read it
                var fileContents = File.ReadAllText(fi.FullName, Encoding.UTF8); //read as utf 8

                //NOTE: passing in null will automatically for the web configuration section to be loaded in!
                var output = LessWeb.Parse(fileContents, null);

                DefaultFileWriter.WriteContentToStream(provider, sw, output, type, http, origUrl);

                return(true);
            }
            catch (Exception ex)
            {
                ClientDependencySettings.Instance.Logger.Error(string.Format("Could not write file {0} contents to stream. EXCEPTION: {1}", fi.FullName, ex.Message), ex);
                return(false);
            }
        }
Example #10
0
 public void HasValidLevel(LogLevel level)
 {
     using var writer = new DefaultFileWriter($"{nameof(HasValidLevel)}", level);
     writer.Level.Should().Be(level);
 }
Example #11
0
 public DefaultFileWriterShould()
 {
     _fileName = $"{nameof(DefaultFileWriterShould)}.log";
     _sender   = typeof(DefaultFileWriterShould);
     _writer   = new DefaultFileWriter(_fileName);
 }