private ApiOperation GetApiOperation(string path, ApiMethod method, string body)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentException("path");
            }

            if (IsAbsolutePath(path))
            {
                throw new ArgumentException(
                          String.Format(CultureInfo.CurrentUICulture, ResourceHelper.GetString("RelativeUrlRequired"), "path"),
                          "path");
            }

            Uri apiUri = this.GetResourceUri(path, method);

            if (this.Session == null)
            {
                throw new LiveConnectException(ApiOperation.ApiClientErrorCode, ResourceHelper.GetString("UserNotLoggedIn"));
            }

            ApiOperation operation = null;

            switch (method)
            {
            case ApiMethod.Get:
            case ApiMethod.Delete:
                operation = new ApiOperation(this, apiUri, method, null, null);
                break;

            case ApiMethod.Post:
            case ApiMethod.Put:
            case ApiMethod.Copy:
            case ApiMethod.Move:
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }

                if (string.IsNullOrWhiteSpace(body))
                {
                    throw new ArgumentException("body");
                }

                operation = new ApiWriteOperation(this, apiUri, method, body, null);
                break;

            default:
                Debug.Assert(false, "method not suppported.");
                break;
            }

            return(operation);
        }
Example #2
0
        public void TestExecute()
        {
            WebRequestFactory.Current = new TestWebRequestFactory();
            LiveConnectClient connectClient = new LiveConnectClient(new LiveConnectSession());
            Uri       requestUri            = new Uri("http://foo.com");
            ApiMethod apiMethod             = ApiMethod.Copy;
            string    body = string.Empty;
            SynchronizationContextWrapper syncContextWrapper = SynchronizationContextWrapper.Current;

            var apiOperation =
                new ApiWriteOperation(connectClient, requestUri, apiMethod, body, syncContextWrapper);
        }