Beispiel #1
0
        internal async Task AddFileAsync(IStorageItem file)
        {
            if (file != null)
            {
                string faToken  = StorageApplicationPermissions.FutureAccessList.Add(file);
                var    document = new RdlnDocument
                {
                    Id    = Guid.NewGuid().ToString(),
                    Path  = file.Path,
                    Name  = file.Name,
                    Title = file.Name,
                    Token = faToken
                };

                var documentWasChanged = await _documentService.FillDocumentDataAsync(document).ConfigureAwait(true);

                if (documentWasChanged)
                {
                    var count = DatabaseManager.Connection.Insert(document);

                    if (count > 0)
                    {
                        GroupedDocuments.Add(document);

                        DocumentAdded?.Invoke(this, document);

                        RaisePropertyChanged(nameof(LibraryIsEmpty));
                    }
                }
            }
        }
        internal void Init(RdlnDocument doc, List<RdlnCategory> categories)
        {
            if (String.IsNullOrEmpty(doc.RawFields))
            {
                _knownValues = new Dictionary<string, string>();
            }
            else
            {
                _knownValues = JsonConvert.DeserializeObject<Dictionary<string, string>>(doc.RawFields);
            }

            _categories = categories;

            DocumentCategory = doc.Category;

            UpdateFields(DocumentCategory);
        }
Beispiel #3
0
        private void RemoveDoc(RdlnDocument doc)
        {
            if (doc != null)
            {
                try
                {
                    var result = DatabaseManager.Connection.Delete(doc);
                    if (result != 0)
                    {
                        GroupedDocuments.Remove(doc);
                    }

                    RaisePropertyChanged(nameof(LibraryIsEmpty));
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }
        }
Beispiel #4
0
        private async void EditDoc(RdlnDocument document)
        {
            if (document != null)
            {
                try
                {
                    var documentWasChanged = await _documentService.FillDocumentDataAsync(document).ConfigureAwait(true);

                    if (documentWasChanged)
                    {
                        GroupedDocuments.Remove(document);
                        DatabaseManager.Connection.Update(document);
                        GroupedDocuments.Add(document);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }
        }
Beispiel #5
0
        internal void AddFileByPattern(IStorageItem file, string pattern, string delimiter)
        {
            if (file != null)
            {
                string faToken  = StorageApplicationPermissions.FutureAccessList.Add(file);
                var    document = new RdlnDocument
                {
                    Id    = Guid.NewGuid().ToString(),
                    Path  = file.Path,
                    Name  = file.Name,
                    Title = file.Name,
                    Token = faToken
                };
                try
                {
                    //var pattern = await ApplicationData.Current.LocalFolder.ReadAsync<string>(Constants.Settings.PATTERN).ConfigureAwait(true);


                    var documentWasChanged = _documentService.FillDocumentDataByPattern(document, pattern, delimiter);

                    //if (documentWasChanged)
                    {
                        var count = DatabaseManager.Connection.Insert(document);

                        if (count > 0)
                        {
                            GroupedDocuments.Add(document);

                            DocumentAdded?.Invoke(this, document);

                            RaisePropertyChanged(nameof(LibraryIsEmpty));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }
        }
Beispiel #6
0
        private async void OpenFile(RdlnDocument doc)
        {
            if (doc != null && !String.IsNullOrEmpty(doc.Path))
            {
                try
                {
                    var file = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(doc.Token);

                    var success = await Windows.System.Launcher.LaunchFileAsync(file);
                }
                catch (FileNotFoundException ex)
                {
                    var dialog = new MessageDialog("File cannot be opened. It was moved or deleted.", "File not found");
                    await dialog.ShowAsync();

                    Debug.WriteLine(ex);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }
        }
 private void OnDocumentAdded(object sender, RdlnDocument e)
 {
     SetGroupingButtons();
 }
Beispiel #8
0
        public bool FillDocumentDataByPattern(RdlnDocument doc, string pattern, string delimiter)
        {
            if (doc == null)
            {
                throw new ArgumentNullException(nameof(doc));
            }

            var fillResult = false;
            var categories = DatabaseManager.Connection.Table <RdlnCategory>().ToList();

            var name = Path.GetFileNameWithoutExtension(doc.Name);

            var fields = NameHelper.GetFieldsByPattern(name, pattern, delimiter);

            if (fields != null)
            {
                if (!fields.ContainsKey(Constants.GroupCategories.TITLE))
                {
                    fields.Add(Constants.GroupCategories.TITLE, doc.Title);
                }
                if (!fields.ContainsKey(Constants.GroupCategories.AUTHOR))
                {
                    fields.Add(Constants.GroupCategories.AUTHOR, doc.Author);
                }
            }

            doc.RawFields = JsonConvert.SerializeObject(fields);

            if (!fields.ContainsKey("Category"))
            {
                doc.Category = "Default";
            }
            else
            {
                doc.Category = fields["Category"];
            }

            if (fields.TryGetValue("Title", out string title))
            {
                doc.Title = title;
            }

            if (fields.TryGetValue("Author", out string author))
            {
                doc.Author = author;
            }

            if (!categories.Any(c => c.Name == doc.Category))
            {
                var newCategory = new RdlnCategory
                {
                    Id   = Guid.NewGuid().ToString(),
                    Name = doc.Category
                };

                DatabaseManager.Connection.Insert(newCategory);


                foreach (var field in fields)
                {
                    var rdlnField = new RdlnField
                    {
                        Id       = Guid.NewGuid().ToString(),
                        Name     = field.Key,
                        Category = newCategory.Name,
                        Type     = Constants.FieldType.String
                    };

                    DatabaseManager.Connection.Insert(rdlnField);
                }

                fillResult = true;
            }
            return(fillResult);
        }
Beispiel #9
0
        public async Task <bool> FillDocumentDataAsync(RdlnDocument doc)
        {
            if (doc == null)
            {
                throw new ArgumentNullException(nameof(doc));
            }

            var fillResult = false;

            var dialog = new AddDocumentDialog();

            var categories = DatabaseManager.Connection.Table <RdlnCategory>().ToList();


            if (doc.RawFields == null)
            {
                var rawFields = new Dictionary <string, string>();
                rawFields.Add("Title", doc.Title);
                rawFields.Add("Author", doc.Author);
                doc.RawFields = JsonConvert.SerializeObject(rawFields);
            }

            dialog.Init(doc, categories);

            var result = await dialog.ShowAsync();

            if (result == Windows.UI.Xaml.Controls.ContentDialogResult.Primary)
            {
                doc.Title    = dialog.Fields.FirstOrDefault(f => f.Label == "Title")?.Value;
                doc.Author   = dialog.Fields.FirstOrDefault(f => f.Label == "Author")?.Value;
                doc.Category = dialog.DocumentCategory;

                doc.RawFields = JsonConvert.SerializeObject(dialog.Fields.ToDictionary(f => f.Label, f => f.Value));

                if (!categories.Any(c => c.Name == doc.Category))
                {
                    var newCategory = new RdlnCategory
                    {
                        Id   = Guid.NewGuid().ToString(),
                        Name = doc.Category
                    };

                    DatabaseManager.Connection.Insert(newCategory);


                    foreach (var field in dialog.Fields)
                    {
                        var rdlnField = new RdlnField
                        {
                            Id       = Guid.NewGuid().ToString(),
                            Name     = field.Label,
                            Category = newCategory.Name,
                            Type     = "string"
                        };

                        DatabaseManager.Connection.Insert(rdlnField);
                    }
                }

                fillResult = true;
            }
            return(fillResult);
        }