Giter Club home page Giter Club logo

jot's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jot's Issues

Adding an Additional Tracker Breaks Jot for VB

This, I think, is a continuation of Issue #45
This code in the TrackerServices module works:

Sub New()
   Trackr.Configure(Of Window)().Id(Function(w) w.Name, SystemInformation.VirtualScreen.Size).Property(Function(w) w.Top).Property(Function(w) w.Left).Property(Function(w) w.Height).Property(Function(w) w.Width).PersistOn(NameOf(Window.Closing)).StopTrackingOn(NameOf(Window.Closing))
End Sub

I have a wpf window in my Project with x:Name = GeoElements and a grid column with x:Name = C0. When I add this line to the above code:

Trackr.Configure(Of GeoElements)().Property(Function(g) New With {Key g.C0.Width}).PersistOn(NameOf(GeoElements.Closing)).StopTrackingOn(NameOf(GeoElements.Closing))

Tracker breaks when opening the MainWindow (the first window to be opened) with this error:

Inner Exception 1:
ArgumentException: Expression must be writeable
Parameter name: left

Crashes on saving any object with IPAddress property

Hi there, first of all, thanks for your effort on making this lib. We actively use Jot in our projects.

I've encountered a bug when if you have a trackable object, which has IPAddress type property, Jot crashes.

Newtonsoft.Json.JsonSerializationException
"Error getting value from 'ScopeId' on 'System.Net.IPAddress'."
------------
Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target)
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer, Object value, JsonContainerContract contract, JsonProperty member, JsonProperty property, JsonContract& memberContract, Object& memberValue)
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer)
Jot.Storage.Stores.JsonFileStore.SaveValues(Dictionary`2 values)
Jot.Storage.PersistentStoreBase.CommitChanges()
Jot.TrackingConfiguration.Persist()
Jot.StateTracker.RunAutoPersist()
Jot.StateTracker.AutoPersistTrigger_PersistRequired(Object sender, EventArgs e)
Jot.Triggers.DesktopPersistTrigger.OnApplicationClosing()
Jot.Triggers.DesktopPersistTrigger.<.ctor>b__0_0(Object s, ExitEventArgs e)
System.Windows.ExitEventHandler.Invoke(Object sender, ExitEventArgs e)
System.Windows.Application.OnExit(ExitEventArgs e)
System.Windows.Application.DoShutdown()
System.Windows.Application.ShutdownImpl()
System.Windows.Application.ShutdownCallback(Object arg)
System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
System.Windows.Threading.DispatcherOperation.InvokeImpl()
System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
System.Windows.Threading.DispatcherOperation.Invoke()
System.Windows.Threading.Dispatcher.ProcessQueue()
System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
System.Windows.Application.RunDispatcher(Object ignore)
System.Windows.Application.RunInternal(Window window)
System.Windows.Application.Run(Window window)
System.Windows.Application.Run()
MyApp.App.Main() App.xaml.cs: line: 40
System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
System.Threading.ThreadHelper.ThreadStart_Context(Object state)
System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
System.Threading.ThreadHelper.ThreadStart()

We are aware that IPAddress class is not very friendly to serialization so that is why this issue happens.
I guess what Jot needs is to derive a new class IPAddressConverter from the JsonConverter then create a new JsonSerializerSettings and add that converter to the JsonSerializedSettings instance. Then use that settings instance for JsonConvert.SerializeObject() and JsonConvert.DeserializeObject<T>()

If that sounds good to you, I can make a PR for that.

Tracker property is null in TrackingConfiguration<T> class

Hi,

I am excited to use this library in some of my projects. However, I have hit a stumbling block right out of the gate.

I was hoping to use a fluent style syntax to instantiate and configure my tracker. For the configuration, I've copied the example straight from the README. Unfortunately, it looks like the Tracker property of TrackingConfiguration<T> is never set properly. It is only available to the inner TrackingConfiguration.

Here is my code. The resulting tracker variable is null.

Tracker tracker = new Tracker().Configure<Window>()
    .Id(w => w.Name, SystemInformation.VirtualScreen.Size)
    .Properties(w => new { w.Top, w.Width, w.Height, w.Left, w.WindowState })
    .PersistOn(nameof(Window.Closing))
    .StopTrackingOn(nameof(Window.Closing))
    .Tracker;

External / Multiple Monitors

After disconnecting an external monitor from my laptop, windows are now not visible anymore/created off screen.

The saved Configuration contains:
<Item Id="ProjectView_ProjectView.Left" Type="System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">2806.0</Item>

Is clearly off screen screen when I work with my external monitor disconnected.

From a brief look at the code I could maybe hock the ApplyingProperty event to check if width, height, left and right are valid? Do you have anything like that laying around?

Maximize window on correct monitor

If a window is maximized it appears to not get restored on the correct monitor. In my testing the window always gets restored on the primary screen.

According to http://mostlytech.blogspot.de/2008/01/maximizing-wpf-window-to-second-monitor.html and https://social.msdn.microsoft.com/Forums/vstudio/en-US/2ca2fab6-b349-4c08-915f-373c71bd636a/show-and-maximize-wpf-window-on-a-specific-screen?forum=wpf
The WindowState Property should be applied after the window loaded event was fired.

Moving the call to .Apply() to the LoadedEvent handler on the window fixes this problem.

But maybe there could be a more elegant solution?

It is getting quite complicated, my "minimal" window setup:

public partial class ProjectView : Window
    {
        private TrackingConfiguration JotTracker;

        public ProjectView()
        {
            InitializeComponent();

            JotTracker = StateTrackerService.Tracker.Configure(this);
            JotTracker.ApplyingProperty += StateTrackerService.StateConfig_ApplyingProperty;
            JotTracker.IdentifyAs("ProjectView")
               .AddProperties<ProjectView>(w => w.Height, w => w.Width, w => w.Left, w => w.Top, w => w.WindowState)
               .RegisterPersistTrigger(nameof(Closed));

                Loaded += ProjectView_Loaded;
        }

        private void ProjectView_Loaded(object sender, RoutedEventArgs e)
        {
            JotTracker.Apply();
        }
}

[REQUEST] Add overload for AddProperties() method

Hi.

Maybe could you consider to add an overload for the AddProperties method that can take as parameter an Expression of an array of properties instead of using 'params' to take a variable number of expressions?.


See. In the example of the Readme.md written in C#, the syntax is so simple with the current method parameters but a little bit repetitive:

AddProperties<Window>(w => w.Height, w => w.Width, w => w.Top, w => w.Left, w => w.WindowState);

And for VB.NET usage this takes the need to write more repetitive code:

AddProperties(Of Window)(Function(w) x.Height, Function(w) w.Width, Function(w) w.Top, Function(w) w.Left, Function(w) w.WindowState)

Then, by adding the requested overload we could simplify the syntax for both C# and VB.NET to something like this:

AddProperties<Window>((w) => new[] {w.Height, w.Width, w.Top, w.Left, w.WindowState});
and:
AddProperties(Of Window)(Function(w) {w.Height, w.Width, w.Top, w.Left, w.WindowState})

Thanks for read.

Type Initializer throwing an error

For a wpf Window called GeoElements with a grid column named C0, I have:

Trackr.Configure(Of GeoElements)().Property(Function(g) New With {Key g.C0.Width}).PersistOn(NameOf(GeoElements.Closing)).StopTrackingOn(NameOf(GeoElements.Closing))

This throws an error at run-time:

Inner Exception 1:
ArgumentException: Expression must project properties as an anonymous class e.g. f => new { f.Height, f.Width } or access a single property e.g. f => f.Text.

Strange json file name

Instead of getting a filename like this MainWindow_MainWindow.json
I get this {Width=1920, Height=1200}..json

What have I done wrong?

Using VS2019, WPF, .NET Framework 4.7.2, Jot 2.0.1

// Anders

I want to persist DataGridView

Hi all,
i would like to persist all DataGridViewColumn state into json,
but i have no idea how to do...
I use Jot 1.4.1.0 version.

Persist and load Net 6 TimeOnly type

Hi...

I'm using Jot in a project with Net 6 and WPF.

When I try to store and load properties of type TimeOnly, the first time, the properties are persisted fine, but in next application run, the values are not loaded and my properties are all with values of 0:0 (0 hours, 0 minutes).

How change config file name.

How can I rename a configuration file?

In Windows forms i have:
"[WindowsFormsApp1.Form1]{Width=1920, Height=1080}.Form1.json"

Setup for Caliburn.Micro and WPF without a code behind.

I have been using Jot a long time and have always loved it, now I have been tasked with converting everything to WPF and removing all write behind code and instead using a viewmodel. I have not been able to find a way to make jot work with this, Is it even possible? another change is Net core.

NullReferenceError on Application close

Hi,
Thanks for great library! I had to tinker a bit to get it working in my case, so here is the issue and solution in case it helps. ( Great that you made it extendable!)

I have windows forms application running on,
NET 4.7.02558,
VS 2017.
Jot version 1.4.1.0

ISSUE:
When closing application, persist invokes save routine after Form has been disposed(probably?) and that results in NullReferenceError from one of custom control component Properties.

It could be that IsAlive is not working properly in this case. Offending component is toolbarDropDown inside custom control along with richtextbox. This is placed to the main Form. Property "SelectedItem" is propagated by getter/setter on custom control level. Value of that property is readable during FormClosing and FormClosed events. CustomControl getter/setter:

public string SelectedItem { get => (string) toolStripHeaders.SelectedItem; set => toolStripHeaders.SelectedItem = value;}

SOLUTION:
I'm not sure if this is proper way, but my solution was to ride on FormClosing event, so I created custom ITriggerPersist class with following constructor

public FormPersistTrigger()
        {
            foreach (System.Windows.Forms.Form fmt in System.Windows.Forms.Application.OpenForms)
            {
                fmt.FormClosing += (s, e) => { OnApplicationClosing(); };
            }
        }

Current git version is using following event.

else //winforms
                System.Windows.Forms.Application.ApplicationExit += (s, e) => { OnApplicationClosing(); };

Here is the stack trace when using stock PersistTrigger:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Windows.Forms.ToolStripComboBox.get_SelectedItem()
   at LabelWorkshop.ConfigEditorControl.get_SelectedItem() in D:\programming\LabelWorkshop\LabelWorkshop\ConfigEditorControl.cs:line 74
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
   at Jot.TrackingConfiguration.<>c__DisplayClass65_0.<CreateDescriptor>b__0(Object obj)
   at Jot.TrackingConfiguration.Persist()
   at Jot.StateTracker.RunAutoPersist()
   at Jot.StateTracker.AutoPersistTrigger_PersistRequired(Object sender, EventArgs e)
   at Jot.Triggers.DesktopPersistTrigger.OnApplicationClosing()
   at Jot.Triggers.DesktopPersistTrigger.<.ctor>b__0_1(Object s, EventArgs e)
   at System.Windows.Forms.Application.RaiseExit()
   at System.Windows.Forms.Application.ThreadContext.Dispose(Boolean postQuit)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm

How get data from IStore?

I need to get the saved window positions (Top, Width, Height, Left, WindowState) to position a Splash windows before the main window is shown.

I have tried:

Services.Tracker.Track(this);

var topDict = Services.Tracker.Store.GetData("Top");
var widthDict = Services.Tracker.Store.GetData("Width");
var heightDict = Services.Tracker.Store.GetData("Height");
var leftDict = Services.Tracker.Store.GetData("Left");

But the returned dictionaries are empty.
The json file looks like this

[
  {
    "Type": "System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
    "Name": "Top",
    "Value": 226.0
  },
  {
    "Type": "System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
    "Name": "Width",
    "Value": 749.0
  },
  {
    "Type": "System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
    "Name": "Height",
    "Value": 493.0
  },
  {
    "Type": "System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
    "Name": "Left",
    "Value": 923.0
  },
  {
    "Type": "System.Windows.WindowState, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
    "Name": "WindowState",
    "Value": 0
  }
]

I rather not read the json file directly, so what am I doing wrong and how do it right?

WPF MVVM - how to save controls?

Hi, I'm trying to use caliburn.micro and MVVM to save some controls in my app. This is the Constructor of my MainView (MainViewModel):

        public Tracker Tracker { get; set; } = new Tracker();
        public MainViewModel()
        {
            Tracker.Configure<MainViewModel>()
                .Id(p => p.MyMainWindow)

                .Property(p => p.RunHiddenCheckBox)

            Tracker.Track(this);
        }

That's how RunHiddenCheckBox property looks like:

        public bool RunHiddenCheckBox
        {
            get { return _runHiddenCheckBox; }
            set
            {
                _runHiddenCheckBox = value;
                if (RunHiddenCheckBox)
                {
                    RunAtStartUpCheckBox = true;
                    RunAtStartUpCheckBoxIsEnabled = false;
                }
                else
                {
                    RunAtStartUpCheckBoxIsEnabled = true;
                    WindowShowInTaskbar = true;
                }
            }
        }

MyMainWindow is just a string property.
No exceptions are being thrown, however, the library doesn't create any folders and .json files. Any idea why?
I guess I have to put .PersistOn somewhere but not sure where and what to put in. I tried:
.PersistOn(nameof(PropertyChanged), RunHiddenCheckBox);
But I'm getting NullReferenceException.


Update: Ok, I found the solution:
.PersistOn(nameof(PropertyChanged), this);
^ I had to put the above to save all controls. I hope this will help somebody.

Items duplicated in MyList {set;get;} which is a property inside the ObjectToBeTracked

I am tracking an object.. when closing the app and opening the JSON file: the JSON string is correct, but when running the application the second time: all lists properties are duplicated (number of items inside the list is duplicated), and when closing the application and checking the JSON file: the file is becoming larger due to the duplication of data.

idFunc is null when calling GetStoreId

I have just upgraded to version 2.1.11 via NuGet (.NET Framework 4.8)
Now I get System.NullReferenceException on the GetStoreId()
It's idFunc that is null!

in version 2.0.3 this worked.


// 1. get the tracking config for MainWindow
var cfg = Services.Tracker.Configure<Window>();
// 2. get the storeId of this window (do you have the window instance at this point? If not, you can use a throwaway window instance with the same Name)
var storeId = cfg.GetStoreId(this);
// 3. getting the values for the specified storeId
var dict = Services.Tracker.Store.GetData(storeId); // here I get a NullReferenceException 

Any idea on what could be wrong?

Cast Error

I have a wpf window called People that has three grid columns. With one column named col0 and using this configuration:

Trackr.Configure(Of People)().Property(Function(p) p.col0.Width).PersistOn(NameOf(Window.Closing)).StopTrackingOn(NameOf(Window.Closing))

I get this error:

TRACKING: Applying tracking to property with key='Width' failed. ExceptionType:'InvalidCastException', message: 'Specified cast is not valid.'!

I'm using V2.2.11

Save user settings

Hi Is there an example of saving user settings, I've had a good hunt but can't seem to find an example

Nested object

I'm not sure if this was supported or not but I had a nested object which was serialized and stored in my settings. An example

public class Settings
{
	[Track]
	public int Prop1 {get; set;]
	
	[Track]
	public NestedObject Prop2 {get; set;]
}

public class NestedObject
{
	public int Prop1 {get; set;]
	
	public int Prop12 {get; set;]
}

Up until 2.11.12 I was using it without any problems. But with this line change Convert.ChangeType(v, pi.PropertyType)

TrackedProperties[pi.Name] = new TrackedPropertyInfo(x => pi.GetValue(x), (x, v) => pi.SetValue(x, Convert.ChangeType(v, pi.PropertyType)));

I'm required to implement IConvertible?

Concurrency Problem? Loosing Settings in Production

Hi,
I am a little bit desperate, because some of our users are loosing a very important setting during working and i can't reproduce it.
However I have only one string setting looking like this

[
{
"Type": "System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"Name": "CustomerName",
"Value": "dev"
}
]

And on some Windows PCs this settings gets something like this, even though it was filled correctly before.
[
{
"Type": null,
"Name": "CustomerName",
"Value": null
}
]

Do you have any idea how this could happen, and how I could try to reproduce it?

Jot throwing an exception

With this definition of Jot tracking:
Sub New() Trackr.Configure(Of Window)().Id(Function(w) w.Name).Property(Function(w) w.Top).Property(Function(w) w.Left).Property(Function(w) w.Height).Property(Function(w) w.Width).PersistOn(NameOf(Window.Closing)).StopTrackingOn(NameOf(Window.Closing)) End Sub

Jot works fine.

However when I add a new configuration:
Sub New() Trackr.Configure(Of Window)().Id(Function(w) w.Name).Property(Function(w) w.Top).Property(Function(w) w.Left).Property(Function(w) w.Height).Property(Function(w) w.Width).PersistOn(NameOf(Window.Closing)).StopTrackingOn(NameOf(Window.Closing)) Trackr.Configure(Of People)().Id(Function(p) p.Name).Property(Function(p) p.col0.ActualWidth).Property(Function(p) p.col1.ActualWidth).PersistOn(NameOf(People.Closing)).StopTrackingOn(NameOf(People.Closing)) End Sub

Jot throws an error:

Inner Exception 1:
ArgumentException: Expression must be writeable
Parameter name: left

Note that the error occurs on the first configuration NOT on the added configuration!

XML documentation file is missing in distribution

Jot's source code contains XML documentation. However, in Jot.csproj:33 the documentation file is generated only for debug builds. I would recommend to generate them only for release builds instead, so that consumers of the NuGet package can take advantage of documentation in Visual Studio's IntelliSense.

Persisting a list

Hi, is it possible to persist a list I have defined a property but nothing gets saved on a persist event, I've checked the demos but can't
see any example of this, can you point me in the right direction Cheers

[Trackable] public List<ZoneInfo> ZoneInfos;

`public class ZoneInfo
{

    public float Cost { get; set; }
  
    public int Radius { get; set; }
  
    public string Name { get; set; }
}`

How to persist ListView?

I just found that it seems like items in ListView can't be tracked and persisted, do we have a solution here?

No documentation

When something is released officially on Nuget it is customary to have updated documentation, as the update to 2.0.0 broke everything in my code,

Lower Target Framework to or Build Additional Packages for .NET 4.5/4.5.1

Jot currently targets .NET Framework 4.5.2+, however, the solution builds successfully and all tests pass when targeting .NET 4.5 or 4.5.1 as well. Targeting a lower framework increases the number of projects that can use this project (specifically mine, but others would benefit as well).

Persistent bug with Caliburn.Micro

I'm using WPF, .Net Core 3.1 and Caliburn.Micro 4.0.117-alpha. I encountered a persistent bug while trying to implement Screen class to my Model. This is how my "stuff" looks like:
BindableCollection<TestModel> Test = new BindableCollection<TestModel>(); (The same happens with ObservableCollection<>)
In my constructor:

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

                .Property(p => p.Test, "test")
                .PersistOn(nameof(PropertyChanged));

My TestModel:

    public class TestModel : Screen
    {
        public string Test { get; set; }
    }

When adding item to Test, this is what I get in .json file:

  {
    "Type": "Caliburn.Micro.BindableCollection`1[[yeye.Models.TestModel, yeye, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], Caliburn.Micro.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null",
    "Name": "test",
    "Value": [
      {}
    ]
  }

So it's empty value, however, If I remove Screen class, it works perfectly. The reason why I want to implement the class is so I can use NotifyOfPropertyChange method. Obviously, I could implement my own NotifyOfPropertyChange method. Just pointing it out because it was a nightmare to debug it haha.

Forget

Is there a functionality to forget all or certain settings. I want to implement something like "my.exe -ResetAll" to forget settings.

Renaming or Deleting a Property

When I rename a serialized property, i would expect that the old one is deleted and the new one is added.

However the old one is living forever in the serialized .json.

Confused with the new syntax

Hi. The last time I used JOT was the version 1.41. I updated to version 2.x and I don't know how to translate my old code of old JOT syntax. Someone could help me?:

VB.NET Syntax on a Windows Forms project:

Private ReadOnly stateTracker As New StateTracker()
' ...
Me.stateTracker.Configure(Me).IdentifyAs(NameOf(Form1)).AddProperties(Of Form)(Function(x) x.DesktopLocation).Apply()
Me.stateTracker.Configure(Me.ToggleSwitchUserInactivity).IdentifyAs(NameOf(Me.ToggleSwitchUserInactivity)).AddProperty(Of ToggleSwitch)(Function(x) x.Checked).Apply()

I tried this while trying to figure out how to properly write the equivalency :

Me.stateTracker.Configure(Of ToggleSwitch).Id(Function(x) x.Name).Properties(Function(w) New With {Key w.Checked}).PersistOn(NameOf(Me.FormClosing))

However it throws a exception with this message:

Expression must project properties as an anonymous class e.g. f => new { f.Height, f.Width } or access a single property e.g. f => f.Text.

Here ๐Ÿก„ is the full code I need to update to the new syntax. I just track 1 property for 3 different controls, and the form DesktopLocation property.

( the source-code is small and are just 4 lines of code to check... )

UPDATE

I found a workaround by @anakic at: #36

Thanks in advance.

Crash while persisting

I am using (and loving!) Jot in a WPF app in the Windows Store. Their built-in crash reporting is returning this stack trace of a crash:

Frame	Image	Function	Offset
0	mscorlib_ni	System.IO.__Error.WinIOError	0x208	
1	mscorlib_ni	System.IO.FileStream.Init	0x2E1	
2	mscorlib_ni	System.IO.FileStream..ctor	0x43	
3	mscorlib_ni	System.IO.StreamWriter.CreateFile	0x4A	
4	mscorlib_ni	System.IO.StreamWriter..ctor	0x4A	
5	mscorlib_ni	System.IO.File.InternalWriteAllText	0x41	
6	mscorlib_ni	System.IO.File.WriteAllText	0x2C	
7	Jot	Jot.Storage.Stores.JsonFileStore.SaveValues	0xEF	
8	Jot	Jot.Storage.PersistentStoreBase.CommitChanges	0x19	
9	Jot	Jot.TrackingConfiguration.Persist	0x1B5	
10	Jot	Jot.TrackingConfiguration._RegisterPersistTrigger_b__58_1	0xC	
11	mscorlib_ni	System.EventHandler.Invoke	0x2	
12	PresentationFramework_ni	System.Windows.Window.OnLocationChanged	0xCBB09F	
13	PresentationFramework_ni	System.Windows.Window.WmMoveChangedHelper	0x51	

Unfortunately they don't provide the actual exception message, but the issue appears to be the File.WriteAllText in JsonFileStore.SaveValues. There definitely needs to be some error handling around this call, since it could fail for example if the user doesn't have permission to write there or the disk is full.

Using Jot in a VB Application

I am trying to use Jot in my VB WPF application but there is not a one-to-one correspondence with the C# Demo application. Is such an example available?

ITrackingAware AsGeneric not serialising any data on Persist

Hello,

I am interested in using this library in a project of mine but while testing it out I have come across an issue.

I made a basic project using the WPF Demo that's in this repo as a reference but was scratching my head when the AppSettings class was being serialised as "[]".
I downloaded the Jot Repo and compiled the TestWPF demo project and it has the same issue, the AppSettings class is serialised as "[]".

The window position json is being serialised ok, so it appears to be isolated to the use of the ITrackingAware interface.

I did a quick step through the TrackingConfiguration.Persist method and it appears that the issue is caused by TrackedProperties not containing any properties. I don't have the time currently to dig further. Hopefully someone that's familiar with the code base will be able to figure this out relatively
easily.

Not working for Windows Forms

Hey, I'm new using this lib. I just took the example from the readme.md and adapted it to use for a Form isntead of a WPF Window. The next code pretends to save and restore the location of a Form, but it does not restore the location...

    Public Sub New()
        MyClass.InitializeComponent()

        Tracker.Configure(Me).IdentifyAs(NameOf(Form1)).
                AddProperties(Of Form)(Function(x As Form) x.Location).
                RegisterPersistTrigger(NameOf(Form.LocationChanged)).
                Apply()

    End Sub

I'm missing something to do?.

Jot creates two folders

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.

Breaking changes in version 2

What happened, that version 2 introduced big breaking changes?

I've been building my project on Jot's TrackableAttribute. How whould I update to version 2 with as little intrusion as possible? Also it would be good if the settings that are on my users computers would not be lost.

My current version 1.4.1 approach:

// in ctor of base view model (WPF & MVVM)
Configuration = stateTracker.Configure(this)
    .IdentifyAs("static")
    .SetAutoPersistEnabled(true); // persist at application shutdown

Configuration.StatePersisted += Configuration_StatePersisted;
Configuration.StateApplied += Configuration_StateApplied;
protected virtual void Configuration_StateApplied(object sender, EventArgs e) 
{ 
    // Enable child class to react on this event
}
protected virtual void Configuration_StatePersisted(object sender, EventArgs e) 
{
    // Enable child class to react on this event
}
// every child view model marks relevant properties with TrackableAttribute 
// and has it automatically persisted and restored
[Trackable]
public string Property1 { get; set; }

The files I'm ending up with are:
%appdata%\myproject\MyViewModel_static.json

[
  {
    "Type": "System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
    "Name": "Property1",
    "Value": "foo"
  }
]

Closing app with minimized window

I have a strange problem. When i minimize window and then close the app - next time the app gets created is waaaay off the screen.

Configuration code:

public MainWindow()
{
     InitializeComponent();
     SourceInitialized += MainWindow_SourceInitialized;
}

private void MainWindow_SourceInitialized(object sender, EventArgs e)
{
      Persistance.Tracker.Configure(this).Apply();
 }

The settings file looks like that:

[
  {
    "Type": "System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
    "Name": "Height",
    "Value": 828.0
  },
  {
    "Type": "System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
    "Name": "Width",
    "Value": 1242.0
  },
  {
    "Type": "System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
    "Name": "Top",
    "Value": -32000.0
  },
  {
    "Type": "System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
    "Name": "Left",
    "Value": 0.0
  },
  {
    "Type": "System.Windows.WindowState, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
    "Name": "WindowState",
    "Value": 0
  }
]

Cannot save controls from Pages or other Windows

I'm saving controls from MainWindow (and it works)

        public MainWindow()
        {
            InitializeComponent();

            Persistence.Tracker.Configure<MainWindow>()
                .Property(p => p.ThemeToggleSwitch.IsChecked, true, "Theme")
                .Property(p => p.RunAtStartUpCheckBox.IsChecked, false, "Run at startup")
                .Property(p => p.DefaultTimeZoneCheckBox.IsChecked, false, "timezone checkbox")
                .Property(p => p.TimeZoneIntegerUpDown.Value, 0, "timezone value");

            Persistence.Tracker.Track(this);
        }

My Persistence class:

    class Persistence
    {
        public static Tracker Tracker = new Tracker();

        static Persistence()
        {
            Tracker.Configure<Window>()
                .Id(w => w.Name)
                .Properties(w => new {w.Height, w.Width, w.Top, w.Left })
                .PersistOn(nameof(Window.Closing))
                .StopTrackingOn(nameof(Window.Closing));
        }
    }

I have a few Pages and an Window, therefore, I want to save controls from them. However, I cannot do it with this:

        public MainWindow()
        {
            InitializeComponent();

            //Persistence.Tracker.Configure<PageBattleMetrics>()
            //    .Property(p => p.NotifyCheckbox.IsChecked, false, "Notify checkbox");

            //Persistence.Tracker.Track(Data.PageBattleMetrics);

            Persistence.Tracker.Configure<MainWindow>()
                .Property(p => p.ThemeToggleSwitch.IsChecked, true, "Theme")
                .Property(p => p.RunAtStartUpCheckBox.IsChecked, false, "Run at startup")
                .Property(p => p.DefaultTimeZoneCheckBox.IsChecked, false, "timezone checkbox")
                .Property(p => p.TimeZoneIntegerUpDown.Value, 0, "timezone value");

            Persistence.Tracker.Track(this);
        }

Any idea what I should do to also save controls from other Pages and Windows?

Class 'TrackingEventArgs' is never used

I was reviewing the sources in order to get an understanding on how the project works, and stumbled upon this warning.

How is the issue expected to be solved:

  • By removing the unused class?
  • By using it somehow?

[REQUEST] Include XML documentation file for NuGet package.

@anakic As it seems you have XML'ed documented all or almost all members in your source-code, then please consider to include the generated XML source documentation file for people that install and use the library through NuGet package. Otherwise it is a real pain to figure out the purpose of each member and for each method parameter without any documentation/explanation shown in the IntelliSense popups.

Thanks for consider it.

Way 2-4 tracked object id

This question comes only from reading the documentation specifically the "4 ways of initializing TrackingConfiguration". It looks like each tracked object needs an id associated with it, its clear when using way 1 the id comes from the call to IdenitifyAs. How is the Id determined in ways 2, 3, and 4?
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.