コード例 #1
0
        private async Task <User> GetUser()
        {
            Dictionary <string, string> data = new Dictionary <string, string>();
            string uri = "user/username/" + Windows.Storage.ApplicationData.Current.LocalSettings.Values["username"];
            Dictionary <string, object> feedraw = await HttpHelpers.Get <Dictionary <string, object> >(data, uri);

            User second = ((JObject)feedraw["data"]).ToObject <User>();

            return(second);
        }
コード例 #2
0
        public async void LoadFeed()
        {
            List <Change> output             = new List <Change>();
            Dictionary <string, string> data = new Dictionary <string, string>();

            data.Add("limit", limit.ToString());
            data.Add("offset", offset.ToString());
            string uri = "user/feed/" + Windows.Storage.ApplicationData.Current.LocalSettings.Values["username"];
            Dictionary <string, object> feedraw = await HttpHelpers.Get <Dictionary <string, object> >(data, uri);

            List <Dictionary <string, object> > experiments = ((JArray)feedraw["data"]).ToObject <List <Dictionary <string, object> > >();

            foreach (Dictionary <string, object> ind in experiments)
            {
                BitmapImage temp = new BitmapImage(new Uri("ms-appx:///Assets/placeholder.png"));;
                if (ind.ContainsKey("meta"))
                {
                    if (ind["meta"] != null)
                    {
                        Debug.WriteLine("Test");
                        temp = await GenImage(ind["meta"] as string);
                    }
                }
                foreach (string key in ind.Keys)
                {
                    if (key != "meta")
                    {
                        List <object> l = ((JArray)ind[key]).ToObject <List <object> >();
                        for (int i = 0; i < l.Count; i++)
                        {
                            Dictionary <string, object> top    = ((JObject)l[i]).ToObject <Dictionary <string, object> >();
                            Dictionary <string, object> middle = ((JObject)top["changes"]).ToObject <Dictionary <string, object> >();
                            foreach (string keytwo in middle.Keys)
                            {
                                Dictionary <string, string> bottom = ((JObject)middle[keytwo]).ToObject <Dictionary <string, string> >();
                                output.Add(new Change((DateTime)top["timestamp"], key, temp, bottom));
                            }
                        }
                    }
                }
            }
            output.Sort((x, y) => DateTime.Compare(y.Created, x.Created));
            for (int i = 0; i < output.Count; i++)
            {
                Feed.Items.Add(output[i]);
            }
            Waiting.Visibility = Visibility.Collapsed;
        }
コード例 #3
0
 public async void Save()
 {
     await Task.Run(async() =>
     {
         // Create sample file; replace if exists.
         Windows.Storage.StorageFolder storageFolder =
             Windows.Storage.ApplicationData.Current.LocalFolder;
         Windows.Storage.StorageFile sampleFile =
             await storageFolder.CreateFileAsync(FileName + ".mport",
                                                 Windows.Storage.CreationCollisionOption.ReplaceExisting);
         JsonSerializerSettings settings = new JsonSerializerSettings
         {
             TypeNameHandling = TypeNameHandling.All
         };
         string fileserial             = Serialize.Xml_Serialize_Object <Experiment>((Experiment)this);
         Dictionary <string, object> o = new Dictionary <string, object>();
         o.Add("usertoken", Windows.Storage.ApplicationData.Current.LocalSettings.Values["usertoken"]);
         o.Add("experiment", this);
         try
         {
             try
             {
                 await Windows.Storage.FileIO.WriteBytesAsync(sampleFile, Encoding.UTF8.GetBytes(fileserial));
                 Dictionary <string, object> d = await HttpHelpers.Put <Dictionary <string, object> >(o, "experiment");
                 if ((bool)d["success"] == true)
                 {
                     Debug.WriteLine("Yay!");
                 }
             }
             catch
             {
                 Debug.WriteLine("Failed to Save Experiment");
             }
         }
         catch (Exception e)
         {
             Debug.WriteLine(e.Message);
         }
     });
 }
コード例 #4
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            Button       b    = sender as Button;
            ProgressRing ring = new ProgressRing()
            {
                Width      = 25,
                Height     = 25,
                Foreground = new SolidColorBrush(Colors.Black),
                IsActive   = true
            };

            b.Content = ring;
            Dictionary <String, String> dict     = new Dictionary <string, string>();
            Dictionary <String, object> response = new Dictionary <string, object>();
            Dictionary <String, object> user     = new Dictionary <string, object>();
            string        dialogText             = "";
            var           settings = ApplicationData.Current.LocalSettings;
            ContentDialog d        = new ContentDialog()
            {
                PrimaryButtonText = "Ok"
            };

            if (_username == "" && _password == "")
            {
                dialogText = "Please fill out all of the required fields";
            }
            else
            {
                dict.Add("Username", _username);
                dict.Add("Password", _password);

                response = await HttpHelpers.Post <Dictionary <string, object> >(dict, "auth/login");

                if (response == null)
                {
                    dialogText = "Sorry, something went wrong";
                }
                else if (response.ContainsKey("success") && (bool)response["success"] == true)
                {
                    dialogText            = "Welcome, " + Username + "!";
                    d.PrimaryButtonClick += delegate
                    {
                        this.Frame.Navigate(typeof(UserPage));
                    };

                    user = await HttpHelpers.Get <Dictionary <string, object> >(dict, "user/username/" + Username);

                    if ((bool)user["success"] == true)
                    {
                        User userdata = ((JObject)user["data"]).ToObject <User>();
                        userdata.Save();
                        settings.Values["usertoken"] = response["token"];
                        settings.Values["username"]  = Username;
                    }
                    else
                    {
                        dialogText = "What??";
                    }
                }
                else
                {
                    Dictionary <string, object> error = ((JObject)response["error"]).ToObject <Dictionary <string, object> >();
                    if ((string)error["type"] == "Password")
                    {
                        dialogText = "Incorrect Password";
                    }
                    else if ((string)error["type"] == "Database")
                    {
                        dialogText = "Please include all of the required information";
                    }
                    else if ((string)error["type"] == "NoUser")
                    {
                        dialogText = "Sorry, that user doesn't exist.";
                    }
                    else
                    {
                        dialogText = "Oops, something went wrong";
                    }
                }
            }
            d.Title = dialogText;

            await d.ShowAsync();
        }