public static Color GetColourFromName(string name) { List <string> colours = new List <string>() { "#f25022", "#7fba00", "#00a4ef", "#ffb900", "#737373", "#4285F4", "#DB4437", "#F4B400", "#0F9D58" }; Random ran = new Random(); int ind = ran.Next(0, colours.Count); name = FilterCharacters(name); if (string.IsNullOrWhiteSpace(name)) { return(Color.FromHex(colours[ind])); } try { int sum = 0; for (int i = 0; i < name.Length; i++) { char c = name[i]; // declare it in loop - you overwrite it here anyway sum += char.ToUpper(c) - 64; } int index = sum % 9; return(Color.FromHex(colours[index])); } catch (Exception ex) { Crashes.TrackError(ex, Logic.GetErrorProperties(ex)); return(Color.FromHex(colours[ind])); } }
public static async Task Update(UserData user) { try { string url = "user/update"; string content = await BaseClient.PutEntities(url, JsonConvert.SerializeObject(user)); } catch (Exception ex) { Crashes.TrackError(ex, Logic.GetErrorProperties(ex)); } }
public static async Task CreateConfess(Confess confess) { try { string url = "confess/add"; string content = await BaseClient.PostEntities(url, JsonConvert.SerializeObject(confess)); } catch (Exception ex) { Crashes.TrackError(ex, Logic.GetErrorProperties(ex)); } }
public static async Task Delete(string id) { try { string url = $"chat/delete?id={id}"; string content = await BaseClient.DeleteEntities(url); } catch (Exception ex) { Crashes.TrackError(ex, Logic.GetErrorProperties(ex)); } }
public static async Task DeleteConfess(string guid) { try { string url = $"confess/delete?guid={guid}"; string content = await BaseClient.DeleteEntities(url); LocalStore.Confession.DeleteLoader(guid); } catch (Exception ex) { Crashes.TrackError(ex, Logic.GetErrorProperties(ex)); } }
public static async Task <ConfessLoader> DeleteComment(string guid, string ConfessGuid) { try { string url = $"comment/delete?guid={guid}&confess={ConfessGuid}&key={await Logic.GetKey()}"; string content = await BaseClient.DeleteEntities(url); ConfessLoader data = JsonConvert.DeserializeObject <ConfessLoader>(content); return(data); } catch (Exception ex) { Crashes.TrackError(ex, Logic.GetErrorProperties(ex)); return(null); } }
public static async Task <ObservableCollection <ConfessLoader> > FetchAllConfess() { try { string url = $"confess/fetchall?key={await Logic.GetKey()}"; string content = await BaseClient.GetEntities(url); ObservableCollection <ConfessLoader> data = JsonConvert.DeserializeObject <ObservableCollection <ConfessLoader> >(content); return(data); } catch (Exception ex) { Crashes.TrackError(ex, Logic.GetErrorProperties(ex)); return(new ObservableCollection <ConfessLoader>()); } }
internal static async Task <string> GetName() { try { string url = $"generic/getaname"; string content = await BaseClient.GetEntities(url); string data = JsonConvert.DeserializeObject <string>(content); return(data); } catch (Exception ex) { Crashes.TrackError(ex, Logic.GetErrorProperties(ex)); return(""); } }
public static async Task <ConfessSender> Post(string guid, bool isComment, string confessguid) { try { string url = $"dislike/add?key={await Logic.GetKey()}&guid={guid}&isComment={isComment}&confess={confessguid}"; string content = await BaseClient.GetEntities(url); ConfessSender data = JsonConvert.DeserializeObject <ConfessSender>(content); return(data); } catch (Exception ex) { Crashes.TrackError(ex, Logic.GetErrorProperties(ex)); return(null); } }
internal static async Task LeaveRoom(string roomID) { try { if (string.IsNullOrEmpty(roomID)) { roomID = await Logic.GetRoomID(); } string url = $"chat/leave?id={roomID}"; await BaseClient.GetEntities(url); } catch (Exception ex) { Crashes.TrackError(ex, Logic.GetErrorProperties(ex)); } }
public static void VibrateNow() { try { // Or use specified time TimeSpan duration = TimeSpan.FromMilliseconds(100); Vibration.Vibrate(duration); } catch (FeatureNotSupportedException ex) { Crashes.TrackError(ex, Logic.GetErrorProperties(ex)); } catch (Exception ex) { Crashes.TrackError(ex, Logic.GetErrorProperties(ex)); } }
internal static async Task <ObservableCollection <ChatRoomLoader> > Rooms() { try { string url = $"chat/fetchrooms"; string content = await BaseClient.GetEntities(url); ObservableCollection <ChatRoomLoader> data = JsonConvert.DeserializeObject <ObservableCollection <ChatRoomLoader> >(content); return(data); } catch (Exception ex) { Crashes.TrackError(ex, Logic.GetErrorProperties(ex)); return(new ObservableCollection <ChatRoomLoader>() { }); } }
public static async Task <Confess> FetchOneConfessByGuid(string guid) { try { string url = $"confess/fetch/guid?guid={guid}"; string content = await BaseClient.GetEntities(url); Confess data = JsonConvert.DeserializeObject <Confess>(content); return(data); } catch (Exception ex) { Crashes.TrackError(ex, Logic.GetErrorProperties(ex)); return(new Confess() { }); } }
internal static async Task <Setting> GetSettings() { try { string url = $"setting/fetch"; string content = await BaseClient.GetEntities(url); Setting data = JsonConvert.DeserializeObject <Setting>(content); return(data); } catch (Exception ex) { Crashes.TrackError(ex, Logic.GetErrorProperties(ex)); return(new Setting() { }); } }
public static string FilterCharacters(string input) { try { if (string.IsNullOrWhiteSpace(input)) { return(Constants.DefaultName); } Regex regex = new Regex("[^a-zA-Z0-9]"); return(regex.Replace(input, "")); } catch (Exception ex) { Crashes.TrackError(ex, Logic.GetErrorProperties(ex)); return(Constants.DefaultName); } }
internal static async Task <UserData> Get() { try { Guid?installId = await AppCenter.GetInstallIdAsync(); string url = $"user/fetch?appcenter={installId.Value.ToString()}"; string content = await BaseClient.GetEntities(url); UserData data = JsonConvert.DeserializeObject <UserData>(content); return(data); } catch (Exception ex) { Crashes.TrackError(ex, Logic.GetErrorProperties(ex)); return(new UserData() { }); } }
public static async Task <ConfessLoader> CreateComment(Comment comment, string confessGuid) { try { string url = $"comment/add"; CommentPoster poster = new CommentPoster() { Comment = comment, ConfessGuid = confessGuid, Key = await Logic.GetKey() }; string content = await BaseClient.PostEntities(url, JsonConvert.SerializeObject(poster)); ConfessLoader data = JsonConvert.DeserializeObject <ConfessLoader>(content); return(data); } catch (Exception ex) { Crashes.TrackError(ex, Logic.GetErrorProperties(ex)); return(null); } }
internal static async Task <ObservableCollection <ChatLoader> > ChatsByRoom(string roomID) { try { if (string.IsNullOrEmpty(roomID)) { roomID = await Logic.GetRoomID(); } string url = $"chat/fetchchats?roomID={roomID}"; string content = await BaseClient.GetEntities(url); ObservableCollection <ChatLoader> data = JsonConvert.DeserializeObject <ObservableCollection <ChatLoader> >(content); return(data); } catch (Exception ex) { Crashes.TrackError(ex, Logic.GetErrorProperties(ex)); return(new ObservableCollection <ChatLoader>() { }); } }
internal static async Task <string> PostImageStream(byte[] input) { try { Stream stream = new MemoryStream(input); using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(Constants.BaseURL); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(Constants.AuthorizationHeaderType, await Logic.GetToken()); StreamContent inputData = new StreamContent(stream); string urlLink = "chat/postimage"; HttpResponseMessage response = await client.PostAsync(urlLink, inputData).ConfigureAwait(false); var result = await response.Content.ReadAsStringAsync(); return(result); } } catch (Exception ex) { Crashes.TrackError(ex, Logic.GetErrorProperties(ex)); return(string.Empty); } }