示例#1
0
        /// <summary>
        /// Saves the file to local temp.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="data">The data.</param>
        /// <param name="size">The size.</param>
        /// <returns>Dump file thread</returns>
        private Thread SaveFileToLocalTemp(DumpedMediaFile file, byte[] data, int size)
        {
            FileDumper fileDumper = new FileDumper()
            {
                File = file, Data = data, Size = size
            };
            Thread dumpThread = new Thread(new ThreadStart(fileDumper.Dump));

            dumpThread.Start();
            return(dumpThread);
        }
示例#2
0
        /// <summary>
        /// Loads the media.
        /// </summary>
        /// <param name="groupId">The group id.</param>
        /// <param name="from">Image From.</param>
        /// <param name="count">The count.</param>
        /// <returns>
        /// List of DumpedMediaFiles
        /// </returns>
        /// <exception cref="System.Exception">Unable to find TempWebFolder setting.</exception>
        public IEnumerable <DumpedMediaFile> LoadMedia(int groupId, int from, int count)
        {
            if (string.IsNullOrEmpty(this.tempFolder))
            {
                throw new Exception("Unable to find TempWebFolder setting.");
            }

            var dumpedList = new List <DumpedMediaFile>();

            IStoreDataSource  ds = new StoreDataProvider(this.connectionString);
            List <MediaDraft> list;

            if (groupId == 0)
            {
                list = ds.LoadAllMedia().ToList();
            }
            else
            {
                list = ds.LoadPartMedia(groupId, from, count).ToList();
            }

            var threadList = new List <Thread>();

            foreach (var item in list)
            {
                var cachedItem = this.ReadItemFromCache(item.Id);
                if (cachedItem != null)
                {
                    this.logger.Info(string.Format("Reading image from cache. Image Id = {0}", item.Id));
                    dumpedList.Add(cachedItem);
                }
                else
                {
                    this.logger.Info(string.Format("Dumping image and putting to cache. Image Id = {0}", item.Id));

                    if (item.ServerFilePath != null)
                    {
                        string guid          = Guid.NewGuid().ToString();
                        string localFileName = Path.GetFileName(item.ServerFilePath).Replace(" ", string.Empty);

                        string currentFolder = Path.Combine(this.tempFolder, guid);
                        Directory.CreateDirectory(currentFolder);

                        var di = new DumpedMediaFile();
                        di.Thumbnail.LocalFilePath = Path.Combine(
                            currentFolder, string.Format("{0}_{1}_{2}", item.Id, this.thumbnailLiteral, localFileName));
                        di.Preview.LocalFilePath = Path.Combine(
                            currentFolder, string.Format("{0}_{1}_{2}", item.Id, this.previewLiteral, localFileName));
                        di.Fullsize.LocalFilePath = Path.Combine(
                            currentFolder, string.Format("{0}_{1}_{2}", item.Id, this.fullsizeLiteral, localFileName));

                        di.Id      = item.Id;
                        di.GroupId = item.GroupId;

                        threadList.Add(this.SaveFileToLocalTemp(di, item.Media, item.FileSize));

                        di.FileDateTime = item.FileDateTime;

                        di.Thumbnail.GlobalFileUrl = string.Format(
                            @"/temp/{0}/{1}",
                            guid,
                            string.Format("{0}_{1}_{2}", item.Id, this.thumbnailLiteral, localFileName));
                        di.Preview.GlobalFileUrl = string.Format(
                            @"temp/{0}/{1}",
                            guid,
                            string.Format("{0}_{1}_{2}", item.Id, this.previewLiteral, localFileName));
                        di.Fullsize.GlobalFileUrl = string.Format(
                            @"temp/{0}/{1}",
                            guid,
                            string.Format("{0}_{1}_{2}", item.Id, this.fullsizeLiteral, localFileName));

                        this.AddItemToCache(di);

                        dumpedList.Add(di);
                    }
                }
            }

            foreach (var thread in threadList)
            {
                thread.Join();
            }

            return(dumpedList);
        }
示例#3
0
 /// <summary>
 /// Adds the item to cache.
 /// </summary>
 /// <param name="item">The item.</param>
 private void AddItemToCache(DumpedMediaFile item)
 {
     this.cachedData.Add(item);
 }
示例#4
0
 /// <summary>
 /// Adds the specified item.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <returns>True / False</returns>
 public bool Add(DumpedMediaFile item)
 {
     dump.AddOrUpdate(item.Id, item, (i, file) => item);
     return(dump.ContainsKey(item.Id));
 }