I am very new to C# and Microsoft Visual Studio, so, with that in mind, I am teaching myself and have started a project (excuse my lack of vocabulary). What I have so far is a WPF project that looks good but offers zero functionality. The general functionality I envision is this:
The Main Window has multiple buttons which navigate to multiple pages. (Achieved this already)
On each page navigated to, I want to display information from a website. (?)
Using the web information, I want control another program on the desktop. (?)
Are points (2) and (3) possible using C#?
Let me illustrate the scenario. A person submits information (username) into a website. That website contacts a server and sends back data about that person/username. The website then stores this data and usernames on a list visible to the users. There are five different lists and five navigable xaml pages via the main window on the program. I want to display each list on each page. Using the data found on the website and now my program, I want to send a command to a program/script running on the desktop and have it perform an action (type the usernames somewhere using AutoHotKey and AutoScriptWriter, which is essentially updating a special notepad file).
The answers I am looking for are not "this is how you do specifically what you're asking" but rather "Use these tools/features in C# and start there". If what I want from this program is possible, I have these follow up questions:
The information submitted to that website would be constant, so would the web information viewed through the program be updated/refreshed in real-time?
Would creating an entirely new website to work with the program be more beneficial than using an existing website and scraping information from it?
Can a program communicate with another program on a local virtual desktop via Oracle VirtualBox?
If someone used this program on their computer, could they command the program/script on my computer via the internet?
Quick answers to your various questions:
Is not a question...
Websites are just user interfaces sitting on top of logic defined on a webserver - if you can interact with the logic (i.e. a webservice) instead of with the raw UI layer (which is HTML) you should rather do that. You can find a control which will render HTML information but this is unlikely to be the best approach for what you want to do.
Yes, through COMInterop with the Windows Shell - quite an advanced topic and I hope you understand Windows SDK, memory management and unmanaged, unsafe pointer-based code quite well.
Follow-up questions:
I don't understand the question - you're submitting information constantly or the information you're submitting is always the same? You would need to trigger the refresh of the web information (i.e. request the particular page) when you want a refreshed rendering of the webpage.
Most beneficial would not be using the user interface at all (webpage) and establishing a link to the logic layer instead and requesting the data directly via a web service - it gives you the most control in your WPF application.
Yes, but again, very advanced stuff - it's not simple or easy and comes with a host of challenges such as local security and automation APIs for VirtualBox.
Doubtful unless you wrote the code to be internet-enabled which again, is an advanced topic.
If I understood your situation correctly, you can use the WebClient class to communicate with your web server and use the returned string by it to generate the content.
WebClient web = new WebClient();
web.Headers.Add("HTTP Header", "Header Value");
web.Headers.Add("POST Data Header", "POST Data Value");
string response = web.DownloadString(new Uri("https://www.myserver.net/mypage"));
// Implement your processing on response variable here to generate and present data to the user.
And you can use the StandardOutput of the Process class to get the output of any programs on the local machine.
Process proc = new Process();
proc.StartInfo.FileName = #"C:\Path\to\my\executable.exe";
proc.Start();
proc.StartInfo.RedirectStandardOutput = true;
// Start the process...
proc.Start();
// Retrieve the output...
string output = proc.StandardOutput.ReadToEnd();
Related
As a DBA/SQL Server Developer, I'm often asked to produce web pages where users can view the data in the database and edit them, and see the edits they've made straight away (without refreshing the page). I know nothing about ADO.NET or C#, but I would like to be able to give users this very simple functionality. Essentially I'm looking for three things:
to display a table of data in a webpage retrieved from a SQL Server stored procedure
to display a text box in the same webpage where users can input data
to display a button in the webpage that takes the inputted data from the text box, runs it through the stored procedure as a parameter, and refreshes the table.
Ideally I'd like this all to happen without the user having to refresh the webpage.
My questions are: is this kind of thing possible? How difficult is it to achieve? And how do I do it? I don't have the time to learn web development in full. I wouldn't need the vast majority of skills I'd learn even if I did learn it in full. I just really need this basic functionality, to produce ultra simple pages when user requests come in.
If anyone knows of any examples of just this kind of thing, that I can copy, they would be greatly appreciated!
You don't really need to use MVC, WebForms or even C# for that matter. Using one of those would be killing a ant with a rocket launcher.
Look into node.js and pug, using a RESTFUL API to deliver the information you need. I don't believe you will need more than two hours to provide your users with the interface you told us.
Node has a awesome package called express, it sets up everything for you and uses Pug on the starter template.
You can check out a tutorial right here.
Actually it will also take 2 hours doing with Webforms or MVC . I recommend using Entity Framework to make it super simple.
Webforms may be a bit older technology but will be faster to develop this specific page (assuming you only targeting Desktop users). Otherwise MVC is the way to go.
You can Check the tutorial.
https://learn.microsoft.com/en-us/aspnet/mvc/overview/getting-started/introduction/getting-started
So, here's the use case. I work for Salesforce Marketing Cloud as a technology architect. We have a very robust "Marketing Cloud" app which I don't do any development on. I don't have access to source code/etc. I do have access to the application though, as a user.
Quick 2 sentence overview of the application: big companies like "Company A" utilize our software to be able to send billions of emails (promotional and transactional) to their customers. So, say you get an email from "Company A" telling you of all the great products they offer - that email is sent from our system.
So, the use case: the Marketing Cloud application, for simplicity's sake, is able to create an email from HTML. Basically, the user (myself) can copy/paste HTML into the huge text field, and click Save, and the email code is saved into the back end (SQL Server table). This application does not have any kind of source control to manage the different versions of the "email" that the user decides to create/change/modify.
Now, I have access to develop a customized "whatever" via C#/SSJS that has access to all of the elements in the database that the application writes to. So, if I wanted to grab the latest version of an "email" saved by a user, I can simply write a SQL query to grab this content.
Here's my goal: To create a very simple version control system without getting into the source code of the application. Ambitious, I know. I have all the different pieces of this mapped out in a document, but the one obstacle I'm running into is "how can I capture the 'save' event for when a user clicks 'save' and saves an email"? I believe this is a client side event, but I'm not 100% sure. My initial thought is to write a browser extension, but not knowing exactly what browser extensions have the capability of doing, I'm not sure if this is a good route to take. How can I capture an event from a UI from a web based application when I don't have access to the source code?
today, I use Selenium to parse data from a website. Here is my code:
public ActionResult ParseData()
{
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl(myURL);
IList<IWebElement> nameList = driver.FindElements(By.XPath(myXPath));
return View(nameList);
}
The problem is, whenever it runs, it opens new window at myURL location, then get the data, and leave that window opening.
I don't want Selenium to open any new window here. Just run at the background and give me the parsed data. How can I achieve that? Please help me. Thanks a lot.
Generally I agree with andrei: why use Selenium if you are not planning to interact with browser window?
Having said that, simplest thing to do to prevent Selenium from leaving the window open, is to close it before returning from the function:
driver.Quit();
Another option, if the page doesn't have to be loaded in Firefox, is to use HtmlUnit Driver instead (it has no UI)
Well, it seems that on each web request you are creating (though, not closing / disposing) a Selenium driver object. As I have said in the comment, there may be better solutions for your problem...
As you want to fetch a web page and extract some data from it, feel free to use:
WebClient
WebRequest
A web application is not very a hospitable environment for a Selenium driver instance IMHO. Though, if you still want to play a bit with it, make the Selenium instance static and reuse it among requests. Still, if it will be used from concurrent requests (multiple threads running at the same time), a crush is very probable :) You have the option to protect the instance (locks, critical section etc.) but then you will have zero scalability.
Short answer: fetch the data by in another way, Selenium is just for automatic exploration tests as far as I know...
But...
If you really have to explore that website - the source of your data - with Selenium... Then fetch the data using Selenium in advance - speculatively, in another process (a console application that runs in background) and store it in some files or in a database. Then, from the web application, read the data and return it to your clients :)
If you do not have yet the data the client has asked for, respond with some error - "please try again in 5 minutes", and tell the console application (that's running in background) to fetch that data (there are various ways of communicating across process boundaries - the web app and the console app in our case, but you can use a simple file / db for queuing "data requests" - whatever)...
Please answer for Dummies ;) ... Absolute newbie to web programming, especially new to Drupal. We have some modules written in C#, that access a database in MySQL and works on it (it's a student information system actually. We have some forms created in C#, through which interface student's can enter their details onto the database and we have desktop applications which work on those data). Now we need to create a website so that student's can enter information through the internet. We can not re-write the whole modules in PHP, and we want to use Drupal to create the website. So how to do that?
Not really a direct answer, but some points that you need to consider. How complicated this will be depends on how much interoperability you need between the C# code and Drupal.
Does Drupal need to use the forms written in C# in order to enter the data in the DB, or could data entry be done directly from PHP (As in, is there any validation or processing of data in the C# forms that needs to be done?) If not, it seems like the easiest way would be to build a page in Drupal that can enter the data directly into the MySQL database.
Otherwise, the easiest way to get the programmes to talk to each other might be outputting the data to another format — e.g. XML or JSON. (Here's a similar question with someone using JSON as the intermediary data type) You could have your PHP form create an XML document in a temp folder, with the C# programme polling this folder for new files every X minutes and use them as an input into its application.
It will really depend on your workflow — how immediate does the processing of data need to be? Is the flow of data in/out, or in only — i.e does there need to be a set of results returned to the user?
I need to create a web application that prints checks. Because of the nature of the program, it needs to be very secure, and each action needs to be logged. I need to be able to generate a check, print a check, allow reprints if needed, etc.
I've got the generation of the checks completed. I've decided to make a PDF (so that i don't get any browser header/footer garbage). What I'd like to do is not even save that PDF to a file but to instead send the data directly to a printer. Basically, I'd like for the user to enter the amount of the check, select which account it's going to be printed for, then click a button that sends the data for that check directly to the printer. I don't even want the user to be able to view the PDF of what's to be printed.
Has anyone done something similar to this in ASP.NET?
Thanks.
[EDIT]
The original question I asked was answered with ActiveX controls. I, however, decided to do it a different way. Instead of printing a PDF, I've decided to create an image of the background of the check. I will then use that image (.jpg), and manipulate it by placing the appropriate text (MICR line, amount, check date, etc.) on it using System.Drawing.Graphics and stored X,Y coordinates and font preferences in my DB. From there, I can use the System.Drawing.Printing namespace to send the new .jpg file to a network printer from the web server, eliminating the need for an activeX control and further tightening security because the new image of the finished check is never saved, and the user never has access to the overlay of the check.
Thanks for your help.
If you look at how postal services tackle this problem, you'll notice that a simple web application won't do. To have control over how and when items are sent to the printer, ActiveX compontents or Java software is used.
[Edit]
Small clarification: I ment that the software has to run on the client-side as opposed to your suggested server-side suggestion.
If you want to go the .NET route, you're down to an ActiveX in Managed C++ or a Click-Once application that is launched from the web (allows more of the .NET language, but can be decompiled and altered).
We have implemented this scenario in a couple of ways. First, we have the traditional PDF solution, where the server generates the PDF print image, returns it to the browser which is then displayed via the PDF plug-in and optionally printed.
Second, we wrote a client-side ActiveX component to handle the print. Pass the input values to a backend web service which uses FOP to format the print into PCL. The PCL is passed back to the ActiveX component who then sends the PCL directly to the users default printer. No PDF required here.
Either way works, but only the second option - which will require you to implement some client-side piece - meets all your requirements.
There isn't really a way to do this. You can only send a document to the user which the user can then send to the printer. There are ways to prompt the print dialogue to pop straight up, but the web would be pretty insecure if you were allowed to control how data was managed on the user's machine.
NKCSS is right that it would require software actually installed on the user's machine. You have done as much as you can by making it a PDF that the user is prompted to print.
If you had the cheque as html, you can used styles to show/hide content just for the printer as discussed in this post: here
There's no way to do this completely securely. Even if you force the PDF to print directly to the user's default printer, that itself could be a PostScript or PDF printer like PDFCreator. So they could still get a viewable PDF in the end.