コード例 #1
0
ファイル: PicasaService.cs プロジェクト: dej-27/j
        public void CreateAlbum(PicasaAlbum album, StringResultCallback callback)
        {
            album.User = ACCOUNT;

            XmlSerializer serializer = new XmlSerializer(typeof(PicasaAlbum));
            MemoryStream stream = new MemoryStream();
            serializer.Serialize(stream, album);
            stream.Position = 0;
            StreamReader reader = new StreamReader(stream);
            var albumXMLbody = reader.ReadToEnd();

            WebClient client = new WebClient();
            string url = String.Format(ALBUM_CREATE_FEED, ACCOUNT);

            SetAuthHeaders(client);
            client.Headers[HttpRequestHeader.ContentType] = "application/atom+xml";

            client.UploadStringCompleted += (o, args) =>
            {

                if (args.Error == null)
                {
                    callback("200");
                }
                else
                {
                    callback("500");
                }
            };

            client.UploadStringAsync(new Uri(url), albumXMLbody);
        }
コード例 #2
0
ファイル: PicasaService.cs プロジェクト: dej-27/j
        //public void SetAuthToRequest(HttpWebRequest request)
        //{
        //    if (AuthToken != null)
        //    {
        //        //Authorization: GoogleLogin auth=yourAuthValue
        //        request.Headers["Authorization"] = String.Format("GoogleLogin auth={0}", AuthToken);
        //    }
        //}
        private void GetRequest(string uri, string method, object state, StringResultCallback callback)
        {
            //WebClient client = new WebClient();

            //client.DownloadStringCompleted += (o, args) => {
            //    callback(args.Result);
            //};

            //client.DownloadStringAsync(new Uri(uri

            //var httpRequest = WebRequest.CreateHttp(uri);
            //httpRequest.Method = method;

            //SetAuthToRequest(httpRequest);

            //httpRequest.BeginGetResponse((result) =>
            //{
            //    var request = (HttpWebRequest)result.AsyncState;
            //    var response = request.EndGetResponse(result);

            //    var stream = response.GetResponseStream();
            //    var reader = new StreamReader(stream);

            //    if (callback != null)
            //    {
            //        callback(reader.ReadToEnd());
            //    }
            //    stream.Close();
            //    reader.Close();
            //}, httpRequest);
        }
コード例 #3
0
ファイル: PicasaService.cs プロジェクト: dej-27/j
        //private static ManualResetEvent allDone = new ManualResetEvent(false);
        public void Login(string account, string password, StringResultCallback callback)
        {
            //AuthToken = "DQAAAMcAAABtg8ivmzbztgEs3KAWU3yhlUKQsQKkNEA3eOuqdcd6wt-RUtDmV5wy1Ch-JifgCXT1TAQzTQh4YF6EMfFdSVhEnzBcbQsdBwUmae0es6DI_gp-gAx9vUOule_99xaorbGLFeq3Pwc4fSCo3enGiVzcjnUXCubtsCi5MmE5-cYuvb1f5_vSaM_5EU8CW3mw-6O3xReV1VF1wL4PAY4OYOApFbcQOGyZwI5FSB0zWsnwSijX18N6Jwyf_21NR8RCgFULMR_w7GGMpoEmzBO3LRC0";
            //callback(AuthToken);

            WebClient client = new WebClient();

            client.UploadStringCompleted += (o, args) =>
            {
                //TODO: handle errors

                var loginResult = args.Result;
                string token = loginResult.Split(new string[] { "Auth=" }, StringSplitOptions.None).Last();
                AUTH_TOKEN = token;
                ACCOUNT = account;

                callback(AUTH_TOKEN);
            };

            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("accountType={0}&", "HOSTED_OR_GOOGLE");
            sb.AppendFormat("service={0}&", "lh2");
            sb.AppendFormat("Email={0}&", account);
            sb.AppendFormat("Passwd={0}&", password);
            sb.AppendFormat("source={0}", "Gulp-CalGulp-1.05"); //TODO: change to my app

            client.Headers["Content-type"] = "application/x-www-form-urlencoded";
            client.UploadStringAsync(new Uri(LOGIN_URL), "POST", sb.ToString());

            //var httpRequest = WebRequest.CreateHttp(LOGIN_URL);
            //httpRequest.Method = "POST";
            //httpRequest.ContentType = "application/x-www-form-urlencoded";

            //httpRequest.BeginGetRequestStream((result) =>
            //{

            //    StringBuilder sb = new StringBuilder();

            //    sb.AppendFormat("accountType={0}&", "HOSTED_OR_GOOGLE");
            //    sb.AppendFormat("service={0}&", "lh2");
            //    sb.AppendFormat("Email={0}&", account);
            //    sb.AppendFormat("Passwd={0}&", password);
            //    sb.AppendFormat("source={0}", "Gulp-CalGulp-1.05");

            //    var request = (HttpWebRequest)result.AsyncState;
            //    Stream postStream = request.EndGetRequestStream(result);
            //    byte[] byteArray = Encoding.UTF8.GetBytes(sb.ToString());

            //    postStream.Write(byteArray, 0, sb.Length);
            //    postStream.Close();

            //    request.BeginGetResponse((authResult) =>
            //    {
            //        var request2 = (HttpWebRequest)authResult.AsyncState;
            //        var response2 = request.EndGetResponse(authResult);

            //        var stream = response2.GetResponseStream();
            //        var reader = new StreamReader(stream);

            //        if (callback != null)
            //        {
            //            string authResponse = reader.ReadToEnd();
            //            string token = authResponse.Split(new string[] { "Auth=" }, StringSplitOptions.None).Last();
            //            AuthToken = token;
            //            callback(token);
            //        }
            //        stream.Close();
            //        reader.Close();
            //    }, request);

            //}, httpRequest);

            ////httpRequest.BeginGetResponse((result) =>
            ////{
            ////    var request = (HttpWebRequest)result.AsyncState;
            ////    var response = request.EndGetResponse(result);

            ////    var stream = response.GetResponseStream();
            ////    var reader = new StreamReader(stream);

            ////    if (callback != null)
            ////    {
            ////        callback(reader.ReadToEnd());
            ////    }
            ////    stream.Close();
            ////    reader.Close();
            ////}, httpRequest);
        }
コード例 #4
0
ファイル: PicasaService.cs プロジェクト: dej-27/j
        public void DeletePicasaAlbum(string albumId, StringResultCallback callback)
        {
            WebClient client = new WebClient();
            string url = String.Format(ALBUM_DELETE_FEED, ACCOUNT, albumId);

            SetAuthHeaders(client);

            client.Headers[HttpRequestHeader.IfNoneMatch] = Guid.NewGuid().ToString();
            client.Headers["X-HTTP-Method-Override"] = "DELETE";

            //TODO: add error handling
            client.UploadStringCompleted += (o, args) =>
            {
                if (args.Error == null)
                {
                    callback("200");
                }
                else
                {
                    callback("500");
                }
            };
            client.UploadStringAsync(new Uri(url), "POST");

            /////////////////////////////Works/////////////////////////////////////
            //HttpWebRequest httpWebRequest = HttpWebRequest.CreateHttp(url);
            //httpWebRequest.Headers[HttpRequestHeader.IfNoneMatch] = HTTP_ETAG;
            //httpWebRequest.Headers[HttpRequestHeader.Authorization] = String.Format("GoogleLogin auth={0}", AUTH_TOKEN);

            //httpWebRequest.Method = "DELETE";

            //httpWebRequest.BeginGetResponse((aResult) =>
            //{
            //    HttpWebRequest req = (HttpWebRequest)aResult.AsyncState;
            //    HttpWebResponse res = (HttpWebResponse)req.EndGetResponse(aResult);
            //}, httpWebRequest);
        }
コード例 #5
0
 private static extern int list_all_hardlinks(string path, StringResultCallback f);
コード例 #6
0
 private static extern int get_reparse_point_target(string path, out uint unrecognizedReparseTag, StringResultCallback callback);