Cloud Workflow XAML:
Action -- http://www.jqd.com/cloud/IAlert/VIXAlert
[Namespace in WCF contract]/WCF Contract/MethodName
IMPORTANT --- MUST END W/O SLASH
Body --- <VIXAlert xmlns="http://www.jqd.com/cloud/"><msg>VIXUnder40</msg></VIXAlert>
<methodname xmlns="[Namespace]"><paramName>..
Url ---- sb://servicebus.windows.net/services/jqdsolution/anything/
Listener:
TransportClientEndpointBehavior cred =
new TransportClientEndpointBehavior();
cred.CredentialType = TransportClientCredentialType.UserNamePassword;
cred.Credentials.UserName.UserName = "jqdsolution";
cred.Credentials.UserName.Password = "xxxxxx";
NetEventRelayBinding nerb = new NetEventRelayBinding();
ServiceHost host = new ServiceHost(typeof(AlertListener),
new Uri("sb://servicebus.windows.net/services/jqdsolution/anything/")
);
host.AddServiceEndpoint("VIXAlertListener.IAlert", nerb, "sb://servicebus.windows.net/services/jqdsolution/anything/");
host.Description.Endpoints[0].Behaviors.Add(cred);
host.Open();
Console.WriteLine("VIX Listener Ready");
Console.ReadLine();
host.Close();
Handle firewall port blocking using HTTP mode:
ServiceBusEnvironment.OnewayConnectivity.Mode = ConnectivityMode.Http;
ServiceBusEnvironment.OnewayConnectivity.HttpModeRelayClientCredentials = cred;
ServiceBusEnvironment.OnewayConnectivity.HttpModeMessageBufferLocation = new Uri("http://servicebus.windows.net/services/jqdsolution/VIXAlertListener/" + Guid.NewGuid().ToString());
WCF Code:
[ServiceContract(Name = "IAlert", Namespace = "http://jqd.com/cloud/")]
public interface IAlert
{
[OperationContract(IsOneWay=true)]
void VIXAlert(string msg);
}
[ServiceBehavior(Name = "AlertListener", Namespace = "http://jqd.com/cloud/")]
public class AlertListener : IAlert
{
public void VIXAlert(string msg)
{
Console.WriteLine("Got Alert: " + msg);
}
}
Note that Namespace must match those in Cloud WF Action and NetEventRelayBinding
assume OneWay
Monday, January 5, 2009
Link to Cloud Workflow Orchestration by NetEventRelayBinding
Tuesday, December 16, 2008
Add execution timeout for a block of code
delegate void EndProcessingWithTimeoutDelegate(ManualResetEvent m);
.....
bool TimedOut = true;
EndProcessingWithTimeoutDelegate d = delegate
{
ret = acctsAlloc.EndProcessing(MxEnumProcessAction.MxeProcessActionSave);
TimedOut = false;
m.Set();
};
d.BeginInvoke(m, null, null);
m.WaitOne(60000);
if (TimedOut) {
...
}
else
{
}
Note that Timeout in 60 seconds
Tuesday, November 18, 2008
WCF MSMQ Integration Binding Configurations
WCF service is just as normal:
public interface IGMOWCFTrace
{
[OperationContract(IsOneWay = true, Action = "*")]
void WriteLine(MsmqMessagegmoLogMsmq);
}
host = new ServiceHost(typeof(GMO.XIPCommon.Logging.GMOWCFTraceService));
and Service config need to specify msmq and exactlyOnce=false for non-transactinal queue.
<system.serviceModel>
<services>
<service
name="GMO.XIPCommon.Logging.GMOWCFTraceService" >
<endpoint address="msmq.formatname:DIRECT=OS:.\private$\Logging"
binding="msmqIntegrationBinding"
bindingConfiguration="LoggingProcessorBinding"
contract="GMO.XIPCommon.Logging.IGMOWCFTrace">
</endpoint>
</service>
</services>
<bindings>
<msmqIntegrationBinding>
<binding name="LoggingProcessorBinding" exactlyOnce="false" >
<security mode="None" />
</binding>
</msmqIntegrationBinding>
</bindings>
</system.serviceModel>
WCF client has MSMQ code and optionally WCF Code:
public override void WriteLine(object o)
{
Message msg = new Message();
msg.Body = (GMO.XIPCommon.Logging.GMO_LOG_DataContract)o;
loggingQueue.Send(msg);
}
Note Client Configuration can optionally have WCF serviceModel to hint WCF services start processing. This is not absolutely needed but some of my test showed logging
stuck in MSMQ until a call is made to WCF Services:
<system.serviceModel>
<client>
<endpoint name="LoggingEndpoint"
address="msmq.formatname:DIRECT=OS:.\private$\Logging"
binding="msmqIntegrationBinding"
bindingConfiguration="LoggingBinding"
contract="GMO.XIPCommon.Logging.IGMOWCFTrace">
</endpoint>
</client>
<bindings>
<msmqIntegrationBinding>
<binding name="LoggingBinding" exactlyOnce="false" >
<security mode="None" />
</binding>
</msmqIntegrationBinding>
</bindings>
</system.serviceModel>
In other words, MSMQ integration need both MSMQ Code and WCF client code.
Wednesday, November 12, 2008
Sql Query Notification setup code
string cs = "Server=vcgmo;Initial Catalog=AdventureWorks; User Id=sa; password=xxxxxx;";
SqlConnection cn;
SqlDependency.Start(cs);
cn = new SqlConnection(cs);
cn.Open();
SqlDataReader r;
SqlCommand cmd;
SqlDependency sd;
SqlDataAdapter ad;
cmd = new SqlCommand("[dbo].[uspTest]", cn);
sd = new SqlDependency(cmd);
sd.OnChange += new OnChangeEventHandler(sd_OnChange);
r = cmd.ExecuteReader();
SqlDependency.Stop(cs);
void sd_OnChange(object sender, SqlNotificationEventArgs e) { }
Note: To enable SQL Notification, must run
ALTER DATABASE [DatabaeName] SET ENABLE_BROKER;
in the Database
Wednesday, November 5, 2008
Call C++ Open MP from C# code
static OMPCommon.TestCallback cb = new OMPCommon.TestCallback(Test);
static void Main(string[] args)
{
OMPCommon.Helper.UseOMP(cb);
Console.ReadLine();
}
static void Test(int i)
{
Console.WriteLine(i);
Thread.Sleep(5000);
}
// Set VS2008 C++ project Properties -->Configure --> C/C++ Language --> Support OpenMP
#include <omp.h>
#pragma once
using namespace System;
namespace OMPCommon {
public delegate void TestCallback(int i);
public ref class Helper
{
public:
static void UseOMP(TestCallback^ cb)
{
omp_set_num_threads(10);
#pragma omp parallel for
for (int i=0;i<20; i++)
{
cb(i);
}
}
};
}
Convert System.String to bstr
GMOBlotter::GMOBlotter(String^ TraderName, String^ TraderPassword, String^ XIPDBServer)
{
::bstr_t trader, pwd, server;
trader.Attach(static_cast(System::Runtime::InteropServices::Marshal::StringToBSTR(TraderName).ToPointer()));
pwd.Attach(static_cast(System::Runtime::InteropServices::Marshal::StringToBSTR(TraderPassword).ToPointer()));
server.Attach(static_cast(System::Runtime::InteropServices::Marshal::StringToBSTR(XIPDBServer).ToPointer()));
::MxEnumReturnCode ret;
ret=pMxgXOM->Login(trader, pwd, server, L"GMO_INTRADAY",::MxeEncryptionMethodNone);
};
Wednesday, October 15, 2008
VBS for NT services installation
Install/Uninstall by Name:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
("SELECT * FROM Win32_Service WHERE Name = 'IA DB Logging'")
For Each objService in colListOfServices
objService.StopService()
objService.Delete()
Next
Install by source exe
DIM objShell
set objShell = wscript.createObject("wscript.shell")
iReturn = objShell.Run("C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\installUtil IACalcDaemon.exe")
Subscribe to:
Posts (Atom)