anakic/Jot

Jot creates two folders

Coke21 opened this issue · 6 comments

Hi,
I have been using your library for a while in .NET Framework and recently in .NET Core 3.0. I have noticed that in the later, for some reason Jot creates two folders in the Roaming folder. I thought that I've made some kind of error so I created another project in .NET Core 3.0 and I still have this problem. Please take a look at what I mean:
https://gyazo.com/78c2b349670073565b601884678632d0
I was using Jot 2.0.1 and now 2.0.3 but still the same above bug.
Also, when I moved from 2.0.1 to 2.0.3 I've noticed the naming of the file has changed:
https://gyazo.com/67d5297d4f5bf82e0a7fdf8448613c67
How can I remove the info in the square brackets?

This is how my MainWindow.xaml.cs looks like:

    public partial class MainWindow : Window
    {
        public static Tracker Tracker { get; set; } = new Tracker();

        public MainWindow()
        {
            InitializeComponent();

            Tracker.Configure<MainWindow>()
                .Id(p => p.Name)
                .Properties(p => new { p.Height, p.Width, p.Top, p.Left })

                .Property(p => p.CheckBox.IsChecked, true, "Test checkbox")

                .PersistOn(nameof(Closing));

            Tracker.Track(this);
        }
    }

I don't see any mistakes in the above code, though.

Hey.

Question 1:
The first folder is the name of the company, and the second folder is the name of the product. You can edit the name of the product in the project properties under Application->Assembly name, and you can change the company name under Package->Company. Jot reads the company and product names if they're available. These were optional attributes in the full framework, but apparently are mandatory for .NET Core projects. If you want to use a specific folder for storage, you can do it like so:

new Jot.Tracker(new Jot.Storage.JsonFileStore(@"C:\New folder"))

Question 2:
Yes, in v2.0.3. Jot started adding the type name as part of the identifier by default. You can turn it off in the Id method with the optional includeType parameter, like so:

.Id(x => x.Name, includeType: false);

Oh yes, you are right. Thank you so much for your help.
I have one more question, I'm using Caliburn.Micro and I implemented an interface for my ObservableCollection Items:

        private ObservableCollection<ISettingsModel> _items = new ObservableCollection<ISettingsModel>();
        public ObservableCollection<ISettingsModel> Items
        {
            get { return _items; }
            set
            {
                _items = value;

                NotifyOfPropertyChange(() => Items);
            }
        }

Items are binded to the ListView - <ListView ItemsSource="{Binding Items}"/>
Constructor of MainViewModel:

            Tracker tracker = new Tracker();
            tracker.Configure<MainViewModel>()
                .Id(p => p.WindowName, includeType: false)

                .Property(p => p.Items, "Items")

                .PersistOn(nameof(PropertyChanged));

            tracker.Track(this);

The items save when I close the program, however, when I open the program, the items reset. How can I fix it?
Edit: If I specify ObservableCollection<SettingsModel> then It works fine, however, I would like to try it with the interface.

My first thought is that Newtonsoft.Json does not know which type of object to create (when deserializing), it cannot create an instance of an interface. Jot uses Newtonsoft.Json for (de)serialization. Can you take a look at the .json file Jot created and see the type info for the Items property? If it says ObservableCollection without type information for specific types than that's the issue for sure. Not sure if that behavior can be configured.

Yeah, when I explicitly put ObservableCollection<SettingsModel> it works and the .json looks like this:
System.Collections.ObjectModel.ObservableCollection``1[[ProjectName.Models.SettingsModel, ...
When I try ObservableCollection<ISettingsModel> (with interface):
System.Collections.ObjectModel.ObservableCollection``1[[ProjectName.Interfaces.ISettingsModel, ...
The above crashes at the startup of the program and it reverses back to the default settings.

Yeah, that makes sense. It's possible to tell Newtonsoft.Json to include the information about the object types via the TypeNameHandling property of the JsonSerializerSettings object. Can you make the below change in the JsonFileStore.cs, line 169 and see if it works with the interface.

Instead of TypeNameHandling.None use TypeNameHandling.All

Closing this as the type handling is a separate issue.