public static async Task <bool> Register(Guid appGuid, string email, string password, string userName) { MessageBuss.Send("BeginLoading", null); var res = await DXAPI.Register(email, password, userName, appGuid, UserRole.Client); MessageBuss.Send("EndLoading", null); if (res.Status == APIResponseStatus.Success) { if (!res.IsDuplicated) { return(true); } } return(false); }
public static async Task <UploadResponse> Upload(string group, string fileName) { MessageBuss.Send("BeginLoading", null); try { var req = WebRequest.Create($"{URL.Files}/{group}"); req.Method = "POST"; var reqStream = await req.GetRequestStreamAsync(); var uploader = new FileUploader(reqStream); req.ContentType = $"multipart/form-data; boundary={uploader.Boundary}"; string type = Path.GetExtension(fileName).Substring(1); await uploader.UploadFiles( new UploadFile[] { new UploadFile() { Name = "file", FileName = fileName, ContentType = $"image/{type}" } }, null); var res = await req.GetResponseAsync(); using (var sr = new StreamReader(res.GetResponseStream(), Encoding.Default)) { MessageBuss.Send("EndLoading", null); return(APIResponse.Parse <UploadResponse>(await sr.ReadToEndAsync())); } } catch { } MessageBuss.Send("EndLoading", null); return(APIResponse.Empty <UploadResponse>()); }
public static async Task <bool> Login(string email, string password) { MessageBuss.Send("BeginLoading", null); LoginResponse res = await DXAPI.Login(email, password, UserRole.Client); if (res.Status == APIResponseStatus.Success && res.Result == LoginResult.Success) { DXNetwork.User = new DXUser(res.UID, res.UserName, email); MessageBuss.Send("LoginStateChanged", (res.UID, res.UserName, email)); MessageBuss.Send("EndLoading", null); return(true); } DXNetwork.User = null; MessageBuss.Send("LoginStateChanged", null); MessageBuss.Send("EndLoading", null); return(false); }