예제 #1
0
        /// <summary>
        /// Récupérer un objet en fonction de son id
        /// </summary>
        /// <returns>The by.</returns>
        /// <param name="id">Identifier.</param>
        public static Model.Media FindBy(long id)
        {
            string sql = "SELECT * FROM link WHERE id = @id";

            Model.Media m = null;

            try {
                SQLiteConnection c     = Dao.Open();
                SQLiteCommand    query = new SQLiteCommand(sql, c);
                query.Parameters.AddWithValue("@id", id);
                SQLiteDataReader reader = query.ExecuteReader();

                while (reader.Read())
                {
                    m          = new Model.Media();
                    m.id       = reader.GetInt64(0);
                    m.url      = reader.GetString(1);
                    m.sender   = reader.GetString(2);
                    m.genre    = reader.GetString(3);
                    m.author   = reader.GetString(4);
                    m.title    = reader.GetString(5);
                    m.isViewed = reader.GetInt16(6);
                }

                reader.Close();
                query.Dispose();
                c.Close();

                Console.WriteLine("FindBy");
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
                throw new Exception(ex.Message);
            }
            return(m);
        }
예제 #2
0
        /// <summary>
        /// Récupérer tous les objets
        /// </summary>
        /// <returns>The all.</returns>
        public static List <Model.Media> FindAll()
        {
            List <Model.Media> medias = new List <Model.Media>();
            string             sql    = "SELECT * FROM link";

            try {
                SQLiteConnection c      = Dao.Open();
                SQLiteCommand    query  = new SQLiteCommand(sql, c);
                SQLiteDataReader reader = query.ExecuteReader();

                while (reader.Read())
                {
                    Model.Media m = new Model.Media();
                    m.id       = reader.GetInt32(0);
                    m.url      = reader.GetString(1);
                    m.sender   = reader.GetString(2);
                    m.genre    = reader.GetString(3);
                    m.author   = reader.GetString(4);
                    m.title    = reader.GetString(5);
                    m.isViewed = reader.GetInt16(6);
                    medias.Add(m);
                }

                reader.Close();
                query.Dispose();
                c.Close();

                Console.WriteLine("FindAll");
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
                throw new Exception(ex.Message);
            }
            return(medias);
        }
예제 #3
0
        public void PlayMedia(Model.Media media)
        {
            if (media == null || (media.Stream == false && System.IO.File.Exists(media.Path) == false))
            {
                return;
            }

            switch (media.Type)
            {
            case Model.Media.MediaType.MUSIC:
                PlayMusic(media as Model.Music);
                break;

            case Model.Media.MediaType.PICTURE:
                PlayPicture(media as Model.Picture);
                break;

            case Model.Media.MediaType.VIDEO:
                PlayVideo(media as Model.Video);
                break;
            }

            _IsPlayingPlaylist = false;
            CurrentMediaName   = media.Name;
            _CurrentMediaType  = media.Type;
        }
예제 #4
0
        /// <summary>
        /// Mettre à jour un objet en fonction de son id
        /// </summary>
        /// <param name="m">M.</param>
        public static Model.Media Update(Model.Media m)
        {
            string sql = "UPDATE link SET url = @url, sender = @sender, genre = @genre, author = @author, title = @title, isViewed = @isViewed WHERE id = @id";

            Model.Media media = null;

            try {
                SQLiteConnection c     = Dao.Open();
                SQLiteCommand    query = new SQLiteCommand(sql, c);
                query.Parameters.AddWithValue("@id", m.id);
                query.Parameters.AddWithValue("@url", m.url);
                query.Parameters.AddWithValue("@sender", m.sender);
                query.Parameters.AddWithValue("@genre", m.genre);
                query.Parameters.AddWithValue("@author", m.author);
                query.Parameters.AddWithValue("@title", m.title);
                query.Parameters.AddWithValue("@isViewed", m.isViewed);
                query.Prepare();
                query.ExecuteNonQuery();

                query.Dispose();
                c.Close();

                media = m;
                Console.WriteLine("Updated");
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
                throw new Exception(ex.Message);
            }
            return(media);
        }
        public bool HasMedia(String playlistName, Model.Media media)
        {
            try
            {
                if (string.IsNullOrEmpty(playlistName) || media == null || string.IsNullOrEmpty(media.Path))
                {
                    return(false);
                }
                if (xelement.Elements("Playlist").Any(row => (row != null && row.Attribute("name") != null &&

                                                              row.Element("Element") != null &&
                                                              row.Element("Element").Element("Path") != null &&
                                                              row.Element("Element").Element("Element") != null &&
                                                              row.Element("Element").Element("Type") != null &&

                                                              row.Attribute("name").Value == playlistName &&
                                                              row.Element("Element").Element("Path").Value == media.Path &&
                                                              Boolean.Parse(row.Element("Element").Element("Stream").Value) == media.Stream &&

                                                              (Model.Media.MediaType)Enum.Parse(typeof(Model.Media.MediaType), row.Element("Element").Element("Type").Value) == media.Type
                                                              )))
                {
                    return(true);
                }
                return(false);
            }
            catch (Exception e)
            {
                Console.WriteLine("FAILED HasMedia catch: '{0}'", e);
                return(false);
            }
        }
        public System.Collections.ObjectModel.ObservableCollection <Model.Playlist> GetPlaylists()
        {
            System.Collections.ObjectModel.ObservableCollection <Model.Playlist> playlistsCollection = new System.Collections.ObjectModel.ObservableCollection <Model.Playlist>();

            try
            {
                IEnumerable <System.Xml.Linq.XElement> playlists = xelement.Elements("Playlist");
                foreach (var playlist in playlists)
                {
                    System.Collections.ObjectModel.ObservableCollection <Model.Media> medias = new System.Collections.ObjectModel.ObservableCollection <Model.Media>();
                    IEnumerable <System.Xml.Linq.XElement> elements = playlist.Elements("Element");
                    foreach (var elem in elements)
                    {
                        if (elem != null &&
                            elem.Element("Path") != null &&
                            elem.Element("Stream") != null &&
                            elem.Element("Type") != null)
                        {
                            Model.Media media = null;

                            switch ((Model.Media.MediaType)Enum.Parse(typeof(Model.Media.MediaType), elem.Element("Type").Value))
                            {
                            case Model.Media.MediaType.MUSIC:
                                media = new Model.Music(elem.Element("Path").Value, Boolean.Parse(elem.Element("Stream").Value));
                                break;

                            case Model.Media.MediaType.PICTURE:
                                media = new Model.Picture(elem.Element("Path").Value, Boolean.Parse(elem.Element("Stream").Value));
                                break;

                            case Model.Media.MediaType.VIDEO:
                                media = new Model.Video(elem.Element("Path").Value, Boolean.Parse(elem.Element("Stream").Value));
                                break;
                            }

                            if (media != null)
                            {
                                medias.Add(media);
                            }
                        }
                    }
                    playlistsCollection.Add(new Model.Playlist()
                    {
                        Name   = playlist.Attribute("name").Value,
                        Medias = medias
                    });
                }
            }
            catch { Console.WriteLine("FAILED GetPlaylists catch"); }

            return(playlistsCollection);
        }
 public void DownPlaylistItem(Model.Media media)
 {
     if (CurrentPlaylist != null && media != null)
     {
         int index = CurrentPlaylist.Medias.IndexOf(media);
         if (index < CurrentPlaylist.Medias.Count - 1 && index != -1)
         {
             var swap = CurrentPlaylist.Medias[index + 1];
             CurrentPlaylist.Medias.RemoveAt(index + 1);
             CurrentPlaylist.Medias.Insert(index, swap);
         }
     }
 }
        public void DeletePlaylistItem(Model.Media media)
        {
            if (CurrentPlaylist != null && media != null)
            {
                XML.PlaylistXML playlistXML = new XML.PlaylistXML();

                playlistXML.Load("playlists.xml");
                if (playlistXML.HasMedia(CurrentPlaylist.Name, media))
                {
                    playlistXML.RemovePlaylistItem(CurrentPlaylist.Name, media);
                    playlistXML.WriteInFile("playlists.xml");
                    CurrentPlaylist.Medias.Remove(media);
                }
            }
        }
 public void AddPlaylistItem(String playlistName, Model.Media media)
 {
     try
     {
         foreach (var playlist in xelement.Elements("Playlist"))
         {
             if (playlist.Attribute("name") != null && playlist.Attribute("name").Value == playlistName)
             {
                 System.Xml.Linq.XElement newTag =
                     new System.Xml.Linq.XElement("Element",
                                                  new System.Xml.Linq.XElement("Path", media.Path),
                                                  new System.Xml.Linq.XElement("Stream", media.Stream),
                                                  new System.Xml.Linq.XElement("Type", media.Type)
                                                  );
                 playlist.Add(newTag);
             }
         }
     }
     catch { Console.WriteLine("FAILED AddPlaylistItem catch"); }
 }
 public void RemovePlaylistItem(String playlistName, Model.Media media)
 {
     try
     {
         foreach (var playlist in xelement.Elements("Playlist"))
         {
             foreach (var elem in playlist.Elements("Element"))
             {
                 if (elem.Element("Path") != null &&
                     elem.Element("Stream") != null &&
                     elem.Element("Type") != null &&
                     elem.Element("Path").Value == media.Path &&
                     Boolean.Parse(elem.Element("Stream").Value) == media.Stream &&
                     (Model.Media.MediaType)Enum.Parse(typeof(Model.Media.MediaType), elem.Element("Type").Value) == media.Type)
                 {
                     elem.Remove();
                 }
             }
         }
     }
     catch { Console.WriteLine("FAILED RemovePlaylistItem catch"); }
 }
예제 #11
0
        /// <summary>
        /// Insérer un objet
        /// </summary>
        /// <param name="m">M.</param>
        public static Model.Media Insert(Model.Media m)
        {
            string sql = "INSERT INTO link (url, sender, genre, author, title, isViewed) VALUES (@url, @sender, @genre, @author, @title, @isViewed)";

            Model.Media media = null;

            try {
                SQLiteConnection c     = Dao.Open();
                SQLiteCommand    query = new SQLiteCommand(sql, c);
                query.Parameters.AddWithValue("@url", m.url);
                query.Parameters.AddWithValue("@sender", m.sender);
                query.Parameters.AddWithValue("@genre", m.genre);
                query.Parameters.AddWithValue("@author", m.author);
                query.Parameters.AddWithValue("@title", m.title);
                query.Parameters.AddWithValue("@isViewed", m.isViewed);
                query.Prepare();
                query.ExecuteNonQuery();

                long id = c.LastInsertRowId;
                if (id > 0)
                {
                    m.id = id;
                }
                else
                {
                    m = null;
                }

                query.Dispose();
                c.Close();

                media = m;
                Console.WriteLine("Inserted");
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
                throw new Exception(ex.Message);
            }
            return(media);
        }
예제 #12
0
        /// <summary>
        /// Supprimer un objet
        /// </summary>
        /// <param name="m">M.</param>
        public static Model.Media Delete(Model.Media m)
        {
            string sql = "DELETE FROM link WHERE id = @id";

            Model.Media media = null;

            try {
                SQLiteConnection c     = Dao.Open();
                SQLiteCommand    query = new SQLiteCommand(sql, c);
                query.Parameters.AddWithValue("@id", m.id);
                query.Prepare();
                query.ExecuteNonQuery();

                query.Dispose();
                c.Close();

                media = m;
                Console.WriteLine("Deleted");
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
                throw new Exception(ex.Message);
            }
            return(media);
        }
예제 #13
0
        // Taken from http://www.w3.org/TR/css3-mediaqueries/ section 4
        private static bool IsSetFeature(Model.Media type, string featureName)
        {
            switch (featureName.ToLowerInvariant())
            {
            case " grid":
            case "device-height":
            case "device-width":
            case "height":
            case "width": return(type.In(Visual) || type.In(Tacticle));

            case "resolution":
            case "device-aspect-ratio":
            case "aspect-ratio":
            case "orientation": return(type.In(Bitmap));

            case "monochrome":
            case "color-index":
            case "color": return(type.In(Visual));

            case "scan": return(type == Model.Media.tv);

            default: throw new InvalidOperationException("Unexpected feature name [" + featureName + "]");
            }
        }
예제 #14
0
            public async Task <UpdateMediaResult> Handle(UpdateMediaCommand cmd, CancellationToken cancellationToken)
            {
                var result = await _mediator.Send(new FindByIdQuery(cmd.MediaId));

                var mapper = new Mapper(_mapperConfiguration);

                Model.Media media = mapper.Map <Model.Media>(result);

                if (media.Handle(cmd))
                {
                    var dao = mapper.Map <ContentDAO>(media);

                    try
                    {
                        var filter = Builders <ContentDAO> .Filter.Eq(x => x.Id, dao.Id);

                        var options = new FindOneAndReplaceOptions <ContentDAO> {
                            ReturnDocument = ReturnDocument.After
                        };

                        var update = await _db.Content.FindOneAndReplaceAsync(filter, dao, options);

                        return(new UpdateMediaResult
                        {
                            MediaId = dao.Id.ToString(),
                            ProfileId = dao.InstructorId
                        });
                    }
                    catch (Exception)
                    {
                        return(null);
                    }
                }

                return(null);
            }
예제 #15
0
        private Model.Media ProcessFile(
            string file)
        {
            Model.Media retMedia = new Model.Media();

            string originalFileName = GetFileName(file);
            string fileName = originalFileName;

            MediaType type;
            IMediaTypeDao dao = DaoFactory.GetDao<IMediaTypeDao>();
            IMediaDao mdao = DaoFactory.GetDao<IMediaDao>();

            IList<MediaType> types = dao.Get(new MediaType {
                FileTypes = new List<string> { GetFileType(fileName) }
            });

            if (types.Count > 0) {
                type = types[0];
            } else {
                type = dao.Get("misc_docs");
            }

            retMedia.Type = type;

            string webPath = this.GetFilePathSuffix(string.Empty);

            string filePath = Path.Combine(WebInfo.BasePath, webPath);

            Directory.CreateDirectory(filePath);

            retMedia.File = new FileRecord {
                Name = fileName,
                Path = webPath
            };

            retMedia.Name = originalFileName;
            retMedia.Comments = request["media_comments"];
            retMedia.CreatedDate = DateTime.Now;
            retMedia.UpdatedDate = DateTime.Now;

            mdao.Save(retMedia);

            return retMedia;
        }
        private Model.Media ProcessFile(
            MvcPostedFile file)
        {
            Model.Media retMedia = new Model.Media();

            string originalFileName = this.GetFileName(file.Name);
            string fileName = originalFileName;
            if (this.IncludeTimeStamp == "yes") {
                fileName = DateTime.Now.ToString("yyyyMMddHHmmssffff-") + originalFileName;
            }

            MediaType type;
            IMediaTypeDao dao = DaoFactory.GetDao<IMediaTypeDao>();

            type = dao.Get(this.GetFileType(fileName));

            if (type == null) {
                type = dao.Get("misc_docs");
            }

            retMedia.Type = type;

            string webPath = this.GetFilePathSuffix(this.SavePathSuffix);

            string filePath = Path.Combine(WebInfo.BasePath, webPath);

            Directory.CreateDirectory(filePath);

            UploadMediaFilter filter = new UploadMediaFilter();
            filter.Fill(request);

            if ((filter.ResizeImage.HasValue)
                    && (filter.ResizeImage.Value == true)
                    && (filter.ResizeHeight.HasValue)
                    && (filter.ResizeWidth.HasValue)) {

                Bitmap image = this.GetResizedImage(
                        file.InputStream,
                        filter.ResizeWidth.Value,
                        filter.ResizeHeight.Value);

                fileName = Path.GetFileNameWithoutExtension(fileName) + ".jpeg";
                image.Save(Path.Combine(filePath, fileName), ImageFormat.Jpeg);

            }
            else {
                file.SaveAs(Path.Combine(filePath, fileName));
            }

            retMedia.File = new FileRecord {
                Name = fileName,
                Path = webPath
            };
            retMedia.Name = originalFileName;
            retMedia.Comments = request["media_comments"];

            retMedia.CreatedDate = DateTime.Now;
            retMedia.UpdatedDate = DateTime.Now;

            return retMedia;
        }
예제 #17
0
            public async Task <string> AddInstructorAudioMedia(string instructorId, string firstName, string lastName, string title, int durationInMinutes, DateTime recordingDate, DateTime uploadDate, byte[] streamedFileContent)
            {
                // TODO: calculate this some way automatically... someday
                string fileExtension = "m4a";

                // Generate Container Name - InstructorSpecific
                string containerName = $"{firstName[0].ToString().ToLower()}{lastName.ToLower()}-{instructorId}";

                // TODO: calculate this some way automatically... someday
                string contentType = "audio/mp4";
                // TODO: calculate this some way automatically... someday
                FileType fileType = FileType.audio;

                string authorName      = $"{firstName} {lastName}";
                string authorShortName = $"{firstName[0]}{lastName}";
                string description     = $"{authorShortName} - {title}";

                // TODO: Get this from FFMPEG... someday
                long duration = (durationInMinutes * 60000);

                // Generate new filename
                string fileName = $"{firstName[0].ToString().ToLower()}{lastName.ToLower()}-{Guid.NewGuid()}";

                // TODO: Move this to a BlobCreatedResponse object
                BlobCreatedEvent blobCreatedResult;

                try
                {
                    // Update file properties in storage
                    Dictionary <string, string> fileProperties = new Dictionary <string, string>();
                    fileProperties.Add("ContentType", contentType);

                    // update file metadata in storage
                    Dictionary <string, string> metadata = new Dictionary <string, string>();
                    metadata.Add("author", authorShortName);
                    metadata.Add("tite", title);
                    metadata.Add("description", description);
                    metadata.Add("duration", duration.ToString());
                    metadata.Add("recordingDate", recordingDate.ToString());
                    metadata.Add("uploadDate", uploadDate.ToString());

                    var fileNameWExt = $"{fileName}.{fileExtension}";

                    blobCreatedResult = await _cloudStorageService.CreateBlob(containerName, fileNameWExt, streamedFileContent, "audio", fileProperties, metadata);
                }
                catch (StorageException e)
                {
                    throw e;
                }

                Model.Media media = Model.Media.Create(string.Empty, instructorId, authorName, fileName, fileType, fileExtension, recordingDate, uploadDate, ContentDetails.Create(title, description, duration, blobCreatedResult.Size, 0, new List <string>()), StateDetails.Create(StatusType.STAGED, DateTime.MinValue, DateTime.UtcNow, DateTime.MaxValue), Manifest.Create(new Dictionary <string, string>()));

                // upload to MongoDB
                if (!blobCreatedResult.Error)
                {
                    var mapper = new Mapper(_mapperConfiguration);

                    var dao = mapper.Map <ContentDAO>(media);

                    try
                    {
                        await _db.Content.InsertOneAsync(dao);
                    }
                    catch (Exception)
                    {
                        return(string.Empty);
                    }

                    return(dao.Id.ToString());
                }
                else
                {
                    // metadata wasn't stored, remove blob
                    await _cloudStorageService.DeleteBlob(containerName, fileName, "audio");

                    throw new AddMediaException($"An issue occurred during media upload: rolling back storage change");
                }
            }
예제 #18
0
 public MonitorShowMediaErrorEvent(Model.Media media)
 {
     _media = media;
 }
        private Model.Media ProcessFile(
            string file)
        {
            Model.Media retMedia = new Model.Media();

            ////string originalFileName = this.GetFileName(file);
            //string fileName = originalFileName;

            //MediaType type;
            //IMediaTypeDao dao = DaoFactory.GetDao<IMediaTypeDao>();

            //IList<MediaType> types = dao.Get(new MediaType {
            //    FileTypes = new List<string> { this.GetFileType(fileName) }
            //});

            //if (types.Count > 0) {
            //    type = types[0];
            //}
            //else {
            //    type = dao.Get("misc_docs");
            //}

            //retMedia.Type = type;

            //string webPath = this.GetFilePathSuffix(string.Empty);

            //string filePath = Path.Combine(WebInfo.BasePath, webPath);

            //Directory.CreateDirectory(filePath);

            //retMedia.File = new FileRecord {
            //    Name = fileName,
            //    Path = webPath
            //};

            //retMedia.Name = originalFileName;

            //retMedia.CreatedDate = DateTime.Now;
            //retMedia.UpdatedDate = DateTime.Now;

            return retMedia;
        }