public void VideoFile_NewFileEntryWithData_Accept()
 {
     var testDateTime = DateTime.Now;
     var videoFile1 = new VideoFile(1, "path", null, testDateTime, testDateTime);
     Assert.True(videoFile1.Id == 1);
     Assert.True(videoFile1.Path == "path");
     Assert.True(videoFile1.Tags == null);
     Assert.True(videoFile1.DateAdded == testDateTime);
     Assert.True(videoFile1.DateEdited == testDateTime);
 }
        // add a file to the database, or ovewrites an existing file
        // returns a response
        public static Response AddFile(VideoFile file, int parentId, bool overwrite)
        {
            // locate the video file if it exists
            VideoFile databaseFile = GetFile(file.Id);
            string[] rows =
            {
                "path",
                "date_added",
                "date_edited"
            };
            string[] data =
            {
                file.Path,
                (file.DateAdded.Equals(DateTime.MinValue)) ? DateTime.Now.ToString() : file.DateAdded.ToString(),
                DateTime.Now.ToString(),
            };
            if (databaseFile == null)
            {
                // insert a new file if none exists
                bool success = Database.SimpleInsertQuery(_table, rows, data);
                if (success == false)
                {
                    return Response.FailedDatabase;
                }
                else
                {
                    // get the new file's ID
                    int id = Database.GetLastInsertID(_table);
                    Response tagSuccess = AssociateFileTags(file.Tags, id);
                    return (tagSuccess.Equals(Response.Success)) ? Response.Success : Response.FailedDatabase;

                }
            }
            else if (overwrite)
            {
                // overwrite the old file if overwrite true
                bool success = Database.SimpleUpdateQuery(_table, "id", file.Id, rows, data);
                if (success == false)
                {
                    return Response.FailedDatabase;
                }
                else
                {
                    // get the new file's ID
                    int id = Database.GetLastInsertID(_table);
                    Response tagSuccess = AssociateFileTags(file.Tags, id);
                    return (tagSuccess.Equals(Response.Success)) ? Response.Success : Response.FailedDatabase;

                }
            }
            else
            {
                return Response.FailedOverwrite;
            }
        }
 public void PopulateFields(VideoFile inputFile)
 {
     ClearFields();
     Manager.CurrentFile = inputFile;
     foreach (var t in inputFile.Tags)
     {
         if (t.Data == null) return;
         var type = Tags.GetTagType(t.TypeId);
         switch (type.Name)
         {
             case "display_name":
                 TitleTextBox.Text = t.Data;
                 break;
             case "file_type":
                 FiletypeValueLabel.Text = t.Data;
                 break;
             case "length":
                 try
                 {
                     var length = Convert.ToInt32(t.Data);
                     length /= 1000;
                     var minutes = length / 60;
                     var seconds = length % 60;
                     LengthValueLabel.Text = minutes + " min " + seconds + " sec";
                 }
                 catch (Exception e)
                 {
                     Console.WriteLine("movie length grab failed");
                 }
                 break;
             case "framerate":
                 BitrateValueLabel.Text = t.Data + " fps";
                 break;
             case "genre":
                 GenreTextBox.Text = t.Data;
                 break;
             case "url":
                 URLTextBox.Text = t.Data;
                 break;
             case "description":
                 DescriptionTextBox.Text = t.Data;
                 break;
             case "color":
                 ColorPickerPanel.BackColor = ColorTranslator.FromHtml("#" + t.Data);
                 break;
             case "thumbnail":
                 pictureBox1.ImageLocation = t.Data;
                 break;
             default:
                 Console.WriteLine("Unexpected Tag: " + t.Data);
                 break;
         }
     }
 }
 public void DisplayVideoFileMetadata(VideoFile file)
 {
     _parentManager.MetadataManager.DisplayVideoFileMetadata(file);
 }
 // helper method for code portability
 private static void DoAddTag(VideoFile file, TagEntry tag)
 {
     // remove an old version if it's there
     if (file.Tags.Contains(tag))
     {
         file.Tags.Remove(tag);
     }
     file.Tags.Add(tag);
 }
 public void DisplayVideoFileMetadata(VideoFile file)
 {
     _control.PopulateFields(file);
 }
 // delete a file from the database by ID
 public static bool DeleteFile(VideoFile file)
 {
     // no need to check if it exists; nothing will happen if not
     return Database.SimpleDeleteQuery(_table, "id", file.Id) && Database.SimpleDeleteQuery(_fileLocationsTable, "file_id", file.Id);
 }
        // associate a file_location relationship with the id of the file's parent folder
        public static Response AssociateFileLocation(VideoFile file, int parentId)
        {
            // locate the video file if it exists
            string[] rows =
            {
                "file_id",
                "folder_id"
            };
            string[] data =
            {
                file.Id.ToString(),
                parentId.ToString()
            };

            // insert a new file location
            bool success = Database.SimpleInsertQuery(_fileLocationsTable, rows, data);

            return (success) ? Response.Success : Response.FailedDatabase;
        }
 public void VideoFile_NewFileEntry_Accept()
 {
     var videoFile1 = new VideoFile("path", null);
     Assert.True(videoFile1.Path == "path");
     Assert.True(videoFile1.Tags == null);
 }
        // This adds all video files in a directory to the database and returns them in a list
        private List<VideoFile> MapContainedVideoFiles(DirectoryInfo dir, int parentId)
        {
            // Get the list to store successful additions
            List<VideoFile> files = new List<VideoFile>();

            // Get all supported file extensions
            string[] extensions = GetSupportedFileExtensions();

            // For each supported extension:
            for (int i = 0; i < extensions.Length; i++)
            {
                // Get all contained video files of the same type
                FileInfo[] videoFiles = dir.GetFiles("*." + extensions[i]);

                // For each video file with the current extension:
                for (int j = 0; j < videoFiles.Length; j++)
                {
                    // Create a database VideoFile object for the file
                    VideoFile file = new VideoFile(videoFiles[j].FullName, GetDefaultTags(videoFiles[j]));

                    // Try to add the file to the database
                    Response response = Files.AddFile(file, parentId, true);

                    // Report if file addition was unsuccessful
                    if (response == Response.Success)
                    {
                        file = GetAddedVideoFile(file.Path);
                        Files.AssociateFileLocation(file, parentId);
                        files.Add(file);
                    }
                    else {
                        Console.WriteLine("Files table addition failed:\n    " + videoFiles[j].FullName);
                    }
                }
            }
            Console.WriteLine(files.Count + " video files found");
            return files;
        }
 internal void CreateVideoIcon(VideoFile f)
 {
     string[] paths = f.Path.Split(Convert.ToChar("\\"));
     string name = paths[paths.Length - 1];
     var item = new ListViewItem
     {
         Name = name,
         Text = name,
         Tag = f,//f.Path,
         BackColor = Color.Azure,
         SubItems =
         { //TODO: get time working, it doesn't want to parse
             f.Tags.Find(t => (Tags.GetTagType(t.TypeId).Name == "file_type")).Data,
             f.Tags.Find(t => (Tags.GetTagType(t.TypeId).Name == "framerate")).Data
         }
     };
     fullList.Add(item);
     gridView.Items.Add(item);
 }