Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //NumberStreamReader numberStreamReader = new NumberStreamReader();
            StreamOperations streamOperations = new StreamOperations();

            streamOperations.WriteToFile();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Copies output files to the cache directory, and also saves a '.names' file referring to he original target relative
        /// paths of these files.
        /// </summary>
        /// <param name="outputs">Build outputs to be copied</param>
        /// <param name="targetRoot">Root directory for the build outputs</param>
        /// <param name="cacheDir">Target directory for the copy operation</param>
        private void SaveOutputs(IEnumerable <TargetRelativePath> outputs, IFileSystemDirectory targetRoot, IFileSystemDirectory cacheDir)
        {
            using (var names = cacheDir.CreateTextFile(NamesFileName))
            {
                int idx = 0;
                foreach (var outputPath in outputs)
                {
                    try
                    {
                        // It is possible that the returned path is a special path and does not refer to an existing file
                        // In this case we only have to save the filename, without its contents
                        if (targetRoot.Exists(outputPath))
                        {
                            using (var source = targetRoot.ReadBinaryFile(outputPath))
                                using (var target = cacheDir.CreateBinaryFile(idx.ToString(CultureInfo.InvariantCulture)))
                                {
                                    StreamOperations.Copy(source, target);
                                }
                        }

                        names.WriteLine("{0};{1}", outputPath.RelativeRoot, outputPath.RelativePath);
                        idx++;
                    }
                    catch (IOException ex)
                    {
                        log.WarnFormat("IOException while reading {0}: {1}", outputPath, ex.Message);

                        if (!outputPath.RelativePath.ToLowerInvariant().EndsWith(".vshost.exe"))
                        {
                            throw;
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Copies a source file to a target location, but only if it does not exist yet, with the same MD5 checksum
        /// as the source
        /// </summary>
        /// <param name="sourceDirectory">Source root directory</param>
        /// <param name="sourceFileName">Source file's relative path</param>
        /// <param name="targetRoot">Target root directory</param>
        /// <param name="targetRelativePath">Target file's relative path</param>
        private void CopyIfDifferent(IFileSystemDirectory sourceDirectory, string sourceFileName, IFileSystemDirectory targetRoot, string targetRelativePath)
        {
            bool copy       = true;
            long sourceSize = sourceDirectory.GetFileSize(sourceFileName);

            if (targetRoot.Exists(targetRelativePath))
            {
                long targetSize = targetRoot.GetFileSize(targetRelativePath);
                if (sourceSize == targetSize)
                {
                    byte[] sourceChecksum = ComputeChecksum(sourceDirectory, sourceFileName);
                    byte[] targetChecksum = ComputeChecksum(targetRoot, targetRelativePath);

                    copy = !sourceChecksum.SequenceEqual(targetChecksum);
                }
            }

            if (copy)
            {
                using (var source = sourceDirectory.ReadBinaryFile(sourceFileName))
                    using (var target = targetRoot.CreateBinaryFileWithDirectories(targetRelativePath))
                        StreamOperations.Copy(source, target);
            }
            else
            {
                log.DebugFormat("File {0} is the same as the cached one", targetRelativePath);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Copies a file from the FS repository to a given target directory
 /// </summary>
 /// <param name="path">Path to the file in the FS repository</param>
 /// <param name="targetDir">Target directory</param>
 /// <param name="targetFileName">Target file name</param>
 public void Copy(string path, IFileSystemDirectory targetDir, string targetFileName)
 {
     using (var source = GetDirectory(path).ReadBinaryFile(Path.GetFileName(path)))
         using (var target = targetDir.CreateBinaryFile(targetFileName))
         {
             StreamOperations.Copy(source, target);
         }
 }
Ejemplo n.º 5
0
        public bool LoadImage(int productId, int sort, string pFilePath)
        {
            // byte[] imageData,
            Stream fileStream = new FileStream(pFilePath, FileMode.Open);

            _productImageService.ProcessImageProduct(Convert.ToInt32(productId), StreamOperations.ConvertStreamToByteArray(fileStream), sort);
            fileStream.Close();
            return(true);
        }
Ejemplo n.º 6
0
        private void Copy(SuiteRelativePath sourcePath, string relativePath)
        {
            var relativeDir = Path.GetDirectoryName(relativePath);
            var fileName    = Path.GetFileName(relativePath);
            var targetDir   = targetRoot.GetChildDirectory(project.Module.Name, createIfMissing: true);

            IFileSystemDirectory realTargetDir = String.IsNullOrWhiteSpace(relativeDir)
                ? targetDir
                : targetDir.GetChildDirectory(relativeDir, createIfMissing: true);

            using (var source = suiteRoot.ReadBinaryFile(sourcePath))
                using (var target = realTargetDir.CreateBinaryFile(fileName))
                    StreamOperations.Copy(source, target);
        }
Ejemplo n.º 7
0
        private void MergeOutputForProduct(Product product, ISet <TargetRelativePath> outputs)
        {
            log.InfoFormat("Merging {0} files to product output directory {1}...",
                           outputs.Count, new TargetRelativePath(product.Name, String.Empty));

            var productOutput = targetRoot.GetChildDirectory(product.Name, createIfMissing: true);

            foreach (var sourcePath in outputs)
            {
                if (sourcePath.RelativeRoot != product.Name) // Postprocessors can generate output to product output directory directly
                {
                    using (var source = targetRoot.ReadBinaryFile(sourcePath))
                        using (var target = productOutput.CreateBinaryFileWithDirectories(sourcePath.RelativePath))
                            StreamOperations.Copy(source, target);
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Runs this builder
        /// </summary>
        /// <param name="context">Current build context</param>
        /// <returns>Returns a set of generated files, in target relative paths</returns>
        public override ISet <TargetRelativePath> Run(IBuildContext context)
        {
            if (output != null)
            {
                output.Message(String.Format("Resolving reference {0}", reference.Uri));
            }

            var depsRoot   = targetRoot.CreateDirectory("deps");
            var sourcePath = reference.Uri.OriginalString.Substring(7).Replace('/', Path.DirectorySeparatorChar).TrimEnd(Path.DirectorySeparatorChar);
            var fileName   = Path.GetFileName(sourcePath);

            using (var source = new FileStream(sourcePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (var target = depsRoot.CreateBinaryFile(sourcePath))
                {
                    StreamOperations.Copy(source, target);
                }

            return(new HashSet <TargetRelativePath>(new[]
            {
                new TargetRelativePath(targetRoot.GetRelativePath(depsRoot), fileName)
            }));
        }
Ejemplo n.º 9
0
 private void Copy(TargetRelativePath sourcePath, string relativePath)
 {
     using (var source = targetRoot.ReadBinaryFile(sourcePath))
         using (var target = targetDirectory.CreateBinaryFileWithDirectories(relativePath))
             StreamOperations.Copy(source, target);
 }