/// <summary> /// Copy the file with the given extension related to the attribute file into the /// destination directory /// </summary> /// <param name="file">The attribute file</param> /// <param name="fileExtensionSource">File extension of the source file to copy</param> /// <param name="destinationDirectory">Destination directory</param> /// <param name="fileExtensionDestination">File extension of the destination file</param> protected void CopyFile(AttributeFile file, string fileExtensionSource, string destinationDirectory, string fileExtensionDestination = null) { if (file?.Path == null) { throw new InvalidOperationException(Strings.TXT_NO_FILE_SELECTED); } var source = Path.Combine( Path.GetDirectoryName(file.Path) ?? string.Empty, file.Title + fileExtensionSource); if (!File.Exists(source)) { throw new InvalidOperationException(Strings.TXT_SOURCE_FILE_MISSING); } if (string.IsNullOrEmpty(fileExtensionDestination)) { fileExtensionDestination = fileExtensionSource; } var destination = Path.Combine( destinationDirectory, file.Title + fileExtensionDestination); File.Copy(source, destination); if (!File.Exists(destination)) { throw new IOException(Strings.TXT_COPY_FAILED); } }
/// <summary> /// Verify that the file doesn't exists at the destination and the destination is writable /// </summary> /// <param name="file">Source file to copy</param> public virtual bool Verify(AttributeFile file = null) { if (file == null) { file = this.lastAttributeFile; } this.lastAttributeFile = file; try { if (file == null || !File.Exists(file.Path)) { throw new InvalidOperationException(Strings.TXT_NO_FILE_SELECTED); } if (file.Title.Length > 15) { throw new InvalidOperationException(Strings.TXT_INVALID_FILE_NAME); } this.ValidateDate(file, FileAttributeName.ErstelltDatum, true); this.ValidateDate(file, FileAttributeName.GeprueftDatum, true); this.ValidateDate(file, FileAttributeName.FreigegebenDatum, true); this.ValidateOrderNumber(file, FileAttributeName.AuftragsNummer, false); var fileToCheck = Path.Combine(this.configuration.SourceDirectory, file.Title + ".pdf"); if (!File.Exists(fileToCheck)) { throw new InvalidOperationException(Strings.TXT_PDF_DOES_NOT_EXIST); } // funktioniert zwar, Anzeige wird aber nicht akutalisiert wenn das File geschlossen wird. Deshalb vorl�ufig deaktiviert. if (this.IsFileLocked(fileToCheck)) { throw new InvalidOperationException(Strings.TXT_PDF_FILE_IS_OPENED); } if (!Directory.Exists(this.configuration.DestinationDirectory)) { throw new InvalidOperationException(Strings.TXT_DESTINATION_MISSING); } fileToCheck = Path.Combine(this.configuration.ArchiveTifDirectory, file.Title + ".tif"); if (File.Exists(fileToCheck)) { throw new InvalidOperationException(Strings.TXT_DESTINATION_FILE_EXISTS); } return(true); } catch (InvalidOperationException ex) { this.Message = ex.Message; return(false); } }
private void WriteEloFile(string fileName, AttributeFile file, MainViewModel viewModel) { using (var stream = new StreamWriter(fileName, false, System.Text.Encoding.UTF8)) { var attributes = this.GetFileAttributes(file, viewModel.Sap.Data); foreach (var attribute in attributes .Where(a => a.Name.GetOrder() != 0) .OrderBy(a => a.Name.GetOrder())) { this.WriteEloAttribute(stream, attribute.Name, attribute.Value); } } }
/// <summary> /// Updates the attributes of the file by the data of the SAP view model /// </summary> /// <param name="file">The attribute file</param> /// <param name="sapData">SAP view model</param> private IEnumerable <FileAttribute> GetFileAttributes(AttributeFile file, SapData sapData) { foreach (var attribute in file.Attributes) { yield return(attribute); } foreach (var converter in FileAttributeParser.ConvertDefinitions) { yield return(new FileAttribute( converter.Key, null, converter.Value(file, sapData))); } }
/// <summary> /// Delete the file with the given extension related to the attribute file /// </summary> /// <param name="file">The attribute file</param> /// <param name="fileExtension">File extension of the file to delete</param> protected void DeleteFile(AttributeFile file, string fileExtension) { if (file?.Path == null) { throw new InvalidOperationException(Strings.TXT_NO_FILE_SELECTED); } var source = Path.Combine( Path.GetDirectoryName(file.Path) ?? string.Empty, file.Title + fileExtension); if (File.Exists(source)) { File.Delete(source); } }
/// <summary> /// Validate a ordernumber. required format is /// - RFQ_123456789 /// - RFQ_123456 /// - nicht 9 Zeichen lang /// - nicht 1- oder 1-... /// </summary> /// <param name="file">Attribute file</param> /// <param name="name">name of the attribute to check</param> /// <param name="required">Indicates if a date is required or not</param> private void ValidateOrderNumber(AttributeFile file, FileAttributeName name, bool required) { if (!required && string.IsNullOrEmpty(file[name])) { return; } if (string.IsNullOrEmpty(file[name])) { throw new InvalidOperationException($"{Strings.TXT_MISSING_ORDER_NUMBER}"); } var regexOrderNumber = "(^RFQ_.{0,5}$)|(^RFQ_.{7,8}$)|(^RFQ_.{10,99}$)|(^1-$)|(^1-[.]+)|(^[0-9]{9}$)"; if (Regex.IsMatch(file[name], regexOrderNumber)) { throw new InvalidOperationException($"{Strings.TXT_INVALID_ORDER_NUMBER}"); } }
/// <summary> /// Validate a date. required format is yyyy-mm-dd /// </summary> /// <param name="file">Attribute file</param> /// <param name="name">name of the attribute to check</param> /// <param name="required">Indicates if a date is required or not</param> private void ValidateDate(AttributeFile file, FileAttributeName name, bool required) { if (!required && string.IsNullOrEmpty(file[name])) { return; } if (string.IsNullOrEmpty(file[name])) { throw new InvalidOperationException($"{Strings.TXT_MISSING_DATE}: {name}"); } if (!Regex.IsMatch(file[name], "\\d{4}-\\d{2}-\\d{2}")) { throw new InvalidOperationException($"{Strings.TXT_INVALID_DATE}: {name}"); } if (!DateTime.TryParse(file[name], out _)) { throw new InvalidOperationException($"{Strings.TXT_INVALID_DATE}: {name}"); } }
public override bool Verify(AttributeFile file = null) { if (!base.Verify(file)) { return(false); } try { var fileToCheck = Path.Combine(this.configuration.PendingDirectory, file.Title + ".dwg"); if (File.Exists(fileToCheck)) { throw new InvalidOperationException(Strings.TXT_PENDING_FILE_EXISTS); } return(true); } catch (InvalidOperationException ex) { this.Message = ex.Message; return(false); } }
public void ProcessZipFile(NameDefinitionType nameDefinitionType, FileInfo file) { #region File Path Strings string fileName = file.Name.Replace(file.Extension, ""); string outputPath = Path.Combine(OutputDirectoryPath, fileName); string codePageFilePath = Path.Combine(outputPath, $"{fileName}.cpg"); string projectionFilePath = Path.Combine(outputPath, $"{fileName}.prj"); //string dbfMetadataFilePath = Path.Combine(outputPath, $"{fileName}.dbf.xml"); //string shpMetadataFilePath = Path.Combine(outputPath, $"{fileName}.shp.xml"); string attributeFilePath = Path.Combine(outputPath, $"{fileName}.dbf"); string shapeFilePath = Path.Combine(outputPath, $"{fileName}.shp"); #endregion File Path Strings #region File Infos FileInfo codePageFileInfo = new FileInfo(codePageFilePath); FileInfo projectionFileInfo = new FileInfo(projectionFilePath); //FileInfo dbfMetadataFileInfo = new FileInfo(dbfMetadataFilePath); //FileInfo shpMetadataFileInfo = new FileInfo(shpMetadataFilePath); FileInfo attributeFileInfo = new FileInfo(attributeFilePath); FileInfo shapeFileInfo = new FileInfo(shapeFilePath); #endregion File Infos #region Directory Prep if (Directory.Exists(outputPath)) { Console.WriteLine($"Deleting Directory: {outputPath}"); FileSystem.DeleteDirectory(outputPath, UIOption.OnlyErrorDialogs, RecycleOption.DeletePermanently); } #endregion Directory Prep #region File Extraction Console.WriteLine($"\rExtracting {file.Name} to {outputPath}\t\t"); ZipFile.ExtractToDirectory(file.FullName, outputPath); #endregion File Extration #region File Prep Console.WriteLine("Removing XML Files"); foreach (string isoFile in Directory.EnumerateFiles(outputPath, "*.xml")) { FileSystem.DeleteFile(isoFile, UIOption.OnlyErrorDialogs, RecycleOption.DeletePermanently); } if (attributeFileInfo.Exists && attributeFileInfo.Name.Length > 8) { Console.WriteLine("Renaming Attribute File"); string newName = "Attrib.dbf"; FileSystem.RenameFile(attributeFilePath, newName); attributeFilePath = Path.Combine(outputPath, newName); attributeFileInfo = new FileInfo(attributeFilePath); } #endregion File Prep #region File Processing Console.WriteLine("Processing files"); CodePageFile codePageFile = new CodePageFile(codePageFileInfo); ProjectionFile projectionFile = new ProjectionFile(projectionFileInfo); //MetadataFile dbfMetadataFile = new MetadataFile(dbfMetadataFileInfo); //MetadataFile shpMetadataFile = new MetadataFile(shpMetadataFileInfo); //MetadataFile metadataFile = new MetadataFile(dbfMetadataFileInfo.Exists ? dbfMetadataFileInfo : shpMetadataFileInfo); //if (dbfMetadataFile.Exists && shpMetadataFile.Exists) //{ // Console.WriteLine($"{fileName} has both shape and attribute metadata files!"); // Debugger.Break(); //} AttributeFile attributeFile = new AttributeFile(attributeFileInfo); ShapeFile shapeFile = projectionFile.Exists ? new ShapeFile(shapeFileInfo, projectionFile.SRID) : null; #endregion if (shapeFile != null) { DataColumn newColumn = new DataColumn("GEOM", typeof(SqlGeometry)); attributeFile.Records.Tables[0].Columns.Add(newColumn); foreach (Shape shape in shapeFile.Shapes) { attributeFile.Records.Tables[0].Rows[shape.RecordNumber - 1][newColumn.ColumnName] = shape.DTGeometry; } } using (SqlBulkCopy sbc = new SqlBulkCopy(DataHelper.DefaultConnectionString)) { sbc.SqlRowsCopied += Sbc_SqlRowsCopied; sbc.DestinationTableName = Pluralizer.Pluralize(nameDefinitionType.ToString()); sbc.BatchSize = DataHelper.DefaultBatchSize; sbc.BulkCopyTimeout = DataHelper.DefaultTimeoutSeconds; foreach (DataColumn column in attributeFile.Records.Tables[0].Columns) { sbc.ColumnMappings.Add(column.ColumnName, column.ColumnName); } sbc.WriteToServer(attributeFile.Records.Tables[0]); } #region Directory Cleanup Console.WriteLine($"Deleting Directory: {outputPath}"); FileSystem.DeleteDirectory(outputPath, UIOption.OnlyErrorDialogs, RecycleOption.DeletePermanently); #endregion Directory Cleanup }
/// <summary> /// Returns a string value containing the command line arguments to pass directly to the executable file. /// </summary> /// <returns> /// A string value containing the command line arguments to pass directly to the executable file. /// </returns> protected override string GenerateCommandLineCommands() { const string errorReturnValue = ""; if (false == ValidateInputAssemblies() || false == ValidateOutputFile()) { return(errorReturnValue); } #region " ILMerge.exe Command-Line Arguments " /* * [/lib:directory]* * [/log[:filename]] * [/keyfile:filename [/delaysign]] * [/internalize[:filename]] * [/t[arget]:(library|exe|winexe)] * [/closed] * [/ndebug] * [/ver:version] * [/copyattrs [/allowMultiple]] * [/xmldocs] * [/attr:filename] * ([/targetplatform:<version>[,<platformdir>]]|v1|v1.1|v2|v4) * [/useFullPublicKeyForReferences] * [/zeroPeKind] * [/wildcards] * [/allowDup[:typename]]* * [/allowDuplicateResources] * [/union] * [/align:n] * /out:filename * <primary assembly> [<other assemblies>...] */ #endregion " ILMerge.exe Command-Line Arguments " var builder = new CommandLineBuilder(); if (null != DuplicateTypeNames && DuplicateTypeNames.Length > 0) { foreach (var item in DuplicateTypeNames) { var typeName = item.ItemSpec; builder.AppendSwitch(string.Format("/allowDup:{0}", typeName.Trim())); } } else if (AllowDuplicateTypeNames) { builder.AppendSwitch("/allowDup"); } if (AllowMultipleAssemblyLevelAttributes) { builder.AppendSwitch("/allowMultiple"); } if (AllowWildCards) { builder.AppendSwitch("/wildcards"); } if (AllowZeroPeKind) { builder.AppendSwitch("/zeroPeKind"); } if (false == string.IsNullOrWhiteSpace(AttributeFile)) { builder.AppendSwitch(string.Format("/attr:\"{0}\"", AttributeFile.Trim())); } if (Closed) { builder.AppendSwitch("/closed"); } if (CopyAttributes) { builder.AppendSwitch("/copyattrs"); } if (false == DebugInfo) { builder.AppendSwitch("/ndebug"); } if (DelaySign) { builder.AppendSwitch("/delaysign"); } if (FileAlignment != DefaultFileAlignment) { builder.AppendSwitch(string.Format("/align:{0}", FileAlignment)); } if (Internalize) { builder.AppendSwitch(string.Format("/internalize{0}", string.IsNullOrWhiteSpace(ExcludeFile) ? "" : string.Format(":\"{0}\"", ExcludeFile.Trim()))); } if (false == string.IsNullOrWhiteSpace(KeyFile)) { builder.AppendSwitch(string.Format("/keyfile:\"{0}\"", KeyFile.Trim())); } if (false == string.IsNullOrWhiteSpace(LogFile)) { builder.AppendSwitch(string.Format("/log:\"{0}\"", LogFile.Trim())); } if (false == PublicKeyTokens) { builder.AppendSwitch("/useFullPublicKeyForReferences"); } if (null != SearchDirectories && SearchDirectories.Length > 0) { foreach (var item in SearchDirectories) { var directory = item.ItemSpec; builder.AppendSwitch(string.Format("/lib:\"{0}\"", directory.Trim())); } } // Target Platform if (false == string.IsNullOrWhiteSpace(TargetPlatformDirectory) && false == string.IsNullOrWhiteSpace(TargetPlatformVersion)) { var value = string.Format("{0},\"{1}\"", TargetPlatformVersion.Trim().ToLowerInvariant(), TargetPlatformDirectory.Trim()); builder.AppendSwitch(string.Format("/targetplatform:{0}", value)); } if (false == string.IsNullOrWhiteSpace(TargetType)) { builder.AppendSwitch(string.Format("/target:{0}", TargetType.Trim().ToLowerInvariant())); } if (UnionMerge) { builder.AppendSwitch("/union"); } if (XmlDocumentation) { builder.AppendSwitch("/xmldocs"); } if (false == string.IsNullOrWhiteSpace(Version)) { builder.AppendSwitch(string.Format("/ver:{0}", Version.Trim())); } // OutputFile is added after all other switches and before the InputAssemblies. builder.AppendSwitch(string.Format("/out:\"{0}\"", OutputFile)); // InputAssemblies must be added after all other switches. if (null != InputAssemblies && InputAssemblies.Length > 0) { foreach (var inputAssemblyPath in InputAssemblies) { builder.AppendTextUnquoted(string.Format(" \"{0}\"", inputAssemblyPath)); } } return(builder.ToString()); }
/// <summary> /// Creates a new instance of the <see cref="AttributeFileViewModel"/> class /// </summary> /// <param name="attributeFile">DTO of the file represented by this view model</param> public AttributeFileViewModel(AttributeFile attributeFile) { this.attributeFile = attributeFile; this.OpenFile = new OpenFileCommand(this.attributeFile); }
/// <summary> /// Creates a new instance of the <see cref="OpenFileCommand"/> class. /// </summary> /// <param name="attributeFile">Attribute file to open related files for</param> public OpenFileCommand(AttributeFile attributeFile) { this.attributeFile = attributeFile; }