private void WriteToFileHelper(string filePath) { TurnOnAllSecurityProtocolTypes(); InstrumentProfileReader reader = new InstrumentProfileReader(); InstrumentProfileWriter writer = new InstrumentProfileWriter(); IList <InstrumentProfile> profilesFromHttp = reader.ReadFromFile(dxfToolsHost, dxfToolsUser, dxfToolsPassword); Assert.Greater(profilesFromHttp.Count, 0); writer.WriteToFile(filePath, profilesFromHttp); IList <InstrumentProfile> profilesFromFile; using (FileStream inputStream = new FileStream(filePath, FileMode.Open)) { profilesFromFile = reader.Read(inputStream, filePath); } Assert.AreEqual(profilesFromHttp.Count, profilesFromFile.Count); /* NOTE: Next commented code may not performed if current instrument * format was extended with new. */ //for (int i = 0; i < profilesFromHttp.Count; i++) { // Assert.AreEqual(profilesFromHttp[i], profilesFromFile[i]); //} }
private static void Main(string[] args) { if (args.Length == 0) { PrintUsage(); return; } var path = args[0]; var user = string.Empty; var password = string.Empty; var token = string.Empty; const string ZIP_FILE_PATH = "profiles.zip"; try { var reader = new InstrumentProfileReader(); IList <InstrumentProfile> profiles; if (IsFilePath(path)) { //Read profiles from local file system using (var inputStream = new FileStream(path, FileMode.Open)) { profiles = reader.Read(inputStream, path); } } else { if (args.Length >= 2) { if (args[1].Equals("-T")) { if (args.Length >= 3) { token = args[2]; } else { PrintUsage(); return; } } else { user = args[1]; if (args.Length >= 3) { password = args[2]; } } } //Read profiles from server profiles = string.IsNullOrEmpty(token) ? reader.ReadFromFile(path, user, password) : reader.ReadFromFile(path, token); } //Iterate through received profiles Console.WriteLine("Profiles from '{0}' count: {1}", path, profiles.Count); Console.WriteLine("Print first {0} instruments:", MaxPrintCount); for (var i = 0; i < Math.Min(profiles.Count, MaxPrintCount); i++) { Console.WriteLine("#{0}:{1}", i, profiles[i]); } if (profiles.Count > MaxPrintCount) { Console.WriteLine(" {0} instruments left...", profiles.Count - MaxPrintCount); } //Write profiles to local file system var writer = new InstrumentProfileWriter(); writer.WriteToFile(ZIP_FILE_PATH, profiles); } catch (Exception exc) { Console.WriteLine($"Exception occured: {exc}"); } }
private static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine( "Usage: dxf_instrument_profile_sample <host> <user> <password>\n" + "or: dxf_instrument_profile_sample <file>\n" + "where\n" + " host - The valid host to download instruments (https://tools.dxfeed.com/ipf)\n" + " user - The user name to host access\n" + " password - The user password to host access\n" + " file - The name of file or archive (.gz or .zip) contains instrument profiles\n\n" + "example: dxf_instrument_profile_sample https://tools.dxfeed.com/ipf demo demo\n" + "or: dxf_instrument_profile_sample profiles.zip\n" ); return; } var path = args[0]; var user = string.Empty; var password = string.Empty; const string ZIP_FILE_PATH = "profiles.zip"; try { var reader = new InstrumentProfileReader(); IList <InstrumentProfile> profiles; if (IsFilePath(path)) { //Read profiles from local file system using (var inputStream = new FileStream(path, FileMode.Open)) { profiles = reader.Read(inputStream, path); } } else { if (args.Length >= 2) { user = args[1]; } if (args.Length >= 3) { password = args[2]; } //Read profiles from server profiles = reader.ReadFromFile(path, user, password); } //Iterate through received profiles Console.WriteLine("Profiles from '{0}' count: {1}", path, profiles.Count); Console.WriteLine("Print first {0} instruments:", MAX_PRINT_COUNT); for (var i = 0; i < Math.Min(profiles.Count, MAX_PRINT_COUNT); i++) { Console.WriteLine("#{0}:{1}", i, profiles[i]); } if (profiles.Count > MAX_PRINT_COUNT) { Console.WriteLine(" {0} instruments left...", profiles.Count - MAX_PRINT_COUNT); } //Write profiles to local file system var writer = new InstrumentProfileWriter(); writer.WriteToFile(ZIP_FILE_PATH, profiles); } catch (Exception exc) { Console.WriteLine($"Exception occured: {exc}"); } }