Пример #1
0
        public static void LoadLogs()
        {
            var     vidlog      = new VideoLog();
            dynamic productions = new Productions();
            dynamic episodes    = new Episodes();
            dynamic orderItems  = new OrderItems();
            dynamic channels    = new Channels();
            var     orders      = new Orders();

            var rand = new Random();

            Console.WriteLine("Deleting logs...");
            vidlog.Delete();

            foreach (var order in orders.All())
            {
                //pull the orderItems
                var items = orderItems.Find(OrderID: order.ID);

                //loop the items
                foreach (var item in items)
                {
                    var slug = item.SKU;
                    if (slug == "yearly")
                    {
                        Console.WriteLine("Loading Productions and Episodes for Annual...");

                        //create a download log for each production and episode
                        foreach (var p in productions.All())
                        {
                            var eps = episodes.Find(ProductionID: p.ID);
                            foreach (var e in eps)
                            {
                                var log = new {
                                    Slug          = item.SKU,
                                    EpisodeNumber = e.Number,
                                    Email         = order.Email,
                                    //the download file for the episode
                                    FileName = p.Slug + "_" + e.Number + ".zip",
                                    FileSize = e.HDFileSize,
                                    //1 day lag
                                    LogDate     = order.CreatedAt.AddDays(1),
                                    OrderItemID = item.ID
                                };
                                vidlog.Insert(log);
                            }
                        }
                    }
                    else if (slug == "monthly")
                    {
                        //create a stream log for each production and episode
                        Console.WriteLine("Loading Productions and Episodes for Monthly...");
                        foreach (var p in productions.All())
                        {
                            var eps = episodes.Find(ProductionID: p.ID);
                            foreach (var e in eps)
                            {
                                var log = new {
                                    Slug          = item.SKU,
                                    EpisodeNumber = e.Number,
                                    Email         = order.Email,
                                    //the download file for the episode
                                    FileName = p.Slug + "_" + e.Number + ".flv",
                                    FileSize = e.StreamFileSize,
                                    //1 day lag
                                    LogDate     = order.CreatedAt.AddDays(1),
                                    OrderItemID = item.ID
                                };
                                vidlog.Insert(log);
                            }
                        }
                    }
                    else
                    {
                        var p   = productions.First(Slug: item.SKU);
                        var eps = episodes.Find(ProductionID: p.ID);
                        Console.WriteLine("Loading log for {0}...", p.Slug);
                        foreach (var e in eps)
                        {
                            var log = new {
                                Slug          = item.SKU,
                                EpisodeNumber = e.Number,
                                Email         = order.Email,
                                //the download file for the episode
                                FileName = p.Slug + "_" + e.Number + ".zip",
                                FileSize = e.HDFileSize,
                                //1 day lag
                                LogDate     = order.CreatedAt.AddDays(1),
                                OrderItemID = item.ID
                            };
                            vidlog.Insert(log);
                        }
                    }
                }
            }
        }