Esempio n. 1
0
    public static MediaListModel  CreateModel(this Medium medium)
    {
        var model = new MediaListModel();
        model.MediaID = medium.MediaID;
        model.Name = medium.Name;
        model.Location = medium.Location;

        try
        {
        var location = medium.Location;

        var extension = Path.GetExtension(location);
        if (!String.IsNullOrEmpty(extension) && !String.IsNullOrEmpty(location) && !String.IsNullOrEmpty(extension))
        {
            var path = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) +
                       HttpRuntime.AppDomainAppVirtualPath;
            // var path = VirtualPathUtility.ToAbsolute("~/");

            if (path.Contains("eAd.Website"))
            {
                path = "http://localhost/eAd.Website/";
            }

            model.ThumbnailUrl = medium.ThumbnailUrl;

            if (Displayableurls.Contains(Path.GetExtension(location)))
            {
                model.DisplayLocation = !(String.IsNullOrEmpty(location))
                                            ? "/Uploads/Temp/Media" + "/" + "Thumb" +
                                              Path.GetFileNameWithoutExtension(location) + extension
                                            : "/Content/Images/no_image.gif";
            }
            else if (!String.IsNullOrEmpty(medium.ThumbnailUrl) &&
                     Displayableurls.Contains(Path.GetExtension(medium.ThumbnailUrl)))
            {
                model.DisplayLocation = medium.ThumbnailUrl;
            }
            else
            {
                model.DisplayLocation = "/Uploads/Temp/Media" + "/" + "Thumb" +
                                        Path.GetFileNameWithoutExtension(location) + ".jpg";
            }

            model.DisplayLocation = path + model.DisplayLocation.Replace("\\", "/");
            model.ThumbnailUrl = path + model.ThumbnailUrl.Replace("\\", "/");

        }
        }
        catch (Exception)
        {
        }
        return model;
    }
Esempio n. 2
0
    public List<MediaListModel> GetMyMedia(long stationID)
    {
        var container = new eAdEntities();

        var source = new List<MediaListModel>();

        var station = (from s in container.Stations
                       where s.StationID == stationID
                       select s).FirstOrDefault<Station>();

        if (station != null)
        {
            EntityCollection<Grouping> groupings = station.Groupings;

            foreach (Grouping grouping in groupings)
            {
                foreach (Theme theme in grouping.Themes)
                {
                    using (IEnumerator<Medium> enumerator3 = theme.Media.GetEnumerator())
                    {
                        Func<MediaListModel, bool> predicate = null;

                        Medium media;

                        while (enumerator3.MoveNext())
                        {
                            media = enumerator3.Current;

                            if (predicate == null)
                            {
                                predicate = l => l.MediaID == media.MediaID;
                            }

                            if (source.Where(predicate).Count<MediaListModel>() <= 0)
                            {
                                var item = new MediaListModel
                                {
                                    MediaID = media.MediaID,
                                    DisplayLocation = media.Location,
                                    Duration = media.Duration.Value
                                };

                                source.Add(item);
                            }
                        }
                    }
                }
            }
        }

        return source;
    }
Esempio n. 3
0
    public static bool DownloadMedium(MediaListModel item, List<MediaListModel> playlist, IPlayer player)
    {

        AsyncCompletedEventHandler handler = null;

        string path = Constants.AppPath + item.DisplayLocation;

        string location = item.DisplayLocation;

        bool flag = false;

        if (System.IO.File.Exists(path) && (new FileInfo(path).Length > 0L))
        {

            flag = true;

        }

        if ((from i in playlist

                where i.DisplayLocation == path

                select i).Count<MediaListModel>() <= 0)
        {

            MediaListModel model = item;

            model.DisplayLocation = path;

            if (flag)
            {

                model.Downloaded = true;

            }

            if (playlist.Contains(item))
            {

                playlist.Remove(item);

            }

            playlist.Add(model);

            if (flag)
            {

                return true;

            }

        }

        FileUtilities.FolderCreate(Path.GetDirectoryName(path));

        WebClient client = new WebClient();

        try
        {

            client.DownloadProgressChanged += delegate(object sender, DownloadProgressChangedEventArgs e)
            {

                Switcher.PageSwitcher.Dispatcher.BeginInvoke(
                    DispatcherPriority.Normal, new ThreadStart(() =>
                {

                    if (
                        MainWindow
                        .
                        Instance
                        .
                        Update_Progress
                        .
                        Visibility ==
                        Visibility
                        .
                        Hidden)
                    {

                        MainWindow
                        .
                        Instance
                        .
                        Update_Progress
                        .
                        Visibility
                            =
                            Visibility
                            .
                            Visible;

                    }

                    double
                    num
                        =
                        double
                        .
                        Parse
                        (e
                         .
                         BytesReceived
                         .
                         ToString
                         ());

                    double
                    num2
                        =
                        double
                        .
                        Parse
                        (e
                         .
                         TotalBytesToReceive
                         .
                         ToString
                         ());

                    if (
                        !downloads
                        .
                        Contains
                        (e))
                    {

                        downloads
                        .
                        Add
                        (e);

                        TotalBytes
                        +=
                            num2;

                    }

                    TotalBytesIn
                    +=
                        num;

                    double
                    num3
                        =
                        (TotalBytesIn/
                         TotalBytes)*
                        100.0;

                    MainWindow
                    .
                    Instance
                    .
                    Update_Progress
                    .
                    Value
                        =
                        (num3 +
                         MainWindow
                         .
                         Instance
                         .
                         Update_Progress
                         .
                         Value)/
                        2.0;



                }));

            };

            if (handler == null)
            {

                handler = delegate(object sender, AsyncCompletedEventArgs args)
                {

                    lock (DownLoadsLock)
                    {

                        runningDownloads--;

                    }

                    HideProgressBar();

                    item = (from i in playlist

                            where i.DisplayLocation == path

                            select i).FirstOrDefault<MediaListModel>();

                    if (item != null)
                    {

                        item.Downloaded = true;

                        if (!System.IO.File.Exists(path) || (new FileInfo(path).Length <= 0L))
                        {

                            playlist.Remove(item);

                            Console.WriteLine("Downloaded Corrupted File");

                        }

                    }

                    if (args.Error == null)
                    {

                        lock (DownLoadsLock)
                        {

                            Thread.Sleep(200);

                        }

                        if (runningDownloads == 0)
                        {

                            player.UpdatePlayList();

                        }

                    }

                };

            }

            client.DownloadFileCompleted += handler;

            if (!flag)
            {

                lock (DownLoadsLock)
                {

                    runningDownloads++;

                }

                Uri address = new Uri(Constants.ServerUrl + location.Replace(@"\", "/"));

                client.DownloadFileAsync(address, path);

            }

        }

        catch (TimeoutException exception)
        {

            Console.WriteLine("Got {0}", exception.GetType());

        }

        catch (CommunicationException exception2)
        {

            Console.WriteLine("Got {0}", exception2.GetType());

        }

        finally
        {

            if (client != null)
            {

                client.Dispose();

            }

        }

        return false;

    }