public Task <Result> GetFile(IASync async, string path) { if (async.UserToken != null) { var user = async.Token <UserInfo>(); if (!File.Exists(path)) { throw new FileNotFoundException($"not Find file{path}"); } var stream = File.Open(path, FileMode.Open, FileAccess.Read); var key = ++user.Key; if (user.FileGetDictionary.TryAdd(key, stream)) { Console.WriteLine($"Get File {path}"); return(Task.FromResult <Result>(async.Res(key, stream.Length))); } else { stream.Dispose(); return(Task.FromResult <Result>(async.Res())); } } return(Task.FromResult <Result>(async.Res())); }
public Task <int> CreateFile(IASync async, string path) { if (async.UserToken != null) { var user = async.Token <UserInfo>(); var stream = File.Open(path, FileMode.Create, FileAccess.Write); var key = ++user.Key; if (user.FilePushDictionary.TryAdd(key, stream)) { Console.WriteLine($"UP File {path}"); return(Task.FromResult(key)); } else { stream.Dispose(); return(null); } } else { return(null); } }
public async Task <bool> WriteFile(IASync async, int fileID, byte[] data, int count, long offset, uint crc) { if (async.UserToken != null) { var user = async.Token <UserInfo>(); if (CRC32.GetCRC32(data) != crc) { return(false); } if (user.FilePushDictionary.ContainsKey(fileID)) { var Stream = user.FilePushDictionary[fileID]; Stream.Position = offset; await Stream.WriteAsync(data, 0, count); return(true); } return(false); } return(false); }
public void FileClose(IASync token, int fileID) { if (token.UserToken != null) { var user = token.Token <UserInfo>(); if (user.FilePushDictionary.ContainsKey(fileID)) { user.FilePushDictionary.TryRemove(fileID, out FileStream cc); cc.Dispose(); } } }
public async Task <string> ToMessage(IASync async, string account, string msg) { var userinfo = async.Token <UserInfo>(); if (userinfo != null && async.IsValidate) { var touser = UserList.Find(p => p.UserName == account); if (touser != null) { var cx = touser.token.MakeAsync(async as AsyncCalls).Get <ClientMethods>(); var ret = (await cx.MsgToUser(userinfo.Nick, msg)).As <string>(); if (ret != null) { return(ret); } } } return(null); }