/*----< uploads file to Receiver instance >--------------------*/ /* * expects fully qualified file name for file being sent */ public bool postFile(string fileSpec) { FileStream fs = null; long bytesRemaining; try { string fileRef = FileNameEditor.storageFolderRef(fileSpec); fs = File.OpenRead(fileSpec); bytesRemaining = fs.Length; channel.openFileForWrite(fileRef); while (true) { long bytesToRead = Math.Min(ServiceClientEnvironment.blockSize, bytesRemaining); byte[] blk = new byte[bytesToRead]; long numBytesRead = fs.Read(blk, 0, (int)bytesToRead); bytesRemaining -= numBytesRead; channel.writeFileBlock(blk); if (bytesRemaining <= 0) { break; } } channel.closeFile(); fs.Close(); } catch (Exception ex) { lastError = ex.Message; return(false); } return(true); }
static void Main(string[] args) { ClientEnvironment.verbose = true; FileNameEditor ed = new FileNameEditor(); bool t = ed.testComponent(); TestUtilities.putLine(); TestUtilities.checkResult(t, "testComponent"); Console.Write("\n\n"); }
/*----< here server responses to messages are defined >--------*/ void initializeDispatcher() { // doTest Func <Msg, Msg> action1 = (Msg msg) => { testComponent(); Msg returnMsg = new Msg(Msg.MessageType.noReply); returnMsg.to = msg.from; returnMsg.from = msg.to; returnMsg.command = msg.command; return(returnMsg); }; dispatcher_.addCommand(Msg.Command.doTest, action1); // getCategories Func <Msg, Msg> action2 = (Msg msg) => { DirList dirList = getCategories(); Msg returnMsg = new Msg(Msg.MessageType.reply); returnMsg.to = msg.from; returnMsg.from = msg.to; returnMsg.argument = msg.argument; foreach (DirName cat in dirList) { returnMsg.arguments.Add(cat); } returnMsg.command = msg.command; return(returnMsg); }; dispatcher_.addCommand(Msg.Command.getCategories, action2); // getFiles Func <Msg, Msg> action3 = (Msg msg) => { FileList fileList = getFiles(msg.argument); Msg returnMsg = new Msg(Msg.MessageType.reply); returnMsg.to = msg.from; returnMsg.from = msg.to; returnMsg.argument = msg.argument; foreach (FileName file in fileList) { returnMsg.arguments.Add(file); } //returnMsg.arguments = fileList; returnMsg.command = msg.command; return(returnMsg); }; dispatcher_.addCommand(Msg.Command.getFiles, action3); // synchLocal Func <Msg, Msg> action4 = (Msg msg) => { string synchPath = FileNameEditor.pathCombine(ServerEnvironment.storagePath, msg.argument); FileSynch fs = new FileSynch(synchPath); fs.isSynched(msg.arguments); Msg replyMsg = new Msg(Msg.MessageType.reply); replyMsg.to = msg.from; replyMsg.from = msg.to; replyMsg.argument = msg.argument; foreach (string file in fs.notInList) { replyMsg.arguments.Add(file); } replyMsg.command = msg.command; return(replyMsg); }; dispatcher_.addCommand(Msg.Command.synchLocal, action4); // synchRemote Func <Msg, Msg> action5 = (Msg msg) => { string synchPath = FileNameEditor.pathCombine(ServerEnvironment.storagePath, msg.argument); FileSynch fs = new FileSynch(synchPath); fs.isSynched(msg.arguments); Msg replyMsg = new Msg(Msg.MessageType.reply); replyMsg.to = msg.from; replyMsg.from = msg.to; replyMsg.argument = msg.argument; foreach (string file in fs.notInSyncDir) { replyMsg.arguments.Add(file); } replyMsg.command = msg.command; return(replyMsg); }; dispatcher_.addCommand(Msg.Command.synchRemote, action5); // sendFile Func <Msg, Msg> action6 = (Msg msg) => { string fileRef = msg.argument; string fileSpec = FileNameEditor.pathCombine(CommEnvironment.serverStoragePath, fileRef); fileSpec = System.IO.Path.GetFullPath(fileSpec); comm_.postFile(fileSpec); Msg replyMsg = new Msg(Msg.MessageType.noReply); replyMsg.to = msg.from; replyMsg.from = msg.to; return(replyMsg); }; dispatcher_.addCommand(Msg.Command.sendFile, action6); // acceptFile Func <Msg, Msg> action7 = (Msg msg) => { comm_.sndr.setFileDestinationPath(ServerEnvironment.storagePath); //string fileRef = msg.argument; //string fileSpec = FileNameEditor.pathCombine(CommEnvironment.serverStoragePath, fileRef); //fileSpec = System.IO.Path.GetFullPath(fileSpec); //comm_.postFile(fileSpec); Msg replyMsg = new Msg(Msg.MessageType.noReply); replyMsg.to = msg.from; replyMsg.from = msg.to; return(replyMsg); }; dispatcher_.addCommand(Msg.Command.acceptFile, action7); }