예제 #1
0
        /// <summary>
        /// Gets versions of every file in a bucket starting with the start file name
        /// </summary>
        /// <param name="bucketId"> id of bucket to search</param>
        /// <param name="startFileName"> starting file name for files</param>
        /// <returns> B2FileList -- list of files in bucket </returns>
        public B2FileList b2_list_file_versions(string bucketId, string startFileName)
        {
            if (!checkStringParamsNotEmpty(new string[] { bucketId }) || !authorized)
            {
                return(null);
            }
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(apiUrl + "/b2api/v1/b2_list_file_versions");
            string         body       = "{\"bucketId\":\"" + bucketId + "\","
                                        + "\"startFileName\":\"" + startFileName + "\"}";
            var data = Encoding.UTF8.GetBytes(body);

            webRequest.Method = "POST";
            webRequest.Headers.Add("Authorization", authorizationToken);
            webRequest.ContentType   = "application/json; charset=utf-8";
            webRequest.ContentLength = data.Length;
            using (var stream = webRequest.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
                stream.Close();
            }

            try
            {
                HttpWebResponse response       = (HttpWebResponse)webRequest.GetResponse();
                var             responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
                B2FileList      fileList       = (B2FileList)Newtonsoft.Json.JsonConvert.DeserializeObject(responseString, typeof(B2FileList));
                return(fileList);
            }
            catch (Exception ex)
            {
                return(null);
            };
        }
예제 #2
0
파일: B2Lib.cs 프로젝트: ijat/b2clone
        private async Task GetB2List()
        {
            Log.Information("Getting updates from B2");

            string nextFileName = "";

            do
            {
                #pragma warning disable 1998
                B2FileList nList = await Client.Files.GetList(nextFileName, 10000);

                nextFileName = nList.NextFileName;
                await nList.Files.ForEachAsync(Environment.ProcessorCount, async b2File =>
                {
                    B2Map[b2File.FileName] = b2File;
                });

                #pragma warning restore 1998
            } while (nextFileName != null);

            Log.Information("Update received | Total objects = {0}", B2Map.Count);
        }