private async void SubmitButton_Click(object sender, RoutedEventArgs e)
        {
            // Status Update
            StatusLabel.Content = "Generating Folder Structure...";

            // If Unified folder doesn't exist then create one
            if (JUnifiedFolder == null)
            {
                // Dispatch a thread to handling generation stuff
                await Task.Factory.StartNew(FolderIterator);
            }

            // Status Update
            StatusLabel.Content = "Folder Structure Mapped Successfully, Now Connecting To Server...";

            // QuickMatch® (1/4): Append a folder for QuickMatch usage
            // Make a copy of JRootFolder to add something interseting to it: QuickMatch® Folders
            JFolder JRootFolderCopy = new JFolder(JUnifiedFolder.FolderName);   // I am not providing a copy constructor in wish that we won't need to use it anywhere else

            JRootFolderCopy.Files   = JUnifiedFolder.Files;                     // Shallow Copy
            JRootFolderCopy.Folders = JUnifiedFolder.Folders.ToList();          // Semi-Deep Copy because we will add new items
            JRootFolderCopy.Folders.Add(new JFolder(App.QuickMatchFolderName)); // Add a blank folder

            // Send Request and Get Content
            MyFormUrlEncodedContent postContent = new MyFormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("username", App.username),
                new KeyValuePair <string, string>("password", App.password),
                new KeyValuePair <string, string>("filecontent", JsonConvert.SerializeObject(JRootFolderCopy, Formatting.Indented))  // Notice that we are only adding this folder here for uploading purpose, for HTML and Local saving we don't do that
            });

            HttpClient          client   = new HttpClient();
            HttpResponseMessage response = await client.PostAsync(App.RESTServiceAddress, postContent);

            // Status Update accordingly
            string responseString = response.Content.ReadAsStringAsync().Result;

            if (responseString == "File successfully received.")
            {
                StatusLabel.Content = "Succeeded!";
            }
            else
            {
                StatusLabel.Content = responseString;
            }
        }
Beispiel #2
0
        private static byte[] GetContentByteArray(IEnumerable <KeyValuePair <string, string> > nameValueCollection)
        {
            if (nameValueCollection == null)
            {
                throw new ArgumentNullException("nameValueCollection");
            }
            StringBuilder stringBuilder = new StringBuilder();

            foreach (KeyValuePair <string, string> current in nameValueCollection)
            {
                if (stringBuilder.Length > 0)
                {
                    stringBuilder.Append('&');
                }

                stringBuilder.Append(MyFormUrlEncodedContent.Encode(current.Key));
                stringBuilder.Append('=');
                stringBuilder.Append(MyFormUrlEncodedContent.Encode(current.Value));
            }
            return(Encoding.Default.GetBytes(stringBuilder.ToString()));
        }
Beispiel #3
0
 public MyFormUrlEncodedContent(IEnumerable <KeyValuePair <string, string> > nameValueCollection)
     : base(MyFormUrlEncodedContent.GetContentByteArray(nameValueCollection))
 {
     base.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
 }