Archive

Archive for the ‘C# Code Comments’ Category

Tight internal cohesion and loose external coupling


I know the philosophy but forget the mantra – “tight internal cohesion” and “loose external coupling” – it’s clearer if you apply your thinking to glue not code.

Advertisements
Categories: C# Code Comments

C# ASP.NET Access to Salesforce Web Service


The traditional approach to accessing a web service in Salesforce is via the webs services API. There is another way, albeit unauthenticated.

1. In Salesforce, build your web methods in a Global Class
2. In Develop –> Apex classes, find the new class and generate the WSDL
3. Create new Windows .NET App and add a button. In the code behind make it so:

private void button1_Click(object sender, EventArgs e)

{


string txtReturnWS;

System.Net.ServicePointManager.Expect100Continue = false;

WebReference1.HelloWorldService objProxy = new WebReference1.HelloWorldService();

objProxy.Url = http://xxx.force.com/forms/services/Soap/class/helloWorld”;

try

{

txtReturnWS = objProxy.GetMessage();

textBox1.Text = txtReturnWS;

}


catch (Exception ex)

{


string message = ex.Message;

}

}


Categories: C# Code Comments

Rackspace Cloud Anomalies


Life in the clouds is no picnic  … especially when you deploy for the first time and discover all is not well in the medium trust environment.
It would be wishful thinking to add <trust level=”Low” /> to the Web.config ..

Anyway, here are a few discoveries I have made ..

In Web.config make the following changes

1. Add requirePermission=”false” so components can be accessed
<configuration>
<configSections>
<!–  Added requirePermission for cloud access –>
<section name=”log4net” type=”log4net.Config.Log4NetConfigurationSectionHandler, log4net” requirePermission=”false”/>
<section name=”dataConfiguration” type=”Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,
Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ requirePermission=”false”/>
.
.
</configSections>
</configuration>

2. Impersonate a valid user
<system.web>
<!–  To allow files and folder access –>
<identity impersonate=”true” userName=”dfw\blah” password=”passwordBlah” />
.
.
</system.web>

3. Issues with the GAC – still working on this
<!–  Yep  … its debug mode  … issues with the AJAX ToolKit –>
<compilation debug=”true” strict=”false”>
.
.
</compilation>

You may also get trouble with third party dll’s that do not run in the medium trust environment. It took me a few hours to rewrite a blowfish encryption dll that did just that.
I will add stuff to this note as I discover them.

Categories: C# Code Comments

Windows Workflow


Yep, I finally made it after half the planet is already doing it (workflow that is!!). Yes – even in England.

I started doing B#’s first walkthrough but that was just a bit simplistic. This one is much better.

Categories: C# Code Comments

Validation – Its just too easy


Yes, I know we have been using this stuff for years but its still a buzz to use instead of custom javascript.

<asp:CompareValidator id=”someID” ControlToValidate=”someControl”
ControlToCompare=”someControl” or ValueToCompare=”someValue”
Type=”Currency|DateTime|Double|Integer|String”
Operator=”DataTypeCheck|Equal|GreaterThan|GreaterThanEqual|LessThan|LessThanEqual|NotEqual”
Display=”Dynamic|None|Static”
ErrorMessage=””
runAt=”server” >
ErrorMessage (e.g. “*”)
</asp:CompareValidator>

<asp:RequiredFieldValidator id=”someID” ControlToValidate=”someField”
Display=”Dynamic|None|Static”
ErrorMessage=”some error message”
RunAt=”Sever”>
ErrorMessage (e.g. “*”)
</asp:RequiredFieldValidator>

<asp:RangeValidator id=”someID” ControlToValidate=”someControl”
MaximumControl=”someControl”
MinimumControl=”someControl”
MaximumValue=”someValue”
MinimumValue=”someValue”
Type=”Currency|DateTime|Double|Integer|String”
Display=”Dynamic|None|Static”
ErrorMessage=”some error message”
RunAt=”server” >
ErrorMessage (e.g. “*”)
</asp:RangeValidator>

<asp:RegularExpressionValidator id=”someID” ControlToValidate=”someControl”
ValidationExpression=”some expression”
ErrorMessage=”some error message”
Display=”Dynamic|None|Static” >
ErrorMessage
</asp:RegularExpressionValidator>

<asp:CustomValidator id=”someID” ControlToValidate=”someControl”
onServerValidation=”someFunctionThatReturnsABoolean”
ClientSideValidation=”someFunction”
ErrorMessage=”some error message”
Display=”Dynamic|None|Static” >
ErrorMessage (e.g. “*”)
</asp:CustomValidator>

<asp:ValidationSummary id=”someID”
Showsummary=”True|False”
DisplayMode=”BulletList|List|SingleParagraph”
HeaderText=”some text”
RunAt=”server” >
</asp:ValidationSummary>

Categories: C# Code Comments

Running a service as an application (or v.v)


public static void Main(string[] args)
{
//If ‘ApplicationMode’ argument was passed then run as a windows application otherwise run as a Windows service.
if (args.Length > 0)
{
foreach (string currentArg in args)
{
if (String.Compare(currentArg, “-applicationmode”, true, CultureInfo.InvariantCulture) == 0)
{
_runningAsService = false;
}
}
}

_exceptionHandler = new ExceptionHandler(_runningAsService, SR.ServiceMainName);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(_exceptionHandler.OnUnhandledException);

if (_runningAsService)
{
//Service
System.ServiceProcess.ServiceBase[] ServicesToRun = new System.ServiceProcess.ServiceBase[] { new DispatchService() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
else
{
//Windows Application
System.Windows.Forms.Form applicationForm = new ApplicationModeForm();
System.Windows.Forms.Application.Run(applicationForm);
}
}

Categories: C# Code Comments

Starter Kits


Starter kits are a great place to…

For me, using an ecommerce starter kit means I don’t have to concern myself with writing the code that takes money from my paying customers – by Visa, Mastercard, PayPal etc.

Hmm … now I just have to get some paying customers!

Categories: C# Code Comments