This is my app architechture. Note that I have conductor as another conductor's child. And I have IHandle for each conductor to receive message from it's child.The message type is same as I use message just to navigating. My problem are I pass ShellView's EventAggregator to it's children.
How about NewConnectionView's EventAggregator ? Since I use it's EventAggregator for navigating on ShellView. And for it's children to navigating on it's ActiveItem.
How to separate these 2 EventAggregators in one ViewModel.
ShellView & NewConnectionView ==> Conductor.Collection.OneActive
+----------------------------------+
| ShellView |_|[]|x|
+----------------------------------+
| +------------------------------+ |
| | | |
| | | |
| | | |
| | ActiveItem | |
| | | |
| | | |
| | | |
| +------------------------------+ |
+----------------------------------+
/ \
/ \
/ \
/ \
/ \
/ \
/ \
+----------------------------------+ +----------------------------------+
| NewConnectionView |_|[]|x| | ConnectionListView |_|[]|x|
+----------------------------------+ +----------------------------------+
| +------------------------------+ | | TextBlock |
| | ComboBox | V | | | +----------------------+ +-----+ |
| +------------------------------+ | | | | | Btn | |
| +------------------------------+ | | | | +-----+ |
| | | | | | | +-----+ |
| | | | | | | | Btn | |
| | | | | | DataGrid | +-----+ |
| | ActiveItem | | | | | +-----+ |
| | | | | | | | Btn | |
| | | | | | | +-----+ |
| | | | | | | |
| +------------------------------+ | | +----------------------+ |
+----------------------------------+ +----------------------------------+
/ \
/ \
/ \
/ \
/ \
/ \
/ \
+----------------------------------+ +----------------------------------+
| FileConnectionView |_|[]|x| | DatabaseConnectionView |_|[]|x|
+----------------------------------+ +----------------------------------+
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
+----------------------------------+ +----------------------------------+
Currently, my approach is using NewConnectionShellView (Screen) as NewConnectionView's (Conductor) parent to separate the EventAggregator. But the problem is, I can't get DisplayName of the NewConnectionView's children to display into my Main Window (ShellView).
Please note that I'm not using MEF. Is there any workaround for my problem ?
+----------------------------------+
| ShellView |_|[]|x|
+----------------------------------+
| +------------------------------+ |
| | | |
| | | |
| | | |
| | ActiveItem | |
| | | |
| | | |
| | | |
| +------------------------------+ |
+----------------------------------+
/ \
/ \
/ \
/ \
/ \
/ \
/ \
+----------------------------------+ +----------------------------------+
| NewConnectionShellView |_|[]|x| | ConnectionListView |_|[]|x|
+----------------------------------+ +----------------------------------+
| +------------------------------+ | | TextBlock |
| | | | | +----------------------+ +-----+ |
| | | | | | | | Btn | |
| | | | | | | +-----+ |
| | | | | | | +-----+ |
| | | | | | | | Btn | |
| | | | | | DataGrid | +-----+ |
| | ActiveItem | | | | | +-----+ |
| | | | | | | | Btn | |
| | | | | | | +-----+ |
| | | | | | | |
| +------------------------------+ | | +----------------------+ |
+----------------------------------+ +----------------------------------+
|
|
|
|
|
|
|
|
V
+----------------------------------+
| NewConnectionView |_|[]|x|
+----------------------------------+
| +------------------------------+ |
| | ComboBox | V | |
| +------------------------------+ |
| +------------------------------+ |
| | | |
| | | |
| | | |
| | ActiveItem | |
| | | |
| | | |
| | | |
| +------------------------------+ |
+----------------------------------+
/ \
/ \
/ \
/ \
/ \
/ \
/ \
+----------------------------------+ +----------------------------------+
| FileConnectionView |_|[]|x| | DatabaseConnectionView |_|[]|x|
+----------------------------------+ +----------------------------------+
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
+----------------------------------+ +----------------------------------+
It sounds like you want to use one instance of the event aggregator for shell/plugin communication, and one instance per plugin for inter-view model communication. I would recommend using both an IoC container and register the shell event aggregator as a singleton, and then using factories which have a reference to the container to resolve instances of your view models.
You could have one message type which changes the display name and is published on the instance of the shell view event aggregator, and one message type which changes the current active item and is used on all event aggregator instances.
Related
I'm currently working on a Localization for my Blazor project. But I'm not so sure about my the file locations. Currently, my file-structrue looks like this:
|
|-- Resources
| |
| |-- Services
| | |
| | |--MyResourceFile.resx
| |
| |--ViewModels
| | |
| | |--MyOtherResourceFile.resx
When adding a new language, i thought you can structure it like this to make it more organized by language:
|
|-- Resources
| |
| |-- en-US
| | |
| | |-- Services
| | | |
| | | |--MyResourceFile.en-US.resx
| | |
| | |-- ViewModels
| | |
| | |--MyOtherResourceFile.en-US.resx
| |
| |-- fr-FR
| |
| |-- Services
| | |
| | |--MyResourceFile.fr-FR.resx
| |
| |-- ViewModels
| |
| |--MyOtherResourceFile.fr-FR.resx
Is this even possible, or should I keep everything in the same Resources-Folder?
I am not sure about the namespaces, because they have to be identical as the cs-class which injects the resx-files with the IStringLocalizer:
namespace WATO.PxApp.Application.ViewModels
{
public class SettingsAdressenViewModel : CustomBaseViewModel
{
#region Dependencies
private readonly IStringLocalizer<SettingsAdressenViewModel> loc;
public SettingsAdressenViewModel(
IStringLocalizer<SettingsAdressenViewModel> loc)
{
this.loc = loc;
}
}
}
Besides that, how can I switch between the languages? currently I Inject the location of the Resources-Folder
serviceCollection.AddLocalization(options => options.ResourcesPath = "Resources");
I have two pages that inherit from the Base class.
In Base, I declared a string, the value of which I set on the A Page. After switching to the B Page, the value of this string is overwritten as empty.
Is there a way to pass this string between these pages?
You are wrong, page A does not share instance data with page B. Although they share the same base class. They are different instances. Inheritance is about extending base classes with extra information. This also means that multiple Page A instances won't share data as well.
+----------------+ +----------------+
| Page A | | Page B |
| +------------+ | | +------------+ |
| | BaseClass | | | | BaseClass | |
| | +--------+ | | | | +--------+ | |
| | | string | | | | | | string | | |
| | +--------+ | | | | +--------+ | |
| +------------+ | | +------------+ |
+----------------+ +----------------+
Who is creating Page A/B? This class can also be responsible to pass data between Page A and B. (passing via contructor/properties)
+------------+
| DataClass |
| +--------+ |
| | string | |
| +--------+ |
+------------+
/ \
+----------------+ +----------------+
| Page A / | | \ Page B |
| +------------+ | | +------------+ |
| | BaseClass | | | | BaseClass | |
| | | | | | | |
| +------------+ | | +------------+ |
+----------------+ +----------------+
For anyone with similar problem I solved it by using design pattern called mono state.
Basically I created public class which has static variables that store values for me. Then I refer to them by creating object of that class.
I was wondering if I could select values from joined tables
my tables are as following:
mysql> desc tblvitsign;
+-----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| vitsignid | int(11) | NO | PRI | NULL | |
| bp | varchar(30) | YES | | NULL | |
| bpstat | varchar(100) | YES | | NULL | |
| hr | varchar(30) | YES | | NULL | |
| hrstat | varchar(100) | YES | | NULL | |
| rr | varchar(30) | YES | | NULL | |
| rrstat | varchar(100) | YES | | NULL | |
| temp | varchar(30) | YES | | NULL | |
| tempstat | varchar(100) | YES | | NULL | |
| weight | varchar(50) | YES | | NULL | |
| height | varchar(30) | YES | | NULL | |
| bmi | varchar(30) | YES | | NULL | |
| bmistatus | varchar(30) | YES | | NULL | |
| patientid | int(11) | YES | MUL | NULL | |
| date | date | YES | | NULL | |
+-----------+--------------+------+-----+---------+-------+
mysql> desc tblpatient;
+--------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| patientid | int(11) | NO | PRI | NULL | |
| lastname | varchar(30) | YES | | NULL | |
| firstname | varchar(30) | YES | | NULL | |
| middlename | varchar(30) | YES | | NULL | |
| gender | varchar(15) | YES | | NULL | |
| birthday | date | YES | | NULL | |
| age | varchar(30) | YES | | NULL | |
+--------------+--------------+------+-----+---------+-------+
i joined them like so:
mysql> select a.lastname, a.firstname, a.middlename, b.bp, b.bpstat, b.hr, b.hrstat, b.rr, b.rrstat, b.temp, b.tempstat,
b.weight, b.height, b.bmi, b.bmistatus from tblpatient a left join
tblvitsign b on a.patientid = b.patientid;
+----------+-------------+------------+--------+--------+------+--------+------+--------+------+----------+--------+--------+-------+-----------+
| lastname | firstname | middlename | bp | bpstat | hr | hrstat | rr | rrstat | temp | tempstat | weight | height | bmi | bmistatus |
+----------+-------------+------------+--------+--------+------+--------+------+--------+------+----------+--------+--------+-------+-----------+
| Smith | Mark | Richards | 120/80 | Normal | 75 | Normal | 15 | Normal | 37 | Normal | 56 | 1.7 | 19.38 | Normal |
+----------+-------------+------------+--------+--------+------+--------+------+--------+------+----------+--------+--------+-------+-----------+
I am making a query for my search bar and I used this query using concat and like functions but it returns an empty set
mysql> select a.lastname, a.firstname, a.middlename, b.bp, b.bpstat,
b.hr, b.hrstat, b.rr, b.rrstat, b.temp, b.tempstat, b.weight,
b.height, b.bmi, b.bmistatus from tblpatient a left join tblvitsign b
on a.patientid = b.patientid where concat('a.lastname', 'a.firstname',
'a.middlename', 'b.bp', 'b.bpstat', 'b.hr', 'b.hrstat', 'b.rr',
'b.rrstat', 'b.temp', 'b.tempstat', 'b.weight', 'b.height', 'b.bmi',
'b.bmistatus') like '%ma%';
Empty set (0.14 sec)
is there a better way of doing this?
I'm trying to filter and sort data from a table based on the number of entries in one column
| OrderID | DateOrdered | EnteredById | OtherData | OtherData2 |
-----------------------------------------------------------------------
| 1 | 2/2/2017 | 3 | asdf | sadfsf |
| 2 | 2/2/2017 | 4 | asdf | sadfsf |
| 3 | 2/3/2017 | 4 | asdf | sadfsf |
| 4 | 2/4/2017 | 3 | asdf | sadfsf |
| 5 | 2/4/2017 | 4 | asdf | sadfsf |
| 6 | 2/6/2017 | 5 | asdf | sadfsf |
This is a C# project, there is a working model set up for the table (Orders)
I need to use Linq with Entity to return an array of objects, the whole row, sorted by the number of orders entered by each EnteredById and only where there has been more than one entry by that EnteredById.
In the end, it should be:
| OrderID | DateOrdered | EnteredById | OtherData | OtherData2 |
-----------------------------------------------------------------------
| 2 | 2/2/2017 | 4 | asdf | sadfsf |
| 3 | 2/3/2017 | 4 | asdf | sadfsf |
| 5 | 2/4/2017 | 4 | asdf | sadfsf |
| 4 | 2/4/2017 | 3 | asdf | sadfsf |
| 1 | 2/2/2017 | 3 | asdf | sadfsf |
The code I've written is an absolute mess so I haven't posted it here. Does anybody have the secret Linq answer?
var result = objListOrder.GroupBy(o=>o.EnteredById).Where((x,groupid)=> x.Count()>1).SelectMany((x,groupid)=>x).OrderBy(o=>o.EnteredById);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a predefined List<string> Wellnames = new List<string>(){"CAM1","CAM2","CAM3"};
I have a text file, which is always in the same format as shown. How do I extract/read the highlighted numbers in the example? i,e. for CAM1 and similarly for CAM2 and CAM3.
here is the excerpt of the file:
1------------------------------------------------------------------------------------------------------------------------------913
ALLOC Allocation/bundle report 10835.0000 Days report step 228, 1 Sep 2015
------------------------------------------------------------------------------------------------------------------------------
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Streamline | | | | | | |
| Bundle | | Surface Rate | Surface Volumes | | | |
|------------------------| Flow |-----------------------------------------------------------------------------------------------------------| Total Reservoir | Pore |PV weighted|
| Start | End | Direct | Oil | Water | Gas | Oil | Water | Gas | Rate | Volume | Pressure |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| | SM3/D | Fraction | SM3/D | Fraction | SM3/D | Fraction | SM3 | SM3 | SM3 | RM3/D | Fraction | RM3 | Bar |
| |-----------------------------------------------------------------------------------------------------------------------------------------------------------|
| CAM1 | | 9.13e-001 | | 3.14e+001 | | 9.13e-001 | | 7.55e+004 | 1.50e+005 | 7.55e+004 | 3.26e+001 | 1.06e+000 | 2.29e+005 | 6.21e+001 |
| CAM1 CAM138 | Outflow | 2.82e-001 | 3.09e-001 | 9.63e+000 | 3.07e-001 | 2.82e-001 | 3.09e-001 | 1.99e+004 | 3.88e+004 | 1.99e+004 | 1.00e+001 | 3.07e-001 | 5.96e+004 | 6.17e+001 |
| CAM1 CAM255 | Outflow | 3.34e-002 | 3.66e-002 | 3.00e+000 | 9.57e-002 | 3.34e-002 | 3.66e-002 | 1.86e+004 | 4.05e+004 | 1.86e+004 | 3.07e+000 | 9.40e-002 | 6.00e+004 | 6.30e+001 |
| CAM1 CAM177 | Outflow | 2.12e-001 | 2.32e-001 | 1.10e+001 | 3.50e-001 | 2.12e-001 | 2.32e-001 | 1.94e+004 | 3.66e+004 | 1.94e+004 | 1.13e+001 | 3.46e-001 | 5.68e+004 | 6.13e+001 |
| CAM1 CAM582 | Outflow | 3.17e-001 | 3.47e-001 | 5.72e+000 | 1.82e-001 | 3.17e-001 | 3.47e-001 | 7.77e+003 | 1.33e+004 | 7.77e+003 | 6.10e+000 | 1.87e-001 | 2.14e+004 | 6.13e+001 |
| CAM1 CAM354 | Outflow | 6.87e-002 | 7.53e-002 | 2.05e+000 | 6.53e-002 | 6.87e-002 | 7.53e-002 | 9.80e+003 | 2.04e+004 | 9.80e+003 | 2.14e+000 | 6.56e-002 | 3.07e+004 | 6.34e+001 |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
this Regex will get you what you need.
#"\|\s+CAM1\s+(\S+)\s+\|\s+\S+\s+\|\s+(\S+)\s+\|\s+\S+\s+\|\s+(\S+)\s+\|\s+\S+\s+\|\s+(\S+)"
just change CAM1 for what you are looking for.
I put together an example for you here
I'm assuming you know how to read the file line-by-line. Once you have a particular data line in a string, you can use the Split() method on the '|' character. You'll get back a zero-based array, with each element holding the data from one column. Index into the array at index 0 and trim the value to check for your identifier CAM1, etc. If it's the one you want, you can grab the other values from their indexes in the array.
Seems like the simplest approach given the rigid data format.
IMO the best approach for solving this, is to iterate the file line by line using a StreamReader and then parsing out the necessary information.
public dynamic Read(string file)
{
using (var streamReader = new StreamReader(File.OpenRead(file))
{
while ((var line = streamReader.ReadLine()) != null)
{
if (line.StartsWith("| CAM", StringComparison.OrdinalIgnoreCase))
{
var columns = line.Split('|').Select(x => x.Trim());
// Parse the values here, put them in a DTO
}
}
}
}