Exemplo n.º 1
0
        /// <summary>Creates or overwrites a file at the given path.</summary>
        /// <param name="virtualPath">The path of the file to create.</param>
        /// <param name="inputStream">An input stream of the file contents.</param>
        public virtual void WriteFile(string virtualPath, Stream inputStream)
        {
            string path = MapPath(virtualPath);

            if (!Directory.Exists(Path.GetDirectoryName(path)))
            {
                Directory.CreateDirectory((Path.GetDirectoryName(path)));
            }

            if (FileExists(virtualPath))
            {
                using (Stream fileStream = File.OpenWrite(path))
                {
                    long length = TransferBetweenStreams(inputStream, fileStream);
                    fileStream.SetLength(length);
                }
            }
            else
            {
                using (Stream fileStream = File.Create(path))
                {
                    TransferBetweenStreams(inputStream, fileStream);
                }
            }

            if (FileWritten != null)
            {
                FileWritten.Invoke(this, new FileEventArgs(virtualPath, null));
            }
        }
Exemplo n.º 2
0
        public static void WriteAllText(string path, string contents)
        {
            string[] pathlist = path.Split('/');
            int      vol      = Convert.ToInt32(pathlist[0].Replace(":", ""));
            var      dir      = Mounts[vol];

            for (int i = 1; i <= pathlist.Length - 2; i++)
            {
                dir = dir.FindDirectoryByName(pathlist[i]);
            }

            if (!FileExists(path))
            {
                try
                {
                    dir.AddFile(new File(pathlist[pathlist.Length - 1], Encoding.UTF8.GetBytes(contents), false, CurrentUser));
                }
                catch { }
            }
            else
            {
                var f = dir.FindFileByName(pathlist[pathlist.Length - 1]);
                f.Data = Encoding.UTF8.GetBytes(contents);
            }
            FileWritten?.Invoke(path);
        }
Exemplo n.º 3
0
        public void WriteFile(string virtualPath, System.IO.Stream inputStream, DateTime?lastWriteTime = null)
        {
            string path = MapPath(virtualPath);

            if (!Directory.Exists(Path.GetDirectoryName(path)))
            {
                Directory.CreateDirectory((Path.GetDirectoryName(path)));
            }

            if (FileExists(virtualPath))
            {
                ReplaceFile(virtualPath, inputStream);
            }
            else
            {
                CreateFile(virtualPath, inputStream);
            }

            if (lastWriteTime.HasValue)
            {
                File.SetLastWriteTimeUtc(path, lastWriteTime.Value.ToUniversalTime());
            }

            if (FileWritten != null)
            {
                FileWritten.Invoke(this, new FileEventArgs(virtualPath, null));
            }
        }
Exemplo n.º 4
0
        public void WriteFile(string virtualPath, Stream inputStream)
        {
            var request = new PutObjectRequest()
                          .WithMetaData("Expires", DateTime.Now.AddYears(10).ToString("R"))
                          .WithBucketName(this.bucketName)
                          .WithCannedACL(S3CannedACL.PublicRead)
                          .WithTimeout(60 * 60 * 1000)          // 1 hour
                          .WithReadWriteTimeout(60 * 60 * 1000) // 1 hour
                          .WithKey(FixPathForS3(virtualPath));

            var contentType = virtualPath.Substring(virtualPath.LastIndexOf(".", StringComparison.Ordinal));

            if (string.IsNullOrWhiteSpace(contentType))
            {
                request.ContentType = contentType;
            }

            request.WithInputStream(inputStream);
            using (this.s3.PutObject(request)) { }

            if (FileWritten != null)
            {
                FileWritten.Invoke(this, new FileEventArgs(FixPathForN2(virtualPath), null));
            }
        }
        public void WriteFile(string virtualPath, Stream inputStream)
        {
            GetCloudBlockBlobFile(virtualPath).UploadFromStream(inputStream);

            if (FileWritten != null)
            {
                FileWritten.Invoke(this, new FileEventArgs(virtualPath, null));
            }
        }
Exemplo n.º 6
0
        public void WriteFile(string virtualPath, Stream inputStream, DateTime?lastWriteTime = null)
        {
            isp.SaveStream(ToRelative(virtualPath), inputStream, lastWriteTime);

            if (FileWritten != null)
            {
                FileWritten.Invoke(this, new FileEventArgs(virtualPath, null));
            }
        }
Exemplo n.º 7
0
        private void SerializeObject <T>(T fileToWrite, string path)
        {
            var jsonFormatter = new DataContractJsonSerializer(typeof(T));

            using (var file = new FileStream(path, FileMode.OpenOrCreate))
            {
                jsonFormatter.WriteObject(file, fileToWrite);
                FileWritten?.Invoke();
            }
        }
Exemplo n.º 8
0
        public void WriteFile(string virtualPath, Stream inputStream)
        {
            string fixedPath = FixPath(virtualPath);

            InternalWriteFile(fixedPath, inputStream);

            if (FileWritten != null)
            {
                FileWritten.Invoke(this, new FileEventArgs(virtualPath, null));
            }
        }
Exemplo n.º 9
0
        private string RenderFileEntry(FileEntry fe, VariableCollection variables, string dst)
        {
            try
            {
                _logger.Log(LogLevel.Verbose, $"Looking for {fe.RawRelativeSrc} at {fe.PossibleRawSrcPaths.Aggregate((s1, s2) => string.Join(", ", s1, s2))}");
                var asrc = fe.PossibleRawSrcPaths.Select(s => RenderString(_template.FullPath, s, variables, fe.Line, fe.Column)).FirstOrDefault(File.Exists);
                if (asrc == null)
                {
                    _logger.Log(LogLevel.Error, _template.FullPath, fe.Line, fe.Column,
                                $"Source file '{fe.RawRelativeSrc}' not found.");
                    return(null);
                }
                fe.AbsoluteSrc = asrc;

                var adst = Path.Combine(dst, RenderString(_template.FullPath, fe.RawRelativeDst, variables, fe.Line, fe.Column));
                if (File.Exists(adst))
                {
                    _logger.Log(LogLevel.Warning,
                                _template.FullPath, fe.Line, fe.Column,
                                $"Tried to render file to '{adst}', but file exists. Check the template file for duplicate dst attributes.");
                    return(null);
                }

                var dir = Path.GetDirectoryName(adst);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                if (fe.Raw)
                {
                    _logger.Log(LogLevel.Info, $"Copying file '{asrc}' to '{adst}'.");
                    File.Copy(asrc, adst, true);
                }
                else
                {
                    _logger.Log(LogLevel.Info, $"Rendering file '{asrc}'.");
                    var text     = File.ReadAllText(asrc);
                    var rendered = RenderString(asrc, text, variables);
                    _logger.Log(LogLevel.Verbose, $"Writing file '{asrc}' to '{adst}'.");
                    File.WriteAllText(adst, rendered);
                }
                FileWritten?.Invoke(this, new RenderEventArgs(asrc, adst));
                return(adst);
            }
            catch (Exception e)
            {
                _logger.Log(LogLevel.Error, $"Error rendering '{fe.AbsoluteSrc ?? fe.RawRelativeSrc}':\n        {e.Message}");
                return(null);
            }
        }
Exemplo n.º 10
0
        public void WriteFile(string virtualPath, Stream inputStream)
        {
            if (!FileExists(virtualPath))
            {
                CreateFile(FileSystemPath.File(virtualPath), inputStream);
            }
            else
            {
                UpdateFile(FileSystemPath.File(virtualPath), inputStream);
            }

            if (FileWritten != null)
            {
                FileWritten.Invoke(this, new FileEventArgs(virtualPath, null));
            }
        }
Exemplo n.º 11
0
        public void WriteFile(string virtualPath, System.IO.Stream inputStream)
        {
            if (FileExists(virtualPath))
            {
                ReplaceFile(virtualPath, inputStream);
            }
            else
            {
                CreateFile(virtualPath, inputStream);
            }

            if (FileWritten != null)
            {
                FileWritten.Invoke(this, new FileEventArgs(virtualPath, null));
            }
        }
Exemplo n.º 12
0
        public void WriteFile(string virtualPath, System.IO.Stream inputStream)
        {
            string path = MapPath(virtualPath);

            if (!Directory.Exists(Path.GetDirectoryName(path)))
            {
                Directory.CreateDirectory((Path.GetDirectoryName(path)));
            }

            if (FileExists(virtualPath))
            {
                ReplaceFile(virtualPath, inputStream);
            }
            else
            {
                CreateFile(virtualPath, inputStream);
            }

            if (FileWritten != null)
            {
                FileWritten.Invoke(this, new FileEventArgs(virtualPath, null));
            }
        }
Exemplo n.º 13
0
        /// <summary>Creates or overwrites a file at the given path.</summary>
        /// <param name="virtualPath">The path of the file to create.</param>
        /// <param name="inputStream">An input stream of the file contents.</param>
        public virtual void WriteFile(string virtualPath, Stream inputStream)
        {
            string path = MapPath(virtualPath);

            if (FileExists(virtualPath))
            {
                using (Stream fileStream = File.OpenWrite(path))
                {
                    TransferBetweenStreams(inputStream, fileStream);
                }
            }
            else
            {
                using (Stream fileStream = File.Create(path))
                {
                    TransferBetweenStreams(inputStream, fileStream);
                }
            }

            if (FileWritten != null)
            {
                FileWritten.Invoke(this, new FileEventArgs(virtualPath, null));
            }
        }
Exemplo n.º 14
0
 public void WriteFile(string path)
 {
     FileWritten?.Invoke(path);
 }