public static bool HasChanged(this TargetFile targetFile) { FileInfo fileInfo = new FileInfo(targetFile.FilePath); return(fileInfo.Exists && (fileInfo.Length != targetFile.FileSize || fileInfo.LastWriteTime != targetFile.ModifiedTime)); }
internal override IEnumerable <object> Process(IEnumerable <object> input) { // Unlike other pipeline components, converters must initialize/coordinate with the downstream // component to create the output stream e.g. files. _target = (TargetFile)GetDownstreamComponent(); // Get our input explicitly via the input parameter, or implicitly via the upstream component. if (input == null) { // Upstream component must support the IDataReader interface. _reader = (IDataReader)GetUpstreamComponent(); ProcessInput(); } else { foreach (var i in input) { // Input must support the IDataReader interface. _reader = (IDataReader)i; ProcessInput(); } } return(null); }
public bool Execute(string packageName, XmlNode xmlData) { Initialize(xmlData); if (TargetFile != null) { XElement root = TargetFile.Root; if (root == null) { root = new XElement(SourceFile.Root.Name); TargetFile.Add(root); } if (!fileMoved) { MergeElement(SourceFile.Root, root); //Save file TargetFile.Save(TargetFilePath, SaveOptions.None); if (!embeddedResource) { File.Delete(HostingEnvironment.MapPath(SourceFilePath)); } } } return(true); }
public void Writing_Whole_File_In_Streamed_Blocks_Should_Create_Exact_Copy() { //use an output stream which works with buffers StreamedBlockOutputStream os = new StreamedBlockOutputStream(Token, 15000, b => UploadHandler.WriteBlockStreamed(b)); MemoryStream ms = new MemoryStream(SourceFileContents); ms.WriteTo(os); UploadHandler.CompleteTransfer(Token.TransferId); TargetFile.Refresh(); FileAssert.AreEqual(SourceFilePath, TargetFilePath); TargetFile.Delete(); InitToken(); //use a source strem using (var fs = SourceFile.OpenRead()) { fs.WriteTo(Token, SourceFile.Length, 10000, b => UploadHandler.WriteBlockStreamed(b)); UploadHandler.CompleteTransfer(Token.TransferId); TargetFile.Refresh(); FileAssert.AreEqual(SourceFilePath, TargetFilePath); } }
public static TargetFile CreateTargetFile(string sourceFile) { FileInfo file = new FileInfo(sourceFile); Console.WriteLine($" =>>>>>>> Dosya Oluşturma Tarihi \t : {file.LastWriteTime}"); var backupFileYear = file.LastWriteTime.Year; var backupFileMonth = file.LastWriteTime.Month; var backupFileDay = file.LastWriteTime.Day; var backupHour = file.LastWriteTime.Hour; var targetDirectory = $"{backupFileYear}-{backupFileMonth}-{backupFileDay}-{backupHour}"; var targetDrive = System.Configuration.ConfigurationManager.AppSettings["TargetDrive"]; var targetPath = $"{targetDrive}{targetDirectory}"; if (!Directory.Exists(targetPath)) { Directory.CreateDirectory(targetPath); } else { Console.WriteLine($"{targetPath} dizininde zaten mevcut. Kaynak dosya değişmemiş olabilir "); } TargetFile targetFile = new TargetFile { TargetDataFile = Path.Combine(targetPath, $"{targetDirectory}.{dataFileExt}"), TargetLogFile = Path.Combine(targetPath, $"{targetDirectory}.{logFileExt}") }; return(targetFile); }
/// <summary> /// Constructor. Compiles a rules assembly from the given source files. /// </summary> /// <param name="Plugins">All the plugins included in this assembly</param> /// <param name="ModuleFiles">List of module files to compile</param> /// <param name="TargetFiles">List of target files to compile</param> /// <param name="ModuleFileToPluginInfo">Mapping of module file to the plugin that contains it</param> /// <param name="AssemblyFileName">The output path for the compiled assembly</param> /// <param name="Parent">The parent rules assembly</param> public RulesAssembly(IReadOnlyList <PluginInfo> Plugins, List <FileReference> ModuleFiles, List <FileReference> TargetFiles, Dictionary <FileReference, PluginInfo> ModuleFileToPluginInfo, FileReference AssemblyFileName, RulesAssembly Parent) { this.Plugins = Plugins; this.ModuleFileToPluginInfo = ModuleFileToPluginInfo; this.Parent = Parent; // Find all the source files List <FileReference> AssemblySourceFiles = new List <FileReference>(); AssemblySourceFiles.AddRange(ModuleFiles); AssemblySourceFiles.AddRange(TargetFiles); // Compile the assembly if (AssemblySourceFiles.Count > 0) { CompiledAssembly = DynamicCompilation.CompileAndLoadAssembly(AssemblyFileName, AssemblySourceFiles); } // Setup the module map foreach (FileReference ModuleFile in ModuleFiles) { string ModuleName = ModuleFile.GetFileNameWithoutAnyExtensions(); if (!ModuleNameToModuleFile.ContainsKey(ModuleName)) { ModuleNameToModuleFile.Add(ModuleName, ModuleFile); } } // Setup the target map foreach (FileReference TargetFile in TargetFiles) { string TargetName = TargetFile.GetFileNameWithoutAnyExtensions(); if (!TargetNameToTargetFile.ContainsKey(TargetName)) { TargetNameToTargetFile.Add(TargetName, TargetFile); } } /// Write any deprecation warnings for methods overriden from a base with the [ObsoleteOverride] attribute. Unlike the [Obsolete] attribute, this ensures the message /// is given because the method is implemented, not because it's called. if (CompiledAssembly != null) { foreach (Type CompiledType in CompiledAssembly.GetTypes()) { foreach (MethodInfo Method in CompiledType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)) { ObsoleteOverrideAttribute Attribute = Method.GetCustomAttribute <ObsoleteOverrideAttribute>(true); if (Attribute != null) { FileReference Location; if (!TryGetFileNameFromType(CompiledType, out Location)) { Location = new FileReference(CompiledAssembly.Location); } Log.TraceWarning("{0}: warning: {1}", Location, Attribute.Message); } } } } }
protected override void Execute(CodeActivityContext context) { try { var file1 = SourceFile.Get(context); var file2 = TargetFile.Get(context); var handler = new TestXmlCompareHandler(); using (var comparer = new Comparer(handler)) { comparer.Compare(file1, file2, handler); } } catch (Exception ex) { throw; } try { ResultProcessor.CompleteDetailedReport(ResultPath.Get(context)); } catch (Exception ex) { throw; } }
public static void UpdateProperties(this TargetFile targetFile) { FileInfo fileInfo = new FileInfo(targetFile.FilePath); targetFile.FileSize = fileInfo.Exists ? fileInfo.Length : -1; targetFile.ModifiedTime = fileInfo.Exists ? fileInfo.LastWriteTime : DateTime.MinValue; }
public override PackageBuilder[] CreateDefaultBuilders() { List <PackageBuilder> list = new List <PackageBuilder> (); foreach (FileFormat format in Services.ProjectService.FileFormats.GetFileFormatsForObject(RootSolutionItem)) { SourcesZipPackageBuilder pb = (SourcesZipPackageBuilder)Clone(); pb.FileFormat = format; // The suffix for the archive will be the extension of the file format. // If there is no extension, use the whole file name. string fname = format.GetValidFileName(RootSolutionItem, RootSolutionItem.ParentSolution.FileName); string suffix = Path.GetExtension(fname); if (suffix.Length > 0) { suffix = suffix.Substring(1).ToLower(); // Remove the initial dot } else { suffix = Path.GetFileNameWithoutExtension(suffix).ToLower(); } // Change the name in the target file string ext = DeployService.GetArchiveExtension(pb.TargetFile); string fn = TargetFile.Substring(0, TargetFile.Length - ext.Length); pb.TargetFile = fn + "-" + suffix + ext; list.Add(pb); } return(list.ToArray()); }
//-----------< create xml file and write info >-------------- public void xmlCreation(string[] args) { List <string> description; List <string> dependency; List <string> keyword; List <string> category; List <string> child; //get tag names stored by calling getElement function ExtractTags et = new ExtractTags(); et.getElement(args, out category, out child, out description, out dependency, out keyword); FileInfo targetfile; bool exsit; TargetFile tf = new TargetFile(); tf.getFile(args, out targetfile, out exsit); if (exsit) { XmlTextWriter tw = null; string name = targetfile + ".xml"; tw = new XmlTextWriter("090", null); tw.Formatting = Formatting.Indented; tw.WriteStartDocument(); tw.WriteStartElement("xmlfile"); tw.WriteElementString("name", targetfile.ToString()); foreach (string cat in category) { tw.WriteElementString("category", cat); } foreach (string chi in child) { tw.WriteElementString("child", chi); } foreach (string des in description) { tw.WriteElementString("description", des); } foreach (string dep in dependency) { tw.WriteElementString("dependency", dep); } foreach (string key in keyword) { tw.WriteElementString("keyword", key); } tw.WriteElementString("size", targetfile.Length.ToString()); tw.WriteElementString("time-date", targetfile.LastWriteTime.ToString()); tw.WriteEndElement(); tw.WriteEndDocument(); tw.Flush(); tw.Close(); ShowXml(name); } else { Console.Write("\n\n ERROR! {0} can not be found!\n\n", args[0]); } }
public void Initiating_Token_Should_Not_Delete_Existing_File_Yet() { Token = UploadHandler.RequestUploadToken(TargetFilePath, true, SourceFile.Length, ""); TargetFile.Refresh(); Assert.IsTrue(TargetFile.Exists); Assert.AreEqual(2048, TargetFile.Length); }
/// <summary> /// Tries to get an exclusive file lock on the <see cref="TargetFile"/>. /// This causes an exception if the file is in use. /// </summary> protected void EnsureTargetFileIsUnlocked() { //getting an exclusive stream only works if the file was released using (var fs = TargetFile.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)) { fs.Close(); } }
public void Cancelling_Transfer_Before_Writing_Any_Data_Should_Retain_File_That_Would_Have_Overwritten() { Token = UploadHandler.RequestUploadToken(TargetFilePath, true, SourceFile.Length, ""); UploadHandler.CancelTransfer(Token.TransferId, AbortReason.ClientAbort); TargetFile.Refresh(); Assert.IsTrue(TargetFile.Exists); Assert.AreEqual(2048, TargetFile.Length); }
public override void Execute() { var version = GetLastBackupVersion() + 1; var backupPath = string.Format(BackupFomat, TargetFile.FullName, version); TargetFile.CopyTo(backupPath); Log(string.Format("Backed up for: {0} (version {1})", Operator, version)); }
private async void selectTargetFile(object sender, RoutedEventArgs e) { var picker = new Windows.Storage.Pickers.FileOpenPicker(); picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail; picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop; picker.FileTypeFilter.Add("*"); Windows.Storage.StorageFile file = await picker.PickSingleFileAsync(); if (file != null) { // Removes the "New TF will open..." message this.textBlock4.Text = ""; if (this.tf != null) { tf.refreshLetters(); //Refreshes the Linked List counter in previous TargetFile } this.tf = new TargetFile(file, file.Path, tmpEntriesCount); textBlock3.Text = "Finding all characters in the target file, please wait..."; disableAllControls(); await Task.Run(() => findLet()); enableAllControls(); textBlock3.Text = ""; targetFilePath = file.Path; textBlock1.Text = "Target file: " + targetFilePath; button3.IsEnabled = true; if (mf != null && PWS.Count > 0) { button5.IsEnabled = true; } else { button5.IsEnabled = false; } if (listBox.Items.Count > 0) { button2.IsEnabled = true; } else { button2.IsEnabled = false; } } else { // do nothing } }
public override void ApplyChunk(ZiPatchConfig config) { TargetFile.ResolvePath(config.Platform); var file = config.Store == null? TargetFile.OpenStream(config.GamePath, FileMode.OpenOrCreate) : TargetFile.OpenStream(config.Store, config.GamePath, FileMode.OpenOrCreate); file.WriteFromOffset(HeaderData, HeaderKind == TargetHeaderKind.Version ? 0 : HEADER_SIZE); }
public override void ApplyChunk(ZiPatchConfig config) { TargetFile.ResolvePath(config.Platform); var file = config.Store == null? TargetFile.OpenStream(config.GamePath, FileMode.OpenOrCreate) : TargetFile.OpenStream(config.Store, config.GamePath, FileMode.OpenOrCreate); SqpackDatFile.WriteEmptyFileBlockAt(file, BlockOffset, BlockNumber); }
private void OpenButton_Click(object sender, EventArgs e) { CloseFile(); DialogResult dr = TargetFile.ShowDialog(); if (dr == DialogResult.OK) { OpenFile(TargetFile.FileName); } }
private TargetFile CreateTargetFromCustomFormat(IInputFile inputFile) { TargetFile targetFile; var customFormat = (CustomFormat)inputFile; var accountType = GetAccountType(customFormat.Type, EnumFileFormat.Custom); var currencyCode = GetCurrency(customFormat.Currency); targetFile = new TargetFile(customFormat.CustodianCode, customFormat.Name, accountType.ToString(), currencyCode.ToString()); return(targetFile); }
public override void ApplyChunk(ZiPatchConfig config) { TargetFile.ResolvePath(config.Platform); var file = config.Store == null? TargetFile.OpenStream(config.GamePath, FileMode.OpenOrCreate) : TargetFile.OpenStream(config.Store, config.GamePath, FileMode.OpenOrCreate); file.WriteFromOffset(BlockData, BlockOffset); file.Wipe(BlockDeleteNumber); }
private static void TryWatchFile(TargetFile targetFile) { if (Directory.Exists(targetFile.Path)) { Logger.Add($"[{targetFile.Id}] Watching \"{targetFile.FilePath}\""); targetFile.EnableWatcher(); } else { Logger.Add(LogType.Warning, $"[{targetFile.Id}] Unable to watch \"{targetFile.FilePath}\" (path does not exist)"); } }
public void Cancelling_Transfer_While_Uploading_Should_Delete_Partial_File() { Token = UploadHandler.RequestUploadToken(TargetFilePath, true, SourceFile.Length, ""); var block = CreateBufferedBlocks().First(); UploadHandler.WriteBlock(block); UploadHandler.CancelTransfer(Token.TransferId, AbortReason.ClientAbort); TargetFile.Refresh(); Assert.IsFalse(TargetFile.Exists); }
public void Writing_First_Block_Should_Replace_File() { Token = UploadHandler.RequestUploadToken(TargetFilePath, true, SourceFile.Length, ""); var block = CreateBufferedBlocks().First(); UploadHandler.WriteBlock(block); TargetFile.Refresh(); Assert.AreNotEqual(2048, TargetFile.Length); Assert.AreEqual(block.BlockLength, TargetFile.Length); }
public void Writing_Whole_File_In_Buffered_Blocks_Should_Create_Exact_Copy() { BufferedBlockOutputStream os = new BufferedBlockOutputStream(Token, 15000, b => UploadHandler.WriteBlock(b)); MemoryStream ms = new MemoryStream(SourceFileContents); ms.WriteTo(os); UploadHandler.CompleteTransfer(Token.TransferId); TargetFile.Refresh(); FileAssert.AreEqual(SourceFilePath, TargetFilePath); }
public void PrepareTargetFile(TargetFile targetFile, string text, Encoding encoding = null) { PrepareTargetFile(targetFile, FileState.Text); if (encoding == null) { File.WriteAllText(GetPath(targetFile), text); } else { File.WriteAllText(GetPath(targetFile), text, encoding); } }
public void Check_GetOutputFilePath() { string targetfile_Name = "lib"; string expected_OutputPath = Path.Combine(OutputPath, BaseName) + targetfile_Name; //arrange var targetfile = new TargetFile(targetfile_Name); //act var targetfilewriter = new TargetFileWriter(OutputPath, BaseName); var actual = targetfilewriter.GetOutputFilePath(targetfile); actual.Should().Be(expected_OutputPath); }
public static string ReadContent(this TargetFile targetFile, int retries = 3) { while (true) { try { return(File.ReadAllText(targetFile.FilePath, Encoding.UTF8)); } catch (IOException) when(retries-- > 0) { Thread.Sleep(TimeSpan.FromMilliseconds(200)); } } }
private void CheckFile(TargetFile targetFile, CheckType checkType) { if (!targetFile.HasChanged()) { return; } _updateQueue.Add(new UpdateQueueItem(targetFile, checkType)); if (!targetFile.IsWatching) { TryWatchFile(targetFile); } }
public void Uninstall() { if (TargetFile != null) { if (!DeleteTargetFileOnUndo) { CleanFile(); TargetFile.Save(TargetFilePath, SaveOptions.None); } else { File.Delete(TargetFilePath); } } }
public static void WriteContent(this TargetFile targetFile, string content, int retries = 3) { while (true) { try { File.WriteAllText(targetFile.FilePath, content, Encoding.UTF8); return; } catch (IOException) when(retries-- > 0) { Thread.Sleep(TimeSpan.FromMilliseconds(200)); } } }
private void InitRulesAndTargets(string referencesDirectory, string ruleLocation, string targetLocation) { result = new RuleResultData(); ExceptionCollection exceptionCollection = FxCopOM.Initialize(); if ((exceptionCollection != null) && (exceptionCollection.Count > 0)) { foreach (Exception exception in exceptionCollection) { Console.WriteLine("* " + exception.Message); Console.WriteLine(exception.StackTrace); } } FxCopOM.Project = new Project(); FxCopOM.Project.Options.SharedProject = false; FxCopOM.Project.Targets.AddReferenceDirectory(referencesDirectory); TargetFile targetFile = new TargetFile(targetLocation, FxCopOM.Project.Targets); FxCopOM.Engines.LoadTargets(targetFile); FxCopOM.Project.Targets.Add(targetFile); RuleFile ruleFile = new RuleFile(ruleLocation, FxCopOM.Project.RuleFiles); ruleFile.CheckAllChildren(true); FxCopOM.Project.RuleFiles.Add(ruleFile); FxCopOM.Project.Options.Stylesheet = string.Empty; m_ruleFile = ruleFile; m_targetFile = targetFile; }