Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
redleader
Aug 18, 2005

Engage according to operational parameters
Weird German B and weird Turkish I/i are essential parts of any text processing toolkit.

Adbot
ADBOT LOVES YOU

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

EssOEss posted:

Sure. But I want to emphasize that I think that is only a small aside to the real issue - using letter-case APIs for comparison is bad software design already on general principles, even if they worked the same.

C# code:
var a = "Waldstraße";
var b = "Waldstrasse";
Console.WriteLine(a.Equals(b, StringComparison.InvariantCultureIgnoreCase));
Console.WriteLine(a.ToLowerInvariant() == b.ToLowerInvariant());
Try it out

That's a useful demonstration, thanks.

Mr Shiny Pants posted:

That is nice, I forgot about the umlaut.

You mean the "ß"? That's a "sharp S" or Eszett. "Umlaut" is an alternative name for the diaeresis accent (two dots over a letter).

LongSack
Jan 17, 2003

SimonChris posted:

In that case, I would make one API endpoint that returns a list of CharacterListItemDTO's for the listbox, and another endpoint that return a FullCharacterDTO, with all character data, including navigation properties. The latter endpoint would .Include() the navigation properties, whereas the former would just ignore them.

That’s the direction I was heading. My DAL classes have Insert, Update and Delete methods, along with a Get method which returns an observable collection and a Read method which returns a single object (and some miscellaneous methods like RaceHasCharacters(int raceId) which is used to determine whether a race can be deleted).

I’m thinking in this instance, Get returns a collection of CharacterDTO objects, where Read returns a FullCharacterDTO object.

Edit: upon reflection, I think that will work pretty well. My homebrew mapping class copies properties based on the DTO class, so both DTO classes can get mapped from the same entity class, if I put all the navigation properties on the entity. Just need to make sure I .Include the right ones to avoid ContextDisposedExceptions.

LongSack fucked around with this message at 01:11 on Feb 3, 2019

Mr Shiny Pants
Nov 12, 2012

Hammerite posted:

You mean the "ß"? That's a "sharp S" or Eszett. "Umlaut" is an alternative name for the diaeresis accent (two dots over a letter).

Crap, you are right.

GI_Clutch
Aug 22, 2000

by Fluffdaddy
Dinosaur Gum
After giving up on trying to deal with WPF years ago, now I'm trying to get my head around MVVM and had a question about XAML and binding. Well, it's more of an intellisense question. It seems like intellisense works in some places, and not in others.

For example, if I wanted to bind a TextBox to a property in my view model, I can use either of these methods, and I get full intellisense. When I type "Ti", I see the TileWidth property from my view model.
code:
<TextBox Text="{Binding TileWidth, UpdateSourceTrigger=PropertyChanged}"/>
<TextBox Text="{Binding Path=TileWidth, UpdateSourceTrigger=PropertyChanged}"/>
But I want to do some validation on my input. From Googling, it seems there's no way to do this in a single line like the above examples. So, instead I configure the binding like below.

code:
<TextBox>
	<Binding Path="TileWidth" UpdateSourceTrigger="PropertyChanged">
		<Binding.ValidationRules>
			<local:NumericInputRule Minimum="1" />
		</Binding.ValidationRules>
	</Binding>
</TextBox>
The TextBox is bound and the validation rule is applied as expected. However, There is no intellisense provided when entering the Path attribute. I need to manually enter the property name. Is that just how it is? It seems weird to me that it would provide it when using a "shortcut" method, but not when being very verbose.

EssOEss
Oct 23, 2006
128-bit approved
I last used XAML a few years ago but yes, it was definitely like that back then - intellisense worked very much part-time only. Just a part of working with XAML, unfortunately.

GI_Clutch
Aug 22, 2000

by Fluffdaddy
Dinosaur Gum
Oh well, at least it does what I need it to do. Now my biggest issue is that the framerate is terrible on my 144Hz G-sync monitor. I enabled my monitor's on screen refresh rate display. Just moving the mouse cursor around when the window has focus and it averages between 30-40fps. It looks so janky. Click on the desktop and it's back to 144. If I move the window to my secondary monitor (60Hz), it runs at 60fps and looks smooth.

Edit: Apparently this is a bug with using the G-sync for windowed and full screen mode setting. If I change to full screen only, then WPF apps are nice and smooth. I think WPF is trying to draw as few frames as necessary when nothing's happening. If I give it focus and don't touch anything, the fps slowly drops until it gets to 2, causing the monitor to drop its refresh rate to match.

GI_Clutch fucked around with this message at 01:25 on Feb 4, 2019

Sad Panda
Sep 22, 2004

I'm a Sad Panda.
I'm a teacher trying to share my VB projects with young learners so they can modify it. Which files are actually important and which will be re-generated on running? The projects will be Windows Form or maybe Console Applications.

I'm thinking...

\NameOfMyProject
\NameOfMyProject\NameOfMyProject.sln
\NameOfMyProject\NameOfMyProject\*.vb, *.vbproj, *.config, *.resx
\NameOfMyProject\NameOfMyProject\My Project\*

And then delete the bin and obj folders which if I'm understanding are created at compilation and are specific to the computer it was built on anyway?

EssOEss
Oct 23, 2006
128-bit approved
If you ask Visual Studio to create a Git repository with a new project, it will create a .gitignore file that lists all the types of stuff that should not be uploaded to a code repository. You can use that as a reference.

ThePeavstenator
Dec 18, 2012

:burger::burger::burger::burger::burger:

Establish the Buns

:burger::burger::burger::burger::burger:
If you're able to just do everything through version control, it has the added bonus of getting new programmers into the habit of using it as a part of their workflow right away. Visual Studio has a decent GUI for Git so they don't have to tackle the command line if that's something you want to avoid.

If you need the repos to be private, GitHub now has free private repos that allow up to 3 contributors, and Bitbucket allows private repos with up to 5.

Mata
Dec 23, 2003
As far as I can tell, Azure's free offering can't be beat (unlimited free private git repos + lfs with devops)

Careful Drums
Oct 30, 2007

by FactsAreUseless

EssOEss posted:

If you ask Visual Studio to create a Git repository with a new project, it will create a .gitignore file that lists all the types of stuff that should not be uploaded to a code repository. You can use that as a reference.

This may be the same one but I always use the VisualStudio.gitignore hosted here:

https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

30 TO 50 FERAL HOG
Mar 2, 2005



Is there a way to repeat a call to an async method when it completes?

Here's a quick bit of pseudocode that illustrates what I'm trying to accomplish. Essentially, I just want a callback when my ParsePageAsync method completes that stores the result and fires up the method again on the same object. It looks like I could potentially do this with ContinueWith but I'm not sure exactly how to go about that.

code:
class MultiScraper
{
    private ConcurrentQueue<string> ScraperPostData { get; set; }

    // Scraper is a class that actually loads the page data and parses it into an object
    private Scraper[] Scrapers { get; set; }

    internal MultiScraper(ConcurrentQueue<string> Data)
    {
        ScraperPostData = Data;
    }

    internal async Task InitializeAsync()
    {
        var Initializers = new Task<Scraper>[10];

        for (int i = 0; i < 10; i++)
        {
            // Construction of the Scraper class is done using a factory as some initialization is async
            Initializers[i] = Scraper.InitializeAsync();
        }

        Scrapers = await Task.WhenAll<Scraper>(Initializers);
    }

    internal void Start()
    {
        for (int i = 0; i < 10; i++)
        {
            string PostData;
            if (ScraperPostData.TryDequeue(out PostData))
            {
                // When this method completes, I would like to basically have a callback that records the result,
                // dequeues another PostData string and calls the method again, repeating until there are no more
                // elements in the queue
                Scraper[i].ParsePageAsync(PostData);
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
    }
}

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

BIGFOOT EROTICA posted:

Is there a way to repeat a call to an async method when it completes?

Here's a quick bit of pseudocode that illustrates what I'm trying to accomplish. Essentially, I just want a callback when my ParsePageAsync method completes that stores the result and fires up the method again on the same object. It looks like I could potentially do this with ContinueWith but I'm not sure exactly how to go about that.


Based on your comment:

code:
   // When this method completes, I would like to basically have a callback that records the result,
                // dequeues another PostData string and calls the method again, repeating until there are no more
                // elements in the queue
It sounds like you want to use a while loop. Am I missing something?

30 TO 50 FERAL HOG
Mar 2, 2005



It seems like there would be abetter way to go about it than just having a big blocking while(true) that checks each task constantly to see if it has completed.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

BIGFOOT EROTICA posted:

It seems like there would be abetter way to go about it than just having a big blocking while(true) that checks each task constantly to see if it has completed.

Why would it have to be an infinite loop?

while (<thing still has data>) {
await <grab something and process it>
}

It's not blocking, because you're awaiting the result.

30 TO 50 FERAL HOG
Mar 2, 2005



Right but I don't just have one object making these requests, i have 10 (or however many) that each have different sessions/cookies etc for scraping

code:
while(thing still has data)
{
	await process[0].doasync();
	await process[1].doasync();
	await process[2].doasync();
	etc
}
The second one wont run until the first await completes and so on.

I could do
code:
List<Task> tasks;

while(thing still has data)
{
	tasks.Add(process[0].doasync());
	tasks.Add(process[1].doasync());
	tasks.Add(process[2].doasync());
	
	await Task.All(tasks);
}
but if they complete at different times I cant immediately requeue it, i have to wait until they all finish

ThePeavstenator
Dec 18, 2012

:burger::burger::burger::burger::burger:

Establish the Buns

:burger::burger::burger::burger::burger:

BIGFOOT EROTICA posted:

Right but I don't just have one object making these requests, i have 10 (or however many) that each have different sessions/cookies etc for scraping

code:
while(thing still has data)
{
	await process[0].doasync();
	await process[1].doasync();
	await process[2].doasync();
	etc
}
The second one wont run until the first await completes and so on.

I could do
code:
List<Task> tasks;

while(thing still has data)
{
	tasks.Add(process[0].doasync());
	tasks.Add(process[1].doasync());
	tasks.Add(process[2].doasync());
	
	await Task.All(tasks);
}
but if they complete at different times I cant immediately requeue it, i have to wait until they all finish

Inside of the doasync() method, put the while loop around whatever async logic you want to continue.

raminasi
Jan 25, 2005

a last drink with no ice
Yeah I think you're overthinking this:
C# code:
public async Task Listen(ConcurrentQueue<string> things)
{
    while (things still has data)
    {
        await DoWhateverAsync();
    }
}

public async Task ListenMultiple(ConcurrentQueue<string> things, int listenerCount)
{
    var listeners = Enumerable.Range(0, listenerCount).Select(_ => Listen(things));
    await Task.WhenAll(listeners);
}

LongSack
Jan 17, 2003

Trying to learn EF Core / .NET Core, so I'm picking a fairly simple project to get started: A time tracking / reporting system. It's going pretty well so far, but I've run up against a bit of a roadblock. I want to produce a time report based on a date range and aggregating all the hours by category (project), so that when my boss ask me "How many hours did you spend on project Foo in February" i can spit out the numbers.

Using LINQ and EF Core 2.1, and I can't quite figure out how to translate this SQL query (ignore the aliases):
SQL code:
select 
  Sheets.Date as sd,
  Categories.Description as cd,
  sum(TimeEntries.Saturday) as sat, 
  sum(TimeEntries.Sunday) as sun,
  sum(TimeEntries.Monday) as mon,
  sum(TimeEntries.Tuesday) as tue,
  sum(TimeEntries.Wednesday) as wed,
  sum(TimeEntries.Thursday) as thu,
  sum(TimeEntries.Friday) as fri
  from Sheets
    inner join TimeEntries 
      on Sheets.SheetId = TimeEntries.SheetId
      inner join Categories
	    on TimeEntries.CategoryId = Categories.CategoryId
  where Sheets.Date >= '2019-01-01'
  group by Categories.Description, Sheets.Date;
into a LINQ query that returns a collection of this entity class:

C# code:
    class TimeReportEntry
    {
        public DateTime Date { get; set; }
        public string Category { get; set; }
        public decimal Saturday { get; set; }
        public decimal Sunday { get; set; }
        public decimal Monday { get; set; }
        public decimal Tuesday { get; set; }
        public decimal Wednesday { get; set; }
        public decimal Thursday { get; set; }
        public decimal Friday { get; set; }
    }
the TimeEntry entity class has SheetId and CategoryId properties with associated Navigation Properties "Sheet" and "Category".

is it doable? Or should I seek a different method (i.e., just load up all the time entries then work on aggregating / totaling them "manually")

TIA

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

LongSack posted:

Trying to learn EF Core / .NET Core, so I'm picking a fairly simple project to get started: A time tracking / reporting system. It's going pretty well so far, but I've run up against a bit of a roadblock. I want to produce a time report based on a date range and aggregating all the hours by category (project), so that when my boss ask me "How many hours did you spend on project Foo in February" i can spit out the numbers.


Question as an aside from the actual problem you're trying to solve:
Is there a reason you're building your own time tracking software when there are literally dozens of applications that handle time tracking already? If it's just for education, that's fine, but if you're seriously rolling your own home-grown time tracking system for your job with the intent of using it for real, then ew.

LongSack
Jan 17, 2003

New Yorp New Yorp posted:

Question as an aside from the actual problem you're trying to solve:
Is there a reason you're building your own time tracking software when there are literally dozens of applications that handle time tracking already? If it's just for education, that's fine, but if you're seriously rolling your own home-grown time tracking system for your job with the intent of using it for real, then ew.

It’s all about learning. To learn stuff (for me, at least), I need to come up with some concrete problem to solve, then solve it. But if you’re asking me whether I use my programs after writing them, then yes, I do. Primarily for two reasons: one, they do exactly what I need them to do, precisely how I need them to do it; and two, only by using them can I figure out what mistakes I’ve made.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

LongSack posted:

It’s all about learning. To learn stuff (for me, at least), I need to come up with some concrete problem to solve, then solve it. But if you’re asking me whether I use my programs after writing them, then yes, I do. Primarily for two reasons: one, they do exactly what I need them to do, precisely how I need them to do it; and two, only by using them can I figure out what mistakes I’ve made.

What you're doing right now is called "reinventing the wheel". It's a tremendous waste of time.

If you're trying to solve the problem of "I need to track time spent on projects", then the solution is "spend 30 minutes finding a good time tracking application", not "spend dozens if not hundreds of hours writing my own bespoke time tracking application".

epswing
Nov 4, 2003

Soiled Meat
LongSack, you are "reinventing the wheel", but I'd only go so far as to say it's a tremendous expenditure of time. Only you can judge if that time is worth it to you personally.

(I also think it's probably not going to be worth it, but I'm just some guy on the internet, what do I know about what you value ;) )

LongSack
Jan 17, 2003

You both miss the point. The point isn’t finding a time tracking app, that’s trivially easy. The point is writing a program that solves a problem and allows me to learn in the process.

Edit: in case I’m not clear, the point isn’t the program, although they are all useful and I use them daily. The point is the process. The design, the coding, the debugging. The learning.

As an example, the first version of my character portfolio app literally had methods that moved data from the screen fields to the database entity fields and back because I did not understand data binding. By version 10, I have learned a lot, including data binding, value converters, MVVM, and so much more. That is the point.

All it costs is time, and if I’m learning, then it’s not wasted time.

LongSack fucked around with this message at 05:01 on Feb 7, 2019

EssOEss
Oct 23, 2006
128-bit approved
Whenever I have tried to do "GROUP BY" with EF Core, it has just given up. I think the EF Core "code to SQL" translations only work on the most basic cases. For complex queries I just define views.

Note that by default EF Core will give up on many queries, download the entire table and then perform the operation on the client side.

You will want to ensure that you configure it to throw an exception when it tries to do this.

LongSack
Jan 17, 2003

EssOEss posted:

Whenever I have tried to do "GROUP BY" with EF Core, it has just given up. I think the EF Core "code to SQL" translations only work on the most basic cases. For complex queries I just define views.

Note that by default EF Core will give up on many queries, download the entire table and then perform the operation on the client side.

You will want to ensure that you configure it to throw an exception when it tries to do this.

Ok, so maybe for this instance, I fall back to ADO..

B-Nasty
May 25, 2005

EssOEss posted:

Whenever I have tried to do "GROUP BY" with EF Core, it has just given up. I think the EF Core "code to SQL" translations only work on the most basic cases. For complex queries I just define views.

Note that by default EF Core will give up on many queries, download the entire table and then perform the operation on the client side.

SQL is a drat-near perfect language for what it does. This is supported by the fact that it remains, largely unchanged, one of the few languages out there that's both still in wide use and older than most software engineers. Sure, manually advancing a DataReader and assigning object properties from columns is boring an tedious, but that's why micro-ORMs exist. Building complex and efficient queries is a bit of an art, and someone even remotely competent with SQL can do a much better job than EFs bumbling, UNION ALL(UNION ALL(UNION ALL) )

raminasi
Jan 25, 2005

a last drink with no ice

New Yorp New Yorp posted:

What you're doing right now is called "reinventing the wheel". It's a tremendous waste of time.

If you're trying to solve the problem of "I need to track time spent on projects", then the solution is "spend 30 minutes finding a good time tracking application", not "spend dozens if not hundreds of hours writing my own bespoke time tracking application".

Reinventing the wheel is perfectly appropriate if you're studying wheel design.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

raminasi posted:

Reinventing the wheel is perfectly appropriate if you're studying wheel design.

Yeah I'm on Long Sack's side here, this is basically how I learn too.

Shy
Mar 20, 2010

New Yorp New Yorp posted:

What you're doing right now is called "reinventing the wheel". It's a tremendous waste of time.

If you're trying to solve the problem of "I need to track time spent on projects", then the solution is "spend 30 minutes finding a good time tracking application", not "spend dozens if not hundreds of hours writing my own bespoke time tracking application".

Why even work as a dev? Most things have already been written by someone, somewhere, to varying degrees of completeness.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
I've worked at and consulted at enough places where NIH syndrome resulted in everyone struggling to use clunky bespoke software that poorly implements a subset of the functionality of any number of robust, SaaS offerings.

Shy
Mar 20, 2010

Good thing the original question wasn't "which robust saas time tracking app we can use in our company", then? It's not a particularly complex idea and a cool project to learn things on.

Potassium Problems
Sep 28, 2001

New Yorp New Yorp posted:

I've worked at and consulted at enough places where NIH syndrome resulted in everyone struggling to use clunky bespoke software that poorly implements a subset of the functionality of any number of robust, SaaS offerings.

Despite my objections, I authored and maintain a clunky bespoke time tracking / ticketing system at my job and this entire topic touches my very soul.

Also more power to Long Sack, let he who has not written a blog throw the first exception

ljw1004
Jan 18, 2005

rum

Potassium Problems posted:

Despite my objections, I authored and maintain a clunky bespoke time tracking / ticketing system at my job and this entire topic touches my very soul. Also more power to Long Sack, let he who has not written a blog throw the first exception

Back in the 90s I wrote my own CMS (powered by PHP, front end Javascript, worked by altering the raw HTML files on the server's disk) and I still like it better than any others...

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

I made an EDI parser in Bash way back in the day using regex and I'm still pretty sure it's being used at that organization to extract order numbers called in a CRON job, despite them having an existing web application that does the same thing.

downout
Jul 6, 2009

I have a really annoying problem that I cannot wrap my head around. I have an interface that constructs concrete classes. I need to create a class that provides new instantiations of a given concrete implementation of the interface based on the string name of the concrete implementation. So the class should look like:

[code=C#]
class IConstructorFactory()
{
public IModelConstructor<IModel> GetModelConstructor(string modelConstructorName)
}
[/code}

[code=C#]
class ConstructorFactory(string typeName) : IConstructorFactory
{
public ModelConstructor<IModel> GetModelConstructor(string modelConstructorName)
{
//what is needed to return a new instance of new ModelConstructorName<IModel>();
}
}
[/code}

What am I missing here?

edit: I guess that didn't work
edit2:updated names to make more sense and fixed syntax problems

downout fucked around with this message at 05:33 on Feb 9, 2019

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

downout posted:

I have a really annoying problem that I cannot wrap my head around. I have an interface that constructs concrete classes. I need to create a class that provides new instantiations of a given concrete implementation of the interface based on the string name of the concrete implementation. So the class should look like:

code:
class IConstructorFactory()
{
public IModelConstructor<IModel> GetModelConstructor(string modelConstructorName)
}
[/code}

[code=C#]
class ConstructorFactory(string typeName) :  IConstructorFactory
{
public ModelConstructor<IModel> GetModelConstructor(string modelConstructorName)
{
//what is needed to return a new instance of new ModelConstructorName<IModel>();
}
}
What am I missing here?

edit: I guess that didn't work
edit2:updated names to make more sense and fixed syntax problems

Not sure if this is your use case (I don't actually know why you need to load a class via string), but you can use reflection to get a type from a string and instantiate it
e.g.
code:
Type t =  Type.GetType("MyNamespace.MyType");
IModelConstructor frmConta = (IModelConstructor)Activator.CreateInstance(t);

downout
Jul 6, 2009

Bruegels Fuckbooks posted:

Not sure if this is your use case (I don't actually know why you need to load a class via string), but you can use reflection to get a type from a string and instantiate it
e.g.
code:
Type t =  Type.GetType("MyNamespace.MyType");
IModelConstructor frmConta = (IModelConstructor)Activator.CreateInstance(t);

The class has to load via string because the class that uses the class only has the string value to identify the type. Unless there is some way I'm missing that the type can be "registered" or recorded. That said the "Activator.CreateInstance" method you provided doesn't actually compile when using interfaces which is kind of the problem. The class that needs the new instantiation doesn't know the model or constructor and can only "get" it by the name of the model or constructor type. It's possible I'm missing some construction of <T> that would fix this. At runtime the client knows the type of those two details.

Adbot
ADBOT LOVES YOU

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

downout posted:

The class has to load via string because the class that uses the class only has the string value to identify the type. Unless there is some way I'm missing that the type can be "registered" or recorded. That said the "Activator.CreateInstance" method you provided doesn't actually compile when using interfaces which is kind of the problem. The class that needs the new instantiation doesn't know the model or constructor and can only "get" it by the name of the model or constructor type. It's possible I'm missing some construction of <T> that would fix this. At runtime the client knows the type of those two details.

code:
var lazyPersonFactory = new Dictionary<string, Func<IThingy>> 
{
    { "Bar", ()=>new Bar() },
    { "Baz", ()=>new Baz() }
};
etc

[edit]
this still smells like a design problem, specifically a dependency inversion problem. Nothing should be "asking" for a specific type. The specific type should be determined and provided by the askee.

New Yorp New Yorp fucked around with this message at 15:16 on Feb 9, 2019

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply