Ejemplo n.º 1
0
        public MainViewModel(client cl, device d)
        {
            Client = cl;
            Device = d;

            _countDownTimer       = new DispatcherTimer();
            _countDownTimer.Tick += async(o, e) => await countdownTimer();

            _countDownTimer.Interval  = new TimeSpan(0, 0, 0, 1);
            _countDownTimer.IsEnabled = true;
            _countDownTimer.Start();
            _iprep = new IPret();
            restartCountdown();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates IP Address in database. It inserts a new row into the database for the device in question. Done asynchornously no to freeze UI
        /// </summary>
        /// <param name="ip"></param>
        public async void SaveIp(string ip)
        {
            int deviceid = Properties.Settings.Default.deviceId;

            // check if client or device exists
            if (deviceid <= 0)
            {
                return;
            }

            await Task.Run(() =>
            {
                try
                {
                    using (var context = new ipdevicesEntities())
                    {
                        device d = context.devices.Find(deviceid);
                        /// does the device really exist in db?
                        if (d != null)
                        {
                            d.ips.Add(new ip
                            {
                                IP   = ip,
                                Date = DateTime.Now
                            });
                            context.SaveChanges();
                        }
                        else
                        {
                            // if it doesn't, remove device from application registration
                            Console.WriteLine("Device no longer in database. Removed.");
                            Device = null;
                        }


                        _OldAdd = ip; // save ip in settings for later comparisoons
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("An unknown error occurred while updating ip address");
                }
            });
        }
Ejemplo n.º 3
0
        private void check()
        {
            var clientid = (int)IPdevices.Properties.Settings.Default["clientid"];
            var deviceid = (int)IPdevices.Properties.Settings.Default["deviceid"];

            if (clientid > 0)
            {
                try
                {
                    SplashScreenHelper.ShowText("Looking for profile...");
                    using (ipdevicesEntities ipde = new ipdevicesEntities())
                    {
                        // does the client actually exist?
                        if (ipde.clients.Any(o => o.uid == clientid))
                        {
                            Console.WriteLine("Client id " + clientid + " was found");

                            SplashScreenHelper.ShowText("Profile found!");
                            var cl = new client();
                            cl = ipde.clients.Find(clientid);

                            SplashScreenHelper.ShowText("Looking for registered device...");

                            // check for registered devices
                            device dev = null;

                            if (cl.devices.Where(d => d.did == deviceid).DefaultIfEmpty(null).FirstOrDefault() != null)
                            {
                                SplashScreenHelper.ShowText("Device found!");
                                dev = ipde.devices.Find(deviceid);
                            }

                            // give client information and device information
                            main = new Main(cl, dev);
                            // apply the proper datacontet to the notify icon
                            notifyIcon             = (TaskbarIcon)FindResource("MyNotifyIcon");
                            notifyIcon.DataContext = new NotifyIconViewModel((MainViewModel)main.DataContext);

                            SplashScreenHelper.Close();

                            main.Show();
                        }
                        else
                        {
                            // well clientid was found in settings, but it doesn't exist in the db. Then just make sure that we reset settings too!
                            Console.WriteLine("Client id " + clientid + " not found in db, resetting settings to default 0");

                            IPdevices.Properties.Settings.Default.clientid = 0;
                            IPdevices.Properties.Settings.Default.deviceId = 0;
                            IPdevices.Properties.Settings.Default.Save();

                            SplashScreenHelper.Close();

                            openLoginWindow();
                        }
                    }
                    ;
                }
                catch (Exception ex)
                {
                    retry();
                    Console.WriteLine("Error logging in: " + ex.Message);
                }
            }
            else
            {
                SplashScreenHelper.Close();
                openLoginWindow();
            }
        }
Ejemplo n.º 4
0
 public ClientLogin()
 {
     _device = null;
     _client = null;
 }
Ejemplo n.º 5
0
 public Main(client cl, device d)
 {
     InitializeComponent();
     DataContext = new MainViewModel(cl, d);
     this.Title  = this.Title + " v" + Utility.GetPublishedVersion();
 }