コード例 #1
0
        private static void UploadToDisc(CdnItem item)
        {
            try
            {
                var filePath = GetFullFileName(item.Bundle.Path, item.Response.ContentType).TrimStart('/');

                using (var mutex = new Mutex(true, filePath))
                {
                    mutex.WaitOne();

                    if (!storage.IsFile("", filePath))
                    {
                        using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(item.Response.Content)))
                        {
                            item.Bundle.CdnPath = storage.Save(filePath, stream).ToString();
                        }
                    }
                    else
                    {
                        item.Bundle.CdnPath = GetUri(item.Bundle.Path, item.Response.ContentType);
                    }

                    mutex.ReleaseMutex();
                }
            }
            catch (Exception err)
            {
                log.Error(err);
            }
        }
コード例 #2
0
        private static void UploadToDisc(CdnItem item)
        {
            var filePath = GetFullFileName(item.Bundle.Path, item.Response.ContentType).TrimStart('/');
            var fullFilePath = GetFullPhysicalPath(filePath);

            try
            {
                using (var mutex = new Mutex(true, filePath))
                {
                    var wait = mutex.WaitOne(60000);

                    try
                    {
                        CreateDir(fullFilePath);

                        if (!File.Exists(fullFilePath))
                        {
                            var gzip = ClientSettings.GZipEnabled;

                            using (var fs = File.OpenWrite(fullFilePath))
                            using (var tw = new StreamWriter(fs))
                            {
                                tw.WriteLine(item.Response.Content);
                            }

                            item.Bundle.CdnPath = GetUri(filePath);

                            if (gzip)
                            {
                                using (var fs = File.OpenWrite(fullFilePath + ".gz"))
                                using (var zip = new GZipStream(fs, CompressionMode.Compress, true))
                                using (var tw = new StreamWriter(zip))
                                {
                                    tw.WriteLine(item.Response.Content);
                                }
                            }

                        }
                        else
                        {
                            item.Bundle.CdnPath = GetUri(item.Bundle.Path, item.Response.ContentType);
                        }
                    }
                    finally
                    {
                        if (wait)
                        {
                            mutex.ReleaseMutex();
                        }
                    }
                }
            }
            catch (Exception err)
            {
                log.Error(err);
            }
        }
コード例 #3
0
        private static String GetStorePath(CdnItem item)
        {
            var filePath = GetFullFileName(item.Bundle.Path, item.Response.ContentType);

            var cacheKey = item.Bundle.Path;

            if (cacheUri.ContainsKey(cacheKey))
            {
                return(cacheUri[cacheKey]);
            }

            cacheUri.TryAdd(cacheKey, filePath);

            File.WriteAllText(pathToCacheFile, JsonConvert.SerializeObject(cacheUri));

            return(filePath);
        }
コード例 #4
0
        private static String GetStorePath(CdnItem item)
        {
            var filePath = GetFullFileName(item.Bundle.Path, item.Response.ContentType);

            var cacheKey = item.Bundle.Path;

            if (cacheUri.ContainsKey(cacheKey))
                return cacheUri[cacheKey];

            cacheUri.TryAdd(cacheKey, filePath);

            File.WriteAllText(pathToCacheFile, JsonConvert.SerializeObject(cacheUri));

            return filePath;
        }