Play framework Publish–subscribe pattern - meteor

Is there some utility library or like available to refresh webpage when content in database changed? E.g. I've external process which updates database, how to show changes somewhat automatically for end user? Other than some timer based "refresh web page every 1 minute".
I know only one web framework where this is available, Meteor
Publish-subscribe pattern

Related

Initializing an asp.net deployment

I have a basic webforms asp.net site. Currently its working on pre-created sql tables and I have to manually triger it to update data. Moving towards a live deployment though, I'd like to make it more comfortable.
How would I make it so that whenever the server software loads it up, the first thing it does before accepting any requests is to run an initialization sub? Just so I can make sure all the tables are there and if not I would create them etc.
Also, I'd like to run another sub that would trigger the data update periodically every few hours. I was thinking that if I could get my initialization sub, I could just spawn a background thread to deal with that but if theres a built-in option, I'll take it.
whenever the server software loads it up
In asp.net, you have the global.asax file - open the code behind for that and look at the possible overrides. Among them will be:
protected void Application_Start()
This always runs when the application starts up and you could use this to check the DB.
If you're in an "in-house" environment where there's a single live database server and a single live application server, then it should be ok to assume that the database is deployed before the application and you won't need this. If you're providing an application to a third-party or providing it on the web, then this is a good place to check. How you generate the DB is up to you, but checking here is a good idea. You could also have a (hidden) admin page on your site that checks the database connection etc.
trigger the data update periodically
This won't be built-in to asp.net as asp.net waits for requests and responds to them. There are ways around this, but generally triggered externally to the application. The easiest is a simple windows scheduled task that hits a page to trigger the check.
This is what's referred to as "deployment".
If your web site is deployed via MSI, this step should be done in MSI.
If your web site is deployed via Visual Studio "publish" option, this is where you need to create tables.
Some applications indeed do as you say, e.g.: create SQL tables on the 1st run. The problem with this approach is that your app will need sa rights, instead or simple read/write. This could lead to security issues.
Code which runs on web site launch (which is where initialization belongs to) is located in global.asax in:
protected void Application_Start()

Quartz.NET: in the Asp.Net Web vs Console Application

I need to run 4 background gobs for cleaning temp files and proccessing some files. I have chosen Quart.net for the job.
I have a Asp.Net website, which accepts uploading files that will be processed by the Quartz Jobs at night.
First i thought about making a console application for the Quartz jobs, keeping the website and the jobs totally decoupled.
But then, i've seen that i will need some config values (connectionstring and paths to files) that are on the asp.net web.config. So a question came to my mind:
Should i run the jobs through the asp.net instance or should i do this on a console application?
Furthermore, i want that when the Quartz jobs start running, the website show a special page (like "We are processing the files...).
What i care the most is the performance, i don't want the website to be affected by the Quartz jobs, neither the jobs' performance affected by the website.
So, what should i do? Have you done something like this and can give me an advice?
Should i run the jobs through the asp.net instance or should i do this on a console application?
If you want to have to manually trigger them each night, sure. But a console application using the host system's task scheduler seems like a more automated solution. A web application is more of a request/response system, it's not really suited for periodic or long-running actions. Scheduling some sort of background operation on the host, such as a scheduled console application or a windows service, would serve that purpose better.
Note that if it truly needs to be unattended and run even when there's nobody logged in to the server console, a windows service may be a more ideal approach than a console application.
i've seen that i will need some config values (connectionstring and paths to files) that are on the asp.net web.config
Console application have App.config files which serve the same purpose. You can use that.
i want that when the Quartz jobs start running, the website show a special page
You definitely want to keep the two de-coupled. But you may be able to accomplish this easily enough. Maybe have some sort of status flag in the database which indicates if any particular record is "currently being processed". The website can simply look for any records with that flag when a page loads and display that message.
There are likely a couple of different ways to synchronize status here, it doesn't really matter what you choose. What does matter is that the systems remain decoupled and that any status which is statically persisted is handled somewhat carefully to avoid an errant process from leaving an incorrect status. (For example, a background task sets a status of "processing" and then fails in some way. The website would forever indicate that it's processing.)

How can I code my web app so that it knows what web server it's on?

My company has an ASP.NET web app that runs on a web farm that's load balanced by Enterprise Foundry ServerIron XL 8 hardware. For debugging purposes, we've got a page that just reports what server it's running on. Currently, we manually copy a different version of this page to each server, and hardcode the name of that server (e.g. www1, www2, or www3). What I'd like instead is to find a way for the app to determine this information itself, so we don't have to do this manual step, outside of the code itself, but I can't find any way to accomplish this.
So the question is: how can an ASP.NET app be made aware of where it's actually running?
You can do this via IIS itself.
Find the web application. In the app's main config page (features view), under IIS section you'd find HTTP Response Headers. This feature enables you to add/remove headers which need to be sent along with every response of that application.
However, you'd need tools like fiddler to be able to inspect such data.
Another option is a custom server control or user control, placed anywhere within a page which will output that information during it Render phase (as html comment). You can get using System.Environment class.
var mc_name = System.Environment.MachineName;

Updating an existing web app advice for asp.net

I have a web application that is used by several different clients. At the moment the process of updating their end with any changes is like so:
Publish/Compile App
Put relevant files into a zip (not web.config as different db paths for each client and don't want to overwrite)
Generate scripts on SQL Server for all Stored Procedures
Add to zip
Upload zip to Web
WPF App I created that runs from client server downloads zip, extracts files to web app folder and executes scripts for sql server stored procedures
Now this does work but it requires an IT guy at the client end to run the WPF App to update and it can be days before some of them get round to it. So what I would like to do is provide the ability to update the web app from WITHIN the web app. I know I can create a DLL to do the FTP, Extract etc, but how can I get this to display progress on the page?
Or if anyone has an alternative to updating the web app without the need for someone to access the server it's on great as this method makes it hard to let clients know when there is an update available.
You can use i.e.
[assembly: PreApplicationStartMethod(typeof(Your.Type), "MethodNameToCall")]
which is specified in the AssemblyInfo.cs file of a project to do some setup code whenever the application is deployed. This automatically runs on deployment and would allow you to do your copying/setup. You could probably run the WPF App from this code via
System.Diagnostics.Process
UPDATE:
Having re-read this post it seems clear to me that this is about moving from a WPF app to a web based app. Also it appears the poster just wants a method by which to signal back from the code that is updating the file system on the client side so....
Depending on how complex the input required is you may need one or more pages and a navigation system to go forward and back.
However once all input had been taken and the update commenced you have a couple of options - one 'hacky' the other not so.
1 - Hacky) Refresh the page using window.location javascript and setTimeout along with session tracking to update the progress of the threaded coded behind EWWWWW...
2) Create an ajax function using setInterval to poll the server (probably using a callable method decorated with the [WebMethod] attribute. This method can send back arbitrary data back to the ajax call which is then used to update the UI (perhaps using something like jqueryUI progress bar
NOTE: IF you are replacing anything in the bin, touching the web.config or in fact ANY .aspx page. Then you will restart the server automatically... If this is the case then you will have to code a seperate application that will update the other application from the outside + you should signal to any connected users that a shutdown will occur shortly and start blocking new users until the upgrade has completed.

.NET Script Scheduler

Hey I have a .NET .aspx page that I would like to run every hour or so whats the best way to do this ?
I assume it will have to open a browser window to do so and if possible that it closes the window after.
EDIT : I have access over all features on the server
Option 1: The cleanest solution would be to write a Windows application that does the work (instead of an aspx page) and schedule this application on the server using the Windows Task Scheduler. This has a few advantages over the aspx approach:
You can use the features of the Windows Task Scheduler (event log entries if the task could not be started, see the time of the last run, run the task in the context of a specific user, etc.).
You don't need to "simulate" a web browser call.
Your page cannot be "accidentally" called by a web user or a search engine.
It's conceptually cleaner: The main purpose of a web page is to provide information to the client, not to trigger an action on the server.
Of course, there are drawbacks as well:
You have two Visual Studio projects instead of one.
You might need to factor common code into a shared class library. (This can also be seen as an advantage.)
Your system becomes more complex and, thus, potentially harder to maintain.
Option 2: If you need to stick to an aspx page, the easiest solution is probably to call the page via a command-line web client in a scheduled task. Since Windows does not provide any built-in command-line web clients, you'd have to download one such as wget or curl. This related SO question contains the necessary command-line syntax:
Scheduled Tasks for ASP.NET
use this sample to schedule a task in asp.net :
enter link description here
then you need to create Hit.aspx page witch will do what you want. then you should call that page every time (using WebClient class) the task execution time elapsed!
You can use http://quartznet.sourceforge.net/ Quartz Job Scheduler.
With Quartz.net you can write a job which will request your web page with interval you choose.
or alternatively you can write an windows service which will request that web page.

Resources