Пример #1
0
        public static async Task Main(string[] args)
        {
            var log = new LoggerConfiguration()
                      .WriteTo.Console()
                      .WriteTo.File("logs/log.json")
                      .CreateLogger();

            try
            {
                var refreshToken = ConfigurationManager.AppSettings?["RingRefreshToken"];
                Requires.NotNullOrWhiteSpace(refreshToken, nameof(refreshToken));

                var client = new RingClient(refreshToken);

                var devices = await client.GetAllDevicesAsync().ConfigureAwait(false);

                var deviceIds = devices.Select(d => d.Id).ToArray();

                while (true)
                {
                    await client.UpdateSnapshotAsync(deviceIds).ConfigureAwait(false);

                    await Task.Delay(20000).ConfigureAwait(false);

                    Console.WriteLine($"HEARTBEAT: {DateTime.Now}");
                }
            }
            catch (Exception e)
            {
                log.Error(e, "There was an error updating snapshots.");
            }
        }
Пример #2
0
        public async Task <IActionResult> Recording(ulong id, string type, string deviceName, int createdAt)
        {
            RingClient ring;

            try
            {
                var authToken = User.Claims.FirstOrDefault(e => e.Type == "auth_token")?.Value;
                ring = await RingClient.CreateAsync(authToken);
            }
            catch
            {
                return(Challenge());
            }

            try
            {
                RecordingViewModel model = new RecordingViewModel();

                var ding = new Ring.Models.Ding()
                {
                    Id = id, RecordingIsReady = true
                };
                model.RecordingUri = await ring.GetRecordingUriAsync(ding);

                model.Type       = type;
                model.DeviceName = deviceName;
                model.CreatedAt  = new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(createdAt);

                return(View(model));
            }
            catch
            {
                return(NotFound());
            }
        }
Пример #3
0
        static async Task Main(string[] args)
        {
            try
            {
                // Connect to the Ring API using a Ring account username and password.
                var ring = await RingClient.CreateAsync("*****@*****.**", "password");

                // Save the AuthToken for future connections instead of the Ring account username and password.
                // You can create a new connection using an auth token by calling: RingClient.CreateAsync(authToken)
                // The auth token may expire, but you can ask the user for their username and password at that point.
                var authToken = ring.AuthToken;

                // Get the list of the user's devices.
                var devices = await ring.GetDevicesAsync();

                // Check if any devices were returned.
                if (devices.Count > 0)
                {
                    // Get the battery life of the first device.
                    var batteryLife = devices[0].BatteryLife;

                    var deviceDescription = devices[0].Description;

                    Console.WriteLine($"{deviceDescription} battery life: {batteryLife}");
                }

                // Get the list of the user's active dings.
                var activeDings = await ring.GetActiveDingsAsync();

                // Check if there are any active dings.
                if (activeDings.Count > 0)
                {
                    // Get the type of the first active ding.
                    var activeDingType = activeDings[0].Type;

                    Console.WriteLine($"Active ding: {activeDingType}");
                }

                // Get the list of the user's last 15 dings.
                var dings = await ring.GetDingsAsync(15);

                // Check if any dings were returned.
                if (dings.Count > 0)
                {
                    // Get the URI of the recording of the most recent ding.
                    var recordingUri = await ring.GetRecordingUriAsync(dings[0]);

                    // Get the description of the Ring device that the most recent ding occurred from.
                    var dingDeviceDescription = dings[0].Device.Description;

                    Console.WriteLine($"Ding from {dingDeviceDescription}: {recordingUri}");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public RingWindowControl()
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var workspaceMachine = new WorkspaceStateMachine();
            var solutionMachine  = new SolutionStateMachine();
            var commandQueue     = new Queue <IRingCommand>();

            var ringClient = new RingClient(new Uri(_ringServerUri), commandQueue, OutputWriteLine);
            var solution   = new SolutionViewModel(solutionMachine, workspaceMachine, OutputWriteLine, commandQueue);

            _workspace   = new WorkspaceViewModel(solutionMachine, workspaceMachine, OutputWriteLine, commandQueue);
            _ringManager = new RingManager(ringClient, OutputWriteLine);
            DataContext  = new RingWindowViewModel(solutionMachine, workspaceMachine, solution, _workspace);
            InitializeComponent();
        }
Пример #5
0
        public static async Task Main(string[] args)
        {
            string username      = null;
            string password      = null;
            string twoFactorCode = null;

            if (args is null || !args.Any())
            {
                var rawInput = Console.ReadLine();
                args = rawInput.Split(' ');
            }

            bool valid = args != null && args.Length >= 2;

            if (valid)
            {
                username = args[0];
                password = args[1];

                valid = !string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password);
            }

            if (valid && args.Length > 2)
            {
                twoFactorCode = args[2];
            }

            if (!valid)
            {
                Console.WriteLine("Invalid arguments. Valid examples:\nRingRefreshTokenUtil.exe <username> <password>\nRingRefreshTokenUtil.exe <username> <password> <2fa code>");
                return;
            }

            var client       = new RingClient();
            var refreshToken = await client.AuthenticateAsync(username, password, twoFactorCode).ConfigureAwait(false);

            if (string.IsNullOrWhiteSpace(refreshToken))
            {
                Console.WriteLine("A refresh token was not received. Check your email or text messages for a 2fa code and run again with the code. Example:\nRingRefreshTokenUtil.exe <username> <password> <2fa code>");
            }
            else
            {
                Console.WriteLine(refreshToken);
            }
        }
Пример #6
0
        public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var ring = await RingClient.CreateAsync(model.EmailAddress, model.Password);

                    var claims = new List <Claim>
                    {
                        new Claim("auth_token", ring.AuthToken)
                    };

                    var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);

                    var authProperties = new AuthenticationProperties {
                        IsPersistent = model.StayLoggedIn
                    };

                    await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity), authProperties);

                    if (!string.IsNullOrEmpty(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }

                    return(RedirectToAction("Index", "Activity"));
                }
                catch (SecurityException)
                {
                    ModelState.AddModelError("", "The provided email address and/or password are incorrect.");
                }
                catch (Exception)
                {
                    ModelState.AddModelError("", "The Ring service failed to login.");
                }
            }

            ViewData["ReturnUrl"] = returnUrl;

            return(View(model));
        }
Пример #7
0
        public async Task <IActionResult> Index()
        {
            RingClient ring;

            try
            {
                var authToken = User.Claims.FirstOrDefault(e => e.Type == "auth_token")?.Value;
                ring = await RingClient.CreateAsync(authToken);
            }
            catch
            {
                return(Challenge());
            }

            try
            {
                return(View(await ring.GetDevicesAsync()));
            }
            catch
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }