Some VB6 and Windows Forms applications are still great but probably you need them to reach a bigger audience.
There are now amazing devices with internet access, but all of then different in hardware and software combinations.
HTML and in particular HTML5 five technologies provide an unifying set of technologies that are supported by the main industry vendors. HTML5 browsers are available on tables, cell phones, linux/mac/windows PCs.
In this post I will add references to other pages which do a great work on explaining how to use this approach to host a Windows Forms App inside a WebBrowser.
The technique described here is a deployment solution to ease distribution of applications modernized from legacy technologies to Windows Forms, maybe using the Artinsoft\Mobilize.NET tools ;)
NOTE: "This workaround of .NET Winforms to WPF and then hosting it in a browser isn't truly moving a Windows based application to a web based application. e.g. database calls will be made from inside the browser on the users PC to the database, not via the IIS server. Therefore this functionality is most useful if you have connected your Winforms UI to you back-end code using web services, then you can have a somewhat web based application."
Adam Berent gives step by step instrutions:
Figure 1: Example of Windows Forms applications running inside FireFox browser using an XBAP wrapper.
Some details that are missing in this article are related to how to publish the application on IIS, and these can described as:
1. Create a test Certificate within Visual Studio and sign it against the project.
The following links provides information on how to sing the xbap with your own certificate.
2. Within VS publish the application.
4. Install the certificate on the Client PCs
The certificate must be added in the trusted publisher and in the trusted root authority. If this is not done correctly you get the error 'Trust not granted'
In this post I will add references to other pages which do a great work on explaining how to use this approach to host a Windows Forms App inside a WebBrowser.
The technique described here is a deployment solution to ease distribution of applications modernized from legacy technologies to Windows Forms, maybe using the Artinsoft\Mobilize.NET tools ;)
NOTE: "This workaround of .NET Winforms to WPF and then hosting it in a browser isn't truly moving a Windows based application to a web based application. e.g. database calls will be made from inside the browser on the users PC to the database, not via the IIS server. Therefore this functionality is most useful if you have connected your Winforms UI to you back-end code using web services, then you can have a somewhat web based application."
Adam Berent gives step by step instrutions:
Figure 1: Example of Windows Forms applications running inside FireFox browser using an XBAP wrapper.
Some details that are missing in this article are related to how to publish the application on IIS, and these can described as:
1. Create a test Certificate within Visual Studio and sign it against the project.
The following links provides information on how to sing the xbap with your own certificate.
2. Within VS publish the application.
4. Install the certificate on the Client PCs
The certificate must be added in the trusted publisher and in the trusted root authority. If this is not done correctly you get the error 'Trust not granted'
I think Silverlight is a great technology that can be use to create great applications, or as a migration target from Visual Basic 6, Powerbuilder or Windows Forms apps which can take advantage of a very simplified deployment approach.
And use Artinsoft/ Mobilize automated solutions (see http://www.artinsoft.com/visual-basic-6-or-csharp-to-the-web.aspx )
Deployment is as simple as just publish your SL application on your intranet and your clients just need to press F5 to have the latest SL version.
Silverlight provides a good balance between ease of development and platform features(XAML and .NET and Visual Studio).
Silverlight can run cross-platform. (On Windows and Mac using the official Microsoft implementation and on Linux using Moonlight.
Support For Silverlight 4
Support For Silverlight 5
NOTE: Moonlight provides support for 32 and 64 bit Linux. It supports Silverlight 2.0, and some features of silverlight 3 and 4, but is not currently an active project.
"In the past, Web developers often used ActiveX controls to provide rich client-side functionality in their Web applications. Now developers can easily build objects using the Microsoft .NET Framework that are more compact, lightweight, secure and can be hosted within Internet Explorer. By hosting .NET Windows Forms controls in Internet Explorer, developers can accomplish many client-side Web development goals..."
This is an excellent introduction from Thiru Thangarathinam article in CodeGuru
In the rest of this article he provides great details on how to accomplish this task.
Figure 1: Example of simple Hello Word Windows Forms App embedded in Browser
Figure 2: Example of a more complex Windows Forms App consuming data from a Web Service
" However before using Windows Forms controls in IE, you need to be aware of the benefits and limitations. The main benefits include:
-
The ability to deliver dynamic rich user experience through the Web
-
Automatic caching of compiled code on the client
-
Seamless integration with .NET Code Access Security that allows you to leverage the .NET security model from within the client side
-
Improved performance over Java applets
-
It requires Windows operating system on the client side
-
Internet Explorer 6.0-9.0 is the only browser that provides support for this type of hosting
-
It requires .NET runtime to be installed on the client machine.
-
It also requires Windows 2000 and IIS 5.0 or above on the server side"
Artinsoft\Mobilize.Net helps legacy application to be modernized using the Windows Forms technology. Doing this upgrade revitalizes your application code and allows you to take advantage of the new platforms features like ClickOnce deployment.
What is ClickOnce deployment?
"ClickOnce is a deployment technology that enables you to create self-updating Windows-based applications that can be installed and run with minimal user interaction. Visual Studio provides full support for publishing and updating applications deployed with ClickOnce technology if you have developed your projects with Visual Basic and Visual C#.
ClickOnce deployment overcomes three major issues in deployment:
-
Difficulties in updating applications. With Microsoft Windows Installer deployment, whenever an application is updated, the user can install an update, an msp file, and apply it to the installed product; with ClickOnce deployment, you can provide updates automatically. Only those parts of the application that have changed are downloaded, and then the full, updated application is reinstalled from a new side-by-side folder.
-
Impact to the user's computer. With Windows Installer deployment, applications often rely on shared components, with the potential for versioning conflicts; with ClickOnce deployment, each application is self-contained and cannot interfere with other applications.
-
Security permissions. Windows Installer deployment requires administrative permissions and allows only limited user installation; ClickOnce deployment enables non-administrative users to install and grants only those Code Access Security permissions necessary for the application.
In the past, these issues sometimes caused developers to decide to create Web applications instead of Windows-based applications, sacrificing a rich user interface for ease of installation. By using applications deployed using ClickOnce, you can have the best of both technologies."
Click Once Deployment Strategies
There are 3 deployment strategies:
- Install from Web or a Network Share
- Install from a CD
- Start from the Web or Network share
For a quick overview of how to use the ClickOnce deployment take a look at Shahar Gvirtz's post http://weblogs.asp.net/shahar/archive/2008/01/29/how-to-use-clickonce-to-deploy-your-applications.aspx
We have some Mac Minis in our server room and I forgot the VNC password.
I could connect physically to the machine but I needed a DVI monitor and I did not have one :(
Answer:
Connect thru putty.exe and use this excellent command:
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -on -clientopts -setvnclegacy -vnclegacy yes -clientopts -setvncpw -vncpw mypasswd -restart -agent -privs -all
I was trying to profile an ASP.NET application that was hosted on my local IIS.
But everytime I started the profiler I got a message like:
"Could not start IIS"
"Couldn't open metabase ..." "account has reduced privileges..." bla bla.
I could not understand why? My account is in the administrator group and yes,
Visual Studio was running as Administrator
Solution:
1. Run cmd as Administrator
2. c:\windows\microsoft.net\framework\v4.0.30319
3. aspnet_regiis
4. aspnet_regiis -ga Domain\User
And then log off and log in
I you are debugging an Android App you use the command
adb logcat to display all sort of output from the device. (And I mean it ALL SORT of output).
So if your are working with PhoneGap/Cordova and only want to see your console.log messages, just run something like this
adb logcat *:S CordovaLog:D
Now, we all write pages and HTML5 apps that must work in Mac/Linux/Windows/iPhone/iPad/S3/Nexus... you name it.
And sadly not all browsers behave the same, so a common problem is that you have to bind your code to all sort of events.
My friend Luis Diego send me a nice javascript library that tries to use the microsoft win8 idea of unified all these events under an umbrella of pointer events.
Pointer.js is the library proposed there. I tried it on my HTC WP7 and not everything works. On my pc works very nice and still need to tried on some mobile devices.
I might need some tune up but is a great start.
If you try to upload large files you might get an exception like
HttpException: Maximum request lenght exceeded.
This problem occurs because the default value for the maxRequestLength parameter in the section
of the machine.config or Web.config file is 4096 (4M).
So any file with a size bigger will fail.
However I think that the max size that you can write here is 2G 2097151
Some info can be found here: http://support.microsoft.com/default.aspx?scid=kb;EN-US;295626
So to change that for 512mb use something like:
<configuration>
<system.web>
<httpRuntime maxRequestLength="524288" />
</system.web>
</configuration>
If you ever wonder, if Crystal Reports can be used on the cloud in Windows Azure, well the answer is you can.
These two links provides some guidance on this matter:
http://scn.sap.com/people/coy.yonce/blog/2011/05/02/sap-crystal-reports-and-microsoft-sql-azure (this one is in English)
http://blogs.msdn.com/b/luispanzano/archive/2011/04/11/crystal-reports-en-windows-azure.aspx (this one is in Spanish but Bing and Google Translate do a nice work here ;) )
Crystal Reports was a tool very used by VB6 developers.
Sometimes when you are migrating a VB6 applications, you find a lot of reports created with this tool.
What should you do? Should you rewrite them on another technology?
Well that really depends on project requirements, but Crystal Reports has good support for VS2010, both for 32 and 64 bit environments.
So you don't need to throw away your reports you can still use Crystal Reports.
However that hard thing to do is where to find Crystal Reports for VS. Do you need to buy some software for that?
I have found that you can download Crystal Reports for VS2010 is just that the links are a little hidden. My friend Victor send me the following information which has been very useful for this task:
a) For Deployment Environment:
1. Download the Redistributable Package for Visual Studio according to the platform (32 bits or 64 bits). And install it. You will find the installer in the following link:
2. Give access to the user executing the IIS process to the path for the Temp Folder (C:\Windows\Temp or the corresponding folder on windows installation).
3. Download the "Microsoft SQL Server 2008 Feature Pack", where you can find the "Microsoft SQL Server 2008 Native Client ". Download the corresponding installer according to the platform of the server (x86, x64 or IA64).
b) For Development environment:
1. Download the "Complete Package" for development on Visual Studio 2010. Please be sure that if you're on a 64 bits machine, you check the "Install 64 bits Runtime" before you click on finish when you complete the installation.
2. Be sure that the current user running on your machine has access to the Temp Folder (C:\Windows\Temp or the corresponding folder on windows installation)
3. If you don't have the Microsoft SQL Server 2008 Native Client Provider (sqlncli10), download the "Microsoft SQL Server 2008 Feature Pack", where you can find the "Microsoft SQL Server 2008 Native Client ". Download the corresponding installer according to the platform of the server (x86, x64 or IA64).
4. To create a new report please be sure you use a "OLE DB (ADO)" Connection and that you're using the "SQL Server Native Client 10.0" Provider, and use the right login information. If the report was previously created with a different provider, please change it on the "Set Datasource Location", editing the Provider field.
This issue is mostly cause by timing issues when calling a multi-threaded app.
Some workarounds:
1. Set the application visible property to false. For example if using Word make word visible property false at the start of the method and set it back to true at the end.
This will delay some GUI changes avoiding timing issues.
2. Insert some Thread.Sleep calls (yes this is ugly)
3. Register and IOleMessageFilter. I have copied an implementation from the MSDN
Just copy this class in your code.
At the start of the method call
MessageFilter.Register();
// This registers the IOleMessageFilter to handle any threading
// errors.
And at the end
MessageFilter.Revoke();
public class MessageFilter : IOleMessageFilter
{
//
// Class containing the IOleMessageFilter
// thread error-handling functions.
// Start the filter.
public static void Register()
{
IOleMessageFilter newFilter = new MessageFilter();
IOleMessageFilter oldFilter = null;
CoRegisterMessageFilter(newFilter, out oldFilter);
}
// Done with the filter, close it.
public static void Revoke()
{
IOleMessageFilter oldFilter = null;
CoRegisterMessageFilter(null, out oldFilter);
}
//
// IOleMessageFilter functions.
// Handle incoming thread requests.
int IOleMessageFilter.HandleInComingCall(int dwCallType,
System.IntPtr hTaskCaller, int dwTickCount, System.IntPtr lpInterfaceInfo)
{
//Return the flag SERVERCALL_ISHANDLED.
return 0;
}
// Thread call was rejected, so try again.
int IOleMessageFilter.RetryRejectedCall(System.IntPtr
hTaskCallee, int dwTickCount, int dwRejectType)
{
if (dwRejectType == 2)
// flag = SERVERCALL_RETRYLATER.
{
// Retry the thread call immediately if return >=0 &
// <100.
return 99;
}
// Too busy; cancel call.
return -1;
}
int IOleMessageFilter.MessagePending(System.IntPtr hTaskCallee,
int dwTickCount, int dwPendingType)
{
//Return the flag PENDINGMSG_WAITDEFPROCESS.
return 2;
}
// Implement the IOleMessageFilter interface.
[DllImport("Ole32.dll")]
private static extern int
CoRegisterMessageFilter(IOleMessageFilter newFilter, out
IOleMessageFilter oldFilter);
}
[ComImport(), Guid("00000016-0000-0000-C000-000000000046"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
interface IOleMessageFilter
{
[PreserveSig]
int HandleInComingCall(
int dwCallType,
IntPtr hTaskCaller,
int dwTickCount,
IntPtr lpInterfaceInfo);
[PreserveSig]
int RetryRejectedCall(
IntPtr hTaskCallee,
int dwTickCount,
int dwRejectType);
[PreserveSig]
int MessagePending(
IntPtr hTaskCallee,
int dwTickCount,
int dwPendingType);
}
From:
label {
display: block;
float: left;
width: 150px;
}
Today Joseph was creating a windows service, which had an schedule task to execute something on an Oracle Server.
Everything worked out of the Windows Service but as soon as he added it to the Windows Service, it fail.
He suspected it had something to do with the 64 bit platform so he made sure to compile for AnyCPU, but it did not work...
Answer: It was the OracleClient fault. The OracleClient for ADO.NET do not work for AnyCPU. You need to use the 64 or 32 bit version.
It happen to me that I had a website working perfectly in my IIS and when I went to publish it it looked completely distortionated.
Why !! The eternal why.
I ended finding that it had something to do with the compatibility mode of IE, but why was it changing. It looks like it has some relation with the IIS version. Not sure why.
But the fix is to do something like:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<httpProtocol> <customHeaders> <add name="X-UA-Compatible" value="IE=edge" /> </customHeaders> </httpProtocol>
</system.webServer>
This meta tag instructs the IE to set the compatibility mode to the highest value.
You can use other values as IE7 or IE8So just put that and your site will look nice again :)
I was looking for a pure .NET equivalent of the Windows API function
GetUserDefaultLCID because I want my code to be free of pinvoke references
to avoid posible issues in 64 bits.
However after a lot of digging I found that there is not direct equivalent.
You could use Thread.CurrentThread.CurrentCulture.LCID but it is not exactly the same.
So I found this great post in stackoverflow:
"
For some background information have a look here:
http://blogs.msdn.com/b/michkap/archive/2010/03/19/9980203.aspx
So it seems this problem manifests itself on Vista as well as Windows 7. It occurs because Microsoft seems to be in the process of deprecating the Locale ID in favor of the Locale Name.
To summarize: The relevant API calls all operate on registry values that can be found at HKCU\Control Panel\International. The value "Locale" is maintained for backward compatibility reasons and under normal circumstances is kept in synch with its newer counterpart called "LocaleName". This synch process however doesn't work under some circumstances.
Anyway, the GetThreadLocale API call gets its return value from the "Locale" registry entry mentioned above, while the others (GetUserDefaultLCID, GetSystemDefaultLCID, etc) use the "LocaleName" registry entry.
Hence the confusion.
BTW, the solution mentioned by JP in a previous post should probably be extended to
initialization
SetThreadLocale(GetUserDefaultLCID);
GetFormatSettings;
because (if i'm reading it correctly!) according to the docco the GetUserDefaultLCID call will account for user customizations.
After a bit more research, Vista is not affected at all. I've got some more detail too ...
The relevant API calls all operate on registry values that can be found at HKCU\Control Panel\International. The value " Locale " is maintained for backward compatibility reasons and under normal circumstances is kept in synch with its newer counterpart called " LocaleName ". Under Windows 7 at least, this synch process however doesn't work where processes are being run as another user (i.e. RunAs or Impersonation). This seems to be the case during installation, where the installer is launched from an existing windows session. It does however seem to work correctly if you've booted from the install CD.
GetThreadLocale gets its value from Thread Information Block or Thread Environment Block (TIB or TEB) See: http://en.wikipedia.org/wiki/Thread_Environment_Block For both Vista and Windows 7, the TIB is initialised with the HKCU\Control Panel\International\Locale registry entry at logon. This becomes the default Locale for all threads created during the session. Changing this registry value during a session has no effect on the value returned by the GetThreadLocale API call. The user must log out and log in again to see a change. This is the API call that Delphi uses as the basis to initialize all its locale format strings ( See SysUtils.GetFormatSettings method), from which all date fields are formatted.
GetUserDefaultLCID: in Vista, bases its return value on the HKCU\Control Panel\International\Locale registry entry. In Windows 7, bases its return value on the HKCU\Control Panel\International\LocaleName registry entry. The respective registry entry can be changed during a session and the result is immediately reflected in this API call return value.
SetThreadLocale updates the TIB to reflect the locale provided in the parameter to this call. Note that this only ever effects the thread the API call is executed from. The API calls SetThreadLocale(LOCALE_USER_DEFAULT) and SetThreadLocale(GetUserDefaultLCID) are functionally equivalent. They both derive the source locale as described in the GetUserDefaultLCID API call above."
With that information you could create a function to get that value from the Registry using just .NET framework calls. I do not love that approach either but at least is another alternative
Today I was doing a VS extention as part of my weekend relaxation activities ;)
Everything was great until succendly something was not happening as I expected.
I was adding a context menu to the code window with a dynamic list of options.
And each option had a different click delegate, but my click events were
disrespectfully discarted.
Luckily I found this post: http://www.rauchy.net/blog/?cat=4&paged=2
And now for a tricky part: since you ge\t your instance of CommandBarEvents inside the scope of a method, when the method ends, the Garbage Collector collects it, leaving all the event handlers orphaned. Unless you keep your instance safe from the jaws of the mighty Garbage Collector, your buttons will not respond to clicks.
To do so, just keep your CommandBarEvents instance(s) as member fields of your class. Once your class is disposed, they will be disposed as well.
Thanks Rauchy you saved my day! (And my wife is happy because I'm finally getting out of the bathroom :P)
I found this excellent post from Aasim adbullah
http://connectsql.blogspot.com/2010/12/sql-server-find-and-kill-specific-user.html
SELECT DISTINCT
name AS database_name,
session_id,
host_name,
login_time,
login_name,
reads,
writes
FROM sys.dm_exec_sessions
LEFT OUTER JOIN sys.dm_tran_locks ON sys.dm_exec_sessions.session_id = sys.dm_tran_locks.request_session_id
INNER JOIN sys.databases ON sys.dm_tran_locks.resource_database_id = sys.databases.database_id
WHERE resource_type <> 'DATABASE'
--AND name ='YourDatabaseNameHere'
ORDER BY name
To find out sessions which acquired EXCLUSIVE locks, modify above mentioned query as follow
SELECT DISTINCT
name AS database_name,
session_id,
host_name,
login_time,
login_name,
reads,
writes
FROM sys.dm_exec_sessions
LEFT OUTER JOIN sys.dm_tran_locks ON sys.dm_exec_sessions.session_id = sys.dm_tran_locks.request_session_id
INNER JOIN sys.databases ON sys.dm_tran_locks.resource_database_id = sys.databases.database_id
WHERE resource_type <> 'DATABASE'
AND request_mode LIKE '%X%'
--AND name ='YourDatabaseNameHere'
ORDER BY name