Ejemplo n.º 1
0
        /// <summary>
        /// stream the file to save locally
        /// </summary>
        public void Save(Stream stm)
        {
            WebClientHelper wc = new WebClientHelper(stm);

            wc.RequestCompleted += new EventHandler <RequestCompletedEventArgs>(DownLoadCompleted);
            wc.SendRequest(new Uri(this.SourceBig), null, null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Makes a REST call to facebook server.
        /// </summary>
        /// <param name="parameterList">Parameters for REST call</param>
        /// <param name="useSession">indicator if session should be used or not</param>
        /// <param name="ar"></param>
        /// <remarks>Function made virtual for unittesting</remarks>
        public void SendRequestAsync(IDictionary <string, string> parameterList, bool useSession, AsyncResult ar)
        {
            if (useSession && Session.SessionKey != null)
            {
                parameterList.Add("session_key", Session.SessionKey);
            }

            if (Permissions != null && Permissions.IsPermissionsModeActive)
            {
                parameterList.Add("call_as_apikey", Permissions.CallAsApiKey);
            }

            string postData = CreatePostData(parameterList);

            if (Batch != null && Batch.IsActive)
            {
                Batch.CallListAsync.Add(new BatchRecord(ar, postData));
            }
            else
            {
                WebClientHelper client = new WebClientHelper(ar);
                UriBuilder      uriBd  = new UriBuilder(Constants.FacebookRESTUrl);

                client.Method            = "POST";
                client.RequestCompleted += OnRequestCompleted;
                client.SendRequest(uriBd.Uri, postData);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Starts download of requested image
        /// </summary>
        /// <param name="requestedSize">Size of the image</param>
        /// <param name="callback">Callback that will be called when download completes</param>
        public void GetImageAsync(FacebookImageDimensions requestedSize, GetImageSourceAsyncCallback callback)
        {
#if !SILVERLIGHT
            dispatcher = Dispatcher.CurrentDispatcher;
#else
            dispatcher = System.Windows.Deployment.Current.Dispatcher;
#endif
            Uri = _normal;
            switch (requestedSize)
            {
            case FacebookImageDimensions.Big: Uri = _big; break;

            case FacebookImageDimensions.Small: Uri = _small; break;

            case FacebookImageDimensions.Square: Uri = _square; break;
            }

            if (Uri == null)
            {
                callback(this, new GetImageSourceCompletedEventArgs(new InvalidOperationException(), false, this));
                return;
            }


            WebClientHelper wc = new WebClientHelper(callback);
            wc.RequestCompleted += new EventHandler <RequestCompletedEventArgs>(wc_RequestCompleted);
            wc.SendRequest(Uri, null, null);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Makes a REST call to upload a video to the facebook server.
        /// </summary>
        /// <param name="parameters">Parameters for REST call</param>
        /// <param name="data">the bytes of the file</param>
        /// <param name="contentType"></param>
        /// <param name="uploadUrl">The url to upload the file to</param>
        /// <param name="ar"></param>
        /// <remarks>Function made virtual for unittesting</remarks>
        public void UploadFile(IDictionary <string, string> parameters, byte[] data, string contentType, Uri uploadUrl, AsyncResult ar)
        {
            string boundary = DateTime.Now.Ticks.ToString("x", CultureInfo.InvariantCulture);

            byte[]          postData = CreatePostData(parameters, data, contentType, boundary);
            WebClientHelper client   = new WebClientHelper(ar)
            {
                Method = "POST"
            };

            client.RequestCompleted += OnRequestCompleted;
            client.SendRequest(uploadUrl, postData, String.Concat("multipart/form-data; boundary=", boundary));
        }
        /// <summary>
        /// Starts download of requested image
        /// </summary>
        /// <param name="requestedSize">Size of the image</param>
        /// <param name="callback">Callback that will be called when download completes</param>
        public void GetImageAsync(FacebookImageDimensions requestedSize, GetImageSourceAsyncCallback callback)
        {
            #if !SILVERLIGHT
            dispatcher = Dispatcher.CurrentDispatcher;
            #else
            dispatcher = System.Windows.Deployment.Current.Dispatcher;
            #endif
            Uri = _normal;
            switch (requestedSize)
            {
                case FacebookImageDimensions.Big: Uri = _big; break;
                case FacebookImageDimensions.Small: Uri = _small; break;
                case FacebookImageDimensions.Square: Uri = _square; break;
            }

            if (Uri == null)
            {
                callback(this, new GetImageSourceCompletedEventArgs(new InvalidOperationException(), false, this));
                return;
            }

            WebClientHelper wc = new WebClientHelper(callback);
            wc.RequestCompleted += new EventHandler<RequestCompletedEventArgs>(wc_RequestCompleted);
            wc.SendRequest(Uri, null, null);
        }