Beispiel #1
0
 public void InitializeDownloads(Order order)
 {
     Transaction.Initiate(transaction =>
     {
         var productIds = order.OrderItems.Where(x => x.IsDownloadable).Select(x => x.ProductId).ToList();
         if (!productIds.Any())
         {
             return;
         }
         var allDownloads = GetWithoutBytes(x => productIds.Contains(x.ProductId)).ToList();
         foreach (var orderItem in order.OrderItems.Where(x => x.IsDownloadable))
         {
             var downloads = allDownloads.Where(x => x.ProductId == orderItem.ProductId).ToList();
             foreach (var download in downloads)
             {
                 if (download.ProductVariantId > 0 && orderItem.ProductVariantId != download.ProductVariantId)
                 {
                     continue; //skip this download
                 }
                 var orderItemDownload = new ItemDownload()
                 {
                     DownloadId = download.Id,
                     Active     = download.DownloadActivationType != DownloadActivationType.Manual &&
                                  order.PaymentStatus == PaymentStatus.Complete,
                     UserId = order.UserId
                 };
                 _orderItemDownloadService.Insert(orderItemDownload, transaction);
             }
         }
     });
 }
Beispiel #2
0
        public IActionResult DownloadFile(string guid)
        {
            var download = _downloadService.FirstOrDefault(x => x.Guid == guid);

            if (download == null || !download.Published)
            {
                return(NotFound());
            }
            if (download.RequireLogin && CurrentUser.IsVisitor())
            {
                return(NotFound());
            }

            if (download.RequirePurchase)
            {
                //find the orders of the user
                var orders = _orderService.GetOrders(out _, userId: CurrentUser.Id, storeId: CurrentStore.Id,
                                                     productIds: new List <int>()
                {
                    download.ProductId
                },
                                                     paymentStatus: new List <PaymentStatus>()
                {
                    PaymentStatus.Complete
                }).ToList();
                if (!orders.Any())
                {
                    return(NotFound());
                }
            }

            if (!CurrentUser.IsVisitor())
            {
                //get the download object
                var orderItemDownload = _orderItemDownloadService.FirstOrDefault(x => x.DownloadId == download.Id && x.UserId == CurrentUser.Id);
                if (orderItemDownload != null)
                {
                    if (!orderItemDownload.Active)
                    {
                        return(NotFound());
                    }
                }
                else
                {
                    orderItemDownload = new ItemDownload()
                    {
                        Active        = true,
                        DownloadCount = 0,
                        DownloadId    = download.Id,
                        UserId        = CurrentUser.Id
                    };
                }
                //update the stat
                orderItemDownload.DownloadCount++;
                _orderItemDownloadService.InsertOrUpdate(orderItemDownload);
            }

            return(File(download.FileBytes, download.FileType, $"{download.Title}{download.FileExtension}"));
        }
Beispiel #3
0
        public OrderDownloadModel Create(Download download, ItemDownload itemDownload)
        {
            var model = new OrderDownloadModel()
            {
                Title          = download.Title,
                Description    = download.Description,
                Active         = itemDownload?.Active ?? download.DownloadActivationType != DownloadActivationType.Manual,
                DownloadCount  = itemDownload?.DownloadCount ?? 0,
                DownloadUrl    = ApplicationEngine.RouteUrl(AdminRouteNames.AdminDownloadFile, new { id = download.Id }),
                ItemDownloadId = itemDownload?.Id ?? 0,
                DownloadId     = download.Id
            };

            return(model);
        }
Beispiel #4
0
        public void InitializeDownloads(OrderItem orderItem, PaymentStatus paymentStatus)
        {
            var downloads = GetWithoutBytes(x => x.ProductId == orderItem.ProductId).ToList();

            Transaction.Initiate(transaction =>
            {
                foreach (var download in downloads)
                {
                    if (download.ProductVariantId > 0 && orderItem.ProductVariantId != download.ProductVariantId)
                    {
                        continue; //skip this download
                    }
                    var orderItemDownload = new ItemDownload()
                    {
                        DownloadId = download.Id,
                        Active     = download.DownloadActivationType != DownloadActivationType.Manual && paymentStatus == PaymentStatus.Complete
                    };
                    _orderItemDownloadService.Insert(orderItemDownload, transaction);
                }
            });
        }
        public bool EncaminharParaDownload(ItemDownload objItemDownload)
        {
            string pathBlackhole = Properties.Settings.Default.pref_PastaBlackhole;

            var rgxHash   = new Regex("magnet:.*?btih:(.*?)(?:&|$)", RegexOptions.IgnoreCase);
            var rgxTitulo = new Regex("magnet:.*?[?:&]dn=(.*?)(?:&|$)", RegexOptions.IgnoreCase);

            const string extensaoTorrent = ".torrent";

            string filename      = null;
            string filenameRegex = null;
            string filenameData  = null;
            string sLinkCache;

            foreach (KeyValuePair <RssItem, QualidadeDownload> item in objItemDownload.LstObjRssItem.OrderBy(x => x.Value.nPrioridade))
            {
                string link = item.Key.Link.ToString();

                try
                {
                    Match matchHash   = rgxHash.Match(link);
                    Match matchTitulo = rgxTitulo.Match(link);

                    if (!matchHash.Success)
                    {
                        continue;
                    }

                    string hash = matchHash.Groups[1].Value.ToUpper();

                    sLinkCache = $"http://torcache.net/torrent/{hash}{extensaoTorrent}";

                    if (matchTitulo.Success)
                    {
                        filenameRegex = HttpUtility.UrlDecode(matchTitulo.Groups[1].Value);
                    }

                    using (var wc = new Helper.MyWebClient())
                    {
                        byte[] data = Helper.Retry(() => wc.DownloadData(sLinkCache), TimeSpan.FromSeconds(3), 5);

                        if (string.IsNullOrWhiteSpace(filenameRegex) && !string.IsNullOrEmpty(wc.ResponseHeaders["Content-Disposition"]))
                        {
                            // Pega o nome do arquivo do header Content-Disposition
                            filenameData = wc.ResponseHeaders["Content-Disposition"].Substring(wc.ResponseHeaders["Content-Disposition"].IndexOf("filename=", StringComparison.Ordinal) + 10)
                                           .Replace("\"", "");
                        }

                        filename = filenameRegex ?? filenameData ?? $"{oSerie.sDsTitulo} {nNrTemporada}x{nNrEpisodio}{extensaoTorrent}";

                        if (!filename.EndsWith(extensaoTorrent))
                        {
                            filename += extensaoTorrent;
                        }

                        string torrentPath = Path.Combine(pathBlackhole, filename);

                        if (File.Exists(torrentPath))
                        {
                            File.Delete(torrentPath);
                        }

                        File.WriteAllBytes(torrentPath, data);

                        return(true);
                    }
                }
                catch (Exception e)
                {
                    new MediaManagerException(e).TratarException(string.Format(Mensagens.Ocorreu_um_erro_ao_realizar_o_download_do_episódio_1_do_RSS_0_, link, filename));
                }
            }

            return(false);
        }