Exemple #1
0
        /// <summary>
        /// UI views acquisition and initialization
        /// </summary>
        private void InitializeUI()
        {
            _noteText                    = FindViewById <EditText>(Resource.Id.noteText);
            _saveButton                  = FindViewById <ImageButton>(Resource.Id.saveNoteButton);
            _categoriesListButton        = FindViewById <Button>(Resource.Id.categoriesListButton);
            _categoriesList              = FindViewById <LinearLayout>(Resource.Id.categoriesDialogEntriesList);
            _categoriesListButton.Click += (object sender, EventArgs e) => RevealCategoriesDialog();
            FindViewById <RelativeLayout>(Resource.Id.categoriesDialogBG).Click      += (object sender, EventArgs e) => (sender as RelativeLayout).Visibility = ViewStates.Invisible;
            FindViewById <LinearLayout>(Resource.Id.categoriesDialogContainer).Click += (object sender, EventArgs e) => { };
            FindViewById <TextView>(Resource.Id.categoriesDialogTitle).Typeface       = Typeface.CreateFromAsset(this.Assets, "fonts/MINIONPRO-REGULAR.OTF");
            _categoriesListButton.Typeface = Typeface.CreateFromAsset(this.Assets, "fonts/MINIONPRO-REGULAR.OTF");
            _saveButton.Click += (object sender, EventArgs e) => UpdateNotes();

            if (_originalNote != null)
            {
                _noteText.Text             = _originalNote.Text;
                _categoriesListButton.Text = NoteStorage.GetCurrentCategories(this)[_originalNote.CategoryId];
                _categoriesListButton.Tag  = _originalNote.CategoryId;
            }
            else
            {
                _categoriesListButton.Text = NoteStorage.GetCurrentCategories(this)[0];
                _categoriesListButton.Tag  = 0;
            }
        }
Exemple #2
0
        private void RevealCategoriesDialog()
        {
            var inflater = GetSystemService(Context.LayoutInflaterService) as LayoutInflater;

            _categoriesList.RemoveAllViews();
            View view = this.CurrentFocus;

            if (view != null)
            {
                (this.GetSystemService(InputMethodService) as InputMethodManager)
                .HideSoftInputFromWindow(view.WindowToken, 0);
            }
            foreach (var category in NoteStorage.GetCurrentCategories(this))
            {
                View entry = inflater.Inflate(Resource.Layout.CategoriesDialogItem, null);
                entry.FindViewById <Button>(Resource.Id.categoriesDialogEntryText).Text     = category;
                entry.FindViewById <Button>(Resource.Id.categoriesDialogEntryText).Typeface = Typeface.CreateFromAsset(this.Assets, "fonts/MINIONPRO-REGULAR.OTF");
                entry.Click += (object sender, EventArgs e)
                               => { _categoriesListButton.Text = category;
                                    _categoriesListButton.Tag  = NoteStorage.GetCurrentCategories(this).IndexOf(category);
                                    FindViewById <RelativeLayout>(Resource.Id.categoriesDialogBG).Visibility = ViewStates.Invisible; };
                _categoriesList.AddView(entry);
            }
            FindViewById <RelativeLayout>(Resource.Id.categoriesDialogBG).Visibility = ViewStates.Visible;
        }
Exemple #3
0
 public void Delete()
 {
     if (!string.IsNullOrWhiteSpace(NoteId))
     {
         _deletedNote = NoteStorage.Delete(NoteId);
     }
 }
Exemple #4
0
        private Note ReadFromStorage()
        {
            var result = NoteStorage.GetExisting(NoteId);

            Check.DoEnsureLambda(result != null, () => $"Note {NoteId} does not exist");

            return(result);
        }
Exemple #5
0
        public void Delete()
        {
            Note = NoteStorage.Delete(NoteId);

            Check.DoEnsureLambda(Note != null, () => $"Note {NoteId} does not exist");

            NoteDeleted = true;
        }
Exemple #6
0
        public Note Delete(string noteId)
        {
            _changedNote = NoteStorage.Delete(noteId);

            _changeIsDeletion = true;

            return(_changedNote);
        }
Exemple #7
0
        /// <summary>
        /// Populate list with categories
        /// </summary>
        /// <param name="layout">List layout</param>
        private void PopulateList(LinearLayout layout)
        {
            layout.RemoveAllViews();

            View entry = View.Inflate(_rootActivity, Resource.Layout.CategoriesListItem, null);

            entry.FindViewById <TextView>(Resource.Id.categoryName).Text = _rootActivity.GetString(Resource.String.All);
            entry.FindViewById <TextView>(Resource.Id.categoryName).SetTextColor(BuildColor(_rootActivity.GetString(Resource.String.All)));
            entry.FindViewById <TextView>(Resource.Id.categoryName).Typeface = Typeface.CreateFromAsset(_rootActivity.Assets, "fonts/MINIONPRO-REGULAR.OTF");
            entry.FindViewById <TextView>(Resource.Id.notesCount).Text       = $"({NoteStorage.Notes.Count.ToString()})";

            entry.Click += (object sender, EventArgs e) =>
            {
                if (_selectedEntrys.Count == 0)
                {
                    NotesListFragment.ChangeDataSet(NoteStorage.Notes);
                    MainPageActivity.Navigation.SetCurrentItem(0, true);
                    _selectedCategory = _rootActivity.GetString(Resource.String.All);
                    Refresh(layout);
                }
            };
            entry.LongClick += (object sender, View.LongClickEventArgs e) => { };
            layout.AddView(entry);

            foreach (string category in NoteStorage.GetCurrentCategories(_rootActivity))
            {
                int id = NoteStorage.GetCurrentCategories(_rootActivity).IndexOf(category);
                entry = View.Inflate(_rootActivity, Resource.Layout.CategoriesListItem, null);
                entry.FindViewById <TextView>(Resource.Id.categoryName).Text = category;
                entry.FindViewById <TextView>(Resource.Id.categoryName).SetTextColor(BuildColor(category));
                entry.FindViewById <TextView>(Resource.Id.categoryName).Typeface = Typeface.CreateFromAsset(_rootActivity.Assets, "fonts/MINIONPRO-REGULAR.OTF");
                entry.FindViewById <TextView>(Resource.Id.notesCount).Text       = $"({NoteStorage.Notes.Where(n => n.CategoryId == id).Count().ToString()})";
                entry.Click += (object sender, EventArgs e) =>
                {
                    if (_selectedEntrys.Count == 0)
                    {
                        NotesListFragment.ChangeDataSet(NoteStorage.Notes.Where(n => n.CategoryId == id).ToList());
                        MainPageActivity.Navigation.SetCurrentItem(0, true);
                        _selectedCategory = category;
                        Refresh(layout);
                    }
                };
                if (category != NoteStorage.GetCurrentCategories(_rootActivity)[0])
                {
                    entry.Click += (object sender, EventArgs e) => { if (_selectedEntrys.Count > 0)
                                                                     {
                                                                         LongClickSelectEntry(sender as View);
                                                                     }
                    };
                    entry.LongClick += (object sender, View.LongClickEventArgs e) => LongClickSelectEntry(sender as View);
                }
                else
                {
                    entry.LongClick += (object sender, View.LongClickEventArgs e) => { }
                };
                layout.AddView(entry);
            }
        }
Exemple #8
0
        private void ConfigureBackend(IAppBuilder app)
        {
            var appDataPath = Path.Combine(AppLocalRootPath, "App_Data"); // HostingEnvironment.MapPath("~/App_Data");

            var dbPath   = Path.Combine(appDataPath, "Pim.db");
            var database = NoteLiteDb.GetNoteDatabase($"Filename={dbPath}; Upgrade=true; Initial Size=5MB; Password=;");

            AuthDatabase = database;
            IdentityDatabaseContextFactory = new IdentityDatabaseContextFactory(AuthDatabase);

            var storage = NoteStorage.CreateStandard(database, appDataPath, true);

            storage.Open();

            var languageSetting = ConfigurationManager.AppSettings[AppSettingKeyFulltextIndexLanguages];

            if (string.IsNullOrWhiteSpace(languageSetting))
            {
                languageSetting = "English,Russian";
            }

            var stemmerNames     = languageSetting.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToCaseInsensitiveSet();
            var redundantIndexes = storage.ActiveIndexNames.Where(name => !stemmerNames.Contains(name));

            foreach (var redundantIndexName in redundantIndexes)
            {
                Log.InfoFormat("Removing FT index {0}", redundantIndexName);
                storage.RemoveIndex(redundantIndexName);
            }

            stemmerNames.ExceptWith(storage.ActiveIndexNames);

            storage.OpenOrCreateIndexes(stemmerNames);

            storage.MultiIndex.UseFuzzySearch = true;

            Storage = storage;

            var builder = new ContainerBuilder();

            builder.RegisterControllers(typeof(Startup).Assembly);

            builder.Register(context => Storage).SingleInstance();
            //builder.RegisterType<HomeController>();
            //builder.RegisterType<ViewEditController>();
            //builder.RegisterType<SearchController>();
            builder.Register(c => IdentityDatabaseContextFactory).SingleInstance();

            Container = builder.Build();

            app.UseAutofacMiddleware(Container);

            DependencyResolver.SetResolver(new AutofacDependencyResolver(Container));

            app.UseAutofacMvc();
        }
Exemple #9
0
        public Note CreateNew()
        {
            if (string.IsNullOrWhiteSpace(NewNoteText))
            {
                return(null);
            }

            _changedNote = Note.Create(NewNoteText);

            NoteStorage.SaveOrUpdate(_changedNote);
            NewNoteText = string.Empty;

            return(_changedNote);
        }
 private void AddActualData(NoteStorage note_storage, float value, string note = null)
 {
     accumulate += value;
     if (value > 0f)
     {
         accPositive += value;
     }
     else
     {
         accNegative += value;
     }
     if (note != null)
     {
         note_storage.Add(noteStorageId, value, note);
     }
 }
Exemple #11
0
 /// <summary>
 /// Remove selected categories
 /// </summary>
 private void RemoveCategories()
 {
     foreach (string category in _selectedEntrys
              .Select(view => view.FindViewById <TextView>(Resource.Id.categoryName).Text))
     {
         foreach (Note note in NoteStorage.Notes.Where(note => note.CategoryId == NoteStorage.GetCurrentCategories(_rootActivity).IndexOf(category)))
         {
             note.CategoryId = 0;
         }
         NoteStorage.RemoveCategory(_rootActivity, category);
     }
     SecurityProvider.SaveNotesAsync();
     _selectedEntrys.Clear();
     HideDeleteButton();
     PopulateList(_list);
 }
Exemple #12
0
        public void SetUp()
        {
            _rootStorageDirectory = Path.Combine(TestContext.CurrentContext.WorkDirectory, "IndexedStorage");

            if (Directory.Exists(_rootStorageDirectory))
            {
                Directory.Delete(_rootStorageDirectory, true);
            }

            _indexedStorage = NoteStorage.CreateStandard(_rootStorageDirectory);
            _indexedStorage.Open();

            _indexedStorage.OpenOrCreateIndexes(new [] { "English", "Russian" });

            _testNotes = new[]
            {
                Note.Create("Evaluating Evernote\r\n GMBH encryption support. interface is not too bad, local supported, no symmetric encryption, no fulltext search."),
                Note.Create("Evaluating OneNote\r\n interface is not too bad, local supported, no symmetric key encryption, no fulltext search, although claimed."),
                Note.Create("Government is the great fiction\r\n through which everybody endeavors to live at the expense of everybody else"),
                Note.Create("Stuff location: router \r\n placed into a big box in the garage near the top of the pile, box marked \"electronics\""),
                Note.Create("unbalanced signal converter \r\n in a marked plastic box in laundry"),
                Note.Create("blog post \r\n publishing tomorrow "),
                Note.Create("Quote from Bastiat\r\nFor now, as formerly, every one is, more or less, for profiting by the labors of others. No one would dare to profess such a sentiment; he even hides it from himself; and then what is done? A medium is thought of; Government is applied to, and every class in its turn comes to it, and says, \"You, who can take justifiably and honestly, take from the public, and we will partake."),
                Note.Create("Egg \r\n tolerated well, but high in cholesterol if you beleive it"),
                Note.Create("Masha \r\n Maria Мария"),
                Note.Create("Quote: Mises on education\r\n​It is often asserted that the poor man's failure in the competition of the market is caused by his lack of education. Equality of opportunity, it is said, could be provided only by making education at every level accessible to all. There prevails today the tendency to reduce all differences among various peoples to their education and to deny the existence of inborn inequalities in intellect, will power, and character. It is not generally realized that education can never be more than indoctrination with theories and ideas already developed. Education, whatever benefits it may confer, is transmission of traditional doctrines and valuations; it is by necessity conservative. It produces imitation and routine, not improvement and progress. Innovators and creative geniuses cannot be reared in schools. They are precisely the men who defy what the school has taught them."),
                Note.Create("Испанская «Барселона» объявила о подписании контракта с новым главным тренером Эрнесто Вальверде. Об этом сообщается в клубном Twitter в понедельник, 29 мая."),
            };

            for (var n = 0; n < _testNotes.Length; ++n)
            {
                _testNotes[n].LastUpdateTime = DateTime.Now.AddHours(n - _testNotes.Length);
                _testNotes[n].CreateTime     = _testNotes[n].LastUpdateTime.AddDays(-1);
            }

            _indexedStorage.SaveOrUpdate(_testNotes);

            foreach (var note in _testNotes)
            {
                Assert.IsNotEmpty(note.Id);
                Assert.AreEqual(1, note.Version);
            }

            Assert.IsTrue(_indexedStorage.WaitForFulltextBackgroundWorkToComplete(1000));
        }
Exemple #13
0
        public void Update()
        {
            var newText = NoteText?.Trim();

            Check.DoCheckOperationValid(!string.IsNullOrEmpty(newText), () => "Note text must not be empty.");

            if (Note == null)
            {
                Note = ReadFromStorage();
            }

            if (Note.Text != newText)
            {
                Note.Text           = newText;
                Note.LastUpdateTime = DateTime.Now;

                NoteStorage.SaveOrUpdate(Note);
            }
        }
Exemple #14
0
        public void ExecuteSearch()
        {
            if (PageNumber < 1)
            {
                PageNumber = 1;
            }
            else if (PageNumber > MaxPageCount)
            {
                PageNumber = MaxPageCount;
            }

            var maxResults = MaxPageCount * DefaultResultsPerPage;

            var headers = NoteStorage.SearchInPeriod(
                // ReSharper disable once RedundantArgumentDefaultValue
                PeriodStart, PeriodEnd, Query, maxResults + 1, SearchableDocumentTime.LastUpdate);

            if (_deletedNote != null)
            {
                headers.Remove(_deletedNote);
            }
            else if (headers.Any() && headers.Count > maxResults)
            {
                headers.RemoveAt(headers.Count - 1);
            }

            TotalPageCount = (int)Math.Ceiling((double)headers.Count / DefaultResultsPerPage);

            var headersPage = headers
                              .Skip((PageNumber - 1) * DefaultResultsPerPage)
                              .Take(DefaultResultsPerPage)
                              .ToList();

            SearchResultPage = headersPage
                               .Select(h => NoteStorage.GetExisting(h.Id))
                               .Where(x => x != null)
                               .ToList();

            if (headersPage.Count > SearchResultPage.Count)
            {
                Log.Warn("Fulltext index out of sync: rebuild it");
            }
        }
 public void AddData(NoteStorage note_storage, float value, string note = null, string dataContext = null)
 {
     AddActualData(note_storage, value, note);
     if (dataContext != null)
     {
         ReportEntry reportEntry = null;
         for (int i = 0; i < contextEntries.Count; i++)
         {
             if (contextEntries[i].context == dataContext)
             {
                 reportEntry = contextEntries[i];
                 break;
             }
         }
         if (reportEntry == null)
         {
             reportEntry = new ReportEntry(reportType, note_storage.GetNewNoteId(), dataContext, true);
             contextEntries.Add(reportEntry);
         }
         reportEntry.AddActualData(note_storage, value, note);
     }
 }
Exemple #16
0
        public void LoadLatest()
        {
            var resultCount = MaxNumberOfNotesInRecentList;

            if (_changedNote != null && _changeIsDeletion)
            {
                ++resultCount;
            }

            // ReSharper disable once RedundantArgumentDefaultValue
            var lastHeaders = NoteStorage.GetTopInPeriod(null, DateTime.Now, resultCount, SearchableDocumentTime.LastUpdate);

            LastUpdatedNotes = lastHeaders.Select(h => NoteStorage.GetExisting(h.Id)).Where(x => x != null).ToList();

            if (lastHeaders.Count > LastUpdatedNotes.Count)
            {
                Log.WarnFormat("Fulltext index out of sync: rebuild it");
            }

            // FT index is updated asynchronously, so when we've just created new note it may not be returned
            if (_changedNote != null)
            {
                if (!_changeIsDeletion && !LastUpdatedNotes.Contains(_changedNote))
                {
                    LastUpdatedNotes.Insert(0, _changedNote);
                }
                else if (_changeIsDeletion && LastUpdatedNotes.Contains(_changedNote))
                {
                    LastUpdatedNotes.Remove(_changedNote);
                }
            }

            if (LastUpdatedNotes.Count > MaxNumberOfNotesInRecentList)
            {
                LastUpdatedNotes.RemoveAt(LastUpdatedNotes.Count - 1);
            }
        }
Exemple #17
0
 /// <summary>
 /// Refreshing list method
 /// </summary>
 /// <param name="layout">List layout</param>
 private void Refresh(LinearLayout layout)
 {
     layout.GetChildAt(0).FindViewById <TextView>(Resource.Id.categoryName).SetTextColor(BuildColor(_rootActivity.GetString(Resource.String.All)));
     for (int i = 1; i < layout.ChildCount; i++)
     {
         layout.GetChildAt(i).FindViewById <TextView>(Resource.Id.categoryName).SetTextColor(BuildColor(NoteStorage.GetCurrentCategories(_rootActivity)[i - 1]));
     }
 }
Exemple #18
0
 /// <summary>
 /// Add new category
 /// </summary>
 /// <param name="category">Category name</param>
 private void AddCategory(string category)
 {
     NoteStorage.AddCategory(category);
     PopulateList(_list);
 }
Exemple #19
0
        static void RunIntegrated()
        {
            Console.WriteLine("Available stemmers:");

            foreach (var n in LuceneIndex.GetAvailableSnowballStemmers())
            {
                Console.WriteLine(n);
            }

            var notes = new[]
            {
                Note.Create("Evaluating Evernote\r\n GMBH encryption support. interface is not too bad, local supported, no symmetric encryption, no fulltext search."),
                Note.Create("Evaluating OneNote\r\n interface is not too bad, local supported, no symmetric key encryption, no fulltext search, although claimed."),
                Note.Create("Government is the great fiction\r\n through which everybody endeavors to live at the expense of everybody else"),
                Note.Create("Stuff location: router \r\n placed into a big box in the garage near the top of the pile, box marked \"electronics\""),
                Note.Create("unbalanced signal converter \r\n in a marked plastic box in laundry"),
                Note.Create("blog post \r\n publishing tomorrow "),
                Note.Create("Quote from Bastiat\r\nFor now, as formerly, every one is, more or less, for profiting by the labors of others. No one would dare to profess such a sentiment; he even hides it from himself; and then what is done? A medium is thought of; Government is applied to, and every class in its turn comes to it, and says, \"You, who can take justifiably and honestly, take from the public, and we will partake."),
                Note.Create("Egg \r\n tolerated well, but high in cholesterol if you beleive it"),
                Note.Create("Masha \r\n Maria Мария"),
                Note.Create("Quote: Mises on education\r\n​It is often asserted that the poor man's failure in the competition of the market is caused by his lack of education. Equality of opportunity, it is said, could be provided only by making education at every level accessible to all. There prevails today the tendency to reduce all differences among various peoples to their education and to deny the existence of inborn inequalities in intellect, will power, and character. It is not generally realized that education can never be more than indoctrination with theories and ideas already developed. Education, whatever benefits it may confer, is transmission of traditional doctrines and valuations; it is by necessity conservative. It produces imitation and routine, not improvement and progress. Innovators and creative geniuses cannot be reared in schools. They are precisely the men who defy what the school has taught them."),
                Note.Create("Испанская «Барселона» объявила о подписании контракта с новым главным тренером Эрнесто Вальверде. Об этом сообщается в клубном Twitter в понедельник, 29 мая."),
            };

            var storage = NoteStorage.CreateStandard(@"c:\temp\MyNotes");

            storage.OpenOrCreateIndexes(new[] { "English", "Russian" });

            storage.SearchEngine.UseFuzzySearch = true;

            if (storage.CountAll() > 0)
            {
                storage.Delete(storage.GetAll().ToArray());
            }

            storage.SaveOrUpdate(notes);

            var result1 = storage.GetTopInPeriod(null, DateTime.Now.AddSeconds(-1), 4);

            var result2 = storage.GetTopInPeriod(DateTime.Now.AddSeconds(-10), null, 4);

            // problem in the past: did not find 'erasing' by 'erase'; but 'erasure' works

            bool finish;

            do
            {
                Console.WriteLine();
                Console.Write("Your query: ");
                var queryText = Console.ReadLine();
                finish = string.IsNullOrEmpty(queryText);
                if (!finish)
                {
                    var result = storage.Search(queryText, 100);
                    Console.WriteLine($"Found {result.Count} items");
                    foreach (var hit in result)
                    {
                        Console.WriteLine($"\t {hit.Id} - {hit.Name};");
                        var loaded = storage.GetExisting(hit);

                        if (loaded == null)
                        {
                            Console.WriteLine($"Note {hit.Id} not found in database");
                        }
                    }
                }
            }while (!finish);

            storage.Dispose();
        }
 /// <summary>
 ///     程序打开第一界面
 /// </summary>
 public NoteStoragePage()
 {
     View = new NoteStorage();
     InitializeComponent();
     View.NavigateFolder = navigate_folder;
 }
 protected override void OnPrefabInit()
 {
     Instance = this;
     Subscribe(Game.Instance.gameObject, -1917495436, OnSaveGameReady);
     noteStorage = new NoteStorage();
 }