public FirebaseService()
        {
            stories = new List <Story>();

            Database db = Database.From(Firebase.Core.App.DefaultInstance);

            dataRef = db.GetRootReference();

            DatabaseReference testDir         = dataRef.GetChild("currentSales");
            nuint             handleReference = testDir.ObserveEvent(DataEventType.Value, (snapshot) => {
                NSEnumerator children = snapshot.Children;

                var child = children.NextObject() as DataSnapshot;

                while (child != null)
                {
                    var data = (StoryObj)child.GetValue <NSDictionary>();
                    if (data.ImgUrl != "false")
                    {
                        stories.Add(data);
                    }

                    child = children.NextObject() as DataSnapshot;
                }
            }, (error) =>
            {
                Console.WriteLine(error);
            });
        }
Beispiel #2
0
        public static void Invite(UIViewController thisView, ChatListClass toChat, string inviteeEmail)
        {
            UserClass inviteeUser  = null;
            UserClass inviterUser  = AppData.curUser;
            String    thisChatName = toChat.ChatName;

            AppData.UsersNode.ObserveSingleEvent(DataEventType.Value, (snapshot) =>
            {
                NSEnumerator children = snapshot.Children;
                var childSnapShot     = children.NextObject() as DataSnapshot;

                while (childSnapShot != null)
                {
                    NSDictionary childDict = childSnapShot.GetValue <NSDictionary>();

                    if (childDict.ValueForKey((NSString)"email").ToString() == inviteeEmail)
                    {
                        // user exist
                        inviteeUser = new UserClass
                        {
                            Name  = childDict.ValueForKey((NSString)"name").ToString(),
                            Email = childDict.ValueForKey((NSString)"email").ToString(),
                            Uid   = childDict.ValueForKey((NSString)"uid").ToString()
                        };
                        break;
                    }
                    childSnapShot = children.NextObject() as DataSnapshot;
                }


                if (inviteeUser == null)
                {
                    AlertShow.Alert(thisView, "No Such User", "User is not registered with us");
                    return;
                }

                String invitationTitle = inviterUser.Uid + "|" + thisChatName;

                object[] ownerKeys = { "ownerUid", "ownerEmail", "ownerName" };
                object[] ownerVals = { inviterUser.Uid, inviterUser.Email, inviterUser.Name };
                var ownerDict      = NSDictionary.FromObjectsAndKeys(ownerVals, ownerKeys);

                object[] inviteeKeys = { "chatName", "owner" };
                object[] inviteeVals = { thisChatName, ownerDict };
                var inviteeDict      = NSDictionary.FromObjectsAndKeys(inviteeVals, inviteeKeys);

                DatabaseReference inviteeNode = AppData.UsersNode.GetChild(inviteeUser.Uid);
                inviteeNode.GetChild("myInvitations")
                .GetChild(invitationTitle)
                .SetValue <NSDictionary>(inviteeDict);

                AlertShow.Alert(thisView, "Invitation Sent", "You have successfully invited " + inviteeUser.Name + " to this chat");
            });
        }
        /// <summary>
        /// Firebaseから取得したNSEnumeratorをStateModelと_stateに代入します。
        /// </summary>
        /// <param name="member">ステータス情報</param>
        /// <returns>ステータス情報を代入したStateModel</returns>
        private List <StateModel> ConvertToStateModels(NSEnumerator states)
        {
            _states.Clear();
            while (states.NextObject() is DataSnapshot state)
            {
                _states.Add(new StateModel()
                {
                    Id            = int.Parse(state.Key),
                    Name          = state.GetChildSnapshot("name").GetValue().ToString(),
                    Color         = state.GetChildSnapshot("color").GetValue().ToString(),
                    BgColor_Hex   = state.GetChildSnapshot("hcolor-bg").GetValue().ToString(),
                    TextColor_Hex = state.GetChildSnapshot("hcolor-text").GetValue().ToString(),
                });
            }

            return(_states.OrderBy(x => x.Id).ToList());
        }
Beispiel #4
0
        void OnSearchReturn <T>(Action <List <T> > callback, DataSnapshot snapshot, Stopwatch watch)
        {
            if (snapshot.Exists && snapshot.HasChildren && callback != null)
            {
                watch.Stop();
                Debug.WriteLine("search time: " + watch.ElapsedMilliseconds);
                watch.Restart();

                NSEnumerator   e = snapshot.Children;
                NSObject       o = e.NextObject();
                DataSnapshot   snap;
                NSMutableArray array = new NSMutableArray();

                while (o != null)
                {
                    //Debug.WriteLine(o.ToString());
                    snap = o as DataSnapshot;
                    array.Add(snap.GetValue());
                    o = e.NextObject();
                }

                NSError  error        = null;
                string   itemArrayStr = NSJsonSerialization.Serialize(array, NSJsonWritingOptions.PrettyPrinted, out error).ToString();
                List <T> itemArr      = JsonConvert.DeserializeObject <List <T> >(itemArrayStr);

                watch.Stop();
                Debug.WriteLine("finish search process time: " + watch.ElapsedMilliseconds);

                callback(itemArr);
            }
            else
            {
                List <T> item = new List <T>();
                callback(item);
            }
        }
        /// <summary>
        /// Firebaseから取得したNSEnumeratorをMemberModelに代入します。
        /// </summary>
        /// <param name="member">メンバー情報</param>
        /// <returns>メンバー情報を代入したMemberModel</returns>
        private List <MemberModel> ConvertToMemberModels(NSEnumerator members)
        {
            _members.Clear();
            while (members.NextObject() is DataSnapshot member)
            {
                var last_name            = member.GetChildSnapshot("last_name").GetValue().ToString();
                var first_name           = member.GetChildSnapshot("first_name").GetValue().ToString();
                var last_update_date     = member.GetChildSnapshot("last_update_date").GetValue().ToString();
                var last_update_auto_flg = member.GetChildSnapshot("last_update_is_auto").GetValue().ToString();
                _members.Add(new MemberModel()
                {
                    Id               = int.Parse(member.Key),
                    Name             = $"{last_name} {first_name}",
                    LastName         = last_name,
                    FirstName        = first_name,
                    Status           = int.Parse(member.GetChildSnapshot("status").GetValue().ToString()),
                    LastStatus       = int.Parse(member.GetChildSnapshot("last_status").GetValue().ToString()),
                    LastUpdateDate   = !last_update_date.Equals("") ? DateTime.Parse(last_update_date) : DateTime.MinValue,
                    LastUpdateIsAuto = Convert.ToBoolean(int.Parse(last_update_auto_flg))
                });
            }

            return(_members.OrderBy(x => x.Id).ToList());
        }
        void CreateObserver()
        {
            dataRef.ObserveEvent(DataEventType.ChildAdded, (snapshot) =>
            {
                var key     = snapshot.Key;
                var snapVal = snapshot.GetValue().ToString();
                switch (key)
                {
                case "birthday":
                    authAccount.Birthday = Convert.ToDateTime(snapVal);
                    break;

                case "email":
                    authAccount.Email = snapVal;
                    break;

                case "name":
                    authAccount.Name = snapVal;
                    break;

                case "radius":
                    authAccount.SalesRadius = double.Parse(snapVal);
                    break;
                }
            });


            checkDir = dataRef.GetChild("checkIns");
            checkDir.ObserveSingleEvent(DataEventType.Value, (snapshot) => {
                NSEnumerator children = snapshot.Children;

                var child = children.NextObject() as DataSnapshot;

                while (child != null)
                {
                    var data = (CheckObj)child.GetValue <NSDictionary>();
                    data.Id  = child.Key;
                    checkIns.Add(data);

                    child = children.NextObject() as DataSnapshot;
                }
            }, (error) =>
            {
                Console.WriteLine(error);
            });

            foreach (CheckIn check in checkIns)
            {
                object[] keys   = { "name", "inDate", "spValue", "lat", "lng" };
                object[] values =
                {
                    check.Name,
                    check.InDate.ToString(),
                    check.SpValue,
                    check.Lat,
                    check.Lng
                };
                var checkData = NSDictionary.FromObjectsAndKeys(values, keys, keys.Length);
                //checkDir.UpdateChildValues(checkData);
            }

            watchDir = dataRef.GetChild("watchItems");

            nuint handleAdd = watchDir.ObserveEvent(DataEventType.ChildAdded, (snapshot) => {
                var data = new WatchItem
                {
                    Name = snapshot.GetValue().ToString(),
                    Id   = snapshot.Key
                };
                items.Add(data);
            }, (error) =>
            {
                Console.WriteLine(error);
            });

            nuint handleChenge = watchDir.ObserveEvent(DataEventType.ChildChanged, (snapshot) =>
            {
                var data = new WatchItem
                {
                    Name = snapshot.GetValue().ToString(),
                    Id   = snapshot.Key
                };
                var _item        = items.Where((WatchItem arg) => arg.Id == data.Id).FirstOrDefault();
                var itemIndex    = items.IndexOf(_item);
                items[itemIndex] = data;
            }, (error) => {
            });

            nuint handleDelete = watchDir.ObserveEvent(DataEventType.ChildRemoved, (snapshot) => {
                var data = new WatchItem
                {
                    Name = snapshot.GetValue().ToString(),
                    Id   = snapshot.Key
                };
                items.Remove(data);
            }, (error) =>
            {
                Console.WriteLine(error);
            });
        }