public IDocumentId MakeDocument(IContentManagerArenaId arena, string filePath, FileUsingMode mode = FileUsingMode.AutoDetect, bool deleteSourceFile = false, string fileName = null) { if (arena is null) { throw new ArgumentNullException(nameof(arena)); } if (string.IsNullOrWhiteSpace(filePath)) { throw new ArgumentException(nameof(filePath)); } if (!File.Exists(filePath)) { throw new ArgumentException($"{nameof(filePath)} = '{filePath}' does not exists."); } fileName = fileName ?? Path.GetFileName(filePath); if (string.IsNullOrWhiteSpace(fileName)) { throw new ArgumentException(nameof(fileName) + " is empty."); } if (mode == FileUsingMode.AutoDetect) { mode = PathIsNetworkPath(filePath) ? FileUsingMode.CopySourceFile : FileUsingMode.UseSourceFile; } IDocumentId documentId = null; IContentProvider contentProvider = null; Action <IDocumentId> onCloseArena = OnCloseArenaDeleteDocument; switch (mode) { case FileUsingMode.UseSourceFile: { if (!deleteSourceFile) { onCloseArena = null; } documentId = new DocumentIdImpl(arena, filePath); } break; case FileUsingMode.CopySourceFile: { var arenaFilePath = Path.GetTempFileName(); if (deleteSourceFile) { File.Move(filePath, arenaFilePath, true); documentId = new DocumentIdImpl(arena, arenaFilePath); } else { contentProvider = new FileContentProvider(contentDestinationPath => File.Copy(filePath, contentDestinationPath, true), () => File.Length(filePath)); documentId = new DocumentIdImpl(arena, arenaFilePath); } } break; default: throw new NotImplementedException($"{nameof(mode)}={mode}"); } AddDocumentInfo(documentId, new DocumentInfo(fileName, onCloseArena, contentProvider)); return(documentId); }
private void PushPackage(PackageProject metadata, string packageFormat, byte[] data) { var directory = Path.Combine(configuration.DataPath, metadata.Name, metadata.Version.Name); Directory.CreateDirectory(directory); var file = Path.Combine(directory, GetPackageName(packageFormat, metadata.Name, metadata.Version.Name)); if (File.Exists(file)) { File.Delete(file); } File.WriteAllBytes(file, data); }
private void CreateJob(PackageProject metadata, byte[] data) { string directory = Path.Combine(metadata.Name, metadata.Version.Name); Directory.CreateDirectory(Path.Combine(configuration.DataPath, directory)); string file = Path.Combine(configuration.DataPath, directory, metadata.Name + ".symbols.zip"); if (File.Exists(file)) { File.Delete(file); } File.WriteAllBytes(file, data); using (var zipMemoryStream = new MemoryStream(data)) using (var zipfile = ZipFile.Read(zipMemoryStream)) { var zipInfo = new TransformingWrapperPackageFile(new ZipPackageFile(zipfile), new UrlTransformation()); var addInfo = addInfoBuilder.Build(zipInfo); string binariesDirectory = Path.Combine(directory, "Binaries"); Directory.CreateDirectory(Path.Combine(configuration.DataPath, binariesDirectory)); string sourcesDirectory = Path.Combine(directory, "Sources"); Directory.CreateDirectory(Path.Combine(configuration.DataPath, sourcesDirectory)); foreach (var binaryInfo in addInfo.Binaries) { if (binaryInfo.SymbolInfo == null) { continue; } if (binaryInfo.SymbolHash != binaryInfo.SymbolInfo.Hash) { throw new InvalidOperationException(string.Format("Incorrect hash code for '{0}' binaryHash '{1}' symbolHash '{2}'.", binaryInfo.Name, binaryInfo.SymbolHash, binaryInfo.SymbolInfo.Hash)); } string binaryDirectory = Path.Combine(binariesDirectory, binaryInfo.Name, binaryInfo.SymbolHash); Directory.CreateDirectory(Path.Combine(configuration.DataPath, binaryDirectory)); using (var binaryInfoStream = binaryInfo.File.Stream) { using (var binaryStream = File.OpenWrite(Path.Combine(configuration.DataPath, binaryDirectory, binaryInfo.Name + "." + binaryInfo.Type))) binaryInfoStream.CopyTo(binaryStream); } using (var symbolInfoStream = binaryInfo.SymbolInfo.File.Stream) { using (var symbolStream = File.OpenWrite(Path.Combine(configuration.DataPath, binaryDirectory, binaryInfo.Name + "." + binaryInfo.SymbolInfo.Type))) symbolInfoStream.CopyTo(symbolStream); } string indexDirectory = Path.Combine(configuration.IndexPath, binaryInfo.Name); Directory.CreateDirectory(indexDirectory); File.AppendAllText(Path.Combine(indexDirectory, binaryInfo.SymbolHash + ".txt"), binaryDirectory + Environment.NewLine); var sourceIndex = new List <string>(); foreach (var sourceInfo in binaryInfo.SymbolInfo.SourceInfos.Where(info => info.ActualPath != null)) { string sourcePath = Path.Combine(sourcesDirectory, sourceInfo.KeyPath.Replace(":/", "")); Directory.CreateDirectory(Path.Combine(configuration.DataPath, Path.GetDirectoryName(sourcePath))); sourceIndex.Add(sourceInfo.OriginalPath + "|" + sourceInfo.KeyPath.Replace(":/", "")); using (var sourceInfoStream = sourceInfo.ActualPath.Stream) { using (var convertedStream = SourceConverter.Convert(sourceInfoStream)) { using (var sourceStream = File.OpenWrite(Path.Combine(configuration.DataPath, sourcePath))) convertedStream.CopyTo(sourceStream); } } } var txtFile = Path.Combine(configuration.DataPath, binaryDirectory, binaryInfo.Name + ".txt"); if (File.Exists(txtFile)) { File.Delete(txtFile); } File.WriteAllLines(txtFile, sourceIndex.ToArray()); } } File.Delete(file); }