Exemple #1
0
        public void TaggedFileConstructorTest1()
        {
            var target   = new TaggedFile(VALID_TAGGED_FILE_PATH);
            var fileInfo = new System.IO.FileInfo(VALID_TAGGED_FILE_PATH);

            Check.That(target.FullPath).IsEqualTo(fileInfo.FullName);
        }
Exemple #2
0
        public async Task LoadTextAsyncTest()
        {
            var target   = new TaggedFile(VALID_TAGGED_FILE_PATH);
            var expected = File.ReadAllText(VALID_TAGGED_FILE_PATH);
            var actual   = target.LoadTextAsync();

            Check.That(expected).IsEqualTo(await actual);
        }
Exemple #3
0
        public void LoadTextTest()
        {
            var target   = new TaggedFile(VALID_TAGGED_FILE_PATH);
            var expected = File.ReadAllText(VALID_TAGGED_FILE_PATH);
            var actual   = target.LoadText();

            Check.That(actual).IsEqualTo(expected);
        }
Exemple #4
0
        public static void AssignTag(string file, string tag)
        {
            if (!CheckIfDatabaseExists(file))
            {
#if !DB_DIR_LEVEL
                Directory.CreateDirectory(Path.GetDirectoryName(file));
#endif
                try {
                    // The database does not exists, so we create a blank one
                    var db = GetDatabase(file);
                    db.Dispose();
                    File.SetAttributes(GetDatabasePath(file), FileAttributes.Hidden);
                } catch (Exception exception) {
                    Debug.Log(exception.ToString());
                }
            }

            Debug.Log($"Assign tag '{tag}' to '{file}'");
            try {
                using (var db = GetDatabase(file)) {
                    var collection = db.GetCollection <TaggedFile>();
                    var result     = collection.Find(x => x.file == file);
                    if (result.Count() > 0)
                    {
                        var taggedFile = result.First();
                        taggedFile.tag = tag;
                        collection.Update(taggedFile);
                    }
                    else
                    {
                        var taggedFile = new TaggedFile {
                            file = file,
                            tag  = tag,
                        };
                        collection.Insert(taggedFile);
                    }
                }
            } catch (Exception exception) {
                Debug.Log(exception.ToString());
            }
        }
Exemple #5
0
        public void SetTags(string filePath, ulong?frn, string[]?tags)
        {
            // Get a collection (or create, if doesn't exist)
            var col = db.GetCollection <TaggedFile>(TaggedFiles);

            var tmp = _FindTag(filePath, frn);

            if (tmp == null)
            {
                if (tags != null && tags.Any())
                {
                    // Insert new tagged file (Id will be auto-incremented)
                    var newTag = new TaggedFile()
                    {
                        FilePath = filePath,
                        Frn      = frn,
                        Tags     = tags
                    };
                    col.Insert(newTag);
                    col.EnsureIndex(x => x.Frn);
                    col.EnsureIndex(x => x.FilePath);
                }
            }
            else
            {
                if (tags != null && tags.Any())
                {
                    // Update file tag
                    tmp.Tags = tags;
                    col.Update(tmp);
                }
                else
                {
                    // Remove file tag
                    col.Delete(tmp.Id);
                }
            }
        }
Exemple #6
0
        public void SetTag(string filePath, ulong?frn, string tag)
        {
            // Get a collection (or create, if doesn't exist)
            var col = db.GetCollection <TaggedFile>("taggedfiles");

            var tmp = _FindTag(filePath, frn);

            if (tmp == null)
            {
                if (tag != null)
                {
                    // Insert new tagged file (Id will be auto-incremented)
                    var newTag = new TaggedFile
                    {
                        FilePath = filePath,
                        Frn      = frn,
                        Tag      = tag
                    };
                    col.Insert(newTag);
                }
            }
            else
            {
                if (tag != null)
                {
                    // Update file tag
                    tmp.Tag = tag;
                    col.Update(tmp);
                }
                else
                {
                    // Remove file tag
                    col.Delete(tmp.Id);
                }
            }
        }
Exemple #7
0
 private static void AddToTypedList(TaggedFile file) => taggedFiles = taggedFiles.Add(file);