Skip to content

Commit

Permalink
Some small fix: 1. query return formatting. 2. Media Options 3. Add m…
Browse files Browse the repository at this point in the history
…ultiple documents from folder.
  • Loading branch information
unknown authored and unknown committed Sep 26, 2014
1 parent 62e6fcd commit ca22573
Showing 1 changed file with 52 additions and 3 deletions.
55 changes: 52 additions & 3 deletions DocumentDBSudio/TreeNodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Microsoft.Azure.DocumentDBStudio
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Azure.DocumentDBStudio.Properties;
Expand All @@ -16,6 +17,7 @@ namespace Microsoft.Azure.DocumentDBStudio
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System.Text;
using Microsoft.Azure.Documents;

internal class AccountSettings
{
Expand Down Expand Up @@ -410,6 +412,9 @@ public DocumentCollectionNode(DocumentClient client, Documents.DocumentCollectio
MenuItem myMenuItem9 = new MenuItem("Add Document From File");
myMenuItem9.Click += new EventHandler(myMenuItemAddDocumentFromFile_Click);
this.contextMenu.MenuItems.Add(myMenuItem9);
MenuItem myMenuItem4 = new MenuItem("Add Multiple Documents From Folder");
myMenuItem4.Click += new EventHandler(myMenuItemAddDocumentsFromFolder_Click);
this.contextMenu.MenuItems.Add(myMenuItem4);
MenuItem myMenuItem1 = new MenuItem("Refresh Documents feed");
myMenuItem1.Click += new EventHandler((sender, e) => Refresh(true));
this.contextMenu.MenuItems.Add(myMenuItem1);
Expand All @@ -418,6 +423,7 @@ public DocumentCollectionNode(DocumentClient client, Documents.DocumentCollectio
this.contextMenu.MenuItems.Add(myMenuItem2);
}


void myMenuItemDeleteDocumentCollection_Click(object sender, EventArgs e)
{
string x = this.Tag.ToString();
Expand Down Expand Up @@ -462,6 +468,47 @@ void myMenuItemAddDocumentFromFile_Click(object sender, EventArgs e)
}
}

async void myMenuItemAddDocumentsFromFolder_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = true;

DialogResult dr = ofd.ShowDialog();

if (dr == DialogResult.OK)
{
string status = string.Format("Add {0} files in collection\r\n", ofd.FileNames.Length);
// Read the files
foreach (String filename in ofd.FileNames)
{

// right now assume every file is JSON content
string jsonText = System.IO.File.ReadAllText(filename);
string fileRootName = Path.GetFileName(filename);

object document = JsonConvert.DeserializeObject(jsonText);

try
{
ResourceResponse<Documents.Document> newdocument = await this.client.CreateDocumentAsync((this.Tag as Documents.DocumentCollection).SelfLink, document);
status += string.Format("Succeed adding {0} \r\n", fileRootName);

}
catch (DocumentClientException ex)
{
status += string.Format("Failed adding {0}, statusCode={1} \r\n", fileRootName, ex.StatusCode);
}
catch (Exception ex)
{
status += string.Format("Failed adding {0}, unknown exception \r\n", fileRootName, ex.Message);
}

Program.GetMain().SetResultInBrowser(null, status, false);

}
}
}

void myMenuItemAddDocument_Click(object sender, EventArgs e)
{
//
Expand Down Expand Up @@ -547,14 +594,16 @@ async void QueryDocuments(string queryText, string optional)
foreach (dynamic d in r)
{
index++;
// currently Query.ToString() has Formatting.Indented, but the public release doesn't have yet.
jsonarray += d.ToString();

if (index == r.Count)
{
jsonarray += "]";
}
else
{
jsonarray += ",";
jsonarray += ",\r\n";
}
}

Expand Down Expand Up @@ -749,7 +798,7 @@ async void myMenuItemAttachmentFromFile_Click(object sender, EventArgs eventArg)
};

ResourceResponse<Documents.Attachment> rr = await this.client.CreateAttachmentAsync((this.Tag as Documents.Document).AttachmentsLink,
stream);
stream, options);
string json = rr.Resource.ToString();

Program.GetMain().SetResultInBrowser(json, null, false, rr.ResponseHeaders);
Expand Down Expand Up @@ -1204,7 +1253,7 @@ public UDFsNode(DocumentClient client)
myMenuItem.Click += new EventHandler(myMenuItemAddUDF_Click);
this.contextMenu.MenuItems.Add(myMenuItem);
MenuItem myMenuItem2 = new MenuItem("Add UserDefinedFunction from File");
myMenuItem2.Click += new EventHandler(myMenuItemAddUDF_Click);
myMenuItem2.Click += new EventHandler(myMenuItemAddUDFFromFile_Click);
this.contextMenu.MenuItems.Add(myMenuItem2);
MenuItem myMenuItem1 = new MenuItem("Refresh UserDefinedFunction feed");
myMenuItem1.Click += new EventHandler((sender, e) => Refresh(true));
Expand Down

0 comments on commit ca22573

Please sign in to comment.