- ago
Hi Community,

As stated in one of the community posts, datasets are created on application start.
In my scenario, this is impossible because the user has to log in first, and only after that, I load their personal catalog with the symbols.
To achieve this goal, I reinitialize the DatasetProvider by removing the current datasets and adding the new ones.
After that, I call EventRouter.FireEvent("DataSetProviderReloaded", this);, as mentioned in one of the community posts.
This works, and all my datasets are visible and functional, but the glyphs are not displayed.

Thanks to Glitch, who helped me get it working in a glyph example I made to show my problem in a static dataset, the mentioned trick did not work in my dynamic scenario. See the link about that topic here:
https://www.wealth-lab.com/Discussion/How-to-set-a-custom-glyph-for-a-DataSet-by-own-provider-11335

My question, therefore, is how to get the image updated in my dynamic scenario.
If I use GlyphManager.GetImageSource(resource), the image is there, but using the same resource string on the dataset's GlyphResource, no image is shown.

See my datasetprovider code here
CODE:
public class TaiPanDataSetProvider2 : DataSetProviderBase { private List<DataSet> _dataSets = []; public TaiPanDataSetProvider2() { // Keep the instance to recall initialize from outside. Instance = this; } public override string Name => TaiPanGlobals.ExtensionName; public static TaiPanDataSetProvider2 Instance { get; private set; } public override void Initialize() { base.Initialize(); if (_dataSets.Any()) { // i am not sure if this is neccessary... foreach (var ds in _dataSets) WLHost.Instance.DataSets.Remove(ds); _dataSets.Clear(); UpdateView(); } // if you not logged do nothing, at application startup. if (!TaiPanAdapter.Instance.IsConnected()) return; // It could take a few seconds, so dont anoy the user with "a freeze". WLHost.Instance.ShowWaitStatus(true); try { TaiPanLogAdapter.LogInformation("Reading catalog data."); // currently statics, but will read personal catalogs in later release state. var catalogDatas = TaiPanAdapter.Instance.GetCatalogDatas(TaiPanGlobals.DefaultCatalogIds); // This always gives me the image object _ = GlyphManager.GetImageSource("TaiPanExtension.Resources.logo_small.png", this); _dataSets = catalogDatas.Select(cd => { // Using our own concrete implementation to put some cached data on the dataset. var ds = new TaiPanDataSet { // This does not give me the image. GlyphResource = "TaiPanExtension.Resources.logo_small.png", // as stated in the documents, we prefere our own dataprovider first. PreferredDataProviderName = TaiPanGlobals.ExtensionName, Name = cd.Catalog.Name, // what is that mean? dont know, so leave it better off? what is the default?? IsDynamicEnabled = false, // we made the dataset programatically. IsUserCreated = false, // dont allow symbol changes on the ds, they are fixed. ReadOnlySymbols = true, Symbols = cd.Symbols.Select(i => TaiPanMapper.GetById(i.SymbolNo)).ToList(), }; return ds; }).OfType<DataSet>().ToList(); UpdateView(); } finally { WLHost.Instance?.ShowWaitStatus(false); } } public override List<DataSet> DataSets => _dataSets; private void UpdateView() => EventRouter.FireEvent("DataSetProviderReloaded", this); }


kind regards
mike


0
288
Solved
9 Replies

Reply

Bookmark

Sort
Glitch8
 ( 10.33% )
- ago
#1
Try putting this line:

_ = GlyphManager.GetImageSource("TaiPanExtension.Resources.logo_small.png", this);

as the first statement to execute in your Initialize method.
0
- ago
#2
i did,


but its not working

0
- ago
#3
Here's some more info...

I took Mike's code and modified so I didn't have the references to the classes that I don't have (e.g. TaiPanAdapter, etc.).

I loaded the glyph in the beginning of the Initialize method, and I used the short symbol.

_ = GlyphManager.GetImageSource("WealthLab.Core.Glyphs.Short.png", this);

I set the PreferredDataProviderName = "Alpaca" for each dataset.

I set each dataset's GlyphResource to the correct string for the glyph loaded above.

The Alpaca glyph always appeared, not the "short" triangle glyph.

Here's the code...

CODE:
using System.Collections.Generic; using System.Linq; using WealthLab.Core; using WealthLab.Data; using WealthLab.WPF; namespace WL8Extensions { public class TaiPanDataSetProvider2 : DataSetProviderBase { private List<DataSet> _dataSets = []; public TaiPanDataSetProvider2() { // Keep the instance to recall initialize from outside. Instance = this; } public override string Name => "My Extension"; public static TaiPanDataSetProvider2 Instance { get; private set; } public override List<DataSet> DataSets => _dataSets; public override void Initialize() { base.Initialize(); // This always gives me the image object _ = GlyphManager.GetImageSource("WealthLab.Core.Glyphs.Short.png", this); if (_dataSets.Any()) { // i am not sure if this is neccessary... foreach (var ds in _dataSets) { WLHost.Instance.DataSets.Remove(ds); } _dataSets.Clear(); UpdateView(); } // if you not logged do nothing, at application startup. //if (!TaiPanAdapter.Instance.IsConnected()) // return; // It could take a few seconds, so dont anoy the user with "a freeze". WLHost.Instance.ShowWaitStatus(true); try { //TaiPanLogAdapter.LogInformation("Reading catalog data."); // currently statics, but will read personal catalogs in later release state. string[] catalogDatas = ["D1", "D2"]; //TaiPanAdapter.Instance.GetCatalogDatas(TaiPanGlobals.DefaultCatalogIds); _dataSets = catalogDatas.Select(cd => { // Using our own concrete implementation to put some cached data on the dataset. var ds = new DataSet { GlyphResource = "WealthLab.Core.Glyphs.Short.png", //GlyphResource = "TaiPanExtension.Resources.logo_small.png", PreferredDataProviderName = "Alpaca", Name = cd, // cd.Catalog.Name, // what is that mean? dont know, so leave it better off? what is the default?? IsDynamicEnabled = false, // we made the dataset programatically. IsUserCreated = false, // dont allow symbol changes on the ds, they are fixed. ReadOnlySymbols = true, Symbols = ["CLSK", "MARA"] }; return ds; }).ToList(); UpdateView(); } finally { WLHost.Instance?.ShowWaitStatus(false); } } private void UpdateView() => EventRouter.FireEvent("DataSetProviderReloaded", this); } }
0
- ago
#4
thank you paul, you actually commented the isconnted part out which just returns and not creating any dataset at first.
to make it more mine realisitic you may trigger the initialize from a button in child form of an extension, as i do after the user successfully logged in.
But i tried your solution and the glyph still wont show, although the glypmanager finds it.
i actually have the same problem in the search field of the chart, but i hope it will be solved if the datset has a working glyph because the SymbolChooserItem wants the provider name.
0
Glitch8
 ( 10.33% )
- ago
#5
In your TaiPanDataSet class, I think you should override the virtual get of the GlyphResource property, like this for example (WealthData)

CODE:
//Glyph public override string GlyphResource { get { return WealthDataProvider.Instance.GlyphResource; } }
0
- ago
#6
Thank you Glitch,
unfortunatley that did not work.

I elaborated that it has something to do with the datasets PreferedDataProvider property. if i dont set this property, my icons get shown.
it is not even neccessary to do the discarded call to the glyphmanager.
The GlyphrResource property is just enough.

I just startet to create a github project to elaborate this problem while realizing it has to do with the preferededdataprovider property.
in my project i have a single historydataprovider, inherited from dataproviderbase named "TAI-PAN History".

I added this to the PreferedDataProvider property, but doing this leads to no visible icons with the dataset. as mentioned before, leaving the that out will load them icons correctly.
The problem here is that the chart wont find my provider to show my symbol data.
so the prefereddataprovider property interferes somehow with the icon visibility.
maybe you have an idea.

kind regards
Mike
0
Glitch8
 ( 10.33% )
- ago
#7
If PreferredDataProvider is set, it will attempt to grab the glyph from the provider. Does the provider have a GlyphResource assigned?
1
Best Answer
- ago
#8
thank you, that did the trick.
i overload the glyphresource property and it worked.
but please, tell how someone should be meant to know that this is propagated over different types.
i mean, i explicitly declare the dataset to have a certain glyph.
imagine i want to add individual glyphs to each dataset using where as they use the same dataprovider.
If i dont explicitly set the dataprovider i get an exception in the chart when clicking a symbol in the dataset tree, for example.

But you helped me, thank you.
1
Glitch8
 ( 10.33% )
- ago
#9
No excuses, but glad I could help here in the forum!
0

Reply

Bookmark

Sort