C# FTP library vs FTP command line application - c#

I have an option to use either the C# FTP library or the standard FTP command line application to connect and to retrieve data from an FTP server.
Can some one advice on what to prefer.?
Thanks.

Why would you be using a commandline tool, intended for end users, from code? You'll be having a hard time reading and parsing stdout and stderr to get the responses or errors that result from your commands.
Just use the FtpWebRequest and FtpWebResponse since they provide in a decent, easy-to-use interface that contains error checking and so on.

Try to stay in a language's idiom where possible, so use a library when you can. Errors will be handled using C#'s Exceptions rather than checking some obscure command-line errorlevel value.

Using a Library, you have access to the classes, events, exception handling and so on, which integrate much better with your code. I would say that's more maintainable than having to interpret the text output and return codes of a commmand line application. So my suggestion is to use the library.

Related

Using QuickFix/n to read a FIX log file

I have a FIX format log file and a data structure I've built myself in C#. What I want to do is to run the log file in QuickFix and build my own event listener. In that listener, I'll convert the FIX types into the types I need and fill my DS.
I've been going through the QuickFix tutorials and examples, but couldn't figure it out. I don't need it to go through a network or anything like that.
Please help and thank you,
Yonatan
None of the QuickFIX ports provide this functionality. At best, you could build a simple app that could read the logfile line-by-line and pass each line to QF's Message(string) constructor. To convert that Message to a more specific type, you can feed it to a more-specific-type constructor, such as ExecutionReport(Message).
The above are for the original C++ QF. The other ports (QF/J and QF/n) should have similar mechanisms.
You will not be able to use the MessageCracker to fire OnMessage() events because you're not actually listening on a session. Instead, I'd recommend using a switch or doing an overload based on message class arguments.

Reading quickfix log file

I want to test my trading system by playing execution reports back into my application. Then I could verify that my order/position state is correct.
I found this somewhat related question: how to replay a quickfix log
The difference is that in the article the person was looking for a whole testing tool that would play back a log file. What I was wondering is whether there exists a utility that will take a string representing a FIX message and then just generate a FIX object (ex: ExecutionReport).
Does anything like this exist out there? Has everyone just been writing their own?
It sounds like you simply want a different kind of test tool.
If you've written your app in unit-test-friendly fashion, then you could simply write unit tests to create ExecReport objects and pass them as parameters into some ExecReport-processor component. (I'm guessing you're not designing for UTs, else you probably wouldn't need this suggestion.)
If not, then I think the best thing to do is write another app that your first app can connect to. You could create a simple Acceptor app that can use command-line commands to trigger ExecReports to be sent. If you're using QuickFIX/n (the C# port), you could steal code from QuickFIX/n's example apps "TradeClient" and "Executor".

Compile swf at runtime via C#?

I'd like to know if it's possible to compile an .swf file at runtime via C# (would be called via a Flex Application). I've read some articles about using fsch.exe, but nothing that gave any concrete examples.
I'm fairly certain this is possible, so a secondary question is whether it's feasible on a medium scale. I'd like to allow users to configure an swf, and then compile those settings directly into the swf for delivery rather than relying on external data storage for holding configuration details.
Thanks in advance for any assistance you can offer -
Bill
You should be able to do this fairly simply using a command line compiler.
You need to be able to setup the compiler on your server. http://www.google.com.au/search?hl=en&q=swf+command+line+compiler&btnG=Search&meta=
In your C# code you can then execute a shell command to invoke your compiler. http://www.google.com.au/search?hl=en&q=execute+command+shell+asp+.net&btnG=Search&meta=
One thing to be careful with is waiting for the compiler to finish before attempting to retrieve the compiled file. You will need to process the response from the compiler and ensure that the compilation succeeded.
I don't see why this wouldn't be feasible on a medium scale.
You can try MTASC.. it's command line based ActionScript compiler so you can just use Process.Start to call it and then use the Process.WaitForExit method to wait until it finishes compiling

Using Lisp in C#

As a lot of people pointed out in this question, Lisp is mostly used as a learning experience. Nevertheless, it would be great if I could somehow use my Lisp algorithms and combine them with my C# programs.
In college my profs never could tell me how to use my Lisp routines in a program (no, not writing a GUI in Lisp, thank you).
So how can I?
Try these .Net implementations of Lisp:
IronScheme
IronScheme will aim to be a R6RS
conforming Scheme implementation based
on the Microsoft DLR.
L Sharp .NET
L Sharp .NET is a powerful Lisp-like
scripting language for .NET. It uses a
Lisp dialect similar to Arc but
tightly integrates with the .NET
Framework which provides a rich set of
libraries.
Clojure is a Lisp-1 that is compiled on-the-fly to Java bytecode, leading to very good runtime performance. You can use Clojure, and cross-compile it to a .NET assembly using IKVM's ikvmc. Of course, when used in .NET, Clojure happily generates .NET IL, leading to the same kind of compiled-code performance you can expect when using it on a JVM.
If it's merely the routines you want to use you might try LSharp, which lets you have Lisp expressions in .NET:
http://www.lsharp.org/
The other way around (using .NET from Lisp) would be RDNZL:
http://www.weitz.de/rdnzl/
The .Net 1.1 SDK contains a LISP compiler example. See SDK\v1.1\Tool Developers Guide\Samples\clisp
I know this is a really old question. But I'll try to provide an answer from my own experience and perspective.
To those like us who love the pureness and elegance and simplicity of Scheme/Lisp, I hope this gives you some encouragement and inspiration how they can be very useful in real production :)
I recently open-sourced a Scheme-like interpreter from work called schemy, written in C# (~1500 line of code). And here's the motivation and how it is useful -
Without going into too much detail, I was building a web API server, whose request handling logic is desired to be plug-and-play by other developers/data scientists. There was a clear demand for separation of concern here - the server does not care much about the request handling logic, but it needs to know which requests it can handle and where to find and load the logic for the handlers.
So instead of putting handlers implementation in the server application, the server only provides re-usable "blocks" that can be chained together based on some criteria and logic to form a pipeline, i.e., handlers defined via configuration. We tried JSON/XML to describe such a pipeline and quickly realized that I was essentially building an abstract syntax tree parser.
This was when I realized this was a demand for a lightweight, s-expression based small language. Hence I implemented the embeddable schemy interpreter.
I put an example command handling application here, which captures the essence of the design philosophy for the web server I mentioned above. It works like so:
It extends an embedded Schemy interpreter with some functions implemented
in C#.
It finds .ss scripts which defines a command processing pipeline by using
those implemented functions.
The server finds and persists the composes pipeline from a script by
looking for the symbol EXECUTE which should be of type Func<object, object>.
When a command request comes in, it simply invokes the corresponding
command processor (the one defined by EXECUTE), and responses with the
result.
Finally, here's a complex example script, that provides an online man-page lookup via this TCP command server:
; This script will be load by the server as command `man`. The command
; is consistent of the following functions chained together:
;
; 1. An online man-page look up - it detects the current operating system and
; decides to use either a linux or freebsd man page web API for the look up.
;
; 2. A string truncator `truncate-string` - it truncates the input string, in
; this case the output of the man-page lookup, to the specified number of
; characters.
;
; The client of the command server connects via raw RCP protocol, and can issue
; commands like:
;
; man ls
;
; and gets response of the truncated corresponding online manpage content.
(define EXECUTE
(let ((os (get-current-os))
(max-length 500))
(chain ; chain functions together
(cond ; pick a manpage lookup based on OS
((equal? os "freebsd") (man-freebsd))
((equal? os "linux") (man-linux))
(else (man-freebsd)))
(truncate-string max-length)))) ; truncate output string to a max length
With this script loaded by the command server, a TCP client can issue commands man <unix_command> to the server:
$ ncat 127.0.0.1 8080
man ls
LS(1) FreeBSD General Commands Manual LS(1)
NAME
ls -- list directory contents
SYNOPSIS
ls [--libxo] [-ABCFGHILPRSTUWZabcdfghiklmnopqrstuwxy1,] [-D format]
[file ...]
DESCRIPTION
For each operand that names a file of a type other than directory, ls
displays its name as well as any requested, associated information. For
each operand that names a file of type directory, ls displays the names
of files contained within that directory, as well as any requested,
Perhaps you should take a look at L#. I don't know if it is what you are looking for (haven't touched Lisp since university) but it might be worth to check out.
http://www.lsharp.org/
There is also DotLisp.

Error logging in C#

I am making my switch from coding in C++ to C#. I need to replace my C++ error logging/reporting macro system with something similar in C#.
In my C++ source I can write
LOGERR("Some error");
or
LOGERR("Error with inputs %s and %d", stringvar, intvar);
The macro & supporting library code then passes the (possibly varargs) formatted message into a database along with the source file, source line, user name, and time. The same data is also stuffed into a data structure for later reporting to the user.
Does anybody have C# code snippets or pointers to examples that do this basic error reporting/logging?
Edit: At the time I asked this question I was really new to .NET and was unaware of System.Diagnostics.Trace. System.Diagnostics.Trace was what I needed at that time. Since then I have used log4net on projects where the logging requirements were larger and more complex. Just edit that 500 line XML configuration file and log4net will do everything you will ever need :)
Lots of log4net advocates here so I'm sure this will be ignored, but I'll add my own preference:
System.Diagnostics.Trace
This includes listeners that listen for your Trace() methods, and then write to a log file/output window/event log, ones in the framework that are included are DefaultTraceListener, TextWriterTraceListener and the EventLogTraceListener. It allows you to specify levels (Warning,Error,Info) and categories.
Trace class on MSDN
Writing to the Event Log in a Web Application
UdpTraceListener - write log4net compatible XML messages to a log viewer such as log2console
I would highly recommend looking at log4Net. This post covers the majority of what you need to get started.
Another good logging library is NLog, which can log to a lot of different places, such as files, databases, event logger etc.
I use The Object Guy's Logging Framework--as do most people who try it. This guy has some interesting comments about it.
Enterprise Library is a solid alternative to log4net and it offers a bunch of other capabilities as well (caching, exception handling, validation, etc...). I use it on just about every project I build.
Highly recommended.
Even though I personally hate it, log4net seems to be the de facto standard for C# logging. Sample usage:
log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
log.Error(“Some error”);
log.ErrorFormat("Error with inputs {0} and {1}", stringvar, intvar);
As I said in another thread, we've been using The Object Guy's Logging Framework in multiple production apps for several years. It's super easy to use and extend.
Log4Net is a rather comprehensive logging framework that will allow you to log to different levels (Debug, Error, Fatal) and output these log statements to may different places (rolling file, web service, windows errors)
I am able to easily log anywhere by creating an instance of the logger
private static readonly ILog _log = LogManager.GetLogger(typeof([Class Name]));
and then logging the error.
_log.Error("Error messsage", ex);
Serilog is late to the party here, but brings some interesting options to the table. It looks much like classical text-based loggers to use:
Log.Information("Hello, {0}", username);
But, unlike earlier frameworks, it only renders the message and arguments into a string when writing text, e.g. to a file or the console.
The idea is that if you're using a 'NoSQL'-style data store for logs, you can record events like:
{
Timestamp: "2014-02-....",
Message: "Hello, nblumhardt",
Properties:
{
"0": "nblumhardt"
}
}
The .NET format string syntax is extended so you can write the above example as:
Log.Information("Hello, {Name}", username);
In this case the property will be called Name (rather than 0), making querying and correlation easier.
There are already a few good options for storage. MongoDB and Azure Table Storage seem to be quite popular for DIY. I originally built Serilog (though it is a community project) and I'm now working on a product called Seq, which provides storage and querying of these kinds of structured log events.
You can use built in .NET logging. Look into TraceSource and TraceListeners, they can be configured in the .config file.
Ditto for log4net. I'm adding my two bits because for actual use, it makes sense to look at some open source implementations to see real world code samples with some handy additions. For log4net, I'd suggest off the top of my head looking at subtext. Particularly take a look at the application start and assemblyinfo bits.
Further to the couple of comments realting to the use of the System.Diagnostics methods for logging, I would also like to point out that the DebugView tool is very neat for checking debug output when needed - unless you require it, there is no need for the apps to produce a log file, you just launch DebugView as and when needed.
The built in tracing in System.Diagnostics is fine in the .NET Framework and I use it on many applications. However, one of the primary reasons I still use log4net is that the built in .NET Framework tracing lacks many of the useful full featured appenders that log4net already supplies built in.
For instance there really isn't a good rolling file trace listener defined in the .NET Framework other than the one in a VB.NET dll which really is not all that full featured.
Depending on your development environment I would recommend using log4net unless 3rd party tools are not available, then I'd say use the System.Diagnostics tracing classes. If you really need a better appender/tracelistener you can always implement it yourself.
For instance many of our customers require that we do not use open source libraries when installed on their corporate machines, so in that case the .NET Framework tracing classes are a perfect fit.
Additionally - http://www.postsharp.org/ is an AOP library I'm looking into that may also assist in logging as demonstrated here on code project:http://www.codeproject.com/KB/dotnet/log4postsharp-intro.aspx.
ExceptionLess is one of the easiest nuget package available to use for logging. Its an open source project. It automatically takes care of unhandled exception, and options for manually logs are available. You can log to online or self host on local server.
Log4Net, as others have said, is fairly common and similar to Log4j which will help you if you ever do any Java.
You also have the option of using the Logging Application Block http://www.codeproject.com/KB/architecture/GetStartedLoggingBlock.aspx

Categories