How to add an event receiver to my console application? - c#

I have a simple console application that upload a file to sharepoint and then I do some operations with file that I need to do. Until now everything seems to be correct. But now I need to add an event receiver that when the file is update or deleted the event send a message to service bus indicating the change. I saw a lot of tutorials but none of them show how to do this from the beginning and using console application in c#, I need to know where to start.
PS: I am using VS 2013

Related

Launching an application from another using the wrong app.config

All our custom applications are currently accessed by staff via a custom Toolbar Menu (not built by myself). This is built using vb and uses the line
Process.Start(FileToLaunch, params)
The issue I have is I have built an Application that can send push notifications to mobile devices (This is built with C#, WPF, MVVM, XAML), and it must use its own app.config for these push Notifications to work. This application works perfectly when running it directly by clicking on its .exe the push notifications are all sent successfully.
On launching it from the Toolbar Menu Application via the line of code above, the Notifications Application is looking for the config settings in the Toolbar Menu folder instead of the Notifications application.
This is then causing the following error when sending notifications.
There has been an error, which has been logged.
Error Message: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details
My colleague says that the only way they have dealt with this in the past is to add all relevant config settings to the Toolbar Menu Application app.config.
This does not seem like a good way to work.
If you have any suggestions on how to get the application to launch using the correct config I would be most grateful.
Also please just ask if you need any further information.
Thanks

asp.net or windows service that listen to if you get a Email

I am trying to make a program that will listen to if I recieve a E-mail I got a smtp server and so on.
I want to make a database object with Title and text from the Mail and I might want to evolve it into also saving the attacted file to the database so I can use it it my asp.net program.
I think I need a windows Service that will be listening to the email if it gets a email it will add it to datbase and wait again but I am not sure how to do that. if its possible to program that into my asp.net project then it would be a good thing also
Here is a small design on how I was thinking about it
if you know anything about it feel free to come up with any kind of solutions for me.
Read incoming emails with POP3 or Exchange. I've made something similar before, which was a system where users could add links (a type of linking-scam actually) to different websites. So there was a bunch of people in Asia that had a full-time job searching for relevant sites and emailing a list of these URL's to a specific email-address. A service I had running would check the POP3 inbox every 5 minutes or so and then post these links to the website.
You should make an application that gets run at specific intervals rather than a service, which is much simpler. If you're using Azure as a host you can use the scheduled task service there to make a POST call to a page on your site so you don't have to run the code in a different eco-system. Well, I guess you can do that anyway with scheduled tasks in windows.
Here's a POP3 client for .NET
You could make a C# service that checks the pop3 server in a configured interval, and store them in the DB. There's something like this here:
http://aspsnippets.com/Articles/Fetch-and-Read-emails-from-POP3-mail-server-using-C-and-VB.Net---Part-I.aspx
But as a regular application, you just have to make it to run as service (I think you have a project template for that in VS). You have some info here:
http://msdn.microsoft.com/en-us/library/zt39148a(v=vs.110).aspx
Okay I figured out a good solution for this problem friends :)
What I did was I downloaded the EAGetMail and implamentet it. it basicly works for you in a time interval it will check your mail and make a txt file with all the mails so it wont read it again. it also got a aplication field so everytime it runs it will run the selected application.
So I made a console application that runs trough my folder where it will save all my email's as .eml file. It will check for a sub folder called read if its not there then create it and then check the root folder for .eml files read them and save information from it to the database and then move the file to read.
We did not want to use pop3 cuz we wanted the mails to stay intact så we dont lose any information. so we ran for the IMAP4.
and in the asp.net I just run a query that checks the database and use the files.

Windows Service doesn't complete what it's intended to do and it's suddenly stopped by the system?

I've been stuck with this annoying problem for the last couple of hours, and I've just exhausted my resources. This is what's going on:
I have a Windows Service created using the 4.0 .NET framework. The main functionality of this service is to read all .txt files contained in a folder, validate the formatting of these files and then send them to another folder, create an xml file from those files, and then create a pdf file using the information contained in the xml; I'm using the Report.NET library (http://sourceforge.net/projects/report/) to create these .pdf files.
When I run the service, it does everything it's supposed to do except generate the .pdf file, and then I get the following error:
"Service on Local Computer started and then stopped. Some service stop automatically if they have no work to do."
Also, I forgot to mention, if I debug the windows service using Visual Studio, everything works as intended and the .pdf files are generated correctly.
I've already tried attaching the "main" function to a thread and then starting that thread on the OnStart() method, but that doesn't seem to work, neither adding a timer.

showing a popup form a windows service

Im looking for some advice on an application im creating using a windows service. Basically we have some timesheet software and i need to create a windows service that will poll a db to see if they have completed last weeks timesheet. If they havent completed it i want the application to popup a message stating that it is incomplete and that they should go and complete it.
Ive created a simple service from a tutorial i found and got it to install and run fine. I now need to think about the form side that popups up. Thing is im not sure its a good idea to do this from a service. Can anyone give me a steer on the best way to develop this application using a windows service.
as mentioned earlier you may not create userinterfaces from within Services. In order to achieve this. you have to build another application. you can use Windows Forms or WPF for building the NotificationArea inteagration application.
I would use WCF with net tcp binding to communicate between both applications.
Well as you aslmost said your self. This is not well suited for a windows service since there is nothing going on when a user is not logged in. If on the other hand you were also sending mails AND showing pop up a duel approach would be ideel.
I recommend scrapping the service and only use your form.
You could develop ANOTHER WinForms application that reads from a Database (for example) every X seconds
Your Windows Service will write to the Database indicating whether the job is done or not.
once your Winforms application (that can sit in the system tray for example) reads from the database and sees the job is not done - make it pop up and alert the user.
Just a thought!

How can you attach a C# console application to a running windows service?

I have a windows service that generates logs as it does some execution. I also do console.writeline call for every log message I write into the log file. But since its a windows service the console.write line is not visible.
I want to write a C# console application program that can attach to my service (already running) and it could just show all console.writeline messages that the process (my windows service) is generating.
updated: The volume of log is very frequent ( 50 messages every minute) , I would prefer not want to crowd windows event log for this. Using a cosole window helps to look at logs and exit on convenience
Displaying a window from a service is not a good idea as you would have to find out the "correct" session (Windows allows several users to be logged on) and also requires the service to have access to the user's desktop.
Instead, it is probably easiest to change the Console.WriteLine calls into Trace.WriteLine. Then you can attach to these trace messages, e.g. by using SysIntenal's DebugView.
I think you'll struggle to attach a console to an existing service. Two easy options
write to the windows application log
write to a text file, which you can then open with wintail or similar
Re your update - number 2 would be best then.
You can make the service interactive, in which case you'll see the console window, but you'll always see it, and I think if you close it, you'll stop the service.
Alternatively, make your console monitor read updates out of the log file at a reasonable interval instead of trying to get into the service process directly.
I would suggest you to log messages to Windows Event Viewer, if don't have burning desire to show them on console window. This link would help you...
Send data via UDP and make a simple program to show the data.
You warrant and asynchronous operation and can even send to another host.
I used cygwin to tail on the log file thats created by log4net this seems to do the trick for me.
Thanks for all the help!
Or open the file with http://www.log-expert.de/ and tail away. You can even make it colorful!

Categories

Resources