
Merrion
*Experts*
-
Posts
269 -
Joined
-
Last visited
Merrion's Achievements
Newbie (1/14)
0
Reputation
-
if there are no listeners, why does it matter whether the heartbeat thread is running? Ah - there is a supposed to be a default listener. Kind of like the way "Trace" works. Assuming this is your application I'd like to attach it to existing coded applications
-
Hi I have a static class that acts as a "hearbeat" to allow external listeners to tell if the application is running healthily :- private static HeartbeatListenerCollection _listeners = new HeartbeatListenerCollection(); /// <summary> /// Sends a heartbeat to any heartbeat monitors /// to indicate that the application is running /// </summary> public static void Beat() { // make each heartbeat listener beat foreach (HeartbeatMonitorBase _listener in Listeners) { _listener.Beat(); } } /// <summary> /// Starts the heartbeat with a default frequency /// </summary> static Heartbeat() { // Fire up a thread to invoke hearbeat events // perdiodically... TimerCallback timerDelegate = new TimerCallback(Heartbeat.Beat); AutoResetEvent autoEvent = new AutoResetEvent(false); System.Threading.Timer heartbeatTimer = new System.Threading.Timer(timerDelegate, autoEvent, 0,1000); } /// <summary> /// The listeners attached to the heartbeat /// </summary> /// <remarks > /// These should not be triggered directly but rather the /// Heartbeat.Beat() method should be called /// </remarks> public static HeartbeatListenerCollection Listeners { get { return Heartbeat._listeners; } } } However the static class is only instantiated the first time it is referred to (effectively the heart only starts beating if we start listening to it). Can anyone think of aclever way to instantiate this class at application startup automatically?
-
perhaps it's not dead, but it is pining for the fjords?
-
There's a persist-objects-and-collections to sql database table example that I have posted in the code library on the sister site that may be use to you. It's not ORM but a half-way house...
-
Unfortunately I do need to upload a file - the web site that I'm automating takes a username, password and file to upload... I have written an ASP page to emulate it thus:- Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim RequestOK As Boolean Dim input(Request.TotalBytes) As Byte Request.InputStream.Read(input, 0, Request.TotalBytes) 'Don't send a response until the input is processed... Page.Response.BufferOutput = True Page.Response.ContentType = "application/xml" With Request.Form If .Item("username") = "Merrion" Then If .Item("password") = "Duncan" Then If Page.Request.Files.Count > 0 Then RequestOK = True Page.Request.Files(0).SaveAs("c:\temp\uploaded_file.xml") End If End If End If If Not RequestOK Then Dim ErrOutput As New XmlTextWriter(Page.Response.OutputStream, System.Text.Encoding.UTF8) With ErrOutput .WriteStartDocument() .WriteStartElement("Return") .WriteStartElement("Settings") .WriteElementString("Method", Request.HttpMethod) For h As Integer = 0 To Request.Headers.Count - 1 .WriteElementString(Request.Headers.Keys(h), Request.Headers.Item(h)) Next .WriteEndElement() .WriteStartElement("DataContent") If input.Length = 0 Then .WriteElementString("data", "Not set") Else Dim foo As New System.Text.ASCIIEncoding .WriteElementString("data", foo.GetChars(input, 0, input.Length)) End If .WriteEndElement() .WriteStartElement("Errors") .WriteElementString("FormValues", Request.Form.Count.ToString) For n As Integer = 0 To Request.Form.Count - 1 .WriteElementString(Request.Form.Keys.Item(n), Request.Form.Item(n)) Next .WriteEndElement() 'Errors .WriteEndElement() 'Return .WriteEndDocument() .Close() End With End If End With End Sub But when I write to it from my app (as per the code above) it has no values in the Page.Forms collection - i.e. the return is:- <?xml version="1.0" encoding="utf-8"?> <Return> <Settings> <Method>POST</Method> <Connection>Keep-Alive</Connection> <Content-Length>364</Content-Length> <Content-Type>multipart/form-data; boundary=-----------------------------7d6386366801f6</Content-Type> <Accept>application/xml</Accept> <Expect>100-continue</Expect> <Host>localhost</Host> </Settings> <DataContent> <data>-----------------------------7d6386366801f6 Content-Disposition: form-data; name="username" Merrion -----------------------------7d6386366801f6 Content-Disposition: form-data; name="password" testpwd -----------------------------7d6386366801f6 Content-Disposition: form-data; name="asof" 04Jul06 -----------------------------7d6386366801f6-- </data> </DataContent> <Errors> <FormValues>0</FormValues> </Errors> </Return> but when I use an HTML form to send the data I get:- <?xml version="1.0" encoding="utf-8" ?> - <Return> - <Settings> <Method>POST</Method> <Cache-Control>no-cache</Cache-Control> <Connection>Keep-Alive</Connection> <Content-Length>350</Content-Length> <Content-Type>multipart/form-data; boundary=---------------------------7d61021b7503f8</Content-Type> <Accept>*/*</Accept> <Accept-Encoding>gzip, deflate</Accept-Encoding> <Accept-Language>en-ie</Accept-Language> <Host>localhost</Host> <Referer>http://localhost/PresentValueServlet/getValuation.htm</Referer> <User-Agent>Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 1.0.3705; .NET CLR 2.0.50727)</User-Agent> </Settings> - <DataContent> <data>-----------------------------7d61021b7503f8 Content-Disposition: form-data; name="username" Merrion -----------------------------7d61021b7503f8 Content-Disposition: form-data; name="password" Duncan -----------------------------7d61021b7503f8 Content-Disposition: form-data; name="asof" -----------------------------7d61021b7503f8-- </data> </DataContent> - <Errors> <FormValues>3</FormValues> <username>Merrion</username> <password>Duncan</password> <asof /> </Errors> </Return>
-
I have written an app that "fills in" a web form and posts it. This is done by encoding the parameters in multipart/form-data mode e.g.:- Public Class multipart_formdata #Region "Private constants" Private Const DEF_BOUNDARY As String = "-----------------------------7d6386366801f6" #End Region #Region "Private members" Private _Boundary As String Private _FormText As New StringBuilder #End Region #Region "Public interface" Public ReadOnly Property MultipartBoundary() As String Get Return _Boundary End Get End Property Public ReadOnly Property Text() As String Get Return _FormText.ToString & " " & _Boundary & "-- " End Get End Property Public Sub AddParameter(ByVal ParameterName As String, ByVal ParameterValue As String) _FormText.Append(_Boundary) '----------------------------7ce3023980c _FormText.Append(" ") _FormText.Append("Content-Disposition: form-data; name=") _FormText.Append(QuoteString(ParameterName)) _FormText.Append(" ") _FormText.Append(ParameterValue) _FormText.Append(" ") 'Content-Disposition: form-data; name="UploadFormName"; filename="C:\Directory\UploadFile.txt" 'Content-Type: text/plain ' 'This is a test file for ProjectUpload. '-----------------------------7ce3023980c-- End Sub #End Region #Region "Public constructor" Public Sub New() Me.New(DEF_BOUNDARY) End Sub Public Sub New(ByVal Boundary As String) If Boundary Is Nothing OrElse Boundary = "" Then _Boundary = DEF_BOUNDARY Else _Boundary = Boundary End If End Sub #End Region #Region "Private methods" Private Function QuoteString(ByVal sIn As String) As String Return Chr(34) & sIn & Chr(34) End Function #End Region End Class Then , for example to send a usename and password to a URL you could do thus:- Dim webReq As HttpWebRequest = CType(WebRequest.Create("http://www.test.com"), HttpWebRequest) Dim byteOut() As Byte Dim _form As New multipart_formdata With _form .AddParameter("username", _Username) .AddParameter("password", _Password) End With Dim encoder As New System.Text.UTF8Encoding byteOut = encoder.GetBytes(_form.Text) With webReq .CachePolicy = New System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.BypassCache) .Accept = "*/*" .Method = "POST" 'set the request method to POST .ContentType = "multipart/form-data; boundary=" & _form.MultipartBoundary .ContentLength = byteOut.Length - 1 .Expect = Nothing .Referer = "http://localhost/PresentValueServlet/getValuation.htm" End With Dim outStream As Stream outStream = webReq.GetRequestStream() If outStream.CanWrite Then '\\ write the request string to it... outStream.Write(byteOut, 0, byteOut.Length - 1) outStream.Close() End If The problem is that even though the form data is sent to the web service, the Page.Form property is blank at the recieving end - any ideas?
-
One of the problems of using the windows API for this (believe me, I have a lot of difficult experience in this area) is that some applications do not give the correct number of copies to the spooler monitor. For instance Microsoft Word passes different number of copies depending on whether or not the collation options are set.... Instead you need to parse the spool file and count the number of pages it contains.
-
It would be remiss of me not to add a link to the Evolutionary Computing framework on GotDotNet... ;)
-
The work in progress is up on GotDotNet
-
There's no namespace and the values _ImplementingAssembly and _ImplementingClassType are being read from the .config file OK. Strangely when I do this:- #Region "Instance" Public ReadOnly Property Instance() As Object Get If _Instance Is Nothing Then Try ' Dim hdlSample As ObjectHandle hdlSample = Activator.CreateInstanceFrom(_ImplementingAssembly, _ImplementingClassType) _Instance = hdlSample.Unwrap Catch ex1 As System.TypeLoadException Console.Write(ex1.GetBaseException.ToString) 'Try to find the class yourself... Dim assyPlugIn As System.Reflection.Assembly Dim fiAssy As New System.IO.FileInfo(_ImplementingAssembly) If fiAssy.Exists Then Try assyPlugIn = AppDomain.CurrentDomain.Load(_ImplementingAssembly) Catch fnf As System.IO.FileNotFoundException Console.WriteLine("Could not find " & fnf.FileName) Exit Property End Try Else Exit Property End If Dim typThis As Type For Each typThis In assyPlugIn.GetTypes Console.WriteLine(typThis.Name) If Not typThis.GetInterface("IDataSource", True) Is Nothing Then Console.WriteLine("Gotcha") End If Next End Try End If Return _Instance End Get End Property #End Region It gets to the line Console.WriteLine("Could not find " & fnf.FileName) which means that the FileInfo class sees the file but the CurrentDomain.Load() doesn't. Very strange...
-
[PLAIN][resolved] System.TypeLoadException dynamically loading classes from DLLs[/PLAIN] OK - I am writing an application that allows you to add plug-ins DLLs that implement a specific license. So in the .config file I hagve something like:- <dataSchemaProvidors> <!-- The plug in providors that implement the DataSchemabase classes to write out the DDL for creating the database objects on the target database platform Key= The unique name that the providor is known by ImplementingAssembly = The assembly that holds the providor ImplementingClassType = The class that implements the providor --> <dataSchemaProvidor Key="SQL Server" ImplementingAssembly="SQLServerDataSchema.dll" ImplementingClassType="SQLServerDatasource"/> </dataSchemaProvidors> Then in a totally seperate project I create a DLL called "SQLServerDataSchema.dll" and it exports a public class "SQLServerDatasource". My container program is supposed to instantiate it by:- #Region "Instance" Public ReadOnly Property Instance() As Object Get If _Instance Is Nothing Then _Instance = Activator.CreateInstanceFrom(_ImplementingAssembly, _ImplementingClassType) End If Return _Instance End Get End Property #End Region Where _ImplementingAssembly holds the DLL name and _ImplementingClassType the class name in that DLL. However I am getting an exception: Resolution Ity turns out that even though no namespace was specified the DLL name was used as a default namespace so the config file should have held:- <dataSchemaProvidor Key="SQL Server" ImplementingAssembly="SQLServerDataSchema.dll" ImplementingClassType="SQLServerDataSchema.SQLServerDatasource"/>
-
I own a Triumph GT6 - this one in fact It is currently away being totally restored at vast expense.
-
Then you certainly need to look at the Empower/ISV program. You get the full MSDN universal (5 licenses) fro just $350ish. There are restrictions which you probably qualify for..definitely worth a look.
-
If you do a sleep(10000) in the OnStart() sub if the license is not present then it will time out and stop itself.
-
I know it seems like gravedigging but this really has been sat at the bottom of my todo list for all this while. Attached is an updated version of the framework and a hello world application of same - a program that tries to solve the "Mastermind" game (coloured pegs thing). Any thoughts? Mastermind.zip