Exemplo n.º 1
0
 private void FillListView()
 {
     ViewFileslistView.Items.Clear();
     try {
         filesInLink = myLink.GetFiles();
         if (filesInLink == null || filesInLink.Count == 0)
         {
             return;
         }
         foreach (var file in filesInLink)
         {
             string[] fileDetails = new string[6];
             fileDetails[0] = file.Filename;
             fileDetails[1] = file.FileExtension;
             fileDetails[2] = file.FilePath;
             fileDetails[3] = file.FileSize.ToString();
             fileDetails[4] = file.ModifiedOn.ToString();
             fileDetails[5] = (file.TrackingDisabledOn > new DateTime()) ? "X" : "";
             ListViewItem row = new ListViewItem(fileDetails);
             row.Tag = file.FileID;
             ViewFileslistView.Items.Add(row);
         }
     }
     catch (SqlException) {
         Messenger.ShowDbMsg();
     }
 }
Exemplo n.º 2
0
        private void btnAddFiles_Click(object sender, EventArgs e)
        {
            if (filesToAdd == null || filesToAdd.Count == 0)
            {
                return;
            }
            int nAdded = 0;
            List <TrackedFile> newFiles = new List <TrackedFile>();

            foreach (var file in filesToAdd)
            {
                FileInfo fi = new FileInfo(file);
                if (!fi.Exists)
                {
                    continue;
                }

                bool alreadyInSystem = FileManager.Exists(file);
                if (!alreadyInSystem)
                {
                    TrackedFile newFile = FileManager.AddFile(
                        Path.GetFileNameWithoutExtension(fi.Name),
                        fi.Extension.Substring(1), fi.DirectoryName,
                        (int)fi.Length, fi.CreationTime, fi.LastWriteTime);
                    if (newFile != null)
                    {
                        LogFileAdded(newFile);
                        newFiles.Add(newFile);
                        nAdded++;
                    }
                }
            }
            bool   wantsLink  = chkLinkFiles.Checked;
            string linkResult = null;

            if (wantsLink && nAdded > 1 && newFiles.Count > 1)
            {
                string memo    = txtMemo.Text.Trim();
                var    fileIDs = from file in newFiles
                                 select file.FileID;
                FileLink newLink = LinkManager.AddLink(fileIDs.ToList(), memo);
                if (newLink != null)
                {
                    // Log link creation and each file joined
                    LogLinkCreation(newLink.LinkMemoID, nAdded, memo);
                    LogLinkJoined(newLink, newLink.GetFiles());
                    linkResult = $"\n\nLinked {nAdded} files" +
                                 (string.IsNullOrEmpty(memo) ? "." : $" as '{memo}'.");
                }
            }
            string resultPrompt = $"Added {nAdded} file(s)." +
                                  linkResult;

            Messenger.Show(resultPrompt, caption);
            DialogResult = DialogResult.OK;
            Close();
        }
Exemplo n.º 3
0
        public void GetFilesTest()
        {
            // Get file link for link memo id = 1
            int      linkMemoId = 1;
            FileLink fl         = LinkManager.GetLink(linkMemoId);

            // Get the files for file link
            List <TrackedFile> files = fl.GetFiles();

            // Verify at least one file is returned
            Assert.IsNotNull(files);
        }
Exemplo n.º 4
0
        private void btnAddLink_Click(object sender, EventArgs e)
        {
            if (filesToLink.Count < 2)
            {
                return;                        // Need 2+ files to link
            }
            List <int> memberIDs = new List <int>();

            foreach (var file in filesToLink)
            {
                memberIDs.Add(file.FileID);
            }

            if (memberIDs.Count < 2)
            {
                return;                      // Just in case
            }
            string   linkMemo = txtLinkMemo.Text.Trim();
            FileLink newLink  = null;

            if (string.IsNullOrEmpty(linkMemo))
            {
                newLink = LinkManager.AddLink(memberIDs);
            }
            else
            {
                newLink = LinkManager.AddLink(memberIDs, linkMemo);
            }
            if (newLink == null)
            {
                return;                  // Didn't create
            }
            // Log link creation
            LogLinkCreation(newLink.LinkMemoID, memberIDs.Count, linkMemo);
            LogLinkJoined(newLink, newLink.GetFiles());
            Messenger.Show($"New link created between the {memberIDs.Count} files.", caption);
            DialogResult = DialogResult.OK;
            Close();
        }
Exemplo n.º 5
0
        public void JoinTest()
        {
            // Get file link for link memo id = 1
            int      linkMemoId = 1;
            FileLink fl         = LinkManager.GetLink(linkMemoId);

            // Get the files for file link
            List <TrackedFile> linkedFiles = fl.GetFiles();

            // Verify at least one file is returned
            Assert.IsNotNull(linkedFiles);

            // Get all files
            List <TrackedFile> allFiles = FileManagerDAL.GetFiles();

            // Find a file not in the MemoId = 1 list
            TrackedFile joinFile = null;

            // Get a list of the file IDs of the linked files
            List <int> linkedFileIDs = new List <int>();

            foreach (var file in linkedFiles)
            {
                linkedFileIDs.Add(file.FileID);
            }

            //
            foreach (var file in allFiles)
            {
                if (!linkedFileIDs.Contains(file.FileID))
                {
                    joinFile = file;
                    break;
                }
            }

            // Join file if we have found one
            if (joinFile != null)
            {
                // Join file
                fl.Join(joinFile.FileID);

                // Reteieve file list
                linkedFiles = fl.GetFiles();

                // Fill linedFileIDs with new file ID list
                linkedFileIDs.Clear();
                foreach (var file in linkedFiles)
                {
                    linkedFileIDs.Add(file.FileID);
                }

                // Verify joined file exists in the list
                Assert.IsTrue(linkedFileIDs.Contains(joinFile.FileID));

                // Remove joined file
                fl.RemoveFiles(new List <int> {
                    joinFile.FileID
                });
            }
        }