Exemple #1
0
    void getScheduleData()
    {
        try
        {
            reference.GetValueAsync().ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    throw new Exception("ERROR while fetching data from database!!! Please refresh scene(Click locations)");
                }
                else if (task.IsCompleted)
                {
                    DataSnapshot snapshot = task.Result.Child(dbDetails.getScheduleDBName()).Child(UserName).Child(ScheduleName);

                    string str           = snapshot.GetRawJsonValue();
                    JObject jsonLocation = JObject.Parse(str);
                    IList <string> keys  = jsonLocation.Properties().Select(p => p.Name).ToList();

                    DataSnapshot sharedLocationSnapshot = task.Result.Child(dbDetails.getSharedDBName()).Child(UserName).Child(ScheduleName);

                    string SharedLocationstr   = sharedLocationSnapshot.GetRawJsonValue();
                    JObject jsonSharedLocation = JObject.Parse(str);
                    IList <string> Sharedkeys  = jsonLocation.Properties().Select(p => p.Name).ToList();

                    foreach (string key in keys)
                    {
                        locationsData.Add(key, (string)jsonLocation[key]);
                    }

                    foreach (string key in Sharedkeys)
                    {
                        sharedLocationsData.Add(key, (JObject)jsonLocation[key]);
                    }
                }
            });
        }
        catch (InvalidCastException e)
        {
            // Perform some action here, and then throw a new exception.
            ErrorMessage.text = e.Message;
            ErrorPanel.SetActive(true);
        }
        catch (Exception e)
        {
            // Perform some action here, and then throw a new exception.
            ErrorMessage.text = e.Message;
            ErrorPanel.SetActive(true);
        }
    }
    void getLocationData()
    {
        ScheduleNameTransfer s = ScheduleNameTransfer.Instance;
        string scheduleName    = s.getScheduleName();

        Singleton singleton = Singleton.Instance();
        String    user      = singleton.getUserName();

        reference.GetValueAsync().ContinueWith(task => {
            if (task.IsFaulted)
            {
                // Handle the error...
                Debug.Log("error fetching data");
            }
            else if (task.IsCompleted)
            {
                // getting schedules for a particular user.
                DataSnapshot snapshot = task.Result.Child(dbDetails.getScheduleDBName()).Child(user).Child(scheduleName);

                string str           = snapshot.GetRawJsonValue();
                JObject jsonLocation = JObject.Parse(str);
                IList <string> keys  = jsonLocation.Properties().Select(p => p.Name).ToList();
                //var values = jsonLocation.ToObject<Dictionary<string, object>>();

                foreach (string schedule in keys)
                {
                    Debug.Log(schedule);
                    this.locations.Add(new ScheduleLocation(schedule, (string)jsonLocation[schedule]));
                }
            }
        });
    }
    public void onSave()
    {
        //Creating JSON
        JObject locations = new JObject();
        JObject time      = new JObject();

        foreach (LocationWithTime location in this.locations)
        {
            locations.Add(location.Name, location.Time);
            // time["Time"] = location.Time;
            // locations[location.Name] = time;
        }

        string jsonData = locations.ToString();

        try
        {
            if (ScheduleNameText.text == "")
            {
                throw new Exception("Please enter Tour Name!");
            }

            //Temp until authentication is completed
            Singleton singleton = Singleton.Instance();
            String    user      = singleton.getUserName();
            //String user = "******";

            reference.Child(dbDetails.getTourDBName()).Child(user).Child(ScheduleNameText.text).RemoveValueAsync();

            reference.Child(dbDetails.getScheduleDBName()).Child(user).Child(ScheduleNameText.text).SetRawJsonValueAsync(jsonData).ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    throw new Exception("ERROR while appending values to database.");
                }
                else if (task.IsCompleted)
                {
                    Debug.Log("SUCCESS: DATA ADDED TO DATABASE");
                }
            });
            SceneManager.LoadScene("SchedulesScene");
        }
        catch (InvalidCastException e)
        {
            // Perform some action here, and then throw a new exception.
            ErrorMessage.text = e.Message;
            ErrorPanel.SetActive(true);
        }
        catch (Exception e)
        {
            // Perform some action here, and then throw a new exception.
            ErrorMessage.text = e.Message;
            ErrorPanel.SetActive(true);
        }
    }
Exemple #4
0
        void getScheduleData()
        {
            string UserName     = singleton.getUserName();
            string ScheduleName = singleton.getScheduleName();

            try
            {
                reference.GetValueAsync().ContinueWith(task =>
                {
                    if (task.IsFaulted)
                    {
                        throw new Exception("ERROR while fetching data from database!!! Please refresh scene(Click Tours)");
                    }
                    else if (task.IsCompleted)
                    {
                        DataSnapshot snapshot = task.Result.Child(dbDetails.getScheduleDBName()).Child(UserName).Child(ScheduleName);

                        string str           = snapshot.GetRawJsonValue();
                        JObject jsonLocation = JObject.Parse(str);
                        IList <string> keys  = jsonLocation.Properties().Select(p => p.Name).ToList();

                        int i = 0;
                        foreach (string location in keys)
                        {
                            locations.Add(new TourLocation(location, i + 1));
                            i++;
                        }

                        getCoordinates();
                    }
                });
            }
            catch (InvalidCastException e)
            {
                // Perform some action here, and then throw a new exception.
                ErrorMessage.text = e.Message;
                ErrorPanel.SetActive(true);
            }
            catch (Exception e)
            {
                // Perform some action here, and then throw a new exception.
                ErrorMessage.text = e.Message;
                ErrorPanel.SetActive(true);
            }
        }
Exemple #5
0
        void getScheduleData()
        {
            try
            {
                reference.GetValueAsync().ContinueWith(task =>
                {
                    if (task.IsFaulted)
                    {
                        throw new Exception("ERROR while fetching data from database!!! Please refresh scene(Click Tours)");
                    }
                    else if (task.IsCompleted)
                    {
                        DataSnapshot snapshot = task.Result.Child(dbDetails.getScheduleDBName()).Child(UserName).Child(ScheduleName);

                        Dictionary <string, object> locationData = JsonConvert.DeserializeObject <Dictionary <string, object> >(snapshot.GetRawJsonValue());
                        int i = 0;
                        foreach (string location in locationData.Keys)
                        {
                            locations.Add(new TourLocation(location, i + 1));
                            i++;
                        }

                        getCoordinates();
                    }
                });
            }
            catch (InvalidCastException e)
            {
                // Perform some action here, and then throw a new exception.
                ErrorMessage.text = e.Message;
                ErrorPanel.SetActive(true);
            }
            catch (Exception e)
            {
                // Perform some action here, and then throw a new exception.
                ErrorMessage.text = e.Message;
                ErrorPanel.SetActive(true);
            }
        }