Wednesday, November 18, 2009

C# Regular Expressions

'*' Matches 0 or more patterns.
(e.g. "*[a]" matches 0 or more 'a's)

'+' Matches 1 or more patterns.
(e.g. "+[a]" matches 1 or more 'a's)

'?' Matches 0 or 1 pattern.
(e.g. "?[a]" matches 0 or 1 'a')

'^' Ignores a pattern.
(e.g. "^a" ignores 'a's)
Also, can be used to signify the start of a string.
(e.g. "^[0-9]" will match a string starting with number)

'[]' Used for range patterns.
(e.g. "[0-9]" matches any number between 0 and 9)

'.' will match any character except '\n'.
(e.g. "a.." matches any 3 letter word starting with 'a')

'\d' matches a digit.
(e.g. "\d"matches any 1 character number)

'$' matches the end of a string.
(e.g. "$[a]" matches a string ending in a)


Monday, October 26, 2009

Apple Safari error exception 0xc000000005

I tried to open Safari and it would close and give me an error. It would not stay open for more than 30 seconds.

Running XP SP3

To fix, I had to uninstall safari and delete all history, temp, source files from my harddrive. Uninstalling did not do this. I had to do it manually.

Afterwards, Safari works.

Thursday, October 22, 2009

PHP, Print all $_Post/$_Get Variables

To print all the (Post and Get) variables do...

print_r($_GET);
print_r($_POST);

Wednesday, October 14, 2009

PHP5 and Apache 2

Put the php.ini file in ../Apache2/;


php.ini

doc_root = "C:\Apache\Apache\htdocs\"


httpd.conf

LoadModule php5_module C:/php/php5apache2.dll
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Tuesday, September 22, 2009

C# Directory.GetFiles(string, string)

I wanted to find files in a directory with a sub string in the name "obj".

There is a list of files in the directory ...0bj_????.xsd.

The way to do this is

Directory.GetFiles(path, "obj_*.xsd");

Friday, September 11, 2009

XML and Streams with C#

I wanted to write xml to a stream and back because of the XMLDocument think.

You can go back and forth from XMLDocuments to Streams by:

MemoryStream streamName = new...();

streamName.Write( [ innerXML as byte array ], 0, [size of array]);

XMLDocument document = new ...();

document.Load(streamName);


Now you have a xmldocument.

Friday, September 4, 2009

WCF Service, C#

I wanted to create a WCF service in C#.

Communication was the problem. After creating the service, and implementing the method properly, you must either create a new project in the solution or have a console implementation in the project with the service. In order to communication with the service you must have a console.

This is on the SERVICE side.

using System.ServiceModel;
using System.ServiceModel.Description;
using [SolutionNamespace].[NamespaceList].SimpleService;

class Program
{
static void Main(string[] args)
{
Uri baseAddr = new Uri("http://localhost:8080/SimpleService.svc");
ServiceHost localHost = new ServiceHost(typeof(SimpleService), baseAddr);

try
{
localHost.AddServiceEndpoint(typeof(ISimpleService), new WSHttpBinding(), "SimpleName");

ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
localHost.Description.Behaviors.Add(smb);

localHost.Open();

Console.WriteLine("Server's up...");
Console.ReadLine();
localHost.Close();
}
catch (Exception ex)
{

}
}
}

SimpleService is the class that implements ISimpleService. ISimpleService is the ServiceContract for WCF. "SimpleName" is just a name string.



For the client, you must add a Service Reference to the WCF service. You can name it what ever, but every example I have seen has named it exactly what the service implementation is called. This was quite confusing. You can reference this service inside your console class. SimpleService is the name of the reference inside the CLIENT.
The namespace is the reference to the Service References that the service is referenced by.

This is the CLIENT side.

using [SolutionNamespace].[namespaceList].SimpleService;

class Program
{
static void Main(string[] args)
{
SimpleService client = new SimpleService();

try
{
string data = client.GetData(1);
Console.Write(">:" + data);
Console.ReadKey();
}
catch (Exception ex)
{

}
}
}

This will allow the two to communication between solutions.