示例#1
0
 /// <summary>
 /// Конструктор, принимает объект иконки трея
 /// </summary>
 /// <param name="tb"></param>
 public HeadViewModel(TaskbarIcon tb)
 {
     try
     {
         dispatcher    = Dispatcher.CurrentDispatcher;
         thread_object = new Object();
         //инициализируем объект иконки и объект класса всплывающих сообщений
         this.Tb = tb;
         mb      = new MyBalloon(tb.GetPopupTrayPosition().X, tb.GetPopupTrayPosition().Y);
         mb.baloon_panel.ItemsSource = FormatText.baloon_msg;
         mb.Show();
         //инициализируем переменную для хранения настроек окна
         CheckBoxSettings = new MySettings();
         //инициализируем сериализатор
         formatter = new XmlSerializer(typeof(MySettings));
         //загружаем данные из xml при открытии приложения
         Deserializable();
         //выгружаем из бд список аккаунтов
         dbAccounts = new AccountContext();
         dbAccounts.Accounts.Load();
         Accounts = dbAccounts.Accounts.Local.ToBindingList();
         //выгружаем из бд офсеты
         dbOffsets = new OffsetContext();
         dbOffsets.Offsets.Load();
         offsetsFromDb = dbOffsets.Offsets.FirstOrDefault((p) => p.Version == "1.5.5_2591");
         if (offsetsFromDb != null)
         {
             OpenOffsets();
         }
         //выгружаем настройки из бд, в будующем планируется выполнять этот шаг через вебсервис
         dbSettings = new SettingContext();
         dbSettings.Settings.Load();
         //генерируем уникльный ключ компьютера
         String serial = CalcMethods.GenerateSerialNumber();
         //проверяем, есть ли в бд настройки, привязанные к этому ключу
         settings = dbSettings.Settings.FirstOrDefault((p) => p.Serialnumber == serial);
         //если настройки отсутствуют, то создаем новые и заносим в бд
         if (settings == null)
         {
             settings = new Models.Login.Setting
             {
                 Downloader   = "Downloader/12650 MailRuGameCenter/1265",
                 Serialnumber = CalcMethods.GenerateSerialNumber(),
                 UserId_1     = CalcMethods.RandomStringValue(20),
                 UserId_2     = CalcMethods.RandomStringValue(20),
                 Filepath     = String.Empty
             };
             dbSettings.Settings.Add(settings);
             dbSettings.SaveChanges();
         }
         ApplySettings();
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
示例#2
0
 public void ShowNotification(string title, string message)
 {
     Current.Dispatcher.BeginInvoke(new Action(() =>
     {
         Logger.Info("Notification: {0}: {1}", title, message);
         Hardcodet.Wpf.TaskbarNotification.Interop.Point origin = TaskbarIcon.GetPopupTrayPosition();
         origin.Y += 9; // spawn it as close to the taskbar as we can
         TaskbarIcon.CustomPopupPosition = () =>
         {
             return(origin);
         };
         Notification notification = new Notification(origin, title, message);
         TaskbarIcon.ShowCustomBalloon(notification, PopupAnimation.Slide, null);
     }));
 }
示例#3
0
        public void ShowSnapPane(bool animate = true)
        {
            if (m_ConnectTask == null)
            {
                return;
            }
            if (m_ConnectTask.Status == TaskStatus.Running || m_ConnectTask.Status == TaskStatus.WaitingForActivation)
            {
                // wait for it to complete...
                Task.Run(async() =>
                {
                    while (m_ConnectTask.Status == TaskStatus.Running || m_ConnectTask.Status == TaskStatus.WaitingForActivation)
                    {
                        await Task.Delay(10);
                    }
                    await Current.Dispatcher.BeginInvoke(new Action <bool>(ShowSnapPane), animate);
                }).ConfigureAwait(false);

                return;
            }

            if (m_SnapcastClient.ServerData == null)
            {
                ShowNotification("Connection error", string.Format("Unable to connect to snapserver at {0}:{1}", SnapSettings.Server, SnapSettings.ControlPort));
                return;
            }

            if (TaskbarIcon.CustomBalloon == null || TaskbarIcon.CustomBalloon.IsOpen == false)
            {
                Hardcodet.Wpf.TaskbarNotification.Interop.Point origin = TaskbarIcon.GetPopupTrayPosition();
                origin.Y += 9; // spawn it as close to the taskbar as we can
                TaskbarIcon.CustomPopupPosition = () =>
                {
                    return(origin);
                };
                SnapControl.SnapControl sc        = new SnapControl.SnapControl(origin, m_SnapcastClient);
                PopupAnimation          animation = animate ? PopupAnimation.Slide : PopupAnimation.None;
                TaskbarIcon.ShowCustomBalloon(sc, animation, null);
            }
            else
            {
                TaskbarIcon.CloseBalloon();
            }
        }