Wednesday, May 5, 2010

WCF Alternative Config with MEF

This website describes how to use an alternate config file with WCF.

http://weblogs.asp.net/cibrax/archive/2009/09/08/client-configuration-in-wcf-4-0.aspx

Basically, this is a way to do it, also.

ConfigurationChannelFactory factory = null;
try
{
string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string configFile = path + @"\FOT.Services.Plugins.RAT.MainServer.dll.config";

ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
configFileMap.ExeConfigFilename = configFile;

Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);

System.ServiceModel.EndpointAddress endPointAddress = new System.ServiceModel.EndpointAddress("net.tcp://" + rigIP + ":8052/SatelliteAuthorizationService");

factory = new ConfigurationChannelFactory("NetTcpBinding_IAuthorizationService", config, endPointAddress);

EventLogger.LogEvent(EventLogger.LogCode.Debug, EventLogger.LogLevel.Trace, id: "877", className: "Moderator", methodName: "CreateWell", eventMessage: "Loaded Config File.");
}
catch (Exception ex)
{
EventLogger.LogEvent(EventLogger.LogCode.Unknown_Error, EventLogger.LogLevel.Error, id: "881", className: "Moderator", methodName: "CreateWell", eventMessage: ex.Message, stackTrace: ex.StackTrace);
}
IAuthorizationService client = factory.CreateChannel();
int error = client.CreateWell(authorizationKey, Convert.ToInt32(wellId), databaseName, productType, productVersion);

Monday, April 19, 2010

Threading the UI in WinForms/WPF

I figured out how to put the UI on a separate thread than the functionality.





This is what you do in the MyForm.cs class. Begin invoke on the Dispatcher.

You must create a DELEGATE -> ClickDelegate and cast the new delegate as that.

Thread Static

A variable or class can be static, but only static to a thread using:

Thursday, April 15, 2010

One-click download for text file on HTML

To create a one-click download link on a webpage, for a text file that is basically a 'csv' or comma separated values file, put the '*.csv' extension.


.Net MySQL Connector Error

Apparently there is an error that can occur when a MySQL command tries to execute, but the execution takes longer than the default 'CommandTimeout' of 30 seconds.

To fix the problem, change to MySQLCommand.CommandTimeout to something more useful.

MySQL_Upgrade MySQL_Check fix for "column count of mysql.proc is wrong"

from command prompt: (remember to have NO space between '-p' and '[password]')

C:>mysql_check -u [user] -p[password] --repair --all-databases

This will repair your databases. This does not work on InnoDB.

C:>mysql_upgrade -u [user] -p[password] --all-databases

This will upgrade your databases.

This fixes the 'column count of mysql.proc is wrong' error when using MySQL Workbench on a databases that has been created with MySQL Server earlier than 5.2

Monday, April 5, 2010

Netstat

For networking information there are some handy 'Command Prompt' commands.

%> netstat

-a : listening and established ports
-an : all (I think)
-o: all owning processes with each connection