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
ljw1004
Jan 18, 2005

rum

Drastic Actions posted:

The easiest thing to fix right now is getting rid of hard coded strings and putting them into the resources files. They originally did not have any and everything was hard coded into English in the XAML. I built the English and Japanese Resw files

DON'T USE RESW DIRECTLY!

You should have the single primary language in RESW, and then use XLF files (from the Multilingual App Toolkit) for all other languages. XLF+MAT is the only sane way to manage your translation workflow.

Adbot
ADBOT LOVES YOU

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

ljw1004 posted:

DON'T USE RESW DIRECTLY!

You should have the single primary language in RESW, and then use XLF files (from the Multilingual App Toolkit) for all other languages. XLF+MAT is the only sane way to manage your translation workflow.

My PSN FoulPlay app use XLF, but they won't let me use it here. From what I recall you have to install the Multilingual Toolkit if it's being used, they did not want to have contributors have to install more extra tools just to compile the app (considering I'm the only one at this point who cares about localization).
Nevermind the fact that they don't really have any contributors, but whatever. I'm not sure if there was any other reasons not to. But yeah, XLF and the toolkit make it much easier to actually handle updating everything. I should start pushing for it again.

And also note, these are people who won't update the C++ VCLibs up to version 12, because it causes issues with the app validation and instead of trying to fix it just use the unsupported 11. I just roll with it at this point.

Fuck them
Jan 21, 2011

and their bullshit
:yotj:
I still don't know LINQ to SQL for poo poo.

code:
SELECT Distinct I.trTypeID, T.Category 

FROM [$TABLE].[dbo].[trItem] As I

JOIN [$DIFFERENT_TABLE].[dbo].[trType] As T

On T.trTypeID = I.trTypeID
I've been fiddling with how to turn this into LINQ all day (vb.net, don't laugh, but meh) and just can't figure it out.

Furthermore, I'm not quite sure how to make it into a nice easy to handle associative array to serialize for some knockout for a selectedOptions binding.

XYProblem Explanation:

I've got a big hunk of lovely data. Meh. I want to allow the user to select a bunch of "types" to help drill down queries. Most of the types in the types table are never used. So, select distinct on the actual table of crap, find the unique types that are actually used, join them on the type table to see the description of them, pass that to user. Also, a lot of the types are duplicated - there are three which are categorized as "File", three as "FILE," etc. Input validation didn't occur to anyone apparently! Trying to help drill down with that might be fun. I figure I just might let the user select "File" and just return for all 3 types that match, etc.

Nobody has any documentation about it, they just want it to work. Soon.

I usually use sprocs and ADO.net, but figured I might as well use a little LINQ and make use of the EF scaffolding this project has in it, as I've never done it before and thought I might learn some new things.

I'll get a LINQ book (or just a good .net book) tomorrow when I finally get that first direct hire paycheck :yotj:

Fuck them fucked around with this message at 19:34 on Aug 28, 2014

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

gently caress them posted:

I still don't know LINQ to SQL for poo poo.

Pedantic terminology note: LINQ to SQL is not interchangeable with Entity Framework, they are similar-but-different ORM platforms. L2S is dead, EF is not. You probably mean LINQ to Entities.

Fuck them
Jan 21, 2011

and their bullshit
:yotj:

Ithaqua posted:

Pedantic terminology note: LINQ to SQL is not interchangeable with Entity Framework, they are similar-but-different ORM platforms. L2S is dead, EF is not. You probably mean LINQ to Entities.

I'm the only one here who actually cares about staying current at all, so that's actually useful knowledge to have for when I decide to take the next step and leave this bubble!

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal

gently caress them posted:

I still don't know LINQ to SQL for poo poo.

code:
SELECT Distinct I.trTypeID, T.Category 

FROM [$TABLE].[dbo].[trItem] As I

JOIN [$TABLE].[dbo].[trType] As T

On T.trTypeID = I.trTypeID

If you're using Entity Framework here is an example of a Linq query that does a lot of what you need to do:
code:
query = from t in query
        join sm in _storeMappingRepository.Table
        on new { c1 = t.Id, c2 = "Topic" } equals new { c1 = sm.EntityId, c2 = sm.EntityName } into t_sm
        from sm in t_sm.DefaultIfEmpty()
        where !t.LimitedToStores || storeId == sm.StoreId
        select t;
Another way with methods (not sure if this has the methods you'd need):
code:
var query = _topicRepository.Table;
query = query.Where(t => t.SystemName == systemName);
query = query.OrderBy(t => t.Id);
Edit I'm pretty sure there is a .Distinct() method or similar that you would call after building the query. Something like query = query.Distinct().

Knyteguy fucked around with this message at 19:41 on Aug 28, 2014

Fuck them
Jan 21, 2011

and their bullshit
:yotj:
I think stopping to take a break helped me get it. FIGURES.

code:
        Dim typeIDs = _
        (From I In context.trItems
        Join T In context.trTypes
        On I.trTypeID Equals T.trTypeID
        Select T).Distinct()
Time to test now.

I really need to nag work into getting me a linqpad license.

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal

gently caress them posted:

I think stopping to take a break helped me get it. FIGURES.

code:
        Dim typeIDs = _
        (From I In context.trItems
        Join T In context.trTypes
        On I.trTypeID Equals T.trTypeID
        Select T).Distinct()
Time to test now.

I really need to nag work into getting me a linqpad license.

Ah sorry forgot it was VB.

Fuck them
Jan 21, 2011

and their bullshit
:yotj:

Knyteguy posted:

Ah sorry forgot it was VB.

I'd like to forget it is too :downs:

Fuck them
Jan 21, 2011

and their bullshit
:yotj:
Holy poo poo the generated SQL from this:
http://pastebin.ca/2836448

Dietrich
Sep 11, 2001

Do you need every property from both of the joined tables?

Chill Callahan
Nov 14, 2012
That generated SQL isn't that bad (other than obviously the SELECT *--you probably don't need every column), it just boils down to this:

code:
SELECT *
FROM ( SELECT DISTINCT *
	INNER JOIN (SELECT *
      FROM [dbo].[trType] AS [trType]) AS [Extent2] ON [Extent1].[trTypeID] = [Extent2].[trTypeID]
)  AS [Distinct1]
The real strange thing is your table structure.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Yeah, every time I see columns with Something1, Something2, Something3 that usually indicates a normalization problem.

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


Am I the only one who thinks chaining dot-notation function calls is a gently caress of a lot easier to read? Or is that my C++ background showing? :v:

C# code:
var q = collectionOfFarts
            .Where(x => x.NumFarts > LOTS_OF_FARTS)
            .Select(x => new { x.StinkLevel, x.NumPeopleWhoNoticed })
            .OrderBy(x => x.StinkLevel)
        ;
that OrderBy after the Select is probably wrong, I always seem to gently caress that up either way

Gul Banana
Nov 28, 2003

I think it is, until you want a bunch of range variables sugared. VB makes it more awkward, though - it doesn't allow you to place the periods at the beginnings of lines like that.

mortarr
Apr 28, 2005

frozen meat at high speed

Ciaphas posted:

Am I the only one who thinks chaining dot-notation function calls is a gently caress of a lot easier to read? Or is that my C++ background showing? :v:

Nope, I was writing sql for years before linq was a thing, and I just don't like the way it looks. I always get tangled up mentally translating its syntax back to actual sql and it pisses me off to need to hit google for every goddamn query I try to write that way, so I always end up either writing a view for complex joins / selects and doing the dot notation thing like yourself for the basics.

I'm lucky in that I'm able to write my own views and procs etc I guess, seems like I might be in the minority in here? Don't know how I'd get on if I wasn't able to do that.

Che Delilas
Nov 23, 2009
FREE TIBET WEED
I definitely prefer the fluent (dot) notation. It looks cleaner and more structured, everything separated out clearly into methods, which you can order the way you like (for me, that means in a way that's as close to an SQL query as possible, since I'm familiar with those to begin with; Select -> Where -> OrderBy -> etc.). Beyond that, the fluent notation has a bunch of extension methods that do not have an equivalent in the query notation, so if you need any of those, you're using the fluent notation anyway. FirstOrDefault, Take and Skip immediately come to mind.

Or you can be a horrible horrible monster and do something like:
C# code:
var result =	(from p in db.Products
				where p.Id == selectedId
				select p).FirstOrDefault();
Ewg.

Che Delilas fucked around with this message at 15:50 on Aug 29, 2014

raminasi
Jan 25, 2005

a last drink with no ice
I only use the fluent notation because I don't use LINQ for database operations so I figured that if I'm writing C# it might as well actually look like C#.

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


Assuming the resulting IEnumerable or whatever is the same, the order of your fluent-syntax calls doesn't have an effect on performance, does it? Like doing the .OrderBy() before or after the .Select() or whatever?

raminasi
Jan 25, 2005

a last drink with no ice

Ciaphas posted:

Assuming the resulting IEnumerable or whatever is the same, the order of your fluent-syntax calls doesn't have an effect on performance, does it? Like doing the .OrderBy() before or after the .Select() or whatever?

That's a very strong assumption. Can you give an example of when it holds that you're talking about?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Ciaphas posted:

Assuming the resulting IEnumerable or whatever is the same, the order of your fluent-syntax calls doesn't have an effect on performance, does it? Like doing the .OrderBy() before or after the .Select() or whatever?

At least with LINQ to Objects, the answer is "of course it makes a difference." I can't speak to the SQL generated by LINQ to Entities. It's usually fairly smart about that kind of thing, but it's safer to assume it's dumb.

Let's say you do this:
code:
var result = fooCollection.OrderBy(x=>x.Id)
.Where(x=>x.Value > 100);
That's going to iterate the entire fooCollection to order it. Then it's going to iterate the entire ordered fooCollection to filter it. You have two full iterations of the initial collection.

If you do
code:
var result = fooCollection.Where(x=>x.Value > 100)
.OrderBy(x=>x.Id);
It's going to filter it first, then order the resulting collection. If the initial collection is large and the filtered collection is small, that could make a giant difference.

Che Delilas
Nov 23, 2009
FREE TIBET WEED

Ithaqua posted:

At least with LINQ to Objects, the answer is "of course it makes a difference." I can't speak to the SQL generated by LINQ to Entities. It's usually fairly smart about that kind of thing, but it's safer to assume it's dumb.

So, with Linq to Objects, it actually executes each method immediately, rather than waiting for the results to actually be accessed (the way I understand it does with EF)?

epswing
Nov 4, 2003

Soiled Meat

Che Delilas posted:

So, with Linq to Objects, it actually executes each method immediately, rather than waiting for the results to actually be accessed (the way I understand it does with EF)?

I don't believe so.

code:
var result = fooCollection.Where(x=>x.Value > 100)
                          .OrderBy(x=>x.Id); // no work has been done yet

foreach (var item in result) // Where and OrderBy are executed right here
{
    // do stuff
}
(Right guys?)

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


Ithaqua posted:

At least with LINQ to Objects, the answer is "of course it makes a difference." I can't speak to the SQL generated by LINQ to Entities. It's usually fairly smart about that kind of thing, but it's safer to assume it's dumb.

Let's say you do this:
code:
var result = fooCollection.OrderBy(x=>x.Id)
.Where(x=>x.Value > 100);
That's going to iterate the entire fooCollection to order it. Then it's going to iterate the entire ordered fooCollection to filter it. You have two full iterations of the initial collection.

If you do
code:
var result = fooCollection.Where(x=>x.Value > 100)
.OrderBy(x=>x.Id);
It's going to filter it first, then order the resulting collection. If the initial collection is large and the filtered collection is small, that could make a giant difference.

That was kind of what I figured, but I wanted to be sure. So much of C# and .NET seems like frank witchcraft to me still :v:

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

epalm posted:

I don't believe so.

code:
var result = fooCollection.Where(x=>x.Value > 100)
                          .OrderBy(x=>x.Id); // no work has been done yet

foreach (var item in result) // Where and OrderBy are executed right here
{
    // do stuff
}
(Right guys?)

Right. LINQ to Objects methods execute lazily. In the example above, it doesn't start executing the Where or the OrderBy until you start accessing the values in result.

New Yorp New Yorp fucked around with this message at 17:21 on Aug 29, 2014

ninjeff
Jan 19, 2004

gently caress them posted:

I think stopping to take a break helped me get it. FIGURES.

code:
        Dim typeIDs = _
        (From I In context.trItems
        Join T In context.trTypes
        On I.trTypeID Equals T.trTypeID
        Select T).Distinct()
Time to test now.

I really need to nag work into getting me a linqpad license.

Change this to:
code:
Dim typeIDs = From i In context.trItems
              Join t In context.trTypes On i.trTypeID Equals t.trTypeID
              Select i.trTypeID, t.Category
              Distinct
and you will find a) the LINQ query easier to read and b) the generated SQL much faster.

Sedro
Dec 31, 2008

Ithaqua posted:

Right. LINQ to Objects methods execute lazily. In the example above, it doesn't start executing the Where or the OrderBy until you start accessing the values in result.
OrderBy is a little special because you need to materialize the entire collection in order to produce the first item. It might as well return a list.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Sedro posted:

OrderBy is a little special because you need to materialize the entire collection in order to produce the first item. It might as well return a list.

Right, because it can't know what the first element to return should be until it's reached the last element.

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog
How many of you guys use ILSpy? I started using it because it was easier than getting my employer to pay for Reflector licenses and I've always found the UI a bit clunky. I've started using some of my free time to fix issues that I personally have; does anybody else have any grievances that they'd like someone to look at?

RICHUNCLEPENNYBAGS
Dec 21, 2010

Smugdog Millionaire posted:

How many of you guys use ILSpy? I started using it because it was easier than getting my employer to pay for Reflector licenses and I've always found the UI a bit clunky. I've started using some of my free time to fix issues that I personally have; does anybody else have any grievances that they'd like someone to look at?

dotPeek is available for free too.

spiderlemur
Nov 6, 2010
Is there a good way to integrate certain CMS features into an existing site without having to full on use a CMS? I don't want the CMS taking over the site and disrupting what has already been written, I just need a small portion of that site to support say, creating and displaying articles, with the other site pages / part of the homepage undisturbed.

Are there libraries out there that make it easy to add these kinds of features into an existing site or is the best way just to write it all myself? I'm using MVC.

RICHUNCLEPENNYBAGS
Dec 21, 2010

spiderlemur posted:

Is there a good way to integrate certain CMS features into an existing site without having to full on use a CMS? I don't want the CMS taking over the site and disrupting what has already been written, I just need a small portion of that site to support say, creating and displaying articles, with the other site pages / part of the homepage undisturbed.

Are there libraries out there that make it easy to add these kinds of features into an existing site or is the best way just to write it all myself? I'm using MVC.

Well, depends what you want to do but maybe you can have the two products communicate with a plain old REST API.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

spiderlemur posted:

Is there a good way to integrate certain CMS features into an existing site without having to full on use a CMS? I don't want the CMS taking over the site and disrupting what has already been written, I just need a small portion of that site to support say, creating and displaying articles, with the other site pages / part of the homepage undisturbed.

Are there libraries out there that make it easy to add these kinds of features into an existing site or is the best way just to write it all myself? I'm using MVC.

I think it's possible to convert an existing MVC site into an Orchard module, maybe you could look into that?

Or if that's too complicated, why not just make parts of the site dynamically generated, and only provide editors for those specific parts?

RICHUNCLEPENNYBAGS
Dec 21, 2010

chmods please posted:

I think it's possible to convert an existing MVC site into an Orchard module, maybe you could look into that?

Or if that's too complicated, why not just make parts of the site dynamically generated, and only provide editors for those specific parts?

If that's all you're looking at it's hard to see what the CMS is really giving you over throwing TinyMCE or something over a textbox.

spiderlemur
Nov 6, 2010

RICHUNCLEPENNYBAGS posted:

Well, depends what you want to do but maybe you can have the two products communicate with a plain old REST API.

That's what I was thinking about doing initially, so I'll probably just go with that if there's not some other obvious solution I'm not thinking of.

wwb
Aug 17, 2004

If it is basic "we want humans to do formatted text" we have gone with markdown, perhaps with a raw html saftey valve. Much, much cleaner to deal with than the poo poo the rich text editors spit out.

Another approach is to use some reverse proxy voodoo to poke holes in the CMS-based site for your app. If the parts are self-contained this works real good.

Another thing we are doing a lot of these days is building the custom bits as an mvc specialized content manager serving a web api and then handing the api off to the web hippies to integrate. The main challenge has been that the web hippies suck at specifying what they need to come off the API so you usually get to build that part 3 times. The massive advantage is we can let the web hippies use whatever they want to smoke that week without having to inhale.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

This is a relatively simple question, but I can't seem to google-fu my way to an answer. I'm reading a CSV file like so:
code:
Dim afile As FileIO.TextFieldParser = New FileIO.TextFieldParser("c:\" & filename)
Dim csv As String()
afile.TextFieldType = FileIO.FieldType.Delimited
afile.Delimiters = New String() {","}
afile.HasFieldsEnclosedInQuotes = False

Do While Not afile.EndOfData
 csv = afile.ReadFields
 If csv(0) <> "Col1" AndAlso csv(0) <> "" AndAlso csv(0) <> "LOL I'M A DICKBAG AND DON'T UNDERSTAND CSV SUPERFLUOUS TITLE" Then
  'stuff with csv(0) and csv(1) and so on
 End If
Loop
Except the CSVs I have to read are made by a dickbag who doesn't understand what the gently caress they are for and has this beautiful setup:
code:
Col1,Col2,Col3
Value1,Value2,Value3
(lots of data)
(empty line break)
LOL I'M A DICKBAG AND DON'T UNDERSTAND CSV SUPERFLUOUS TITLE
Value1,Value2,Value3
(lots more data)
My code works, up until the empty line and then it stops parsing and won't touch anything that comes after. At first I thought 'aw crap, it's treating the new line as EndOfData', but some research shows that this apparently is not the case with TextFieldParser:
http://social.msdn.microsoft.com/Fo...orum=vblanguage

According to the documentation I can find, TextFieldParser should keep going until EOF, since it apparently ignores empty lines. I had thought my IF statement above would skip the offending line(s) and keep beavering on, but apparently not. Has anyone run into something like this and have a solution?

mortarr
Apr 28, 2005

frozen meat at high speed
Does anyone have any ideas on how to take a querystring like so:

code:
take=20
&skip=20
&page=2
&pageSize=20
&sort[0][field]=JobBagNumber&sort[0][dir]=asc
&filter[logic]=or&filter[filters][0][value]=what&filter[filters][0][operator]=eq&filter[filters][0][field]=JobBagNumber
&filter[filters][1][value]=what&filter[filters][1][operator]=contains&filter[filters][1][field]=State
&filter[filters][2][value]=what&filter[filters][2][operator]=contains&filter[filters][2][field]=Title
and parse it into a dynamic / expando object based on json like so:

code:
{
  take: "20",
  ...
  sort: [ { field: "JobBagNumber" }, { dir: "asc" } ],
  filter: { 
    logic: "or", 
    filters: [ { value: "what", operator: "eq", field: "JobBagNumber" }, ... ]
  },
  ...
}
I've been bashing my head against a brick wall all day on this goddamn thing.


Edit: gently caress me, just figured out a way to post this data as json instead, now I don't need to do this at all. 15 years of cutting code and I still miss the basics sometimes!

mortarr fucked around with this message at 05:04 on Sep 4, 2014

ljw1004
Jan 18, 2005

rum

Scaramouche posted:

This is a relatively simple question, but I can't seem to google-fu my way to an answer. [snip]

It looks like TextFieldParser doesn't actually buy you much in this situation, and is more trouble than it's worth. I'd do it like this:

code:
Using afile As New IO.StreamReader("TextFile1.csv")
    afile.ReadLine() ' discard the first row, which contains column headings
    While Not afile.EndOfStream
        Dim line = afile.ReadLine()
        Dim csv = line.Split(","c)
        If csv.Count <> 3 Then Continue While
        Console.WriteLine("{0}...{1}...{2}", csv(0), csv(1), csv(2))
    End While
End Using
You'll need some heuristic for how to detect column headings, and blank lines, and subtitles. In your code your heuristic was to look for the exact content. I picked different heuristics in the hope that they'd be more general (i.e. wouldn't need you rewriting your code when the CSV starts looking slightly different).

Adbot
ADBOT LOVES YOU

raminasi
Jan 25, 2005

a last drink with no ice

mortarr posted:

Does anyone have any ideas on how to take a querystring like so:

code:
take=20
&skip=20
&page=2
&pageSize=20
&sort[0][field]=JobBagNumber&sort[0][dir]=asc
&filter[logic]=or&filter[filters][0][value]=what&filter[filters][0][operator]=eq&filter[filters][0][field]=JobBagNumber
&filter[filters][1][value]=what&filter[filters][1][operator]=contains&filter[filters][1][field]=State
&filter[filters][2][value]=what&filter[filters][2][operator]=contains&filter[filters][2][field]=Title
and parse it into a dynamic / expando object based on json like so:

code:
{
  take: "20",
  ...
  sort: [ { field: "JobBagNumber" }, { dir: "asc" } ],
  filter: { 
    logic: "or", 
    filters: [ { value: "what", operator: "eq", field: "JobBagNumber" }, ... ]
  },
  ...
}
I've been bashing my head against a brick wall all day on this goddamn thing.

What have you tried, and what's not working?

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