Beispiel #1
0
        public static DeviceRegistration GetDevice(string token)
        {
            var documentSnapshot = db.Collection("devices").Document(token).GetSnapshotAsync().Result;
            var broken           = documentSnapshot.GetValue <object>("addresses_v2.p0.tokens");

            if (broken != null && broken.GetType().FullName.Contains("List"))
            {
                Console.WriteLine($"[FB] Invalid Tokens array found, deleting it {token}");

                //This will fail to be deserialized, so deleting the tokens array
                DocumentReference           docRef  = db.Collection("devices").Document(token);
                Dictionary <string, object> updates = new Dictionary <string, object>
                {
                    { "addresses_v2.p0.tokens", FieldValue.Delete }
                };
                docRef.UpdateAsync(updates).Wait();

                documentSnapshot = db.Collection("devices").Document(token).GetSnapshotAsync().Result;
                Console.WriteLine($"[FB] Invalid Tokens array successfully deleted {token}");
            }

            DeviceRegistration device = documentSnapshot.ConvertTo <DeviceRegistration>();

            device.ResetDirty();
            device.MigrateData();
            return(device);
        }
Beispiel #2
0
 public static void UpdateDevice(DeviceRegistration device)
 {
     if (device.Dirty)
     {
         Console.WriteLine($"[FB] Updating Document data for {device.token}");
         db.Collection("devices").Document(device.token).SetAsync(device, SetOptions.MergeAll).Wait();
         device.ResetDirty();
     }
 }
Beispiel #3
0
        private static DeviceRegistration GetDeviceByRef(DocumentSnapshot documentSnapshot)
        {
            DeviceRegistration device = null;

            try
            {
                object broken;
                documentSnapshot.TryGetValue <object>("addresses_v2.p0.tokens", out broken);
                if (broken != null && broken.GetType().FullName.Contains("List"))
                {
                    Console.WriteLine($"[FB] Invalid Tokens array found, deleting it {documentSnapshot.Id}");

                    //This will fail to be deserialized, so deleting the tokens array
                    DocumentReference           docRef  = db.Collection("devices").Document(documentSnapshot.Id);
                    Dictionary <string, object> updates = new Dictionary <string, object>
                    {
                        { "addresses_v2.p0.tokens", FieldValue.Delete }
                    };
                    docRef.UpdateAsync(updates).Wait();

                    var newdocumentSnapshot = db.Collection("devices").Document(documentSnapshot.Id).GetSnapshotAsync().Result;
                    device = newdocumentSnapshot.ConvertTo <DeviceRegistration>();
                    Console.WriteLine($"[FB] Invalid Tokens array successfully deleted {documentSnapshot.Id}");
                }
                else
                {
                    device = documentSnapshot.ConvertTo <DeviceRegistration>();
                }

                device.ResetDirty();
                device.MigrateData();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"[FB] EXCEPTION, unable to deserialize the document {documentSnapshot.Id} : {ex.Message}");
            }
            if (device != null)
            {
                Console.WriteLine($"[FB] Document data for {documentSnapshot.Id} document: {JsonConvert.SerializeObject(device)}");
                return(device);
            }
            Console.WriteLine("");

            return(device);
        }