public static void ShowNotification(this Control control, NotificationType notificationType, string message, NotificationLayout notificationlayout) { //var totalNotificationShowingMilliseconds = timeBeforeHiding.TotalMilliseconds; //var jNotifyDelay = totalNotificationShowingMilliseconds > 0 // ? totalNotificationShowingMilliseconds.ToString(CultureInfo.InvariantCulture) // : "undefined"; // equal to not adding anything //var notificationScript = // string.Format( // "$( function () {{ if(typeof $.noty === 'function') {{ $.noty('{0}', '{1}', {2}); }} }} );", // HttpUtility.JavaScriptStringEncode(message), notificationType.ScriptKey, jNotifyDelay); NotifyClass cls = new NotifyClass(); var jsonSerializer = new JavaScriptSerializer(); string layout = notificationlayout.ToString(); string nType = notificationType.ToString(); string response = jsonSerializer.Serialize(new NotifyClass { text = message, layout = layout, type = nType }); //string animateOpen = jsonSerializer.Serialize(new animateOpen { opacity = "show" }); var notificationScript = string.Format( "$( function () {{ if(typeof $.noty === 'function') {{ $.noty({0},{1}); }} }} );", response, "undefined"); // Allow adding multiple notifications by making the key unique var scriptKey = Guid.NewGuid().ToString(); // Adding the call to the pre-render event of the page, so that multiple notification calls // are added in the same order they are rendered in the page, not the order the calls are processed in page life cycle control.PreRender += new EventHandler ((sender, e) => // Note that we need to use ScriptManager to be UpdatePanel friendly // This will still work even if there is no ScriptManager on the page ScriptManager.RegisterStartupScript(control, control.GetType(), scriptKey, notificationScript, // saves us from adding <script> in string and making it harder to re addScriptTags: true)); }
public async void Run(IBackgroundTaskInstance taskInstance) { deferral_ = taskInstance.GetDeferral(); Debug.WriteLine("NotifyTask started"); try { var file = await ApplicationData.Current.LocalFolder.CreateFileAsync("UserSession.dat", CreationCollisionOption.OpenIfExists); var r = await FileIO.ReadTextAsync(file); if (string.IsNullOrEmpty(r)) { return; } if (r.Length < 100) { return; } string User = "******"; string Pass = "******"; InstaApi = InstaApiBuilder.CreateBuilder() .SetUser(new UserSessionData { UserName = User, Password = Pass }) .UseLogger(new DebugLogger(LogLevel.Exceptions)) .Build(); InstaApi.LoadStateDataFromStream(r); if (!InstaApi.IsUserAuthenticated) { await InstaApi.LoginAsync(); } if (!InstaApi.IsUserAuthenticated) { return; } var activities = await InstaApi.GetRecentActivityAsync(PaginationParameters.MaxPagesToLoad(1)); Notifies = await Load(); if (Notifies == null) { Notifies = new NotifyList(); } if (activities.Succeeded) { const int MAX = 9; int ix = 0; foreach (var item in activities.Value.Items) { var text = item.Text; if (item.Text.Contains(" ")) { text = text.Substring(text.IndexOf(" ") + 1); text = text.TrimStart(); } if (!Notifies.IsExists(text)) { try { var n = new NotifyClass { IsShowing = false, ProfileId = item.ProfileId, ProfilePicture = item.ProfileImage, Text = text, TimeStamp = item.TimeStamp.ToString(), Type = item.Type, }; if (item.InlineFollow == null) { var user = await InstaApi.GetUserInfoByIdAsync(item.ProfileId); if (user.Succeeded) { n.Username = user.Value.Username; } } else { n.Username = item.InlineFollow.User.UserName; n.IsFollowingYou = item.InlineFollow.IsFollowing; } Notifies.Add(n); } catch { } } ix++; if (ix > MAX) { break; } } var list = Notifies; list.Reverse(); for (int i = 0; i < list.Count; i++) { var item = list[i]; if (!string.IsNullOrEmpty(item.Username)) { if (!item.IsShowing) { NotifyHelper.CreateNotifyAction($"@{item.Username}", item.Text, item.ProfilePicture); Notifies[i].IsShowing = true; } } } } } catch (Exception ex) { Debug.WriteLine("Notify ex: " + ex.Message); Debug.WriteLine("Source: " + ex.Source); Debug.WriteLine("StackTrace: " + ex.StackTrace); } await Save(); await Task.Delay(1000); deferral_.Complete(); }
public static void Intilialize(TestContext ctx) { notifyClass = new NotifyClass(); }