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");
Related
The following code is my Scenario:
Scenario: TradeOrders
Given Order 'SellOrder' Has Been Registerd
| Side | Price | Amount | IsFillAndKill | ExpireTime |
| 0 | 100 | 5 | false | 2024-02-05 09:30:26.2080000 |
And Order 'BuyOrder' Has Been Defined
| Side | Price | Amount | IsFillAndKill | ExpireTime |
| <Buy> | <Price> | <Amount> | <IsFillAndKill> | <ExpireTime> |
When I Register The Order 'BuyOrder'
Then The following 'Trade' will be created
| BuyOrderId | SellOrderId | Amount | Price |
| <BuyOrderId> | <SellOrderId> | <TradeAmount> | <TradePrice> |
And BuyOrder 'BuyOrder' Should Be Modified like this
| Side | Price | Amount | IsFillAndKill | ExpireTime |
| 1 | 100 | 0 | false | 2024-02-05 09:30:26.2080000 |
Examples:
| Buy | Price | Amount | IsFillAndKill | ExpireTime |
| 1 | 100 | 5 | false | 2024-02-05 09:30:26.2080000 |
Examples:
| <BuyOrderId> | <SellOrderId> | <TradeAmount> | <TradePrice> |
| 1 | 2 | 5 | 100 |
I want to add some examples with different columns but I have faced with below error:
Severity Code Description Project File Line Suppression State
Error Generation error: Message: The example sets must provide the
same parameters.
I appreciate you in advance.
This is not supported in SpecFlow. Since both tables are used in the same scenario, they need to go in the same row. It makes for a wide table, but there isn't anything you can do about it. Second of all, you cannot have < or > tokens in the column headers.
Examples:
| Buy | Price | Amount | IsFillAndKill | ExpireTime | BuyOrderId | SellOrderId | TradeAmount | TradePrice |
| 1 | 100 | 5 | false | 2024-02-05 09:30:26.2080000 | 1 | 2 | 5 | 100 |
You can also put spaces in the column headers so they are easier to read:
Examples:
| Buy | Price | Amount | Is Fill And Kill | Expire Time | Buy Order Id | Sell Order Id | Trade Amount | Trade Price |
| 1 | 100 | 5 | false | 2024-02-05 09:30:26.2080000 | 1 | 2 | 5 | 100 |
The choice to include spaces in column headers is subjective. It is supported to aid readability, but feel free to omit spaces if this does not make the examples table easier to understand.
Let's say my database table Agents is the following,
+------------+----------------------+--------------------+------------+-----------------+---------+
| AgentCode | AgentName | WorkingArea | Commission | PhoneNo | Country |
+------------+----------------------+--------------------+------------+-----------------+---------+
| A007 | Ramasundar | Bangalore | 0.15 | 077-25814763 | |
| A003 | Alex | London | 0.13 | 075-12458969 | |
| A008 | Alford | New York | 0.12 | 044-25874365 | |
| A011 | Ravi Kumar | Bangalore | 0.15 | 077-45625874 | |
| A010 | Santakumar | Chennai | 0.14 | 007-22388644 | |
| A012 | Lucida | San Jose | 0.12 | 044-52981425 | |
| A005 | Anderson | Brisban | 0.13 | 045-21447739 | |
| A001 | Subbarao | Bangalore | 0.14 | 077-12346674 | |
| A002 | Mukesh | Mumbai | 0.11 | 029-12358964 | |
| A006 | McDen | London | 0.15 | 078-22255588 | |
| A004 | Ivan | Torento | 0.15 | 008-22544166 | |
| A009 | Benjamin | Hampshair | 0.11 | 008-22536178 | |
+------------+----------------------+--------------------+------------+-----------------+---------+
What I exactly need to query is as the following(in SQL for better understanding).
SELECT WorkingArea, MIN(Commission)
FROM agents
GROUP BY WorkingArea;
And its result is:-
WorkingArea MIN(Commission)
----------------------------------- ---------------
San Jose .12
Torento .15
London .13
Hampshair .11
New York .12
Brisban .13
Bangalore .14
Chennai .14
Mumbai .11
How can I do the same with .NET Entity Framework?
I tried the following. But it gave me only the MIN(COMMISSION) row.
IEnumerable<Agent> AgentList = _db.Agents
.GroupBy(fields => fields.WorkingArea)
.Select(fields => new Agent
{
Commission = fields.Min(fields => fields.Commission)
});
// If my Model name is Agent its corresponding database table name will be Agent**s**.
Update 1--------------------------------------------------------------------------------------------------
1. How can I do the equivalent to the sql query above, with .NET Entity Framework?
2. What if I want add also the PhoneNo column to the result? like
SELECT WorkingArea, MIN(Commission), PhoneNo
FROM agents
GROUP BY WorkingArea;
You need another type (not Agent) for the result output. Either define a two-field class
class WorkingAreaCommission
{
public string WorkingArea { get; set; }
public double Commission { get; set; }
}
or use anonymous type:
var AgentList = _db.Agents
.GroupBy(fields => fields.WorkingArea)
.Select(fields => new
{
WorkingArea = fields.Key,
Commission = fields.Min(fields => fields.Commission)
});
Update (to answer a question from comments)
If you need result containing more than just key and minimal values, sort by the field you need minimal value from and extract all required fields from the first record:
var AgentList = _db.Agents
.GroupBy(fields => fields.WorkingArea)
.Select(fields => fields
.OrderBy(x => x.Commission)
.Select(x => new {
WorkingArea = x.WorkingArea,
PhoneNo = x.PhoneNo,
Commission = x.Commission
})
.First()
);
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.
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
}
}
}
}
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.