/// <summary>
        ///     Makes a POST call to the Api service
        /// </summary>
        /// <param name="client">the LiveConnectClient object this method is attached to.</param>
        /// <param name="path">relative path to the resource collection to which the new object should be added.</param>
        /// <param name="body">properties of the new resource in name-value pairs.</param>
        public static Task <LiveOperationResult> Post(this LiveConnectClient client, string path, IDictionary <string, object> body)
        {
            client.PostCompleted += OnOperationCompleted;
            var tcs = new TaskCompletionSource <LiveOperationResult>();

            client.PostAsync(path, body, new OperationState <LiveOperationResult>(tcs, client, ApiMethod.Post));

            return(tcs.Task);
        }
Ejemplo n.º 2
0
            public async void LoadProfile(String SkyDriveFolderName = GenericName)
            {
                LiveOperationResult meResult;
                dynamic result;
                bool createLiveFolder = false;

               try
               {
                    LiveAuthClient authClient = new LiveAuthClient();
                    LiveLoginResult authResult = await authClient.LoginAsync(new List<String>() { "wl.skydrive_update" });

                    if (authResult.Status == LiveConnectSessionStatus.Connected)
                    {
                        try
                        {
                            meClient = new LiveConnectClient(authResult.Session);
                            meResult = await meClient.GetAsync("me/skydrive/" + SkyDriveFolderName);
                            result = meResult.Result;
                        }
                        catch (LiveConnectException)
                        {
                            createLiveFolder = true;
                        }
                        if (createLiveFolder == true)
                        {
                            try
                            {
                                var skyDriveFolderData = new Dictionary<String, Object>();
                                skyDriveFolderData.Add("name", SkyDriveFolderName);
                                LiveConnectClient LiveClient = new LiveConnectClient(meClient.Session);
                                LiveOperationResult operationResult = await LiveClient.PostAsync("me/skydrive/", skyDriveFolderData);
                                meResult = await meClient.GetAsync("me/skydrive/");

                            }
                            catch (LiveConnectException)
                            {
                            }
                        }

                    }

               }

               catch (LiveAuthException)
               {
               }

            }
Ejemplo n.º 3
0
 public static async Task<SkyDriveFolderInfo> CreateFolder(
     string folderName, string parentFolder = "/me/skydrive")
 {
     try
     {
         if (session == null)
         {
             await Login();
         }
         var folderData = new Dictionary<string, object> { { "name", folderName } };
         var liveClient = new LiveConnectClient(session);
         LiveOperationResult operationResult = await liveClient.PostAsync(parentFolder, folderData);
         dynamic result = operationResult.Result;
         return new SkyDriveFolderInfo(result);
     }
     catch (LiveConnectException exception)
     {
         throw new Exception("Unable to create folder " + folderName, exception);
     }
 }
        private static async Task<string> CreateFolderInSkydrive(LiveConnectClient client)
        {
            var folderData = new Dictionary<string, object>();

            folderData.Add("name", "EventBuddy");
            var createFolderResult = await client.PostAsync("me/skydrive", folderData);
            dynamic creationResult = createFolderResult.Result;

            return creationResult.id;
        }
Ejemplo n.º 5
0
 private async Task<String> CreateExportFolder(LiveConnectClient client)
 {
     LiveOperationResult opResult = await client.GetAsync("me/skydrive/files");
     var result = opResult.Result;
     IList<object> results = result["data"] as IList<object>;
     if (results == null)
     {
         throw new LiveConnectException();
     }
     object o = results
         .Where(d => (d as IDictionary<string, object>)["name"].Equals(EXPORT_FOLDER))
         .FirstOrDefault();
     string id = null;
     if (o == null)
     {
         var folderData = new Dictionary<string, object>();
         folderData.Add("name", EXPORT_FOLDER);
         opResult = await client.PostAsync("me/skydrive", folderData);
         dynamic postResult = opResult.Result;
         id = postResult.id;
     }
     else
     {
         IDictionary<string, object> folderProperties = o as IDictionary<string, object>;
         id = folderProperties["id"] as string;
     }
     return id;
 }
Ejemplo n.º 6
0
        private async void RunButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Validate parameters
                string path = pathTextBox.Text;
                string destination = destinationTextBox.Text;
                string requestBody = requestBodyTextBox.Text;
                var scope = (authScopesComboBox.SelectedValue as ComboBoxItem).Content as string;
                var method = (methodsComboBox.SelectedValue as ComboBoxItem).Content as string;

                // acquire auth permissions
                var authClient = new LiveAuthClient();
                var authResult = await authClient.LoginAsync(new string[] { scope });
                if (authResult.Session == null)
                {
                    throw new InvalidOperationException("You need to login and give permission to the app.");
                }

                var liveConnectClient = new LiveConnectClient(authResult.Session);
                LiveOperationResult operationResult = null;
                switch (method)
                {
                    case "GET":
                        operationResult = await liveConnectClient.GetAsync(path);
                        break;
                    case "POST":
                        operationResult = await liveConnectClient.PostAsync(path, requestBody);
                        break;
                    case "PUT":
                        operationResult = await liveConnectClient.PutAsync(path, requestBody);
                        break;
                    case "DELETE":
                        operationResult = await liveConnectClient.DeleteAsync(path);
                        break;
                    case "COPY":
                        operationResult = await liveConnectClient.CopyAsync(path, destination);
                        break;
                    case "MOVE":
                        operationResult = await liveConnectClient.MoveAsync(path, destination);
                        break;
                }

                if (operationResult != null)
                {
                    Log("Operation succeeded: \r\n" + operationResult.RawResult);
                }
            }
            catch (Exception ex)
            {
                Log("Got error: " + ex.Message);
            }
        }
Ejemplo n.º 7
0
        private async void btnCreateFolder_Click(object sender, RoutedEventArgs e)
        {
            var client = new LiveConnectClient(Session); // セッションを取得済みであることが前提

            // 作成するフォルダの名前
            var FOLDER_NAME = "{ここにフォルダーの名前を入れる}"; 

            // フォルダの名前やその他の情報を決める
            var data = new Dictionary<string, object>();
            data.Add("name", FOLDER_NAME);
            data.Add("description", "このフォルダは○○アプリで作成した写真を保存するフォルダです");

            // フォルダ作成の要求
            var result = await client.PostAsync("me/skydrive", data);

            // 成功すれば作成したフォルダの情報が取得できる
            var id = result.Result["id"] as string;
            var description = result.Result["description"] as string;

            System.Diagnostics.Debug.WriteLine("{0}:{1}", id, description);
        }
        private async Task<string> CreateDirectoryAsync(string folderName, string parentFolder, LiveConnectClient client)
        {
            string folderId = null;
            string queryFolder;
            LiveOperationResult opResult;
            //Retrieves all the directories.
            if (!parentFolder.Equals(CloudManagerUI.Properties.Resources.OneDriveRoot))
            {
                queryFolder = await GetSkyDriveFolderID(parentFolder, client) + "/files?filter=folders,albums";
                opResult = await client.GetAsync(queryFolder);
            }
            else
            {
                queryFolder = CloudManagerUI.Properties.Resources.OneDriveRoot + "/files?filter=folders,albums";
                opResult = await client.GetAsync(queryFolder);
            }


            dynamic result = opResult.Result;

            foreach (dynamic folder in result.data)
            {
                //Checks if current folder has the passed name.
                if (folder.name.ToLowerInvariant() == folderName.ToLowerInvariant())
                {
                    folderId = folder.id;
                    break;
                }
            }

            if (folderId == null)
            {
                //Directory hasn't been found, so creates it using the PostAsync method.
                var folderData = new Dictionary<string, object>();
                folderData.Add("name", folderName);

                if (parentFolder.Equals(CloudManagerUI.Properties.Resources.OneDriveRoot))
                {
                    var opResultPostRoot = await client.GetAsync(CloudManagerUI.Properties.Resources.OneDriveRoot);

                    var iEnum = opResultPostRoot.Result.Values.GetEnumerator();
                    iEnum.MoveNext();
                    var id = iEnum.Current.ToString();


                    opResult = await client.PostAsync(id, folderData);
                }
                else
                {
                    var opResultPost = await GetSkyDriveFolderID(parentFolder, client);

                    opResult = await client.PostAsync(opResultPost, folderData);
                }

                result = opResult.Result;

                //Retrieves the id of the created folder.
                folderId = result.id;
            }


            return folderId;
        }
Ejemplo n.º 9
0
 private static async Task<string> createSkyDriveFolder(string folderName, LiveConnectClient client)
 {
     var folderData = new Dictionary<string, object>();
     folderData.Add("name", folderName);
     LiveOperationResult operationResult =
         await client.PostAsync("me/skydrive", folderData);
     dynamic result = operationResult.Result;
     // res = string.Join(" ", "Created folder:", result.name, "ID:", result.id);
     return result.id;
 }
Ejemplo n.º 10
0
		private async Task<string> CreateFolder(LiveConnectClient client)
		{
			var folderData = new Dictionary<string, object>();
			folderData.Add("name", _passwordsFolder);
			LiveOperationResult operationResult = await client.PostAsync(_basePath, folderData);
			dynamic result = operationResult.Result;
			return result.id;
		}
Ejemplo n.º 11
0
        public async  void AddContacts()
        {
            //create new LiveSDK contact

            LiveConnectClient client = new LiveConnectClient(Connection.Session);

            LiveOperationResult liveOpResult = await client.GetAsync("me/contacts");

            IDictionary<string, object> myResult = liveOpResult.Result;
            List<object> data = null;
            IDictionary<string, object> contact;
            string contact_fname = String.Empty;
            string contact_lname = String.Empty;
            Dictionary<string, string> contactList = new Dictionary<string, string>();

            if (myResult.ContainsKey("data"))
            {
                 data = (List<object>)myResult["data"];
                 for (int i = 0; i < data.Count; i++)
                 {
                     contact = (IDictionary<string, object>)data[i];
                     if (contact.ContainsKey("first_name"))
                     {
                         //contactList.ElementAt(i).Key =
                        
                         contact_fname = (string) contact["first_name"];
                     }
                     if(contact.ContainsKey("last_name"))
                     {
                         contact_lname = (string)contact["last_name"];
                     }

                     if(contact_fname!=String.Empty && contact_lname!=String.Empty)
                     {
                         contactList.Add(contact_fname, contact_lname);

                         contact_fname = String.Empty;
                         contact_lname = String.Empty;
                     }

                 }
            }

            List<User> usersList = new List<User>();
            User = Connection.MobileService.GetTable<User>();

            usersList = await User.Where(p => p.UserId != Connection.MobileService.CurrentUser.UserId ).ToListAsync();
            for (int i = 0; i < usersList.Count; i++)
            {
                if (!(contactList.ContainsKey(usersList.ElementAt(i).FName) && contactList.ContainsValue(usersList.ElementAt(i).LName)))
                {
                    contact = new Dictionary<string, object>();
                    contact.Add("first_name", usersList.ElementAt(i).FName);
                    contact.Add("last_name", usersList.ElementAt(i).LName);
                    // contact.Add("emails.preferred", usersList.ElementAt(i).Email);
                    contact.Add("emails", new Dictionary<string, object> {
                {"account",usersList.ElementAt(i).Email },
                {"preferred",usersList.ElementAt(i).Email },
                { "personal", usersList.ElementAt(i).Email},
                {"business", usersList.ElementAt(i).Email},
                {"other", usersList.ElementAt(i).Email} 
                });

                    await client.PostAsync("me/contacts", contact);

                }
            }
            // get List of users loop
            //  var contact = new Dictionary<string, object>();
            // contact.Add("first_name", "Michael");
            // contact.Add("last_name", "Crump");
            //contact.Add( "emails.preferred", "*****@*****.**");
            //client.PostAsync("me/contacts", contact);
            MainPage.Success2 = true;

        }
Ejemplo n.º 12
0
 /// <summary>
 /// Create_new_album crates a new album
 /// </summary>
 private async void Create_new_album()
 {
     Dictionary<string, object> folderData = new Dictionary<string, object>();
     folderData.Add("name", NewAlbumName);
     folderData.Add("type", "album");
     LiveConnectClient client = new LiveConnectClient(App.Session);
     LiveOperationResult result = await client.PostAsync("me/skydrive", folderData);
     CreateFolder_Completed(result);
 }
        //Get root SkyDrive directory entries list Completed
        void client_GetRootDirectoryEnrtiesList(object sender, LiveOperationCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                folder_id = this.GetFolderId(e);
                //If there is NO 'OI Shopping List' folder -> create new
                if (folder_id == string.Empty)
                {
                    Dictionary<string, object> folderData = new Dictionary<string, object>();
                    folderData.Add("name", "OI Shopping List");
                    LiveConnectClient createFolderClient = new LiveConnectClient(LiveSession);
                    createFolderClient.PostCompleted += new EventHandler<LiveOperationCompletedEventArgs>(createFolderClient_PostCompleted);
                    createFolderClient.PostAsync("/me/skydrive", folderData);
                }
                else
                {
                    //Set SystemTray.ProgressIndicator.Visibility = false
                    //and enabling file upload button after receiving 'OI Shopping List' folder ID
                    SystemTray.ProgressIndicator.IsVisible = false;
                    UploadButton.IsEnabled = true;
                    //Start downloading SkyDrive data list
                    this.DownloadSkyDriveDataList();
                }

            }
            else
            {
                MessageBox.Show("There is an error occur during loading data from SkyDrive: " + e.Error.Message, "Warning", MessageBoxButton.OK);
                SystemTray.ProgressIndicator.IsVisible = false;
                NavigationService.GoBack();
            }
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Create_new_album crates a new album
 /// </summary>
 private void Create_new_album()
 {
     Dictionary<string, object> folderData = new Dictionary<string, object>();
     folderData.Add("name", NewAlbumName);
     folderData.Add("type", "album");
     LiveConnectClient client = new LiveConnectClient(App.Session);
     client.PostCompleted +=
         new EventHandler<LiveOperationCompletedEventArgs>(CreateFolder_Completed);
     client.PostAsync("me/skydrive", folderData);
 }