public void ReadTest_file_is_empty_gives_empty_Dataset() { DatasourceReader reader = new DatasourceReader(@"Testdata\Empty.csv"); reader.ReadFile(); Assert.AreEqual(0, reader.Count); }
public void ReadTest_no_file_gives_no_content() { DatasourceReader reader = new DatasourceReader(null); reader.ReadFile(); Assert.AreEqual(0, reader.Count); }
public void ReadTest_file_is_valid_gives_two_Correspondances() { DatasourceReader reader = new DatasourceReader(@"Testdata\ValidTwoRows.csv"); reader.ReadFile(); Assert.AreEqual(2, reader.Count); Assert.AreEqual("1001", reader[0].Reportee); Assert.AreEqual("1002", reader[1].Reportee); }
public void ReadTest_file_not_found_throws_exception() { DatasourceReader reader = new DatasourceReader(@"C:\tullball\data.csv"); DirectoryNotFoundException exception = null; try { reader.ReadFile(); } catch (DirectoryNotFoundException ex) { exception = ex; } Assert.IsNotNull(exception); }
/// <summary> /// Start of console application specific logic. /// </summary> protected override void Execute() { // This is where magic happens // Fetch datasett fra en kommaseparert fil, der hver linje er en correspondence DatasourceReader reader = new DatasourceReader(this.Arguments.SourceFile); reader.ReadFile(); Correspondences corrColl = new Correspondences() { SystemUserCode = ConfigurationManager.AppSettings["systemUserCode"], ShipmentReference = Guid.NewGuid().ToString(), SequenceNo = null, Correspondence = new CorrespondencesCorrespondence[reader.Count] }; int index = 0; // For datasettet lages en XML fil med alle correspence fra csv fila // systemUserCode hentes fra app.config foreach (CorrespondenceInput correspondence in reader.GetEnumerable()) { corrColl.Correspondence[index++] = new CorrespondencesCorrespondence() { Reportee = correspondence.Reportee, ServiceCode = this.Arguments.ServiceCode, ServiceEdition = this.Arguments.ServiceEdition, SendersReference = Guid.NewGuid().ToString(), Content = new CorrespondencesCorrespondenceContent() { LanguageCode = correspondence.LanguageCode, MessageTitle = correspondence.MessageTitle, MessageBody = correspondence.MessageBody, MessageSummary = correspondence.MessageSummary, }, VisibleDateTime = correspondence.VisibleDateTime, VisibleDateTimeSpecified = true, IsReservable = correspondence.IsReservable, IsReservableSpecified = true, }; } string destfolder = ConfigurationManager.AppSettings["localPathToFilesToUpload"]; string name = Path.GetFileName(this.Arguments.SourceFile); if (name == null) { return; } string fileName = name.Replace(".csv", ".xml"); string destfile = destfolder.Contains("*") ? destfolder.Replace("*", fileName) : Path.Combine(destfolder, fileName); // XML filene lagres på local path ihht konfigurasjonen localPathToFilesToUpload using (FileStream fileStream = File.Create(destfile)) { XmlSerializer serializer = new XmlSerializer(corrColl.GetType()); serializer.Serialize(fileStream, corrColl); } XmlValidator.Validate(destfile); try { SftpClientHelper.TransferFiles(); File.Delete(destfile); } catch (Exception) { throw; } }
private static async Task __Main(string[] args) { try { Options options = null; Parser.Default.ParseArguments <Options>(args) .WithParsed(opts => options = opts) .WithNotParsed(errs => Console.WriteLine(string.Join(Environment.NewLine, errs))); #if DEBUG options = new Options { Source = @"C:\Users\Andrei\Desktop\values.txt", Destination = @"C:\Users\Andrei\Desktop\values.resx", SourceLanguage = "bg", ResultLanguages = "en;ro" }; #endif if (options == null) { return; } var reader = new DatasourceReader(); var ds = reader.Read(options.Source).ToList(); var translatedDs = new List <List <string> >(); Console.OutputEncoding = System.Text.Encoding.UTF8; foreach (var strs in ds) { Console.WriteLine(string.Join("|", strs)); } Console.WriteLine("--"); Console.WriteLine(); var translators = options.ResultLanguages.Split(';') .Select(lang => new CognitiveTranslator(options.SourceLanguage, lang, Settings.Default.ApiKey1)); foreach (var strs in ds) { var list = new List <string>(); foreach (var str in strs) { list.Add(await translator.TranslateAsync(str)); } translatedDs.Add(list); } foreach (var strs in translatedDs) { Console.WriteLine(string.Join("|", strs)); } var writer = new DatasourceWriter(Path.ChangeExtension(options.Destination, "resx"), new [] { translator.SourceLanguage, translator.DestinationLanguage }); //todo make rule naming resources const string nameOfDictionary = "Rule"; const int indexCyrilic = 2; const int indexNameRule = 1; foreach (var strs in ds.Skip(1)) { writer.Write($"{nameOfDictionary}_{strs[indexNameRule]}", translator.SourceLanguage, strs[indexCyrilic]); } foreach (var strs in translatedDs.Skip(1)) { writer.Write($"{nameOfDictionary}_{strs[indexNameRule]}", translator.DestinationLanguage, strs[indexCyrilic]); } writer.Flush(); Console.WriteLine("--"); Console.WriteLine("Finished!"); } catch (Exception mex) { Console.Error.WriteLine(mex.Message); } finally { Console.ReadKey(); } }