Esempio n. 1
0
        // TODO wrap the rest of these in timeout tasks
        public static async Task <List <Azure_FileHash> > Get_FileHashWithTaskAsync(FileHashType hashType, string hashDetails)
        {
            Task <List <Azure_FileHash> > task = new Task <List <Azure_FileHash> >(() =>
            {
                try
                {
                    string uri = $@"http://{azureHostBaseAddress}/api/FileHash/{(int) hashType}?p={hashDetails}";
                    string msg = $"Getting File Hash From Cache: {hashType} - {hashDetails}";

                    DateTime start = DateTime.Now;
                    ShokoService.LogToSystem(Constants.DBLogType.APIAzureHTTP, msg);

                    string json = GetDataJson(uri);

                    TimeSpan ts = DateTime.Now - start;
                    msg         = $"Got File Hash From Cache: {hashDetails} - {ts.TotalMilliseconds}";
                    ShokoService.LogToSystem(Constants.DBLogType.APIAzureHTTP, msg);

                    return(JSONHelper.Deserialize <List <Azure_FileHash> >(json));
                }
                catch
                {
                    return(new List <Azure_FileHash>());
                }
            });

            if (await Task.WhenAny(task, Task.Delay(30000)) == task)
            {
                return(await task);
            }
            return(await Task.FromResult(new List <Azure_FileHash>()));
        }
Esempio n. 2
0
        // TODO wrap the rest of these in timeout tasks
        public static async Task <List <Azure_FileHash> > Get_FileHashWithTaskAsync(FileHashType hashType, string hashDetails)
        {
            Task <List <Azure_FileHash> > task = new Task <List <Azure_FileHash> >(() =>
            {
                string uri = string.Format(@"http://{0}/api/FileHash/{1}?p={2}", azureHostBaseAddress, (int)hashType,
                                           hashDetails);
                string msg = string.Format("Getting File Hash From Cache: {0} - {1}", hashType, hashDetails);

                DateTime start = DateTime.Now;
                ShokoService.LogToSystem(Constants.DBLogType.APIAzureHTTP, msg);

                string json = GetDataJson(uri);

                TimeSpan ts = DateTime.Now - start;
                msg         = string.Format("Got File Hash From Cache: {0} - {1}", hashDetails, ts.TotalMilliseconds);
                ShokoService.LogToSystem(Constants.DBLogType.APIAzureHTTP, msg);

                return(JsonConvert.DeserializeObject <List <Azure_FileHash> >(json) ??
                       new List <Azure_FileHash>());
            });

            if (await Task.WhenAny(task, Task.Delay(30000)) == task)
            {
                return(await task);
            }
            return(await Task.FromResult(new List <Azure_FileHash>()));
        }
Esempio n. 3
0
        public Hash Get(FileHashType htype)
        {
            if (htype != FileHashType.Mrc)
            {
                throw new ArgumentException($"Mail.ru Cloud supportd only {FileHashType.Mrc} hash type");
            }

            return(Hash);
        }
Esempio n. 4
0
        public Hash Get(FileHashType htype)
        {
            if (htype != FileHashType.YadSha256 && htype != FileHashType.YadMd5)
            {
                throw new ArgumentException($"Mail.ru Cloud supportd only {FileHashType.YadSha256} and {FileHashType.YadMd5} hash type");
            }

            return(Hash);
        }
Esempio n. 5
0
        /// <summary>
        /// Get File hash details from the web cache
        /// When the hash type is a CRC, the hash details value should be a combination of the CRC and the FileSize with an under score in between
        /// e.g. CRC32 = 8b4b52f4, File Size = 380580947.......hashDetails = 8b4b52f4_380580947
        /// </summary>
        /// <param name="hashType"></param>
        /// <param name="hashDetails"></param>
        /// <returns></returns>
        public static List <FileHash> Get_FileHash(FileHashType hashType, string hashDetails)
        {
            string uri = string.Format(@"http://{0}/api/FileHash/{1}?p={2}", azureHostBaseAddress, (int)hashType,
                                       hashDetails);
            string msg = string.Format("Getting File Hash From Cache: {0} - {1}", hashType, hashDetails);

            DateTime start = DateTime.Now;

            JMMService.LogToSystem(Constants.DBLogType.APIAzureHTTP, msg);

            string json = GetDataJson(uri);

            TimeSpan ts = DateTime.Now - start;

            msg = string.Format("Got File Hash From Cache: {0} - {1}", hashDetails, ts.TotalMilliseconds);
            JMMService.LogToSystem(Constants.DBLogType.APIAzureHTTP, msg);

            List <FileHash> hashes = JSONHelper.Deserialize <List <FileHash> >(json);

            return(hashes);
        }
Esempio n. 6
0
 /// <summary>
 /// Get File hash details from the web cache
 /// When the hash type is a CRC, the hash details value should be a combination of the CRC and the FileSize with an under score in between
 /// e.g. CRC32 = 8b4b52f4, File Size = 380580947.......hashDetails = 8b4b52f4_380580947
 /// </summary>
 /// <param name="hashType"></param>
 /// <param name="hashDetails"></param>
 /// <returns></returns>
 public static List <Azure_FileHash> Get_FileHash(FileHashType hashType, string hashDetails)
 {
     return(Get_FileHashWithTaskAsync(hashType, hashDetails).Result);
 }
Esempio n. 7
0
        /// <summary>
        /// Get File hash details from the web cache
        /// When the hash type is a CRC, the hash details value should be a combination of the CRC and the FileSize with an under score in between
        /// e.g. CRC32 = 8b4b52f4, File Size = 380580947.......hashDetails = 8b4b52f4_380580947
        /// </summary>
        /// <param name="hashType"></param>
        /// <param name="hashDetails"></param>
        /// <returns></returns>
        public static List<FileHash> Get_FileHash(FileHashType hashType, string hashDetails)
        {
            string uri = string.Format(@"http://{0}/api/FileHash/{1}?p={2}", azureHostBaseAddress, (int)hashType,
                hashDetails);
            string msg = string.Format("Getting File Hash From Cache: {0} - {1}", hashType, hashDetails);

            DateTime start = DateTime.Now;
            JMMService.LogToSystem(Constants.DBLogType.APIAzureHTTP, msg);

            string json = GetDataJson(uri);

            TimeSpan ts = DateTime.Now - start;
            msg = string.Format("Got File Hash From Cache: {0} - {1}", hashDetails, ts.TotalMilliseconds);
            JMMService.LogToSystem(Constants.DBLogType.APIAzureHTTP, msg);

            List<FileHash> hashes = JsonConvert.DeserializeObject<List<FileHash>>(json) ?? new List<FileHash>();
            return hashes;
        }
Esempio n. 8
0
 /// <summary>
 /// 使用文件和哈希值类型初始化 <see cref="FileHash"/> 的实例。
 /// </summary>
 /// <param name="filePath">要计算哈希值的文件路径。</param>
 /// <param name="hashType">要计算哈希值的类型。</param>
 /// <exception cref="Exception">打开文件时出现错误。</exception>
 public FileHash(string filePath, FileHashType hashType)
 {
     this.FilePath    = filePath;
     this.HashType    = hashType;
     this.HashingFile = File.OpenRead(filePath);
 }