public void Draw() { ClearTexts(); int visibleCount = Math.Min(m_notifications.Count, MyNotificationConstants.MAX_DISPLAYED_NOTIFICATIONS_COUNT); for (int i = 0; i < visibleCount; i++) { MyNotification actualNotification = m_notifications[i]; StringBuilder messageStringBuilder = m_textsPool.Allocate(); Debug.Assert(actualNotification != null); Debug.Assert(messageStringBuilder != null); bool hasConfirmation = actualNotification.HasDefaultDisappearMessage(); messageStringBuilder.Append(actualNotification.GetText()); if (hasConfirmation) { messageStringBuilder.AppendLine(); messageStringBuilder.ConcatFormat(m_defaultNotificationDisapearMessage, MyGuiManager.GetInput().GetGameControlTextEnum(MyGameControlEnums.NOTIFICATION_CONFIRMATION)); } // draw background: Vector2 textSize = MyGuiManager.GetNormalizedSize(m_usedFont, messageStringBuilder, actualNotification.GetScale()); m_textSizes.Add(textSize); m_texts.Add(messageStringBuilder); } MyGuiManager.BeginSpriteBatch(); var offset = new Vector2(VideoMode.MyVideoModeManager.IsTripleHead() ? -1 : 0, 0); // Draw fog Vector2 notificationPosition = Position; for (int i = 0; i < visibleCount; i++) { Vector2 fogFadeSize = m_textSizes[i] * new Vector2(1.6f, 8.0f); MyGuiManager.DrawSpriteBatch(MyGuiManager.GetFogSmallTexture(), notificationPosition + offset, fogFadeSize, m_fogColor, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyVideoModeManager.IsTripleHead()); notificationPosition.Y += m_textSizes[i].Y; } // Draw texts notificationPosition = Position; for (int i = 0; i < visibleCount; i++) { MyNotification actualNotification = m_notifications[i]; MyGuiManager.DrawString(actualNotification.GetFont(), m_texts[i], notificationPosition + offset, actualNotification.GetScale(), Color.White, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyVideoModeManager.IsTripleHead()); notificationPosition.Y += m_textSizes[i].Y; } MyGuiManager.EndSpriteBatch(); }
private async Task ReceiveMessagesFromDeviceAsync(string partition, CancellationToken ct) { var eventHubReceiver = eventHubClient.GetDefaultConsumerGroup().CreateReceiver(partition, DateTime.UtcNow); while (true) { if (ct.IsCancellationRequested) { break; } EventData eventData = await eventHubReceiver.ReceiveAsync(); if (eventData == null) { continue; } string data = Encoding.UTF8.GetString(eventData.GetBytes()); IOTMessageFormat message = JsonConvert.DeserializeObject <IOTMessageFormat>(data); // bool isAlert = Convert.ToBoolean(eventData.Properties["waterAlert"]); if (message.isDry && notificationSentCount < 5) { MyNotification.SendFireBaseNotification(configs.FireBaseConnectionString, message.message); notificationSentCount++; } else { MyNotification.SendFireBaseNotification(configs.FireBaseConnectionString, message.message); } Console.WriteLine("Message received. Partition: {0} Data: '{1}'", partition, data); } }
/// <summary> /// The main task on each run /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void OnTimeEvent(object sender, System.Timers.ElapsedEventArgs e) { System.Console.WriteLine("A Job Begins"); if (JobRunning) { // to avoid conflict, return this run return; } if (!myTimer.AutoReset) { myTimer.Interval = UpdateInterval; myTimer.AutoReset = true; } JobRunning = true; // Check website data if (!File.Exists(websitesPath)) { MessageBox.Show(localeM.GetString("TxtNotFound"), localeM.GetString("InfoFetchError"), MessageBoxButtons.OK); myTimer.Stop(); notifyThread.Abort(); return; } fileManager.Open(websitesPath); if (!fileManager.Validate()) { MessageBox.Show(localeM.GetString("TxtWrongFormat"), localeM.GetString("InfoFetchError"), MessageBoxButtons.OK); myTimer.Stop(); notifyThread.Abort(); return; } fileManager.Fetch(out string url, out string dir); webManager.StartDriver(); while (url != null) { database.Update(url); if (!webManager.Open(url)) { MyNotification.Push(localeM.GetString("Network"), localeM.GetString("CannotConnect") + url); } else { parser.Read(webManager, dir, database); } fileManager.Fetch(out url, out dir); } webManager.StopDriver(); database.Update(); database.Reset(); JobRunning = false; }
// Add notification to the end of the list: public static int AddNotification(MyNotification notification, MyGuiScreenGamePlayType currentScreen) { int currentScreenInt = (int)currentScreen; notification.ResetAliveTime(); m_screenNotifications[currentScreenInt].Add(notification); return(m_screenNotifications[currentScreenInt].Count()); }
//This will be our message listener, this will be triggered when we successfully upload a file public void GetUploadMessage(GSMessage message) { lastUploadId = message.BaseData.GetString("uploadId"); Database.SetDsiplayImageUploadId(Register.userId, lastUploadId); MyNotification notification = new MyNotification(); notification.MakeNotification("Picture Uploaded Successfully!"); }
public static void ShowDialog(this FrameworkElement element, string key) { element.Dispatcher.Invoke(() => { var newNotification = new MyNotification() { Title = LocaleUtil.GetString("Tips"), Content = LocaleUtil.GetString(key) }; dailogService.ShowNotificationWindow(newNotification, configuration); }); }
/// <summary> /// MenuItem3 click event: will exit the whole program /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void IconMenuClickEvent3(object sender, System.EventArgs e) { myTimer.Stop(); if (JobRunning) { MyNotification.Push(localeM.GetString("WaitBackground"), localeM.GetString("WaitExit")); } while (JobRunning) { System.Threading.Thread.Sleep(50); } webManager.StopDriver(); Application.Exit(); }
public static async Task <List <MyNotification> > GetNotifications(int page = 0, int size = 15) { return(await Task.Run(async() => { var vault = new Windows.Security.Credentials.PasswordVault(); var credentialList = vault.FindAllByResource(resourceName); credentialList[0].RetrievePassword(); List <KeyValuePair <String, String> > paramList = new List <KeyValuePair <String, String> >(); //paramList.Add(new KeyValuePair<string, string>("stuNum", appSetting.Values["stuNum"].ToString())); //paramList.Add(new KeyValuePair<string, string>("idNum", appSetting.Values["idNum"].ToString())); paramList.Add(new KeyValuePair <string, string>("stuNum", credentialList[0].UserName)); paramList.Add(new KeyValuePair <string, string>("idNum", credentialList[0].Password)); paramList.Add(new KeyValuePair <string, string>("page", page.ToString())); paramList.Add(new KeyValuePair <string, string>("size", size.ToString())); string response = await NetWork.getHttpWebRequest("cyxbsMobile/index.php/Home/Article/aboutme", paramList); //response = Utils.ConvertUnicodeStringToChinese(response); Debug.WriteLine(response); List <MyNotification> feeds = new List <MyNotification>(); try { if (response != "" || response != "[]") { JObject bbddfeeds = JObject.Parse(response); if (bbddfeeds["status"].ToString() == "200") { JArray bbddarray = JArray.Parse(bbddfeeds["data"].ToString()); for (int i = 0; i < bbddarray.Count; i++) { MyNotification f = new MyNotification(); f.GetAttributes((JObject)bbddarray[i]); feeds.Add(f); } } if (page == 0) //将第一面的数据存入文件,用于后台任务 { IStorageFolder applicationFolder = ApplicationData.Current.LocalFolder; IStorageFile storageFileWR = await applicationFolder.CreateFileAsync("aboutme.txt", CreationCollisionOption.ReplaceExisting); await FileIO.WriteTextAsync(storageFileWR, response); } } } catch (Exception) { } return feeds; })); return(null); }
protected override DataTemplate SelectTemplateCore(System.Object item, DependencyObject container) { FrameworkElement element = container as FrameworkElement; MyNotification noti = item as MyNotification; if (element != null && noti != null) { if (noti.content == "") { return(PraiseTemplate); } else { return(RemarkTemplate); } } return(RemarkTemplate); }
/// <summary> /// MenuItem5 click event: will show a input box to update a new interval /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void IconMenuClickEvent5(object sender, System.EventArgs e) { if (JobRunning) { MyNotification.Push(localeM.GetString("WaitBackground"), localeM.GetString("IntervalWillShow")); } myTimer.AutoReset = false; while (JobRunning) { System.Threading.Thread.Sleep(50); } if (MyUI.IntervalInput(UpdateInterval, out long newInterval) == DialogResult.OK) { UpdateInterval = newInterval; } myTimer.Interval = UpdateInterval; myTimer.Start(); }
public void Add(MyNotification notification) { Debug.Assert(notification != null, "you cannot add null notification"); if (!m_notifications.Contains(notification)) { if (m_notifications.Count >= MyNotificationConstants.MAX_DISPLAYED_NOTIFICATIONS_COUNT) { if (!notification.IsImportant) { return; } int index = m_notifications.FindIndex(IsNotImportant); if (index != -1) { m_notifications.RemoveAt(index); } } m_notifications.Add(notification); } }
/// <summary> /// MenuItem4 click event: will toggle autostart with system /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void IconMenuClickEvent4(object sender, System.EventArgs e) { RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); if (key == null) { Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); } if (key.GetValue(AppID) == null) { #if DEBUG string startPath = Application.ExecutablePath.ToString(); #else string startPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Programs), "Sida Zhu", "Teamclouday", "InfoFetch.appref-ms"); #endif key.SetValue(AppID, startPath, RegistryValueKind.String); MyNotification.Push(localeM.GetString("AutoStart"), localeM.GetString("Activated")); } else { key.DeleteValue(AppID, false); MyNotification.Push(localeM.GetString("AutoStart"), localeM.GetString("Deactivated")); } }
// Add notification to the end of the list: public static int AddNotification(MyNotification notification) { return AddNotification(notification, GetCurrentScreen()); }
public void Remove(MyNotification notification) { m_notifications.Remove(notification); }
bool IsNotImportant(MyNotification notification) { return(!notification.IsImportant); }
public void Add(MyNotification notification) { Debug.Assert(notification != null, "you cannot add null notification"); if (!m_notifications.Contains(notification)) { if (m_notifications.Count >= MyNotificationConstants.MAX_DISPLAYED_NOTIFICATIONS_COUNT) { if (!notification.IsImportant) return; int index = m_notifications.FindIndex(IsNotImportant); if (index != -1) { m_notifications.RemoveAt(index); } } m_notifications.Add(notification); } }
bool IsNotImportant(MyNotification notification) { return !notification.IsImportant; }
// Add notification to the end of the list: public static int AddNotification(MyNotification notification) { return(AddNotification(notification, GetCurrentScreen())); }
// Add notification to the end of the list: public static int AddNotification(MyNotification notification, MyGuiScreenGamePlayType currentScreen) { int currentScreenInt = (int)currentScreen; notification.ResetAliveTime(); m_screenNotifications[currentScreenInt].Add(notification); return m_screenNotifications[currentScreenInt].Count(); }
public void Remove(MyNotification notification) { m_notifications.Remove(notification); }
static void Main(string[] args) { CheckLocalization(); MyNotification.Push(localeM.GetString("ProgramStart"), localeM.GetString("Wait")); if (!Driver.CheckChromeVersion()) { MessageBox.Show(localeM.GetString("UnknownChromeVersion"), localeM.GetString("InfoFetchError"), MessageBoxButtons.OK); System.Environment.Exit(1); } else { if (!Driver.CheckChromeDriver()) { MessageBox.Show(localeM.GetString("ChromedriverDownloadFail"), localeM.GetString("InfoFetchError"), MessageBoxButtons.OK); System.Environment.Exit(1); } else { Driver.UpdateLocalHtml(); } } MyNotification.Push(localeM.GetString("ProgramStarted"), string.Format(localeM.GetString("SystemTrayManage"), (UpdateInterval / 3600000))); webManager = new Website(); fileManager = new FileManager(); parser = new Parser(); #if DEBUG databasePath = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())), "webdata.sqlite"); #else databasePath = "webdata.sqlite"; #endif database = new Database(databasePath); #if DEBUG websitesPath = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())), "websites.txt"); iconPath = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())), "icon.ico"); #else websitesPath = "websites.txt"; iconPath = "icon.ico"; #endif notifyThread = new System.Threading.Thread( delegate() { var menuItem1 = new MenuItem(); menuItem1.Index = 0; menuItem1.Text = localeM.GetString("OpenLocation"); menuItem1.Click += new System.EventHandler(IconMenuClickEvent1); var menuItem2 = new MenuItem(); menuItem2.Index = 1; menuItem2.Text = localeM.GetString("EditWebsites"); menuItem2.Click += new System.EventHandler(IconMenuClickEvent2); var menuItem5 = new MenuItem(); menuItem5.Index = 2; menuItem5.Text = localeM.GetString("ChangeInterval"); menuItem5.Click += new System.EventHandler(IconMenuClickEvent5); var menuItem4 = new MenuItem(); menuItem4.Index = 3; menuItem4.Text = localeM.GetString("ToggleAutostart"); menuItem4.Click += new System.EventHandler(IconMenuClickEvent4); var menuItem3 = new MenuItem(); menuItem3.Index = 4; menuItem3.Text = localeM.GetString("Exit"); menuItem3.Click += new System.EventHandler(IconMenuClickEvent3); var contextMenu = new ContextMenu(); contextMenu.MenuItems.AddRange(new MenuItem[] { menuItem1, menuItem2, menuItem5, menuItem4, menuItem3 }); trayIcon = new NotifyIcon(); trayIcon.Visible = true; trayIcon.Icon = new System.Drawing.Icon(iconPath); trayIcon.DoubleClick += new System.EventHandler(IconDoubleClickEvent); trayIcon.Text = localeM.GetString("IconText"); trayIcon.ContextMenu = contextMenu; Application.Run(); } ); notifyThread.Start(); myTimer = new System.Timers.Timer(); myTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimeEvent); myTimer.AutoReset = false; myTimer.Start(); while (myTimer.Enabled) { System.Threading.Thread.Sleep(20); } notifyThread.Join(); myTimer.Stop(); }