private static async Task <WinofyClient> PrepareClientAsync(HomeConfig config) { var client = new WinofyClient(); if (!string.IsNullOrEmpty(config.AuthorizationToken)) { var result = await client.ValidateTokenAsync(config.Username, config.AuthorizationToken); if (!result.Valid) { config.AuthorizationToken = null; } } while (string.IsNullOrEmpty(config.AuthorizationToken)) { Console.Write("Username : "******"Password : "******"Failed to login. Please check your username and password"); } } client.SetAuthorizationToken(config.AuthorizationToken); if (string.IsNullOrEmpty(config.Device?.Id)) { Console.WriteLine("This device may not be registered"); Console.WriteLine("Tell us the device name and description"); Console.Write("Name : "); var name = Console.ReadLine(); Console.Write("Description : "); var desc = Console.ReadLine(); var device = new Device() { Name = name, Description = desc, Notification = true }; var result = await client.RegisterDeviceAsync(device, true); if (result.Success) { config.Device = device; } else { Console.WriteLine("Failed to register this device. See messages from the server"); Console.WriteLine(result.Message.ToString()); } } using (var sw = new StreamWriter(HomeConfig.ConfigPath)) { sw.Write(JsonConvert.SerializeObject(config, Formatting.Indented)); } return(client); }
public static Task <NotificationResult> SetNotificationAsync(WinofyClient client, NotificationType notification) { return(client.UpdateNotificationAsync(FcmToken, notification)); }