public void RemoveNotificationItem(string id)
        {
            StackPanel content = this.mNotificationScroll.Content as StackPanel;

            foreach (NotificationDrawerItem notificationDrawerItem in content.Children.OfType <NotificationDrawerItem>())
            {
                if (string.Equals(notificationDrawerItem.Id, id, StringComparison.InvariantCultureIgnoreCase))
                {
                    GenericNotificationManager.MarkNotification((IEnumerable <string>) new List <string>()
                    {
                        id
                    }, (System.Action <GenericNotificationItem>)(x => x.IsDeleted = true));
                    int index = content.Children.IndexOf((UIElement)notificationDrawerItem);
                    content.Children.Remove((UIElement)notificationDrawerItem);
                    if (content.Children.Count > index)
                    {
                        content.Children.RemoveAt(index);
                        break;
                    }
                    break;
                }
            }
            if (content.Children.Count != 0)
            {
                return;
            }
            this.noNotifControl.Visibility      = Visibility.Visible;
            this.mNotificationScroll.Visibility = Visibility.Collapsed;
            this.noNotification = true;
        }
 public static void AddNewNotification(
   GenericNotificationItem notificationItem,
   bool dontOverwrite = false)
 {
   lock (GenericNotificationManager.syncNotificationsReadWrite)
   {
     try
     {
       SerializableDictionary<string, GenericNotificationItem> savedNotifications = GenericNotificationManager.GetSavedNotifications();
       if (!dontOverwrite)
       {
         savedNotifications[notificationItem.Id] = notificationItem;
         GenericNotificationManager.SaveNotifications(savedNotifications);
       }
       else
       {
         if (savedNotifications.ContainsKey(notificationItem.Id))
           return;
         savedNotifications[notificationItem.Id] = notificationItem;
         GenericNotificationManager.SaveNotifications(savedNotifications);
       }
     }
     catch (Exception ex)
     {
       Logger.Error("Failed to add notification id : {0} titled : {1} and msg : {2}... Err : {3}", (object) notificationItem.Id, (object) notificationItem.Title, (object) notificationItem.Message, (object) ex.ToString());
     }
   }
 }
        public void RemoveAllNotificationItems()
        {
            StackPanel content = this.mNotificationScroll.Content as StackPanel;

            GenericNotificationManager.MarkNotification(content.Children.OfType <NotificationDrawerItem>().Select <NotificationDrawerItem, string>((Func <NotificationDrawerItem, string>)(_ => _.Id)), (System.Action <GenericNotificationItem>)(_ => _.IsDeleted = true));
            content.Children.Clear();
            this.noNotifControl.Visibility      = Visibility.Visible;
            this.mNotificationScroll.Visibility = Visibility.Collapsed;
            this.noNotification = true;
        }
 public static SerializableDictionary<string, GenericNotificationItem> GetNotificationItems(
   Predicate<GenericNotificationItem> getter)
 {
   lock (GenericNotificationManager.syncNotificationsReadWrite)
   {
     SerializableDictionary<string, GenericNotificationItem> savedNotifications = GenericNotificationManager.GetSavedNotifications();
     SerializableDictionary<string, GenericNotificationItem> serializableDictionary = new SerializableDictionary<string, GenericNotificationItem>();
     Func<KeyValuePair<string, GenericNotificationItem>, bool> predicate = (Func<KeyValuePair<string, GenericNotificationItem>, bool>) (item => getter(item.Value));
     foreach (KeyValuePair<string, GenericNotificationItem> keyValuePair in savedNotifications.Where<KeyValuePair<string, GenericNotificationItem>>(predicate))
       serializableDictionary.Add(keyValuePair.Key, keyValuePair.Value);
     return serializableDictionary;
   }
 }
        public void UpdateNotificationCount()
        {
            SerializableDictionary <string, GenericNotificationItem> notificationItems = GenericNotificationManager.GetNotificationItems((Predicate <GenericNotificationItem>)(x => !x.IsDeleted && !x.IsRead && string.Equals(x.VmName, this.ParentWindow.mVmName, StringComparison.InvariantCulture)));

            if (notificationItems.Count > 0 && !this.ParentWindow.mTopBar.mNotificationCentrePopup.IsOpen)
            {
                Border border1 = new Border();
                border1.VerticalAlignment = VerticalAlignment.Center;
                border1.Height            = 14.0;
                border1.MaxWidth          = 24.0;
                Border    border2    = border1;
                TextBlock textBlock1 = new TextBlock();
                textBlock1.Text                = notificationItems.Count.ToString((IFormatProvider)CultureInfo.InvariantCulture);
                textBlock1.FontSize            = 10.0;
                textBlock1.MaxWidth            = 24.0;
                textBlock1.FontWeight          = FontWeights.Bold;
                textBlock1.VerticalAlignment   = VerticalAlignment.Center;
                textBlock1.HorizontalAlignment = HorizontalAlignment.Center;
                textBlock1.Padding             = new Thickness(3.0, 0.0, 3.0, 1.0);
                TextBlock textBlock2 = textBlock1;
                if (notificationItems.Count > 99)
                {
                    textBlock2.Text = "99+";
                }
                BlueStacksUIBinding.BindColor((DependencyObject)textBlock2, Control.ForegroundProperty, "SettingsWindowTitleBarForeGround");
                BlueStacksUIBinding.BindColor((DependencyObject)border2, Control.BackgroundProperty, "XPackPopupColor");
                border2.CornerRadius = new CornerRadius(7.0);
                border2.Child        = (UIElement)textBlock2;
                Canvas.SetLeft((UIElement)border2, 20.0);
                Canvas.SetTop((UIElement)border2, 9.0);
                if (this.ParentWindow.mTopBar.mNotificationCountBadge == null)
                {
                    return;
                }
                if (GenericNotificationManager.GetNotificationItems((Predicate <GenericNotificationItem>)(x => !x.IsRead && !x.IsDeleted && x.Priority == NotificationPriority.Important)).Count > 0)
                {
                    this.ParentWindow.mTopBar.mNotificationCountBadge.Visibility = Visibility.Collapsed;
                }
                else
                {
                    this.ParentWindow.mTopBar.mNotificationCountBadge.Visibility = Visibility.Visible;
                }
                this.ParentWindow.mTopBar.mNotificationCountBadge.Children.Clear();
                this.ParentWindow.mTopBar.mNotificationCountBadge.Children.Add((UIElement)border2);
            }
            else
            {
                this.ParentWindow.mTopBar.mNotificationCountBadge.Visibility = Visibility.Collapsed;
            }
        }
Exemple #6
0
        private void pikanotificationcontrol_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (this.ParentWindow == null || !this.ParentWindow.mGuestBootCompleted)
            {
                return;
            }
            this.ParentWindow.Utils.HandleGenericActionFromDictionary((Dictionary <string, string>) this.mNotificationItem.ExtraPayload, "notification_ribbon", this.mNotificationItem.NotificationMenuImageName);
            ClientStats.SendMiscellaneousStatsAsync("RibbonClicked", RegistryManager.Instance.UserGuid, RegistryManager.Instance.ClientVersion, this.mNotificationItem.Id, this.mNotificationItem.Title, JsonConvert.SerializeObject((object)this.mNotificationItem.ExtraPayload), (string)null, (string)null, (string)null, "Android");
            GenericNotificationManager.MarkNotification((IEnumerable <string>) new List <string>()
            {
                this.mNotificationItem.Id
            }, (System.Action <GenericNotificationItem>)(x => x.IsRead = true));
            IEnumerable <NotificationDrawerItem> source = (this.ParentWindow.mTopBar.mNotificationDrawerControl.mNotificationScroll.Content as StackPanel).Children.OfType <NotificationDrawerItem>().Where <NotificationDrawerItem>((Func <NotificationDrawerItem, bool>)(_ => _.Id == this.mNotificationItem.Id));

            if (source.Any <NotificationDrawerItem>())
            {
                source.First <NotificationDrawerItem>().ChangeToReadBackground();
            }
            this.ParentWindow.mTopBar.RefreshNotificationCentreButton();
            this.CloseClicked(sender, (EventArgs)e);
        }
 public static SerializableDictionary<string, GenericNotificationItem> MarkNotification(
   IEnumerable<string> ids,
   System.Action<GenericNotificationItem> setter)
 {
   lock (GenericNotificationManager.syncNotificationsReadWrite)
   {
     SerializableDictionary<string, GenericNotificationItem> lstItem = new SerializableDictionary<string, GenericNotificationItem>();
     try
     {
       lstItem = GenericNotificationManager.GetSavedNotifications();
       foreach (string index in ids.Where<string>((Func<string, bool>) (id => id != null && lstItem.ContainsKey(id))))
         setter(lstItem[index]);
       GenericNotificationManager.SaveNotifications(lstItem);
     }
     catch (Exception ex)
     {
       Logger.Error("Failed to mark notification... Err : " + ex.ToString());
     }
     return lstItem;
   }
 }
        internal static void HandleGenericNotification(JObject resJson, string vmName)
        {
            GenericNotificationItem genericItem = new GenericNotificationItem();

            try
            {
                JObject resJson1 = JObject.Parse(resJson["bluestacks_notification"][(object)"payload"][(object)"GenericNotificationItem"].ToString());
                resJson1.AssignIfContains <string>("id", (System.Action <string>)(x => genericItem.Id             = x));
                resJson1.AssignIfContains <string>("priority", (System.Action <string>)(x => genericItem.Priority = EnumHelper.Parse <NotificationPriority>(x, NotificationPriority.Normal)));
                resJson1.AssignIfContains <string>("title", (System.Action <string>)(x => genericItem.Title       = x));
                resJson1.AssignIfContains <string>("message", (System.Action <string>)(x => genericItem.Message   = x));
                resJson1.AssignIfContains <bool>("showribbon", (System.Action <bool>)(x => genericItem.ShowRibbon = x));
                resJson1.AssignIfContains <string>("menuimagename", (System.Action <string>)(x => genericItem.NotificationMenuImageName = x));
                resJson1.AssignIfContains <string>("menuimageurl", (System.Action <string>)(x => genericItem.NotificationMenuImageUrl   = x));
                resJson1.AssignIfContains <bool>("isread", (System.Action <bool>)(x => genericItem.IsRead                 = x));
                resJson1.AssignIfContains <bool>("isdeleted", (System.Action <bool>)(x => genericItem.IsDeleted           = x));
                resJson1.AssignIfContains <bool>("deferred", (System.Action <bool>)(x => genericItem.IsDeferred           = x));
                resJson1.AssignIfContains <string>("creationtime", (System.Action <string>)(x => genericItem.CreationTime = DateTime.ParseExact(x, "yyyy/MM/dd HH:mm:ss", (IFormatProvider)CultureInfo.InvariantCulture)));
                if (!string.IsNullOrEmpty(genericItem.NotificationMenuImageName) && !string.IsNullOrEmpty(genericItem.NotificationMenuImageUrl))
                {
                    genericItem.NotificationMenuImageName = Utils.TinyDownloader(genericItem.NotificationMenuImageUrl, genericItem.NotificationMenuImageName, RegistryStrings.PromotionDirectory, false);
                }
                if (resJson1["ExtraPayload"] != null && !JsonExtensions.IsNullOrEmptyBrackets(resJson1.GetValue("ExtraPayload", StringComparison.InvariantCulture).ToString()))
                {
                    resJson1["ExtraPayload"].AssignIfContains <string>("payloadtype", (System.Action <string>)(x => genericItem.PayloadType = EnumHelper.Parse <NotificationPayloadType>(x, NotificationPayloadType.Generic)));
                    SerializableDictionary <string, string> extraPayload = genericItem.ExtraPayload;
                    if (extraPayload != null)
                    {
                        extraPayload.ClearAddRange <string, string>((Dictionary <string, string>)CloudNotificationManager.HandleExtraPayload(resJson1.GetValue("ExtraPayload", StringComparison.InvariantCulture).ToObject <JObject>(), genericItem.PayloadType));
                    }
                }
                ClientStats.SendMiscellaneousStatsAsync("notification_received", RegistryManager.Instance.UserGuid, RegistryManager.Instance.ClientVersion, genericItem.Id, genericItem.Title, genericItem.ExtraPayload.ContainsKey("campaign_id") ? genericItem.ExtraPayload["campaign_id"] : "", (string)null, (string)null, (string)null, "Android");
                genericItem.IsReceivedStatSent = true;
                if (resJson1["conditions"] != null && !JsonExtensions.IsNullOrEmptyBrackets(resJson1.GetValue("conditions", StringComparison.InvariantCulture).ToString()))
                {
                    resJson1["conditions"].AssignIfContains <string>("app_pkg_on_top", (System.Action <string>)(x => genericItem.DeferredApp     = x));
                    resJson1["conditions"].AssignIfContains <long>("app_usage_seconds", (System.Action <long>)(x => genericItem.DeferredAppUsage = x));
                }
                if (genericItem.ShowRibbon)
                {
                    if (resJson["bluestacks_notification"][(object)"payload"].ToObject <JObject>()["RibbonDesign"] != null)
                    {
                        if (!JsonExtensions.IsNullOrEmptyBrackets(resJson["bluestacks_notification"][(object)"payload"].GetValue("RibbonDesign")))
                        {
                            genericItem.NotificationDesignItem = new GenericNotificationDesignItem();
                            JObject resJson2 = JObject.Parse(resJson["bluestacks_notification"][(object)"payload"][(object)"RibbonDesign"].ToString());
                            resJson2.AssignIfContains <string>("titleforegroundcolor", (System.Action <string>)(x => genericItem.NotificationDesignItem.TitleForeGroundColor     = x));
                            resJson2.AssignIfContains <string>("messageforegroundcolor", (System.Action <string>)(x => genericItem.NotificationDesignItem.MessageForeGroundColor = x));
                            resJson2.AssignIfContains <string>("bordercolor", (System.Action <string>)(x => genericItem.NotificationDesignItem.BorderColor           = x));
                            resJson2.AssignIfContains <string>("ribboncolor", (System.Action <string>)(x => genericItem.NotificationDesignItem.Ribboncolor           = x));
                            resJson2.AssignIfContains <double>("auto_hide_timer", (System.Action <double>)(x => genericItem.NotificationDesignItem.AutoHideTime      = x));
                            resJson2.AssignIfContains <string>("hoverbordercolor", (System.Action <string>)(x => genericItem.NotificationDesignItem.HoverBorderColor = x));
                            resJson2.AssignIfContains <string>("hoverribboncolor", (System.Action <string>)(x => genericItem.NotificationDesignItem.HoverRibboncolor = x));
                            resJson2.AssignIfContains <string>("leftgifname", (System.Action <string>)(x => genericItem.NotificationDesignItem.LeftGifName           = x));
                            resJson2.AssignIfContains <string>("leftgifurl", (System.Action <string>)(x => genericItem.NotificationDesignItem.LeftGifUrl             = x));
                            if (!string.IsNullOrEmpty(genericItem.NotificationDesignItem.LeftGifName) && !string.IsNullOrEmpty(genericItem.NotificationDesignItem.LeftGifUrl))
                            {
                                Utils.TinyDownloader(genericItem.NotificationDesignItem.LeftGifUrl, genericItem.NotificationDesignItem.LeftGifName, RegistryStrings.PromotionDirectory, false);
                            }
                            if (resJson2["background_gradient"] != null)
                            {
                                foreach (JObject jobject in JArray.Parse(resJson2["background_gradient"].ToString()).ToObject <List <JObject> >())
                                {
                                    genericItem.NotificationDesignItem.BackgroundGradient.Add(new SerializableKeyValuePair <string, double>(jobject["color"].ToString(), jobject["offset"].ToObject <double>()));
                                }
                            }
                            if (resJson2["hover_background_gradient"] != null)
                            {
                                foreach (JObject jobject in JArray.Parse(resJson2["hover_background_gradient"].ToString()).ToObject <List <JObject> >())
                                {
                                    genericItem.NotificationDesignItem.HoverBackGroundGradient.Add(new SerializableKeyValuePair <string, double>(jobject["color"].ToString(), jobject["offset"].ToObject <double>()));
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Exception while parsing generic notification. Not showing notification and not adding in notification menu." + ex.ToString());
                return;
            }
            try
            {
                if (string.IsNullOrEmpty(genericItem.Title) && string.IsNullOrEmpty(genericItem.Message))
                {
                    genericItem.IsDeleted = true;
                }
                if (!genericItem.IsDeferred)
                {
                    GenericNotificationManager.AddNewNotification(genericItem, false);
                }
                if (genericItem.ShowRibbon && resJson["bluestacks_notification"][(object)"payload"].ToObject <JObject>()["RibbonDesign"] != null && !JsonExtensions.IsNullOrEmptyBrackets(resJson["bluestacks_notification"][(object)"payload"].GetValue("RibbonDesign")))
                {
                    if (!genericItem.IsDeferred)
                    {
                        BlueStacksUIUtils.DictWindows[vmName].HandleGenericNotificationPopup(genericItem);
                    }
                    else
                    {
                        CloudNotificationManager.HandleDeferredNotification(genericItem);
                    }
                }
                BlueStacksUIUtils.DictWindows[vmName].mTopBar.RefreshNotificationCentreButton();
            }
            catch (Exception ex)
            {
                Logger.Error("Exception when handling notification json. Id " + genericItem.Id + " Error: " + ex.ToString());
            }
        }
 internal GenericNotificationItem GetNotificationItem(string id)
 {
   return GenericNotificationManager.GetNotificationItems((Predicate<GenericNotificationItem>) (_ => _.Id == id)).FirstOrDefault<KeyValuePair<string, GenericNotificationItem>>().Value;
 }
        private void UserControl_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            string fileName = RegistryStrings.InstallDir + "\\HD-RunApp.exe";
            GenericNotificationItem notificationItem = GenericNotificationManager.Instance.GetNotificationItem(this.Id);
            JsonParser jsonParser = new JsonParser(this.ParentWindow.mVmName);

            if (this.ParentWindow != null && this.ParentWindow.mGuestBootCompleted)
            {
                if (notificationItem == null)
                {
                    return;
                }
                ClientStats.SendMiscellaneousStatsAsync("NotificationDrawerItemClicked", RegistryManager.Instance.UserGuid, RegistryManager.Instance.ClientVersion, notificationItem.Id, notificationItem.Title, JsonConvert.SerializeObject((object)notificationItem.ExtraPayload), notificationItem.ExtraPayload.ContainsKey("campaign_id") ? notificationItem.ExtraPayload["campaign_id"] : "", (string)null, (string)null, "Android");
                GenericNotificationManager.MarkNotification((IEnumerable <string>) new List <string>()
                {
                    notificationItem.Id
                }, (System.Action <GenericNotificationItem>)(x => x.IsRead = true));
                this.ChangeToReadBackground();
                this.ParentWindow.mTopBar.RefreshNotificationCentreButton();
                if (notificationItem.ExtraPayload.Keys.Count > 0)
                {
                    this.ParentWindow.Utils.HandleGenericActionFromDictionary((Dictionary <string, string>)notificationItem.ExtraPayload, "notification_drawer", notificationItem.NotificationMenuImageName);
                }
                else
                {
                    try
                    {
                        if (string.Compare(notificationItem.Title, "Successfully copied files:", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(notificationItem.Title, "Cannot copy files:", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            NotificationPopup.LaunchExplorer(notificationItem.Message);
                        }
                        else
                        {
                            Logger.Info("launching " + notificationItem.Title);
                            AppInfo infoFromPackageName = jsonParser.GetAppInfoFromPackageName(this.PackageName);
                            if (infoFromPackageName != null)
                            {
                                string str = "-json \"" + new JObject()
                                {
                                    {
                                        "app_icon_url",
                                        (JToken)""
                                    },
                                    {
                                        "app_name",
                                        (JToken)infoFromPackageName.Name
                                    },
                                    {
                                        "app_url",
                                        (JToken)""
                                    },
                                    {
                                        "app_pkg",
                                        (JToken)this.PackageName
                                    }
                                }.ToString(Formatting.None).Replace("\"", "\\\"") + "\"";
                                Process.Start(fileName, string.Format((IFormatProvider)CultureInfo.InvariantCulture, "{0} -vmname {1}", (object)str, (object)this.ParentWindow.mVmName));
                            }
                            else
                            {
                                this.ParentWindow.Utils.HandleGenericActionFromDictionary(new Dictionary <string, string>()
                                {
                                    {
                                        "click_generic_action",
                                        GenericAction.InstallPlay.ToString()
                                    },
                                    {
                                        "click_action_packagename",
                                        notificationItem.Package
                                    }
                                }, "notification_drawer", "");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex.ToString());
                    }
                    finally
                    {
                        this.ParentWindow.mTopBar.mNotificationCentrePopup.IsOpen = false;
                    }
                }
            }
            else
            {
                if (notificationItem == null)
                {
                    return;
                }
                this.ParentWindow.mPostBootNotificationAction             = this.PackageName;
                this.ParentWindow.mTopBar.mNotificationCentrePopup.IsOpen = false;
            }
        }