Currently we are using cron strings for setting Quartz jobs in our project. But it seems to be either overkill or little confusing to set by a admin guy who is not a developer. So, we try to use a simple string like this,
each 1 seconds on MonTueWedThuFri between 00:01 and 23:59
Is there any existing frameworks (or in Quartz) I will be able to get a cron string out of this string? (I know i can parse this to get a simple trigger, but don't want to DRY)
Currently there isn't one as far as I know. Your example wouldn't work just SimpleTrigger, you would also need a calendar to get rid of firing in the weekend. So in this case CronTrigger would probable be the thing you are looking for.
But back to the original question... There probably isn't any made for Quartz(.NET) and it would quite fast prove itself to be non-trivial.
Currently there is no such implementation yet, I would like to contribute a Contrib (or a patch) once I am done with it. I am currently writing this feature.
Related
I have a fairly large code base sprinkled with a bunch of DateTime.UtcNow, many other calls and TimeSpans, etc.
Now we are introducing tasks with timers, etc and I need to run the system at a variable speed to debug, like a day is 5 minutes, etc.
Since there are a lot of things depending on time and I can't change the logic everywhere, I can do two things:
Create a fake assembly in Visual Studio so I replace DateTime; Or,
I can simply change all the DateTime calls to my own class which would normally just return results from DateTime.
But, ultimately, it boils down to writing a replacement of DateTime and since the code is using more than DateTime.UtcNow, I would like to find a existing solution if possible.
Does anyone know if such a thing exists? I haven't found anything so far
Have you tried mocking?
I would create an interface that returns the time a task must run. That would let you create two classes one for debug and one for release, that way when you are debugging you can return whatever value you need and you won't need to worry about how core classes work.
I hope it helps!
The question is kinda hard to understand but what I'm trying to do is to launch a program and make that program think that the system clock is "some other date and time" and not actually change the system time. How can I do this programmatically using C#?
P.S: I can't alter the program I launch in any way.
EDIT: I just realised that the program checks the time only once after ~4-6 seconds of startup. So I will just change the system clock for 10 seconds and restore it back! Thanks for all the help!
You will have to intercept calls to winAPI like GetSystemTime. C# is not the best instrument for such thing, but nothing impossible. Use any detours library that supports C#. Think of a way to modify program address space (remote thread, WriteProcessMemory, filter DLL).
That is a very general idea of where you may find the solution.
Though if you will ask how to intercept program calls to OS, you will hardly get any answers here, at least if you show no own efforts.
If you know what date/time functions your application uses, you can investigate which system calls those CLR methods use. Once you know, you can test your software in an environment where those calls are intercepted, presumably giving "fake" responses to e.g. DateTime.Now in .NET.
There are utilities that do this for you, for example http://www.nirsoft.net/utils/run_as_date.html
I don't know if the specific system calls intercepted by that utility is the ones used by the framework to give for example DateTime.Now
This is the old question but my answer will probably help someone.
What we do in our project is to use interface like this:
interface IDateTime
{
DateTime Now();
....
}
Then you use IDateTime instead of regular DateTime just everywhere and IoC to get instance of IDateTime.
So, as result you can create any implementation of Now().
Really helpful when writing unit tests.
I want to set expire date for my C# Windows application.
It means that i.e after 30 days my app won't work. It is easy to do when we use system time, it means whenever my program starts i check today date and expire date.
The problem is if the user changes system time, my comparison won't be correct.
What other ways can this be done?
I would figure out a better way to get people to want to pay for the application, because fighting it can be a very futile effort, although you can make it more difficult with things like hardware dongles, phone home services, etc. If your price point is not high, customers won't want to put up with this.
May be keep a dummy .dll file in your app install folder, open it and keep the number of days and install date time. Every time application loads up, check it. .Dll files folks wont try to open and read. May be you can encrypt and store in it too. This could be very simple.
The first line of defense is to check with a server, checking out their system time so that the user cannot change his own. Also try to hide the start date (under some dummy name in the registry perhaps). These are pretty futile things though, smart users will be able to 'crack' this with minimal effort.
It's trivial to disassemble a C# application, so whatever you implement will be liable to easy circumvention. The best choice, in my opinion is to use third-party Licensing tools but do bear in mind that all can be circumvented, although they will be more robust.
How likely is your app to be pirated and is it worth the time/expense to do anything more than cursory checks?
It might be easier to simply have two versions of a DLL - one that must communicate with a server every X days to make sure it's still active and the "unlocked" (purchased) version.
As has been noted, determined users will find a way around whatever you do so you have to evaluate effort/return to determine how much attempting to secure your app is worth.
You could use a website that keeps the time to determine how long the program was installed.
You are probably going to get advice saying that it is not woth your effort.
first I'd wanna say this is my first question here, I'll try to comply to the asking tips the best I can... Also I couldn't find a way to post this in a specific C# section so I just used it in the title.
What I'm trying to accomplish is intercepting the sound output of TeamSpeak, and figuring out which person on the channel is producing the loudest sound. I had a look at TeamSpeak SDK but it's more intended for building your own VoIP software than fooling around with TeamSpeak itself...
At first I'm just going to make a simple program that shows the names of the persons and a dB bar (or something that represents loudness) next to them.
I was surprised to see there isn't much discussion around this, I think there's a lot of cool snippets to be made (this one will be for kicking spastics swiftly.)
I am converting some old C# code, and it has a CountDownLatch using a package called Spring.Threading.Helpers. The odd thing is that I can't find this package on Google - so a) is it still supported? And, if so, where is it documented? b) What I really want to do is wait for a count to get to zero, but interrupt every so many msecs. Would it just be simpler to set up another thread, and do WaitOnes on an Event specifying an interval? TIA
It looks like it is part of spring.net - www.springframework.net - so my better question is: is spring.net a standard part (?) of Microsoft Visual C#?