Ejemplo n.º 1
0
        public static async Task SetCurrentAsync(IDocumentReference?doc)
        {
            if (doc?.Id != Current?.Doc.Id || doc is null)
            {
                listener?.Remove();

                if (doc is null)
                {
                    if (DonorUser.Current is null)
                    {
                        Current     = null;
                        previousUID = null;
                        CurrentUpdated?.Invoke(null);
                        CurrentChanged?.Invoke(null);
                        return;
                    }
                    else
                    {
                        var            bundleCollection = DonorUser.Current.Doc.Collection("DonationBundles");
                        DonationBundle bundle           = new DonationBundle
                        {
                            StripeStatus  = StripeStatus.Pending,
                            GiftAidState  = DonorUser.Current.GiftAidEnabled ? GiftAidState.Unclaimed : GiftAidState.Ineligible,
                            Amount        = 0,
                            UserConfirmed = false
                        };
                        doc = await bundleCollection.AddAsync(bundle);

                        await DonorUser.Current.Doc.UpdateAsync(new { CurrentDonationBundle = doc });
                    }
                }
                listener = doc.AddSnapshotListener((snapshot, ex) => OnCurrentSnapshot(snapshot));
            }
        }
Ejemplo n.º 2
0
        private static void OnCurrentSnapshot(IDocumentSnapshot?snapshot)
        {
            Current = snapshot?.ToObject <DonorUser>();
            CurrentUpdated?.Invoke(Current);
            if (previousUID != Current?.UID)
            {
                previousUID = Current?.UID;
                CurrentChanged?.Invoke(Current);
                CrossFirebasePushNotification.Current.UnsubscribeAll();
                if (!(Current is null))
                {
                    CrossFirebasePushNotification.Current.Subscribe("Urgent_Project");
                }
            }
            _ = DonationBundle.SetCurrentAsync(Current?.CurrentDonationBundle);
            if (!(Current is null) && ThemeEngine.SetTheme(Current.DesiredTheme))
            {
                SecureStorage.SetAsync("ThemePreference", Current.DesiredTheme.ToString());
            }
            var newTopics = Current?.DonatedProjectUIDs.Select(x => "Project_" + x)
                            .Where(x => !CrossFirebasePushNotification.Current.SubscribedTopics.Contains(x));

            if (newTopics?.Any() ?? false)
            {
                CrossFirebasePushNotification.Current.Subscribe(newTopics.ToArray());
            }
            System.Diagnostics.Debug.WriteLine(string.Join(", ", CrossFirebasePushNotification.Current.SubscribedTopics));
        }
Ejemplo n.º 3
0
 private static void OnCurrentSnapshot(IDocumentSnapshot?snapshot)
 {
     Current = snapshot?.ToObject <Team>();
     CurrentUpdated?.Invoke(Current);
     if (previousUID != Current?.UID)
     {
         previousUID = Current?.UID;
         CurrentChanged?.Invoke(Current);
     }
 }
Ejemplo n.º 4
0
 private static void OnCurrentSnapshot(IDocumentSnapshot?snapshot)
 {
     Current = snapshot?.ToObject <DonationBundle>();
     CurrentUpdated?.Invoke(Current);
     if (previousUID != Current?.UID)
     {
         previousUID = Current?.UID;
         CurrentChanged?.Invoke(Current);
     }
     if (Current?.StripeStatus is StripeStatus.Succeeded || Current?.StripeStatus is StripeStatus.Failed)
     {
         _ = SetCurrentAsync(null);
         CurrentProcessed?.Invoke(Current?.StripeStatus is StripeStatus.Succeeded);
     }
 }
Ejemplo n.º 5
0
 public static void SetCurrent(string?uid)
 {
     if (uid != Current?.UID)
     {
         listener?.Remove();
         if (string.IsNullOrEmpty(uid))
         {
             Current     = null;
             previousUID = null;
             CurrentUpdated?.Invoke(null);
             CurrentChanged?.Invoke(null);
             return;
         }
         var doc = Firestore.Collection("Users").Document(uid !);
         listener = doc.AddSnapshotListener((snapshot, ex) => OnCurrentSnapshot(snapshot));
     }
 }
Ejemplo n.º 6
0
 private static void OnCurrentSnapshot(IDocumentSnapshot?snapshot)
 {
     Current = snapshot?.ToObject <PartnerUser>();
     CurrentUpdated?.Invoke(Current);
     if (Current?.UID != previousUID)
     {
         previousUID = Current?.UID;
         CurrentChanged?.Invoke(Current);
     }
     if (Current?.TeamConfirmed ?? false)
     {
         Team.SetCurrent(Current.TeamUID);
     }
     if (!(Current is null) && ThemeEngine.SetTheme(Current.DesiredTheme))
     {
         SecureStorage.SetAsync("ThemePreference", Current.DesiredTheme.ToString());
     }
 }
Ejemplo n.º 7
0
        /*
         * "coord":{"lon":150.9,"lat":-32.27
         * "weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10n"}
         * "base":"cmc stations"
         * "main":{"temp":285.219,"pressure":979.25,"humidity":86,"temp_min":285.219,"temp_max":285.219,"sea_level":1012.14,"grnd_level":979.25
         * "wind":{"speed":5.62,"deg":275.001
         * "rain":{"3h":0.585
         * "clouds":{"all":92
         * "dt":1465138121
         * "sys":{"message":0.003,"country":"AU","sunrise":1465073495,"sunset":1465109900
         * "id":2156034
         * "name":"Muswellbrook"
         * "cod":200}
         */
        public void UpdateCurrent()
        {
            new Thread(() =>
            {
                WeatherData weather = new WeatherData();
                weather.Time        = DateTime.Now;
                weather.Unit        = WeatherData.UnitType.Celcius;

                string url    = CURRENT_WEATHER_URL + API_KEY + "&id=" + Properties.Settings.Default.Widget_Weather_CityID;
                string[] data = SplitData(url.DownloadString());

                foreach (string d in data)
                {
                    if (d.StartsWith("\"weather\""))
                    {
                        // Condition
                        string condition = d.Split(new string[] { "main" }, StringSplitOptions.None)[1].Split(new string[] { "," }, StringSplitOptions.None)[0];
                        WeatherData.WeatherCondition weatherCondition;
                        Enum.TryParse(condition.Substring(3, condition.Length - 4), out weatherCondition);
                        weather.Condition = weatherCondition;
                        // --
                    }
                    else if (d.StartsWith("\"main\""))
                    {
                        // Current Temperature
                        string currentTemp = d.Split("temp")[1].Split(",")[0];
                        double current;
                        if (double.TryParse(currentTemp.Substring(2, currentTemp.Length - 2), out current))
                        {
                            weather.Current = current;
                        }
                        // --
                        // Minimum Temperature
                        string minTemp = d.Split("temp_min")[1].Split(",")[0];
                        double min;
                        if (double.TryParse(minTemp.Substring(2, minTemp.Length - 2), out min))
                        {
                            weather.Minimum = min;
                        }
                        // --
                        // Maximum Temperature
                        string maxTemp = d.Split("temp_max")[1].Split(",")[0];
                        double max;
                        if (double.TryParse(maxTemp.Substring(2, maxTemp.Length - 2), out max))
                        {
                            weather.Maximum = max;
                        }
                        // --
                        // Humidity
                        string humidityVal = d.Split("humidity")[1].Split(",")[0];
                        double humidity;
                        if (double.TryParse(humidityVal.Substring(2, humidityVal.Length - 2), out humidity))
                        {
                            weather.Humidity = humidity;
                        }
                        // --
                    }
                    else if (d.StartsWith("\"sys\""))
                    {
                        string location = d.Split("country")[1].Split(",")[0];
                        location        = location.Substring(3, location.Length - 4);

                        if (weather.Location == "Location Unknown")
                        {
                            weather.Location = ", " + location;
                        }
                        else
                        {
                            weather.Location += ", " + location;
                        }
                    }
                    else if (d.StartsWith("\"name\""))
                    {
                        if (weather.Location == "Location Unknown")
                        {
                            weather.Location = d.Substring(d.IndexOf(":") + 2, d.Length - d.IndexOf(":") - 3);
                        }
                        else
                        {
                            weather.Location = d.Substring(d.IndexOf(":") + 2, d.Length - d.IndexOf(":") - 3) + weather.Location;
                        }
                    }
                }

                CurrentUpdated?.Invoke(null, new WeatherArgs(new WeatherData[] { weather }, WeatherArgs.UpdateType.Current));
            }).Start();
        }