Wednesday, July 27, 2011

Installing Sharepoint Server 2010

<a href="http://www.microsoft.com/resources/msdn/en-us/office/media/video/office.html?uuid=6cf453d2-5943-480c-b747-332fa09ed23a&amp;src=SLPl:embed::uuids" target="_new" title="Installing SharePoint Server 2010">Video: Installing SharePoint Server 2010</a>

Sunday, May 1, 2011

(cautiously) Using extension methods to make (cleaner?) code.

I’ve read allot of warning as I learned about extension methods.  To me they have a similar “feel” to them as macros did in C/C++.  The trap that exists is the ability to make a complicated contraptions that seem really slick when coding but aren’t actually a good thing in the long run – i.e. down the road either you or someone like you will spend more time figuring out what is going on than it’s worth.

Still, I’m using them here and there.  I tell myself I’ve gone down the bad road of complexity in my past experience enough to keep it under control.

But the feeling in the back of my mind is that I’m playing with fire.

Time will tell.

Maybe I’ll come back to this in a half a year and note if I was right to be cautious.

Example Scenario: You are using a BindingSource with a DataSet and a DataGridView.  You want to access the row but it’s a pain to cast twice.

(DataSet1.MyDataRowType)(((DataRowView)(bindingSource[rowIndex])).Row)

I could write a private member function but it would be a one off.   I could write a public static helper member function, but I’d end up with a different style of code:

MyUtility.GetRowAt<DataSet1>.MyDataRowType>(bindingSource, rowIndex)

That’s not really bad.

And the extension method version isn’t much different.

static class MyExt
{        
internal static T
DataRowAtX<T>(
this BindingSource bs, int i)
where T : class
{
return ((DataRowView)bs[i]).Row as T;
}
}

However, with the extension method, my code doesn’t switch over to the “utility call” style, which to me, brings the level of indirection, and the associated complexity more the fray than:

bindingSource.DataRowAtX<DataSet1.MyDataRowType>(e.RowIndex);
Just like macros, my code is what I want it to be right now, and I got around a limitation by leveraging a language feature providing generic extensibility.
So the question is: will I regret this?
 

Tuesday, February 15, 2011

Code to do a simple regex extraction

image

I like about the above:

  • one line does the match and one line does the extraction of the match and the conversion to the target type
  • to me, it reads clearly
  • it seems like a good use of “var” because I don’t care much that “reg” is a GroupCollection

Used LINQ to Coalesce Form Keys

image

Display Multiple Currency Symbols in C#

If you have a money amount:

decimal money = 107.04;

And know the code for a culture:

string cultureName = “en-gb”; // display currency in pounds

Create string containing a culture specific currency:

string formattedCurrency = String.Format(CultureInfo.CreateSpecificCulture(map[cur]), "{0:C}", decimal);

The table is on msdn: http://msdn.microsoft.com/en-us/library/ks7d2abt.aspx

Then you can insert that string into HTML (tested on IE 8):

image

Monday, February 14, 2011

Sql Server 2008 Security/Logins

I’m using windows authentication in an intranet.

The way I am configuring permissions is:

1. Add a login for an individual or group to the instance level security.

2. Set the user mappings for databases I wish to give access, assigning roles.

From: http://www.techrepublic.com/article/understanding-roles-in-sql-server-security/1061781

Predefined database roles:

  • db_owner: Members have full access.
  • db_accessadmin: Members can manage Windows groups and SQL Server logins.
  • db_datareader: Members can read all data.
  • db_datawriter: Members can add, delete, or modify data in the tables.
  • db_ddladmin: Members can run dynamic-link library (DLL) statements.
  • db_securityadmin: Members can modify role membership and manage permissions.
  • db_bckupoperator: Members can back up the database.
  • db_denydatareader: Members can’t view data within the database.
  • db_denydatawriter: Members can’t change or delete data in tables or views.

image

Captain’s Log

This morning I added a feature to the campaign page to copy info to clipboard.

I needed to review the details surrounding how to wire a client side click to individually rendered elements of the template.

Found How to dynamically set control IDs inside a repeater template?

How does one copy to the clipboard via JavaScript?

Found (IE only) http://www.htmlgoodies.com/beyond/javascript/article.php/3458851/Click-Its-Copied.htm

My Code: Copy-To-Clipboard client side click handler.

image 

What can I use for a copy-to-clipboard icon?

A: http://www.iconarchive.com/show/must-have-icons-by-visualpharm/Copy-icon.html
Now the page has the functional copy icon in it:
image 
My Code: ASP.NET logic for putting a copy-to-clipboard icon after the short description of the campaign.
image 
Issue: The feature is not fully useful until I change the ETL to bring in the entire description as opposed to the first 255 characters only. Pros and Cons?
 

Monday, January 24, 2011

Code and Example of FormSerializer utility class.

Scenario

You are writing a windows forms application and you want a simple way to save the location (and possibly other properties) of your WinForms.

Code for FormSerializer

using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Xml.Serialization;
namespace EomApp1.UI
{
    public class FormSerializer
    {
        public static void Serialize(Form f, string path)
        {
            XmlSerializer xs = new XmlSerializer(typeof(FormProps));
            using (Stream s = File.Create(path))
            {
                try
                {
                    FormProps props = new FormProps();
                    props.x = f.Location.X;
                    props.y = f.Location.Y;
                    xs.Serialize(s, props);
                }
                catch
                {
                }
            }
        }
        public static void Deserialize(Form f, string path)
        {
            XmlSerializer xs = new XmlSerializer(typeof(FormProps));
            if (File.Exists(path))
            {
                using (Stream s = File.OpenRead(path))
                {
                    try
                    {
                        FormProps props = (FormProps)xs.Deserialize(s);
                        f.Location = new Point(props.x, props.y);
                    }
                    catch
                    {
                    }
                }
            }
        }
        public class FormProps
        {
            public int x;
            public int y;
        }
    }
}

Monday, December 13, 2010

Today in Excel 2007

Past Special>Formats is useful when you spend time setting up a sheet with customized formatting and then you need to make the sheet expand over/down.

Data>Remove Duplicates is useful when you have rows containing line items and you want, say, all the “names” in one of the columns.  It’s quicker than making a pivot table, which is the other way I know how to do it.

Home>Wrap Text can be thought of as a button with the same functional semantics as Bold or Underline, that is, it’s either on or off for any given position in the document.  It does what it says – if you enter more data than can fit in a column horizontally, and wrap text is in the ON state, then the text will wrap, taking up additional vertical space.

Sunday, December 12, 2010

SQL Server 2008 R2 Feature List (in prog)

http://msdn.microsoft.com/en-us/library/cc645993.aspx

todo: make a list of the most interesting features with respect to my projects.

(in prog)

Bus Thought: intern from Rutgers?

The company I work for recently put an ad out for a database developer. It might make sense to inquire with the CS dept. at Rutgers, where they have a notably theory heavy curriculum, if there are any super star academics who would benefit from an intense stint in the real world.  Someone like me when I was there.  Motivated, smart, but inexperienced.  I would be happy to act as a mentor, and the “apprentice like” environment would be a great way to help make a connection to the “why” of all that theory.

Maybe more on this later…

EOF for now.

Notes: My first look at Azure

ME: Today I am working on Sunday because I want to get ahead of the game.

NOW: listening to a pre-recorded web cast on about Azure, the MS cloud database. notes as I listen.Talking about challenges.

AZURE: How to make applications that are useful and scalable? need disks, memory, hardware - managing a data center is hard. How to get app to the market quickly? Helps to have a simplified deployment path (?). Optimize.  Sample: NFL website - very active during games but not all the time. --> data center optimization --> benefits from pay-as-you-go service platform. Azure enables developers to deploy apps. If it can be hosted in IIS, it can be put into Azure. Blob storage:file system. SQL Azure: database. App fabric: queuing/messaging.  Codename Dallas: analysis and BI. 

AZURE: familiar SQL Server relational model. Uses existing APIs and tools. Friction free provisioning and reduced management (?). Built for cloud with availability and scale.

ME: marketing is annoying.

AZURE: true relational database as a service.

ME: This contrasts to, say, SalesForce (maybe more about this later).

AZURE: Data always available and (automatically?) replicated. self heal because (todo. learn more). Scale. 1GB to 50GB.  Control over load balancing.  business ready SLAs.  data centers are all around the world.

AZURE: Relational. Developers use existing knowledge with building SQL server based relational apps. Azure looks just like SQL server to the app. Requests go through the load balancer.

azure1

Architecture.  Provision with ActiveDirectory (?).  App topologies. – Azure compute/Code Near – use the azure deployed web site – LOW latency.  Code Far – traditional app model (!!!) – Hybrid. Synch up.

ME: OK!  This is a good thing that I was listening.  “Code Far” is the model I am using with my project right now.  It would be a disaster to try and deploy this knowing the latency would be an issue and the product is not really aimed at this (my interpretation).

HOWEVER! We also need a solution for maintaining highly available PHP based sites, so it’s worth learning a little more.  That said I really need to know if the pricing is something I can sell to management.

Interesting the next topic in the web cast addresses this concern.  Maybe they do focus groups or something and people out there like me reacted just like me.

Provisioning.  Account>Server>Database.

azure2

EOF for now.

Wednesday, December 1, 2010

Language Feature Idea - Inner Method

f()
{
// does thing number one only called here
...
f.ff()
...
f.fff()
f.ff()
{
}
f.fff()
{
}
}

Tuesday, November 30, 2010

Idea for OO Language Feature

This is a very simple idea. I should think someone has already thought of it but I haven't heard so here goes:

It occurs to me that there's no value in the convention of using the name of class to specify the constructor.

Why not devote a keyword? Like, say, 'ctor'?

EOP

Saturday, October 23, 2010

Quick Tip: Windows key combination to launch a program from the start menu with adminitrator rights.

Scenario
You need to start a program from the start menu with adminitrator rights. You already know how to do it the long way, by right-clicking and drilling into the properties for the shortcut, but you wish there was a faster way.

How
Open the start menu and type the name of the program just as if you were starting it normally.

Hold down control+shift when you hit enter.


Yay, now the program launches with adminitrator rights!

Friday, October 22, 2010

Foo for Thought: 'Faking' a private readonly property in C#.

Scenario
We find ourselves wanting to implement a public readonly property.

But
We are annoyed by the fact that the internal name is different than the external.

public class C
{
   public C()
   {
      myProp = "V";
   }
   private readonly string myProp;
   public string MyProp { get { return myProp; } }
}

If you have an interface in place like this:

public interface IC
{
   string MyProp { get; }
}
public class C
{
   public C()
   {
      MyProp = "V";
   }
   // ---------------------------------------------------
   // Then as far as the rest of your code is concerned,
   // this is basically the same as if C# supported 
   // public readonly properties.
   // ---------------------------------------------------
   private readonly string MyProp;
   string IC.MyProp { get { return this.MyProp; } }
}
EOF

Hack-A-Riffic Batch Script Pays Off

Why
I'm writing code that uses a REST API and as project input I have a set of URLs to XSD schema files. I use svcutil.exe to download them from the command line and xsd.exe to generate XML serialization code to make it a breeze retrieving and posting valid requests.

I ran into a snag when the long filenames generated by svcutil combined with xsd's behavior that concatenates its input files to form the name of its (one) output file.

So, I took the opportunity to break out the .BAT file. It's been years, but I've done it before, I can do it again, right? (right)

Long story medium sized, I learned the same few things that I had forgotten a few years ago when it had been a few years since I'd done up a .BAT (See the Notables near EOF).

I wasn't terribly proud of my concoction at first, but the next day when I had to add another XSD schema to my code, and it took me all of 13 seconds, I decided I was, in fact, quite proud.

Here it is, code that first bravely deltes all the XSD and CS files in the current directory, then works from a list of names that get plugged into a URL as part of the svcutil command which downlaods each XSD schema one by one. At this point, the files have really long names based on the URL they came from. If xsd.exe got all of them together, it could (would, will, did) exceed the maximum length allowed by the tool (or the O/S I don't know which, take your pick) --> thus! --> my seasoned hacking brain sprung forth the idea to get the names of the recently downloaded files using the special form of the for loop that acts on directory listings (now you really see the roots of bravery) and renamtes them to 1, 2, 3, etc.

Problem solved :)

I *know* there's a fine chance this entire exercise was unnecessary due to there being a more sensible way of achieving the same goal. Yet, I read the help for xsd and svcutil twice, and nothing came to mind. I'll be very happy to have someone tell me my prized script is pointless in exchange for schooling me proper.

cls 
echo OFF 
SETLOCAL ENABLEDELAYEDEXPANSION 
del *.xsd *.cs 
for %%X in (resourceList campaign campaignGroup affiliate affiliateGroup stats payout) do (  
 svcutil.exe /nologo /t:metadata https://da-tracking.com/apifleet/xsd/1_0/%%X.xsd 
) 
set C=/classes /n:DAgents.DirectTrack.Rest 
set N=1 
for %%X in (*.xsd) do (  
 copy %%X !N!.xsd  
 del %%X  
 set /a N=!N!+1 
) 
for %%X in (*.xsd) do (  
 set C=!C! %%X 
) 
xsd %C% 
echo ON 
Notables
  • Use echo OFF/ON to supress extra garbage on the screen while script is running.
  • W.S.T. loop variables, use a single % if entering from DOS prompt and %% if coding a .BAT
  • To code logic that builds up a string via successive concatenation in the body of a loop, use 'SETLOCAL ENABLEDELAYEDEXPANSION' in combination with yet another form of variable referencing as in !N!
  • The for loop has handy features like the ability to loop over the results of a directory list.
  • To do math, use 'set /a'.

EOF

Wednesday, October 20, 2010

Subtlety: When the location of using makes a difference for importing namespaces in C#.

Scenario
You've noticed C# code that imports namespaces with the 'using' keyword in two slightly different syntactic contexts.

  1. At the top of the source code file.
  2. In the body of another namespace.

Understand by Example
namespace My {
  public class C { }
}

namespace My.Foo {
  public class C { }
}

// C from My
namespace My.Bar {
  public class Bar { private C instance; } 
}

// C from My <-- this might be counter intuitive
using My.Foo;
namespace My.Bar {
  public class Bar { private C instance; }
}

// C from My.Foo
namespace My.Baz {
  using Foo;
  public class Baz { private C instance; }
}
EOF

Tuesday, October 19, 2010

Quick Tip: Using Visual Studio Command Prompt Programs from Windows PowerShell

Scenario:

You use the Visual Studio Command Prompt to invoke programs like cs.exe and xsd.exe and you want to invoke those programs from within PowerShell.

Ups:

You can use the right-click to paste short cut that is not available in a regular DOS shell.

Downs:

This procedure explcitly invokes the DOS interpreter causing you to leave the PowerShell immidiate mode environment.

Alt:

It is possible to create a powershell script that causes the same environment changes programatically, but it's more complicated.  See here.

Steps:

Right click on the shortcut (usually found in the start menu) that you would use to launch the Visual Studio Command Prompt.

In the properties window that appears, in the Shortcut tab, locate the value of Target.  It should be something like:

%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" amd64
You may replace amd64 above with one of:

   x86 | ia64 | amd64 | x86_amd64 | x86_ia64

Launch PowerShell.

Use copy and paste (in powershell right-click is a short cut to paste text from the clipboard)  to construct a command similar to:

cmd /k 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat' amd64

EOF