|
I'm going to go one better and assemble a formula 1 engine from kiseka market spare parts
|
|
|
|
|
Don't forget to post a video of its first test run.
Member 13545375 wrote: kiseka market
We drove past there the day (in 2005) before we flew home, when our buses got stuck in a flood downtown.
|
|
|
|
|
Yeah, that's an area to avoid if you can... The city is almost proud to have it as some sort of "right of passage" for those who dare
|
|
|
|
|
Hello, I am trying to match a substring which contains the percent symbol using REGEX W character but it does not seem to work. Below is what I have so far.
string inputString = @"#Test{border-top:Solid blue 1px; border-bottom:1% solid black;}";
string escapedString = Regex.Escape("border-bottom");
string pattern = escapedString + @"\:\s?\d+\W(\s?\w+)*\;?\s?";
Regex rgx = new Regex(pattern);
Match match = rgx.Match(matchedCss);
string matchedString = match.Value;
Console.WriteLine(matchedString);
Console.ReadLine();
The REGEX pattern above should have matched the substring
border-bottom:1% solid black; but for some reason it did not. Please help me resolve this problem, thanks in advance.
modified 29-Nov-17 21:45pm.
|
|
|
|
|
You don't need to escape the colon maybe?
And probably not the semi-colon either?
And after all the begging I had to do to get Chris to add a Regular Expressions Forum[^] , too.
|
|
|
|
|
Hi, thanks for your reply. I have updated my pattern by eliminating the back slash in front of the colon and semicolon as you have suggested. However, it still does not work. Below is the updated pattern
pattern = escapedString + @":\s?\d+\W(\s?\w+)*\s?;?\s?";
modified 29-Nov-17 22:35pm.
|
|
|
|
|
It works for
string inputString = @"#Test{border-top:Solid blue 1px; border-bottom:1% solid black;}";
I put the code provided in VS and got:
Error 1 The name 'matchedCss' does not exist in the current context F:\Project\PlayGround\Playground\Form1.cs 757 56 Playground
So, what text are you actually trying to match?
|
|
|
|
|
ehm:
string inputString = @"#Test{border-top:Solid blue 1px; border-bottom:1% solid black;}";
string escapedString = Regex.Escape("border-bottom");
string pattern = escapedString + @"\:\s?\d+\W(\s?\w+)*\;?\s?";
Regex rgx = new Regex(pattern);
Match match = rgx.Match(inputString);
string matchedString = match.Value;
Console.WriteLine(matchedString);
It works for me. At least when I set the inputString to match you expression.
|
|
|
|
|
It is now working. It was driving me nuts, after everything failed I decided to restart Visual Studio and it started working.
|
|
|
|
|
Rule 1: Whenever a problem goes away on its own, it will come back on its own.
|
|
|
|
|
Means the code that you were looking at was not the code that was running.
Perhaps because it was running a prior build rather than with your updates.
|
|
|
|
|
public async Task<List<ActiveDirectoryUser>> ImportUsersAsync(string basePath)
{
return await Task.Run(() =>
{
List<ActiveDirectoryUser> users = new List<ActiveDirectoryUser>();
var rootEntry = new DirectoryEntry(basePath);
var searcher = new DirectorySearcher(rootEntry);
SearchResultCollection results = searcher.FindAll();
if (results != null)
{
foreach (SearchResult result in results)
{
ActiveDirectoryUser user = new ActiveDirectoryUser();
if (result.Properties.Contains("displayname"))
{
user.DisplayName = (string)result.Properties["displayname"][0];
user.LoginName = (string)result.Properties["samaccountname"][0];
foreach (var prop in result.Properties)
{
DictionaryEntry de = (DictionaryEntry)prop;
ResultPropertyValueCollection rpvc = (ResultPropertyValueCollection)de.Value;
user.Properties.Add(de.Key.ToString(), rpvc[0].ToString());
}
users.Add(user);
}
}
}
return users;
});
}
now, when i run it:
ActiveDirectoryHelper adHelper = new ActiveDirectoryHelper();
var users = adHelper.ImportUsersAsync(basePath);
var user = adHelper.GetUserInfo(serverName, userName);
Console.WriteLine("Done");
How can I know when the async method finished?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
modified 29-Nov-17 12:17pm.
|
|
|
|
|
You don't. The way you set it up, it's "fire and forget".
You've got the await in the wrong place. That should go on the callers side, not the function ...Async side. The Async method should return a Task. That lets the caller await the Task.
Something like this:
private Task<List<string>> GetUsersAsync()
{
return Task.Run(() =>
{
List<string> userList = new List<string>() {
"User1", "User2", "User3", "User4", "User5"
};
Thread.Sleep(5000);
return userList;
});
}
Then you can call it like this (very simple Windows Forms example):
private async void button1_Click(object sender, EventArgs e)
{
var users = await GetUsersAsync();
foreach (string user in users)
{
listBox1.Items.Add(user);
}
}
Is this production quality code? NO! It's meant to be a simple example demonstrating Task/Async/Await. It doesn't handle exceptions and doesn't make sure the Click handler doesn't get called again while the first Task is still running.
System.ItDidntWorkException: Something didn't work as expected.
C# - How to debug code[ ^].
Seriously, go read these articles.
Dave Kreskowiak
|
|
|
|
|
Thank you!
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
var users = adHelper.ImportUsersAsync(basePath);
change in
var users = adHelper.ImportUsersAsync(basePath).Result;
|
|
|
|
|
That's not going to fix the problem at all and you're really not even changing the code. The .Result is implied in the original post.
System.ItDidntWorkException: Something didn't work as expected.
C# - How to debug code[ ^].
Seriously, go read these articles.
Dave Kreskowiak
|
|
|
|
|
No it is not implied... He is just assigning a non started Task to user.
As long as he doesnt await user() or user.Result... Then nothing ever happens with it.
|
|
|
|
|
Oh no... That Result there is making a sync method out of the async method. And Result shouldn't be used like that... You are asking for deadlocks that way.
|
|
|
|
|
Hi,
I am working on Simple injector DI framework. I need good ideas on how to register interface which is consumed in more than one provider (component).
Below is my requirement.
It is WebAPI project where I have a BaggageController class which will get a request for Add Baggage operation, Based on a provider from the request I have to route the request to concerned class. A Provider can be an Airline A or Airline B.
Request for AddBaggage(BaggageRequest, Provider) from client
--> BaggageController --> Business.Baggage.Implementation (Decision) --> Call Provider A
--> Call Provider B
Below is the code I am registering with Simple injector.
container.Register<ibaggageservice, baggageservice="">(Lifestyle.Scoped);
container.Register<iflightservice, providera="">(Lifestyle.Scoped);
container.Register<iflightservice, providerb="">(Lifestyle.Scoped); --> This line throws an error as IFlightService is already registered.
Since my decision would be taken at runtime, I can not use the RegisterConditional method.
Is there any other way to register dependency at runtime using simple injector?
Thank you
|
|
|
|
|
How would the application know which of the two to create, based on only knowing IFlightService? Register a ProviderStrategy that returns either ProviderA or ProviderB.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
In order to do this, Could you please share some example? I have been searching it from quite a long time.
|
|
|
|
|
Nope, just a description. Instead of registering two different classes for a single interface,
container.Register<IFlightService, ProviderA>(Lifestyle.Scoped); You want one class to register. That one class should invoke the required stuff for either ProviderA or ProviderB.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I have a set of calculation methods (10) that return a list of decimals, what is the best (simplest) way to invoke the methods and get the return list of decimals?
public void CalcKeyRef()
{
foreach (KeyRefDB oKR in lAllKeyRef)
{
string sMethod = string.Format("DoKR{0}", oKR.KeyRefID);
List<decimal> lResults = ????
}
}
private List<decimal> DoKR1(List<decimal> lResults)
{
lResults = new List<decimal>();
return lResults;
}
Never underestimate the power of human stupidity
RAH
modified 28-Nov-17 20:28pm.
|
|
|
|
|
All you have are the names of the methods?
Where do they come from?
How often do you need to do this?
|
|
|
|
|
You could use reflection: https://www.dotnetperls.com/getmethod
or perhaps an array of delegates:
public delegate List<decimal> DoKR(List<decimal> lResults);
public DoKR[] DoKRs;
public void SomeInit()
{
DoKRs = new DoKR[] { DoKR1, DoKR2, DoKR3, ... };
}
public void CalcKeyRef()
{
List<decimal> param = new List<decimal>();
foreach (KeyRefDB oKR in lAllKeyRef)
{
List<decimal> lResults = DoKRs[oKR.KeyRefID](param);
}
}
|
|
|
|