private ITaskItem[] GetOutputFiles(PublishInfo[] publishInfos) { List <ITaskItem> list = new List <ITaskItem>(); FileMap map = new FileMap(); if (this.Files != null) { foreach (ITaskItem item in this.Files) { map.Add(item, true); } } if (this.ExtraFiles != null) { foreach (ITaskItem item2 in this.ExtraFiles) { map.Add(item2, false); } } foreach (PublishInfo info in publishInfos) { MapEntry entry = map[info.key]; if (entry != null) { entry.publishInfo = info; } else { base.Log.LogWarningWithCodeFromResources("ResolveManifestFiles.PublishFileNotFound", new object[] { info.key }); } } foreach (MapEntry entry2 in (IEnumerable)map) { if (entry2.publishInfo == null) { entry2.publishInfo = new PublishInfo(); } string extension = Path.GetExtension(entry2.item.ItemSpec); PublishFlags flags = PublishFlags.GetFileFlags(entry2.publishInfo.state, extension, entry2.includedByDefault); if ((flags.IsPublished && string.Equals(entry2.publishInfo.includeHash, "false", StringComparison.OrdinalIgnoreCase)) && this.SigningManifests) { this.canPublish = false; } if (flags.IsPublished) { list.Add(CreateFileItem(entry2.item, entry2.publishInfo.group, entry2.publishInfo.targetPath, entry2.publishInfo.includeHash, flags.IsDataFile)); } } return(list.ToArray()); }
// // Outer funcs // /// <summary> /// This functions asks the AAS REST repository on given location, which AasIds would be availble. /// Using the AasIds, details are retrieved for each inidivudal AAS and synchronized with the /// repository. /// Note: for the time being, the list of file items is recreated, but not synchronized /// Note: due to the nature of long-lasting actions, this is by design async! /// </summary> /// <returns>If a successfull retrieval could be made</returns> public async Task <bool> SyncronizeFromServerAsync() { // access if (true != _connector?.IsValid()) { return(false); } // try get a list of items from the connector var items = await _connector.GenerateRepositoryFromEndpointAsync(); // just re-set FileMap.Clear(); foreach (var fi in items) { if (fi != null) { FileMap.Add(fi); fi.ContainerList = this; } } // ok return(true); }
IDictionary <UInt32, UInt32> CorrectOffsets() { var changes = new SortedDictionary <UInt32, UInt32>(); var list = FileMap.ToList(); var firstinstructioindex = list.FindIndex(x => x.Value is Bytecode.Instruction); var itemoffset = list[firstinstructioindex].Key; for (var i = firstinstructioindex; i >= 0 && i < list.Count; ++i) { var item = list[i]; if (itemoffset != item.Key) { var diff = itemoffset - item.Key; list[i] = new KeyValuePair <UInt32, Object>(itemoffset, item.Value); changes[item.Key] = itemoffset; } var size = (UInt32)GetObjectSize(item.Value); itemoffset += size; } FileMap.Clear(); foreach (var item in list) { FileMap.Add(item.Key, item.Value); } return(changes); }
IDictionary <UInt32, String> ReadStringMap(FileReader reader, FileHeaders.SCENARIO_HEADER header) { var map = new SortedDictionary <UInt32, String>(); reader.Stream.Position = header.StringTableOffset; while (true) { if (reader.Stream.Position == reader.Stream.Length) { break; } var offset = (UInt32)reader.Stream.Position; var str = reader.ReadString(); map.Add(offset, str); FileMap.Add(offset, str); if (str == "") { break; } } return(map); }
// Files private void AddFiles(object obj) { try { FileData root = (FileData)obj; // Folders foreach (FileData folder in root.GetFolders()) { lock (FolderMap) FolderMap.Add(folder.Id, folder); AddFiles(folder); } // Files foreach (FileData file in root.GetFiles()) { // Do not verify if the file is accessible lock (FileMap) FileMap.Add(file.Id, file); } } catch (Exception ex) { Console.WriteLine(ex.Message); } OnFile(); }
/// <summary> /// Unwraps the provided file with either a callback or the target directory /// </summary> /// <param name="wrapperFile">the file that contains the wrapped content</param> /// <param name="targetFile">the target file into which the content is unwrapped</param> /// <param name="unwrappedFiles">a fileMap that contains the unwrapped item</param> /// <param name="performUnzip">indicates whether to actually perform the unpacking process</param> /// <param name="requestStream">a callback that is used to create a new stream if required</param> /// <returns>a value indicating whether the unwrapping was successful</returns> private bool UnwrapFile(Stream wrapperFile, string targetFile, FileMap unwrappedFiles, bool performUnzip, Func <string, Stream> requestStream = null) { FileMapEntry ent; unwrappedFiles.Add(ent = new FileMapEntry(Path.GetFileName(targetFile))); if (performUnzip) { using (GZipInputStream gzis = new GZipInputStream(wrapperFile)) { using ( /*Stream fso = (requestStream == null) * ? new FileStream(targetFile, FileMode.Create, FileAccess.ReadWrite) * : (requestStream(targetFile) ?? * new FileStream(targetFile, FileMode.Create, FileAccess.ReadWrite)))*/ var fso = ent.Open()) { gzis.CopyTo(fso); } } } return(true); }
private void GetOutputSatellites(PublishInfo[] publishInfos, ref List <ITaskItem> assemblyList) { FileMap satelliteMap = new FileMap(); if (_satelliteAssemblies != null) { foreach (ITaskItem item in _satelliteAssemblies) { item.SetMetadata("AssemblyType", "Satellite"); satelliteMap.Add(item, true); } } // Apply PublishInfo state from PublishFile items... foreach (PublishInfo publishInfo in publishInfos) { string key = publishInfo.key + ".dll"; MapEntry entry = satelliteMap[key]; if (entry != null) { entry.publishInfo = publishInfo; } else { Log.LogWarningWithCodeFromResources("ResolveManifestFiles.PublishFileNotFound", publishInfo.key); } } // Go through the AssemblyMap and determine which items get added to ouput SatelliteList based // on computed PublishFlags for each item... foreach (MapEntry entry in satelliteMap) { // If PublishInfo didn't come from a PublishFile item, then construct PublishInfo from the item if (entry.publishInfo == null) { entry.publishInfo = new PublishInfo(); } CultureInfo satelliteCulture = GetItemCulture(entry.item); PublishFlags flags = PublishFlags.GetSatelliteFlags(entry.publishInfo.state, satelliteCulture, _targetCulture, _includeAllSatellites); if (flags.IsPublished && string.Equals(entry.publishInfo.includeHash, "false", StringComparison.OrdinalIgnoreCase) && SigningManifests == true) { _canPublish = false; } if (flags.IsPublished) { assemblyList.Add(CreateAssemblyItem(entry.item, entry.publishInfo.group, entry.publishInfo.targetPath, entry.publishInfo.includeHash)); } else if (flags.IsPrerequisite) { assemblyList.Add(CreatePrerequisiteItem(entry.item)); } } }
/// <summary> /// Unwraps a zip into a given directory /// </summary> /// <param name="zipFile">the zip-file to unwrap into the targetdirectory</param> /// <param name="targetDirectory">the targetdirectory in which to extract all files</param> /// <param name="performUnzip">indicates whether to perform the actual unpacking process</param> /// <param name="getStreamCallback">callback that is used to provide a stream for unwrapped content</param> /// <param name="copyAction">An action defining what happens while copying the content of the Stream to the target file</param> /// <param name="ignoreNullStreams">indicates whether to prevent files, for which the getStreamCallback method returns null, from being unwrapped</param> /// <param name="password">the password that is used to access the zip file</param> /// <returns>an array containing all extracted filenames</returns> private FileMap UnwrapZip(Stream zipFile, string targetDirectory, bool performUnzip, Func <FileMapEntry, Stream> getStreamCallback = null, Action <Stream, Stream> copyAction = null, bool ignoreNullStreams = false, string password = null) { FileMap map = new FileMap(targetDirectory, flattenStructure); if (copyAction == null) { copyAction = (input, output) => { try { input.CopyTo(output); } finally { output.Dispose(); } }; } using (ZipFile fl = new ZipFile(zipFile)) { if (password != null) { fl.Password = password; } foreach (ZipEntry ent in fl) { if (!ent.IsDirectory) { FileMapEntry entry = new FileMapEntry(ent.Name); map.Add(entry); if (performUnzip) { using (Stream s = fl.GetInputStream(ent)) { Stream fs = (getStreamCallback == null) ? entry.Open() : getStreamCallback(entry); if (fs == null && !ignoreNullStreams) { fs = entry.Open(); } if (fs != null) { copyAction(s, fs); } } } } } } return(map); }
/// <summary> /// Untars a file by either using the target directory or streams provided by the getStreamCallback function /// </summary> /// <param name="targetDirectory">the target directory into which to export the unwrapped files</param> /// <param name="tarStream">the tarstream that is used to export the files</param> /// <param name="unpack">indicates whether to actually perform the unpacking process</param> /// <param name="getStreamCallback">a callback that provides streams for each unwrapped file</param> /// <param name="copyAction">the action to execute for copying the content of the stream to the target</param> /// <param name="ignoreNullStreams">indicates whether to prevent using the default-directory when getStreamCallback does return null</param> /// <returns>a filemap that contains all unwrapped files and their result/source paths</returns> private FileMap UnTarFiles(string targetDirectory, TarStreamHelper tarStream, bool unpack, [InstantHandle] Func <FileMapEntry, Stream> getStreamCallback = null, [InstantHandle] Action <Stream, Stream> copyAction = null, bool ignoreNullStreams = false) { FileMap map = new FileMap(targetDirectory, flattenStructure); TarEntry entry; if (copyAction == null) { copyAction = (input, output) => { try { input.CopyTo(output); } finally { output.Dispose(); } }; } while ((entry = tarStream.InputStream.GetNextEntry()) != null) { if (!entry.IsDirectory) { FileMapEntry ent = new FileMapEntry(entry.Name); map.Add(ent); if (unpack) { Stream fout = (getStreamCallback == null) ? ent.Open() : getStreamCallback(ent); if (fout == null && !ignoreNullStreams) { fout = ent.Open(); } if (fout != null) { copyAction(tarStream.InputStream, fout); } } } } return(map); }
private void GetOutputSatellites(PublishInfo[] publishInfos, ref List <ITaskItem> assemblyList) { FileMap map = new FileMap(); if (this.satelliteAssemblies != null) { foreach (ITaskItem item in this.satelliteAssemblies) { item.SetMetadata("AssemblyType", "Satellite"); map.Add(item, true); } } foreach (PublishInfo info in publishInfos) { string str = info.key + ".dll"; MapEntry entry = map[str]; if (entry != null) { entry.publishInfo = info; } else { base.Log.LogWarningWithCodeFromResources("ResolveManifestFiles.PublishFileNotFound", new object[] { info.key }); } } foreach (MapEntry entry2 in (IEnumerable)map) { if (entry2.publishInfo == null) { entry2.publishInfo = new PublishInfo(); } CultureInfo itemCulture = GetItemCulture(entry2.item); PublishFlags flags = PublishFlags.GetSatelliteFlags(entry2.publishInfo.state, itemCulture, this.targetCulture, this.includeAllSatellites); if ((flags.IsPublished && string.Equals(entry2.publishInfo.includeHash, "false", StringComparison.OrdinalIgnoreCase)) && this.SigningManifests) { this.canPublish = false; } if (flags.IsPublished) { assemblyList.Add(CreateAssemblyItem(entry2.item, entry2.publishInfo.group, entry2.publishInfo.targetPath, entry2.publishInfo.includeHash)); } else if (flags.IsPrerequisite) { assemblyList.Add(CreatePrerequisiteItem(entry2.item)); } } }
public override string AddContent(string sourcePath) { string result; if (!FileMap.ContainsKey(sourcePath)) { string destFileName = GenerateContentFileName(sourcePath); FileMap.Add(sourcePath, destFileName); result = destFileName; } else { result = FileMap[sourcePath]; } return(Path.Combine(ExecutionContext.PACKAGE_CONTENT_TAG, result)); }
IDictionary <UInt32, Bytecode.Instruction> ReadFunctions(FileReader reader, List <UInt32> functionoffsets) { var instructionmap = new SortedDictionary <UInt32, Bytecode.Instruction>(); var disassembler = new Bytecode.Disassembler(InstructionTableType); foreach (var offset in functionoffsets) { reader.Stream.Position = offset; disassembler.Disassemble(reader, instructionmap); } foreach (var item in instructionmap) { FileMap.Add(item.Key, item.Value); } return(instructionmap); }
protected void AddContent(string sourcePath, string destFileName) { FileMap.Add(sourcePath, destFileName); }
private ITaskItem[] GetOutputFiles(PublishInfo[] publishInfos) { List <ITaskItem> fileList = new List <ITaskItem>(); FileMap fileMap = new FileMap(); // Add all input Files to the FileMap, flagging them to be published by default... if (Files != null) { foreach (ITaskItem item in Files) { fileMap.Add(item, true); } } // Add all input ExtraFiles to the FileMap, flagging them to NOT be published by default... if (ExtraFiles != null) { foreach (ITaskItem item in ExtraFiles) { fileMap.Add(item, false); } } // Apply PublishInfo state from PublishFile items... foreach (PublishInfo publishInfo in publishInfos) { MapEntry entry = fileMap[publishInfo.key]; if (entry != null) { entry.publishInfo = publishInfo; } else { Log.LogWarningWithCodeFromResources("ResolveManifestFiles.PublishFileNotFound", publishInfo.key); } } // Go through the FileMap and determine which items get added to ouput FileList based // on computed PublishFlags for each item... foreach (MapEntry entry in fileMap) { // If PublishInfo didn't come from a PublishFile item, then construct PublishInfo from the item if (entry.publishInfo == null) { entry.publishInfo = new PublishInfo(); } string fileExtension = Path.GetExtension(entry.item.ItemSpec); PublishFlags flags = PublishFlags.GetFileFlags(entry.publishInfo.state, fileExtension, entry.includedByDefault); if (flags.IsPublished && string.Equals(entry.publishInfo.includeHash, "false", StringComparison.OrdinalIgnoreCase) && SigningManifests == true) { _canPublish = false; } if (flags.IsPublished) { fileList.Add(CreateFileItem(entry.item, entry.publishInfo.group, entry.publishInfo.targetPath, entry.publishInfo.includeHash, flags.IsDataFile)); } } return(fileList.ToArray()); }
/** * 添加POST文件 * * @param key a {@link java.lang.String} object. * @param file a {@link java.io.File} object. */ public void AddPostFile(string key, string file) { FileMap.Add(key, file, AddChoice.Update); }