Having "that mindset"

by Jesse 25. August 2008 03:48

This past friday, something absolutely amazing occured.  Before I get started, let me say first that most of my friends/family have no freakin clue what I do, much less understand to any degree how complex it _can_ be and in effect, don't care what I do, its "something with computers".  Well, my girlfriend started to ask about it because she didn't understand why some of this stuff zaps my brainpower after a day at work.  This was a mix of things that brought this on.  1, an ad on TV about "get a technical degree in multidirectional impact devices!" and 2, I had mentioned I was doing stuff with this really cool-named product, Ninject.

I know she's got the mindset to figure this stuff out and a little mind stretch is never bad so why not?  I offered to show her the bare bones of programming, a simple (cringe) hello world website with the cliche button, textbox and label.  No sweat, easy stuff, went very very smoothly and with a slightly concerned face, she looks at me and comments "this ...really isn't that hard" then something astonishing happened - she says "well, lets do something for the dogs, I want it to say who was a good dog today".  Ok, so we removed the textbox with a dropdown and went along with that until "what if I want to say more than one dog was good? ...and can we make it say the other dogs were bad?".  The ball was rolling at this point!  Did I mention we were using "best practices" in control names too (lbl = label, txt = textbox, etc)?  That she was telling me?  Correctly?  The first time?  She was getting it!

After a while, we ended up making a design decision that we would use a checkboxlist, run though the list, display which dog was good, which was bad now insert the astonishing comment "wait, if we have Buck and Kimber selected, the (verb) tenses won't be right ...we can't have it say Buck Kimber was a good dog.  We'll have to do ...something that figures that out won't we?  And can we put and in there when there's more than one selected?  What about commas?  Is that possible?"  Where's the heavenly awe music when you need it??

We had to write an if statement to check the counts, make a decision and give us a string that was acceptable along with a flag that let us know if it was a good dog comment or bad dog comment.  After about 2 hours, she was happy with what we'd created and was amazed at the level of complexity that something as "simple" as making a page say what dog was good and what dog wasn't.  I also demonstarted that since we put in the work now, if we added 5 more dogs to the list, it didn't matter, it just worked.  When we were finally done she commented, almostly slyly "I'll never look at checkboxes the same ever again" - HA!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

Coding | off topic

Interesting behavior and a difference between List.Contains( and List.Exists(

by Jesse 19. August 2008 05:30

A nice little suprise this morning!  A quick hit on it - .Contains() returns a bool value and expects you to pass in an object that is in your list whereas .Exists expects a predicate (but still returns a boolean).  Let's dive right into this because its easier to show than blab/explain.  Make a new list, shove it into view state.  Feel free to add this where ever you like, just as long as it is not in pageload, make it a button event.

List<string> Ids = new List<string>();
Ids.Add(
"007");
Ids.Add(
"008");
Ids.Add(
"009");
ViewState.Add(
"Agents", Ids);

Drop a second button out there and add the following code...

List<string> SavedAgents = ViewState["Agents"] as List<string>;
string FoundAgent = "008";

bool ContainsAgent = SavedAgents.Contains(FoundAgent);

bool IsSavedAgent = SavedAgents.Exists(delegate(string agent)
{
    
return agent == FoundAgent;
});
 

This works, both values are true.  "So what's the difference?" -- Create yourself the following object...

[Serializable()]
public class Agent
{
    
public string AgentId { get; set; }
    
public string AgentName { get; set; }
    
public string CurrentLocation { get; set; }
    
public Agent(string agentId, string agentName, string currentLocation)
     {
         
this.AgentId = agentId;
         
this.AgentName = agentName;
         
this.CurrentLocation = currentLocation;
     }
}

and switch out the code just a touch that loads up the viewstate...

List<Agent> agentList = new List<Agent>();
agentList.Add(
new Agent("007", "James Bond", "Las Vegas"));
agentList.Add(
new Agent("008", "Unknown", "Unknown"));
agentList.Add(
new Agent("009", "David Brabham", "UK"));
ViewState.Add(
"Agents", agentList);

and the check behind button 2 like so...

List<Agent> SavedAgents = ViewState["Agents"] as List<Agent>;
Agent foundAgent = new Agent("008", "Unknown", "Unknown"
);
bool
 ContainsAgent = SavedAgents.Contains(foundAgent);
bool IsSavedAgent = SavedAgents.Exists(delegate(Agent
agent)
{
     return agent.AgentId == foundAgent.AgentId;

});

This might surprise you, but ContainsAgent will be false.  If you do "return agent == foundAgent" for the .Exists, it will also be false.  I'm -guessing- it's using reflection.  Because of this, I insist using .Exists instead, since you can test properties directly.  Even more curiously, using the various .Equals yeilds false, such as :

bool IsEqual = Equal(SavedAgents[1], foundAgent); ...or

bool IsEqual = SavedAgents[1].Equals(foundAgent); ...or even

bool IsEqual = foundAgent.Equals(SavedAgents[1]);

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

.Net | C# | Coding

Sitefinity modules, the easier way!

by Jesse 16. June 2008 09:07

From my previous posts, I talked about creating a custom module that complies into a dll.  I've discovered that is THE hardest way possible to create a custom control.  The experience was good, but not exactly fun.

Luck would have it, they have a much stupid simpler way.  It's not as shareable, you have to add the files to each and evey site instead of just changing up the web.config.  So what?  There's a download they provide in their documentation that's kind of burried, but no sweat, you can get it here.  It's a full project and it takes a minute to unzip.

Before we get started, let me explain what this custom module does and what we're going to do to it.  The JobsModule consists of 4 user controls, your tried and true ascx files, that do various things, a couple classes, nothing intimidating.  One neat thing they did in this example was use an interface, "IJobsControlPanel", (app_code/jobsmodule.cs:142) to switch between two modes, "Category" and "Type", but in my examples I removed this for simplicity and the real module I was creating does not call for it.  Other files you need to note are all within the /Jobs folder.  Control panel and Toolbox are for the admin side, where the "JobList" and "JobListSummary" are for the user side. 

If you haven't went though the pain and agony of unzipping that file, do so now and let's take a look at the "JobsModule.cs" under the app code directory.  Line 28 begins the Nolics database init which later on, we won't need, but note where it is.  Under the properties region, lies the name/title/descript that will show up on the admin side.  On line 93/94, these are the files that will show up for the user side which will get more into later, just note that is where they are.  Next, take a look at line 112 and 121 as these are you admin controls.  Very easy to do.  Finally, there's the enum and interface for the other items they use for this module.  This is 95% of what it takes to make a module.

For this example, I am going to completely ignore the code behind for the user controls on the public facing side as they are unimportant.  Why?  Because user controls are user controls are user controls.  Make one, make 'em all, which is a very good thing!  Now, let's make a custom module, shall we?  Let's say we have a customer that wants a very very basic control that displays how many orders recieved today with the option to look at yesterday.  Our database table will look something like this...

TableName : Orders
Id  uniqueidentifier, not null, primary key
OrderDate datetime, not null
Quantity int, not null
DollarAmount money, not null
ItemOrdered nvarchar(1000), not null

Very simple, nothing fancy.  For the next step, I went away from the example just a bit and created a "CustomModules" folder under the App_Code directory along with a "DAL" folder with two folders within named "Generated" and "Extended".  See the image below for a bit of clarity. Now move "JobsModule.cs" into the CustomModule folder. Create yourself a folder in the root named "CustomControls" and a folder within it called "Orders" -- this is where the user controls will live.

At this point, if you've never touched subsonic, I would highly suggest jumping over there to brain up on how it works as I will not be covering that aspect.  Also, if you are unfamiliar with subsonic generating only certain tables, add the tag includeTableList="Orders" to your subsonic service.  For reference, this is a comma seperated list and will restrict subsonic to generating only those tables defined there.  Very handy since sitefinity has around 100 tables out of the box.  Generate this table and dump the files into App_Code/DAL/Generated.

Next, make a new class in App_Code/CustomModules and name it "OrdersModule.cs".  On the class declaration, inherit the WebModule from the Telerik namespace, implement the abstract class and change out the constructor from public to static as seen below.

Hop over to the JobsModule and copy the Methods region (override CreateControlPanel and Override CreateToolBoxControls), paste those into your OrdersModule -- don't worry about the string values yet, we'll get to those.  Also copy over the get in JobsModule:83-99 and paste that into the "Controls" override.  Finally, create a private variable of IList<Telerik.Web.IToolboxItems> (look to JobsModule:40 for example).

Now that's prepped, hop over to the CustomControl folder and create 3 user controls - "ControlPanel.ascx", "ToolboxPanel.ascx" and "OrderList.ascx".

ControlPanel needs to inherit the Telerik.IControlPanel and go ahead and give some string values, similar to this...

#region IControlPanel Members private readonly string status = "Orders";
private readonly string title = "Orders";

string IControlPanel.Status
{
     get { return status; }
}

string IControlPanel.Title
{
    
get { return title; }
}

#endregion

In the ToolboxPanel, inherit the Telerik.IControlPanelCommand and give values where necessary (Title for one).

Finally, for OrderList, we don't have to do anything yet.  If you feel like it, drop some text on the page just for rendering reasons.  Guess what? Most of the "behind the scenes" work is already done.  No really!

At this point, it should build and give you a custom module within your sitefinify project.  For the next post, I'll talk about how to wire up the subsonic stuff and even get at some data within sitefinity!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

.Net | C# | Coding | Design

Teaching or lack of

by Jesse 30. May 2008 03:49

A friend of mine has been in school for programming now for nearly 2 years and getting his associates really soon.  Good for him!  On and off he's come and asked me some questions about how to approach certain problems, most of which have been fairly easy to me so I was happy to help and walk him though some of the confusing aspects.  No sweat.

About 2 days ago he approached me about his senior project and that they were doing a website and needed some help with editing, updating employee info.  He also noted that just getting data was a huge pain and took hours for them to get it to work.  No problem, that's easy stuff.  I busted out my favorite ORM tool (subsonic!!!) and showed him how to make his data access life easy.  None of this inline sql crap.  Then I discovered something downright offensive.

We all know architechure is important.  Someone forgot to tell them that.  Further, they didn't seek out any assistance and went crazy.  What they ended up with was a horrific db structure and data access the hardest way known to man (by hand using the object data source).  I kid you not there's a page, an aspx page that has over 1000 lines and its just displaying simple address info, nothing more.  Adding more pain, instead of using 1 page as a one stop shop, every CRUD operation is broken up into individual pages.  View the data over here, edit it over there and save it somewhere else.  I'm not joking.  Just to step it up a notch, the naming conventions are "NewUser" (new employee), "Employee Management" (editing employee data) and "ManagePhoneNumbers" (just to edit phone numbers).  In their defense, the graphics and layout aren't bad, B+.  The links and useability, F.

What are they teaching these students?!  Are the professors this far removed from the real world?  This isn't the first time I've heard of teachers being way way off base and furthers my desire to teach.  It's terrible, sad and pathetic.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Coding | Architecture | Scam

Encryption, Development and AES

by Jesse 16. May 2008 06:55

If the custom module wasn't enough, I'm now wondering off into encryption land.  A quick scouting of the System.Security.Cryptography namespace shows me a ton of stuff to play with.

Ooo, AES.  I like AES.  It runs on my router(s) @ home and is viciously annoying to crack (TKIP f0r t3h w1n!!!11).  Cool, let's use that, its good enough for top secret docs for the gov so it should be good enough for me.  But, as with anything else, there's a catch or ...20.  Here's some basic considerations.

Will this data be searched? 

Searching encrypted data is a royal PITA and a huge overhead.  Example : saving data to a db with encryption happening in the business layer.  A perfectly viable user says to the application "hey, find this" -- you cannot directly ask the database to find it, it is impossible, so every search that happens comes across, ALL OF IT (say 2 million records), decrypts, the search happens, find the records necessary and passes that on.  Not very reasonable nor scalable.  2nd option for this is do it on the sql server itself.  Fundamentally I have a problem with this for 2 reasons.  1, a purely architecture standpoint, this should never be passed off to the data source.  In the real world, it's probably ok to offload some of that overhead, but still, using the OSI model alone says "no no" -- encryption happens in the presentation level and offloading it means you pass though all 7 layers ONCE before you encrypt -- bad bad bad.  2nd, unless the data connection between app/server is encrypted to hell and back itself, your encryption is trumped and effectively worthless.

How much protection is necessary?

The question of the ages.  Understanding the CISSP-ism of protection and risk management: the amount of protection spent on it should be equal to the amount of total loss of one breach by the inverse of the possibility of recurrence.  So say the data is worth 10 million dollars for ONE loss.  The probability of loss is once every 5 years.  10m/5y = 2 million a year should be spent to protect it.  No really.  Now, if there's no REAL value to the data, ie, its personal junk you keep at home for giggles, then whatever the server can handle works fine.  Otherwise, use reasonable + 1.

I'll stop there.  Other questions can range from "Who needs access to it?" to "Where will the server be physically housed" -- but thats somewhat outside of the scope of this post.  Not saying they're unimportant, just "too much" for this post.  I think my first task will be working on getting something simple to encrypt, like a file or a string and work up from there to see how much overhead this thing creates.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

.Net | C# | Coding | Security | Architecture | Law

Sitefinity and Custom Modules

by Jesse 12. May 2008 03:41

I don't know why but it seems the crazy complicated research projects get tossed at me - "Hey, figure out how ________ works".  Well today, it's Sitefinity and custom modules.  Consider this my notes as I work to make this stupid simple and easy.

Before I go down this path, I've collected a ton of links with various things on it that hopefully will make my life easier.  So far, not so much.  I've got a couple problems I'll have to overcome.

  • The ORM (I'm guessing) has generated classes -somehow- and I have no idea where to make those change/update/whatever.  In the sample project Sample.Contracts.Data there's a "Department.dbclass" -- how that is made I have no idea.  There's no app.config, nothing that might tell me how, but I'm guessing I'll have to look into "Nolics.Engine.v4.2" (A referenced class) to find out how its generating this info.  Again, there's no explaination in the sample -- I expect a google search to fix this though.
     
  • The example's out of date (1 year old, May 2007).  Right when I loaded it up, one of the implementations is obsolete - "IControlPanelCommand" needs to be replaced with "CommandPanelBase".  Doesn't seem to be an issue (builds no problem), I'm just wondering what other goodies might be inside...

Good news is it builds right after you re-reference the dlls, no problems there.

*Update* 11:30am - ugh, found the ORM and its freakin expensive, 950 euros.  I'd rather use subsonic but who knows what kinda problems that'll cause...I feel more research coming on.

*more Updates* 5pm - ok, subsonic is very doable, I might even have it all setup and ready.  I'm going to pound out a bit more code and I think its done.  We'll see.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.Net | Coding

Web services, big networks, policies and you

by Jesse 5. May 2008 16:56

Right now I'm working on deploying a project that I never would imagine would be this difficult.  The idea was to swoop in, drop the code, show off (ooooooo ahhhhhhhh) and done.  Does anything ever go according to plan?  Of course not.  Well, this one had a rude surprise waiting on us.

The client I speak of has a huge, global network.  Active directory (which is good!) and somewhere around 10+ forests and god knows how many domains.  It's massive, utterly massive.  I would GUESS they have at least 5000 users on this one domain and probably 50-100k user accounts globally, ignoring groups.  So why is this a problem? :Sarcastic laugh:  A couple few reasons.

  1. Not all (logical) networks are setup "best practice".  Best practice is a cookie cutter template, it doesn't always fit and should be used as a guide so immediately you cannot assume "all domains trust each other" or "all accounts have rights".  Transitive trusts, one way trusts, mutual trusts all mean very different things -- they could screw you in different ways too.
  2. Not all authentication can be trusted to work across domains.  This includes SQL accounts.
  3. Not all network devices allow traffic.  This means your www traffic, ftp, etc might not work across the world.  Chances are, http traffic is your best bet, but its not a sure shot.
  4. Network policies (more specifically, group policy) can be your best friend and your worst enemy.  You may not know which nor have a straight answer.

 

So translate : it means your codes magic won't always work thanks to network conditions -- it also means it might work on one domain (ohio domain lets say), it might on one network (wired works whereas a wireless may not), or it might work across one domain and not another (ohio might work with texas, but not necessarily in reverse or from colorado to texas), it may not run at full speed (ohio's domain has flood control turned on).

This makes my head hurt.  I have to think of ALL the network stuff I haven't used in a while plus the admin stuff and toss some happy code to get a wonderful steaming pile of confusion and pain.  After thinking about this for a minute (ok, half hour) I've decided that after this, I'm going to insist web services, anonymously.  Now before you have me skinned alive, hear me out and here's my thinking behind it.

Anonymous webservices can still be secured protected via https, certificates and credentials.  Sure, you can make a request without any network creds, but the service won't talk back because you don't meet the needs.  "But this'll increase the overhead on the server, it'll slow everything down!" and you would need to be fired -- speed should never trump a security decision.  "But what if an account isn't disabled and cleaned up?!" good point, not your problem, a well administered network will not have this concern. 

Now that those problems are addressed, why anonymous?  More likely than not, a network, and I'm speaking of the whole network, will allow web traffic from point A to point X without too much drama.  Furthermore, once the request gets to that service, I'd bet money that server is sitting in a screened subnet/protected area (I've yet to see one NOT setup like this in a really long time) -- perfect place to make all your sql calls (via ipsec I'm sure).

Will this make code more complicated?  Yes.  Will it tax the server/client more?  No doubt.  Will it drive up costs?  Yes -- BUT, and thats a full, wholesome but, it's meant for enterprise, treat it as such and bring the big guns.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Coding | Design | Architecture

ClubStarterKit - Baseball Edition

by Jesse 28. April 2008 03:30
Took me a while but I finally got around to dumping the files into a zip for download.  My change up includes a sponsor section and a stats page that follows batting and pitching stats.  This is, of course, a modification to the clubstarterkit beta 3 found on codeplex so all the open source goodness applies.

ClubStarterKit-Baseball.zip (7.50 mb)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Coding

Codeplex and SilverSurvey

by Jesse 24. April 2008 16:31
Based on some feedback I got -- I've decided "why not?" and tossed the survey engine I started up to CodePlex.  I'm not going to allow anyone to join in just yet, not until I get the basic stuff setup and there's going to be a nasty learning curve that I feel coming.  So far, I've got the db project up, along with the core project itself (its kinda nice having TFS again!) -- as soon as that's done and rollin', feel free to join in.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Visual Studio | Silverlight | C# | Coding | Tech | Linq

SilverEngine Source Code

by Jesse 21. April 2008 05:33

Ok, I've got my source code ready and hopefully the sql script will work (much easier/smaller than posting up a bak or mdf).  Download it, take a look, make fun of me on twitter.  Honestly, this was/is going to be used at some point for something real (survey engine) other than a research-ish project.  Anyway, enjoy!

SilverEngine.zip (750.98 kb)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.Net | Silverlight | C# | Coding | Design

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

About the author

Like the description says, at my core, I'm a scientist and engineer.  I came from humble beginnings on a 486DX2 Packard Hell playing doom2 on IPX to in a small time retail shop and got into hardware (ISO layers FTW!) and it was all downhill from there.  I'm infinitely curious about almost everything and always wanting to know.

Some of the stuff I'm currently into/researching...

Sitefinity

Ninject

Subsonic

Java

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's, their brother nor their dog's view in anyway.  At all.  Ever.

© Copyright 2007-2008