How to run a .py (Python) file in ASP.NET? - asp.net

I have a GetList.py file which consumes Web Service and saves the output in XML on the server.
How do I invoke GetList.py so it saves the output in XML on the server before displaying the XML output in .ASPX page?

You can create one batch file which contains call to python file and call that batch file from you .net application.
To call batch file, you can use Process class.
For example, suppose you have test.py file containing following code :
print "hello world"
then create one batch file (file having .bat extension) which has following contents :
python C:\test.py
Assuming you are using C#, and ur batchfile is stored in (C:\test.bat) you can use following code to invoke batch file
Process.Start("C:\test.bat");
You can have more details about Process class here

If your server has a Python interpreter installed, use that. (It's usually in /usr/bin/python)
If it doesn't (and it probably doesn't, since you use .NET), use IronPython. It's based on .NET and works very nicely with ASP.NET. Fair warning: if your GetList.py script uses parts of the CPython standard library that haven't been implemented in IronPython, you might have to change the script. See this article to get a basic intro to IronPython and see how it fits in with .NET.

Related

How do I use RESTXQ with BaseX for a simple web app?

I'm trying to create a really basic web app that lets a user upload an xml file with a form, runs an XQuery script which I already have written as a function, and returns the result. I have BaseX running on Tomcat, but for the life of my I cannot understand RESTXQ even though I have a lot of experience with complex XQuery scripts. The BaseX documentation has been no help (http://docs.basex.org/wiki/RESTXQ). What is the basic architecture?
From what I can see, its all keyed on this restxq.xqm file in the webapp directory. If you link to that directory it runs the .xqm file and this is mandated by a web.xml file. But it seems that all of the html sections are also stored within this restxq.xqm file. Wouldn't it make sense so store html sections in separate files for maintenance/reusability?
Also, for my file upload form, do I have the action attribute point to restxq.xqm? I can make the pages all static html since the app is so simple, but where is the index.html file go? This seems WAY more confusing than it has to be.

Call java method from the microsoft docx document

I want to call the one of java method of my java class file from the Microsoft docx type document?
Is there any simple and stable solution available for this ?If anybody having idea on this can you please share it with me?
Thanks in advance
Yatin Baraiya
Microsoft Language for MS docx is Visual Basic, you can't natively call java methods.
You could also execute a shell command to do what you want:
retValue = Shell("command", vbNormalFocus)
Found on How can I execute a shell command using VBA?
One way to do it would be to use IKVM to convert your Java code to a DLL, and to invoke that from say a VSTO Word add-in.
Another way would be to convert your Java code to a web service (SOAP or REST), and call that, either from a Word Add-In, or VBA (ie a Word macro). For SOAP, see for example http://jamesecampbell.blogspot.com.au/2012/11/how-to-consume-web-service-in-microsoft.html

How to create and write data into a file using flex3?

I want to create a file and write some data (userid) into the file at first run of my application, during the second run all the operation (will go to the next state) based on the file data, is it possible? How to create and write data into file?
It depends if you're working on a pure-Flex or an AIR project.
If you are making an AIR application, you can access local files using the File class (more informations can be found here and here) ;
If not, you'll have to use a server-side script (PHP, ColdFusion, Java EE...) to do the job, calling it using a HTTPService object for instance.
If you are not concerned about file's location and max content of file is less than 100 KB then you may make use of Shared Objects in flash.

web.config - auto generate a release version

Simple task, but for some reason no simple solution just yet.
We've all got web.config files - and I haven't worked anywhere yet that doesn't have the problem where someone yells across the room "Sh*t, I've just uploaded the wrong web.config file".
Is there a simple way of being able to auto generate a web.config file that will contain the right things for copying to release? An example of these being:
Swap connection string over to use live database
Change
Switch over to use the live/release logging system, and live/release security settings
(in our case we need to change the SessionState mode to InProc from StateServer - this isn't normal)
If you have others, let me know and I'll update it here so it's easy for someone else to find
Maintaining 2 config files works, but is a royal pain, and is usually the reason something's gone wrong while you're pushing things live.
Visual Studio 2010 supports something like this. Check it out here.
How are you deploying your builds. In my environment, this used to be a pain point too, but now we use cruisecontrol.net and script our builds in nant. In our script, we detect the environment and have different versions of the config settings for each environment. See: http://www.mattwrock.com/post/2009/10/22/The-Perfect-Build-Part-3-Continuous-Integration-with-CruiseControlnet-and-NANT-for-Visual-Studio-Projects.aspx for my blogpost onthe subject of using cruisecontrol.net for build management. Skip to the end fora brief description of how we handle config versions.
In my most recent project I wrote a PowerShell script which loaded the web.config file, modified the necessary XML elements, and saved the file back out again. A bit like this:
param($mode, $src)
$ErrorActionPreference = "stop"
$config = [xml](Get-Content $src)
if ($mode -eq "Production")
{
$config.SelectSingleNode("/configuration/system.web/compilation").SetAttribute("debug", "false")
$config.SelectSingleNode("/configuration/system.web/customErrors").SetAttribute("mode", "off")
$config.SelectSingleNode("/configuration/system.net/mailSettings/smtp/network").SetAttribute("host", "live.mail.server")
$config.SelectSingleNode("/configuration/connectionStrings/add[#name='myConnectionString']").SetAttribute("connectionString", "Server=SQL; Database=Live")
}
elseif ($mode -eq "Testing")
{
# etc.
}
$config.Save($src)
This script overwrites the input file with the modifications, but it should be easy to modify it to save to a different file if needed. I have a build script that uses web deployment projects to build the web app, outputting the binaries minus the source code to a different folder - then the build script runs this script to rewrite web.config. The result is a folder containing all the files ready to be placed on the production server.
XSLT can be used to produce parameterized xml files. Web.config being xml file this approach works.
You can have one .xslt file(having xpath expressions).
Then there can be different xml files like
1. debug.config.xml
2. staging.config.xml
3. release.config.xml
Then in the postbuild event or using some msbuild tasks the xslt can be combined with appropriate xml files to having different web.config.
Sample debug.config.xml file can be
<Application.config>
<DatabaseServer></DatabaseServerName>
<ServiceIP></ServiceIP>
</Application.config>
.xslt can have xpaths referring to the xml given above.
Can have a look at the XSLT transformation This code can be used in some MSBuild tasks or nant tasks and different web.config's can be produced depending on the input config xml files.
This way you just have to manage the xml files.
There is only one overhead that the xslt file which is similar to web.config need to be managed. i.e whenever there is any tag getting added in the web.config the xslt also needs to be changed.
I don't think you can 100% avoid this.
The last years of work ever and ever shows: where human worked, there are fails.
So, here are 3 ideas from my last company, not the best maybe, but better then nothing:
Write an batch file or an C#.Net Application that change your web.config on a doubleclick
Write a "ToDo on Release"-List
Do pair-realesing (== pair programming while realease :))

Not tracking C# designer-generated code: refuses to generate with clean checkout

In our ASP.NET MVC project we have a Strings.resx file and the accompanying autogenerated Strings.Designer.cs file.
Tracking the Strings.Designer.cs file in source control creates a bunch of ugly merge conflicts and it's autogenerated anyway, so we decided to untrack it (remove it from source control and ignore the local copy of the file).
This works well, except that on a fresh checkout of the source the Strings.Designer.cs file doesn't exist. The PublicResXFileCodeGenerator that generates the file from Strings.resx balks with a warning:
"The custom tool 'PublicResXFileCodeGenerator' failed while processing the file 'Views\Setup\App_LocalResources\Strings.resx'."
And as a result, all of the strings in that file generate compile errors. This means you must manually right-click on each Strings.resx file in the project and choose "Run Custom Tool".
Is there any way to get the ResX code generator tool to run automatically even if Strings.Designer.cs doesn't yet exist?
(We've experimented with ResGen but it is finicky--it refuses to generate Strings files with the proper filename and namespace.)
You can use ResGen.exe to explicitly regenerate the .resources and .Designer.cs files from your .resx. Just throw a command that looks something like the following into your prebuild events:
ResGen.exe Strings.resx NameSpace.Strings.resources /publicClass /str:cs,"Your.Namespace",Strings,Strings.Designer.cs
...which will generate a Your.Namespace.Strings.resources file and a Strings.Designer.cs file w/ a "Strings" class in the "Your.Namespace" namespace.
(The /publicClass switch tells ResGen to generate public members, and "cs" is the C# language choice.)
Read more here: http://msdn.microsoft.com/en-us/library/ccec7sz1(VS.80).aspx

Resources