/// <summary> /// Upload a xml file to server database folder /// </summary> /// <param name="client"></param> private static void CallUploadInnerXml(FileTransferService.Client client) { Console.WriteLine("\nInsert file name:"); string saveName = Console.ReadLine(); Console.WriteLine("Insert full xml local path:"); string filePath = Console.ReadLine(); // create a XML document XmlDocument doc = new XmlDocument(); try { // load the document doc.Load($"{filePath}"); // check if is a valid xml doc.LoadXml(doc.InnerXml); } catch (Exception e) { Console.WriteLine($"ERROR! Cannot find a valid xml file on this path: {filePath}"); return; } // Call a function from server // In this case "UploadInnerXml" function Console.WriteLine(client.UploadInnerXml(saveName, doc.InnerXml)); }
/// <summary> /// Get xml list from server database folder /// </summary> /// <param name="client"></param> /// <returns> /// Tuple.Item1 = true - if are xml files on server database folder /// Tuple.Item2 - xml files from server database folder /// </returns> private static Tuple <bool, List <string> > GetXmlFIleFromServer(FileTransferService.Client client) { var xmlList = client.GetServerXmlList(); if (xmlList.Count == 0) { return(new Tuple <bool, List <string> >(false, xmlList)); } return(new Tuple <bool, List <string> >(true, xmlList)); }
private static void CallTransfer(FileTransferService.Client client) { Console.WriteLine("\nSend a message to server:"); // read user input string userInput = Console.ReadLine(); // Call a function from server // In this case "Transfer" function Console.WriteLine(client.Transfer(userInput)); }
/// <summary> /// Create Client /// </summary> /// <returns></returns> private static Tuple <FileTransferService.Client, TTransport> CreateClient() { // Create the transport socket // The socket port must be the same port from server TTransport transport = new TSocket("localhost", 2320); // Wrap socket in a protocol TProtocol protocol = new TBinaryProtocol(transport); // Create the client FileTransferService.Client client = new FileTransferService.Client(protocol); return(new Tuple <FileTransferService.Client, TTransport>(client, transport)); }
/// <summary> /// Download a xml file from server database folder /// </summary> /// <param name="client"></param> /// <returns></returns> private static void CallDownloadInnerXml(FileTransferService.Client client) { var xmlServerFiles = GetXmlFIleFromServer(client); if (!xmlServerFiles.Item1) { Console.WriteLine("\nNo xml files server database!"); return; } Console.WriteLine("\nXml file on server:"); foreach (var xmlFile in xmlServerFiles.Item2) { Console.WriteLine($"{xmlFile}"); } Console.WriteLine("\nPlease insert the fully qualified name of the file you want to download:"); var xmlFileName = Console.ReadLine(); // create a XML document XmlDocument doc = new XmlDocument(); // get innerXml from server var innerXml = client.DownloadInnerXml(xmlFileName); try { // check if received document is a valid xml doc.LoadXml(innerXml); } catch (Exception e) { Console.WriteLine($"\nERROR! Cannot find a valid xml file with this name: {xmlFileName}"); return; } // set saving path string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); var pathToSave = desktopPath + $"\\{xmlFileName}"; // save the document doc.Save(pathToSave); Console.WriteLine($"The xml file was correctly downloaded at this path: '{pathToSave}'."); }