Saturday, December 24, 2011
Thursday, December 1, 2011
xRTML - Chat zone
First version of chat zone is already online, you can now speak with the other ppl that are watching this blog.
Powered by xRTML at http://realtime.co
Update:
Already updated to v1.5 of xRtml
Powered by xRTML at http://realtime.co
Update:
Already updated to v1.5 of xRtml
Sunday, November 27, 2011
C - Function pointer in a struct
Hello readers,
lately im not writing much, not because i don't have much to write about but because im writing a lot at work :P
This time im coming with a old style code, that i bet a lot of you hate.
C
In the next snippet you will see how to define a function inside a struct.
Personally i love to write code in C, not because it is a very productive language, because it isn't, but because it's always a challenge, you have to care about so much things, and you need to know so much about the computer and operative system internals, that every time you write some code in C you learn something new. Hope this snippet was helpful. See you soon ;)
Reference: http://www.cprogramming.com/tutorial/c/lesson1.html
Reference: http://www.cprogramming.com/tutorial/c/lesson1.html
Thursday, November 10, 2011
Node.js - How to read a file from file system
Hi readers,
here i am with a new technology, Node.js,
Node.js is a really cool framework that brings javascript to the server side. You can read more about it at nodejs.org .
In the mean time you can also check the following link: http://realtime.co
To start i am writing a post about how to read a file from file system:
here i am with a new technology, Node.js,
Node.js is a really cool framework that brings javascript to the server side. You can read more about it at nodejs.org .
In the mean time you can also check the following link: http://realtime.co
To start i am writing a post about how to read a file from file system:
Wednesday, October 5, 2011
No Geek - 5th October
5 October 1910 revolution
Portuguese revolution - http://en.wikipedia.org/wiki/5_October_1910_revolution
Wednesday, July 27, 2011
.Net Documentation with SandCastle
Hi folks,
today i am bringing something that most of the people try to skip, create documentation to their code. I am going to show you how to use ghost doc together with sandcastle to produce a beautiful chm documentation file.
Tools (install in order):
1 - Sand Castle
2 - Sand Castle Help File Builder
3 - Ghost Doc (Visual Studio Plugin)
Using Ghost Doc:
1 - Right button over the method or class name you want to comment and press "document this" in the context menu:
2 - Write your comments:
3 - In your project properties check the XML documentation file:
4 - Build your project
Using Sand Castle Help File Builder:
1 - Create New Project: File/New Project
2 - Add References and Documentation Source (XML and dll generated by Visual Studio when you build your project)
3 - Setup your project in the project properties
4 - Build your help file: Documentation/Build Project
today i am bringing something that most of the people try to skip, create documentation to their code. I am going to show you how to use ghost doc together with sandcastle to produce a beautiful chm documentation file.
Tools (install in order):
1 - Sand Castle
2 - Sand Castle Help File Builder
3 - Ghost Doc (Visual Studio Plugin)
Using Ghost Doc:
1 - Right button over the method or class name you want to comment and press "document this" in the context menu:
2 - Write your comments:
3 - In your project properties check the XML documentation file:
4 - Build your project
Using Sand Castle Help File Builder:
1 - Create New Project: File/New Project
2 - Add References and Documentation Source (XML and dll generated by Visual Studio when you build your project)
3 - Setup your project in the project properties
4 - Build your help file: Documentation/Build Project
Thursday, June 23, 2011
Monday, June 6, 2011
Html To Silverlight
Hi again,
here i am coming again with a nice and fresh snippet :)
So, the other day i had a question at work, how can we interact with Silverlight from our Asp.Net application? Immediatly i thought about javascript, because it's known that silverlight and javascript have a great interoperability.
The solution i found, allow to expose a silverlight class methods to javascript, wich means something like this:
Note that i added a attribute to my method that says my method will be a member of my silverlight object when i will access it through javascript.
In javascript i will simply need to use it:
function SendToSilverlight() {
silverlightClient.Content.SilverlightPage.UpdateTextFromBrowser("Teste 1","Teste 2");
}
This is my javascript method that will update my silverlight textbox. Very important, you must initialize the variable 'silverlightClient' in the load event of the silverlight control, so in order to do that add the param to your html silverlight object:
and create the function pluginLoaded in the javascript:
var silverlightClient;
function pluginLoaded(sender, args) {
silverlightClient = sender.getHost();
}
Great hmm? ok, but it is not working yet, why?!
We need to register our sivlerlight object as a ScriptableObject in our html page. You can do that in the Silverlight Application_Startup event handler like this:
private void Application_Startup(object sender, StartupEventArgs e)
{
var page = new MainPage();
this.RootVisual = page;
HtmlPage.RegisterScriptableObject("SilverlightPage", page);
}
And this is evertyhing you need ;)
Source Code:
https://rapidshare.com/files/1606818514/SilverlightHtml.zip
here i am coming again with a nice and fresh snippet :)
So, the other day i had a question at work, how can we interact with Silverlight from our Asp.Net application? Immediatly i thought about javascript, because it's known that silverlight and javascript have a great interoperability.
The solution i found, allow to expose a silverlight class methods to javascript, wich means something like this:
Note that i added a attribute to my method that says my method will be a member of my silverlight object when i will access it through javascript.
In javascript i will simply need to use it:
function SendToSilverlight() {
silverlightClient.Content.SilverlightPage.UpdateTextFromBrowser("Teste 1","Teste 2");
}
This is my javascript method that will update my silverlight textbox. Very important, you must initialize the variable 'silverlightClient' in the load event of the silverlight control, so in order to do that add the param to your html silverlight object:
and create the function pluginLoaded in the javascript:
var silverlightClient;
function pluginLoaded(sender, args) {
silverlightClient = sender.getHost();
}
Great hmm? ok, but it is not working yet, why?!
We need to register our sivlerlight object as a ScriptableObject in our html page. You can do that in the Silverlight Application_Startup event handler like this:
private void Application_Startup(object sender, StartupEventArgs e)
{
var page = new MainPage();
this.RootVisual = page;
HtmlPage.RegisterScriptableObject("SilverlightPage", page);
}
And this is evertyhing you need ;)
Source Code:
https://rapidshare.com/files/1606818514/SilverlightHtml.zip
Thursday, June 2, 2011
Linked In Discussions
Interesting discussion about Flash and Silverlight:
http://www.linkedin.com/groups/Flash-Silverlight-85746.S.55631378?qid=b93c6ee8-f356-4838-851a-b04bcb85301f&goback=%2Egmp_85746%2Egde_85746_member_55631378%2Egmp_85746
http://www.linkedin.com/groups/Flash-Silverlight-85746.S.55631378?qid=b93c6ee8-f356-4838-851a-b04bcb85301f&goback=%2Egmp_85746%2Egde_85746_member_55631378%2Egmp_85746
Friday, May 27, 2011
Silverlight / WPF MVVM - It is just a pattern
Hi,
lately there is a big hype around MVVM (Model-View-ViewModel), but most of the developers cant really understand it.
I have a personal opinion that is based in my experience and in my pragmatic way to see the things.
MVVM is just a pattern, and as a pattern it must be used according your challenge (most of people would use the word problem, but for me problem = challenge) and adapted to your needs.
In this post i wont tell you all the history and theory about it but you can check this articles:
http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
http://blogs.msdn.com/b/johngossman/archive/2005/10/08/478683.aspx
http://en.wikipedia.org/wiki/Model_View_ViewModel
I will tell you how to implement the MVVM base for your application and to "glue" the View to your ViewModel using binding, all the source code is provided in the bottom of the article.
- ViewModelBase: this classe should be the base for all your ViewModels, wich mean all your ViewModels class should extend this one, and all the public properties of your ViewModelBase should call the OnNotifyPropertyChanged method when their value is set.
- RelayCommand: this one is also really important because is the base for all my command bindings, wich allow me to "bind code" to the control command, this means that in your ViewModelBase you will need to have a property of this type if you need to use commands in your view.
This is really the basic, but to start is more than enough and was where i felt more dificulties to understand what was MVVM really about. But you still need to "glue" it to the view, so here are some examples:
- Declare the namespace in you control:
xmlns:ViewModel="clr-namespace:MyApp.ViewModel.Dialogs"
- Specify the data context of your control (in this case it is a child window):
- Bind properties:
ItemsSource="{Binding Buttons}"
- Bind commands:
Command="{Binding ActionCommand}"
Buttons specified in the example were added in the ViewModel:
new List{
new DialogButtonViewModelBase("Cancel", new RelayCommand(() =>
{
MessageBox.Show("Dont want to be logged in.");
})),
new DialogButtonViewModelBase("Ok", new RelayCommand(() =>
{
MessageBox.Show("Ok im logged in.");
})),
})
Source Code:
https://rapidshare.com/files/2608105881/Source.zip
References:
http://blog.galasoft.ch/Default.aspx
http://mvvmlight.codeplex.com/
lately there is a big hype around MVVM (Model-View-ViewModel), but most of the developers cant really understand it.
I have a personal opinion that is based in my experience and in my pragmatic way to see the things.
MVVM is just a pattern, and as a pattern it must be used according your challenge (most of people would use the word problem, but for me problem = challenge) and adapted to your needs.
In this post i wont tell you all the history and theory about it but you can check this articles:
http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
http://blogs.msdn.com/b/johngossman/archive/2005/10/08/478683.aspx
http://en.wikipedia.org/wiki/Model_View_ViewModel
I will tell you how to implement the MVVM base for your application and to "glue" the View to your ViewModel using binding, all the source code is provided in the bottom of the article.
- ViewModelBase: this classe should be the base for all your ViewModels, wich mean all your ViewModels class should extend this one, and all the public properties of your ViewModelBase should call the OnNotifyPropertyChanged method when their value is set.
- RelayCommand: this one is also really important because is the base for all my command bindings, wich allow me to "bind code" to the control command, this means that in your ViewModelBase you will need to have a property of this type if you need to use commands in your view.
This is really the basic, but to start is more than enough and was where i felt more dificulties to understand what was MVVM really about. But you still need to "glue" it to the view, so here are some examples:
- Declare the namespace in you control:
xmlns:ViewModel="clr-namespace:MyApp.ViewModel.Dialogs"
- Specify the data context of your control (in this case it is a child window):
< controls:ChildWindow.DataContext>
< ViewModel:LogonViewModel />
< /controls:ChildWindow.DataContext>
- Bind properties:
ItemsSource="{Binding Buttons}"
- Bind commands:
Command="{Binding ActionCommand}"
Buttons specified in the example were added in the ViewModel:
new List{
new DialogButtonViewModelBase("Cancel", new RelayCommand(() =>
{
MessageBox.Show("Dont want to be logged in.");
})),
new DialogButtonViewModelBase("Ok", new RelayCommand(() =>
{
MessageBox.Show("Ok im logged in.");
})),
})
Source Code:
https://rapidshare.com/files/2608105881/Source.zip
References:
http://blog.galasoft.ch/Default.aspx
http://mvvmlight.codeplex.com/
Sunday, May 22, 2011
Tip - Register WCF Services on IIS 7
Long time ... no post!!
Today i was having a strange issue with WCF services. I wanted to host my WCF service in IIS 7, but it was complaining about the svc files. I searched a little in our friend Dr Google and the answer appeared:
In the Visual Studio command prompt execute the following commands:
1 - ServiceModelReg.exe –ia
2 - aspnet_regiis.exe -i
And your IIS 7 will be ready to host WCF Services ;)
See you soon, Silverlight MVVM tips coming in the next chapters :)
PS: If you will want to start looking at something about MVVM watch these awesome video on MIX 2011:
http://channel9.msdn.com/Events/MIX/MIX11/OPN03
Today i was having a strange issue with WCF services. I wanted to host my WCF service in IIS 7, but it was complaining about the svc files. I searched a little in our friend Dr Google and the answer appeared:
In the Visual Studio command prompt execute the following commands:
1 - ServiceModelReg.exe –ia
2 - aspnet_regiis.exe -i
And your IIS 7 will be ready to host WCF Services ;)
See you soon, Silverlight MVVM tips coming in the next chapters :)
PS: If you will want to start looking at something about MVVM watch these awesome video on MIX 2011:
http://channel9.msdn.com/Events/MIX/MIX11/OPN03
Sunday, February 20, 2011
Sqlite plus Entity Framework 4
I have just started working with Sqlite, and i decided that it would be very interesting to use it together with Entity Framework. So lets just see how to do it:
The first step is to download Sqlite from http://sqlite.phxsoftware.com/ or the direct link http://sourceforge.net/projects/sqlite-dotnet2/files/SQLite%20for%20ADO.NET%202.0/1.0.66.0/SQLite-1.0.66.0-setup.exe/download .
This will install the provider to use with entity framework.
Then we have to had a entity model to our project:
References: http://dotnet.dzone.com/news/sqlite-entity-framework-4
The first step is to download Sqlite from http://sqlite.phxsoftware.com/ or the direct link http://sourceforge.net/projects/sqlite-dotnet2/files/SQLite%20for%20ADO.NET%202.0/1.0.66.0/SQLite-1.0.66.0-setup.exe/download .
This will install the provider to use with entity framework.
Then we have to had a entity model to our project:
And it is done, now we just have to use it:
using (var dataContext = new OurEntities())
{
var statusList = from status in dataContext.Status
select status;
foreach (var status in statusList)
{
Console.WriteLine(status.Name + " - " + status.Description);
}
}
By the way, do not forget to add the connection string to your web.config or app.config:
<connectionStrings>
<add name="OurEntities"
connectionString="metadata=res://*/OurEntityModel.csdl|res://*/OurEntityModel.ssdl|res://*/OurEntityModel.msl;provider=System.Data.SQLite;provider connection string='data source=".\Database\OurDatabase.db"'"
providerName="System.Data.EntityClient"
connectionStrings>;
Notes: If you are using the version 4 of the framework you must add the following line to your web.config or app.config:
<startup useLegacyV2RuntimeActivationPolicy="true">;
<supportedRuntime version="v4.0" startup;
References: http://dotnet.dzone.com/news/sqlite-entity-framework-4
Wednesday, February 16, 2011
My Blogs List
- .Net
- http://geeklyeverafter.blogspot.com
- http://sharpdevpt.blogspot.com
- http://blogs.msdn.com/b/marcelolr/
- http://windowsteamblog.com/windows_phone/b/windowsphone/
- http://team.silverlight.net/
- http://pontonetpt.org/blogs/ricardoperes
- http://timheuer.com/blog/
- http://weblogs.asp.net/dwahlin
- http://weblogs.asp.net/scottgu
- http://weblogs.asp.net/israelio
- http://www.dotnetglobe.com/
- http://weblogs.asp.net/hajan
- http://omundodaprogramacao.xtreemhost.com
- Android
- Ubuntu / Linux
- Tech
Feel free to suggest me more ;)
Code Snippets C# - Session is Null in a Ashx File
What to do if a session is null in a Ashx File?
Because a Ashx File is a HttpHandler, you will just need to implement the interface IRequiresSessionState and your problem is solved.
Reference: http://msdn.microsoft.com/en-us/magazine/cc164128.aspx
Because a Ashx File is a HttpHandler, you will just need to implement the interface IRequiresSessionState and your problem is solved.
Reference: http://msdn.microsoft.com/en-us/magazine/cc164128.aspx
ASP.NET - Application Anatomy
Anatomy
One of the most remarkable features of the ASP.NET execution model, is the possibility to update the application without the need to restart the server and possible damage to users of the application. This means that adding, changing or removing files in the virtual directory can be done without any impact.
After making a change, the migration process to a new Application Domain is executed. This process executes a safe restart to the application and replaces the files in the temporary directory of ASP.NET.
Directories structure:
One of the most remarkable features of the ASP.NET execution model, is the possibility to update the application without the need to restart the server and possible damage to users of the application. This means that adding, changing or removing files in the virtual directory can be done without any impact.
After making a change, the migration process to a new Application Domain is executed. This process executes a safe restart to the application and replaces the files in the temporary directory of ASP.NET.
Directories structure:
- Bin - Contains all the application libraries (dll's)
- APP_CODE - Contains all the classes that are dynamically compiled
- APP_GLOBALRESOURCES - Contains global resources that are used by all application pages
- APP_LOCALRESOURCES - Contains the resources used by the associated page
- APP_WEBREFERENCES - Contains web services references
- APP_DATA - Reserved to Data Storage such as SQL Express databases or xml files.
- APP_BROWSERS - Contains xml files with browsers definitions, wich allow different renders between browsers
- APP_THEMES - Contains the application themes
Global.asax
The file Global.asax, allows you to write code that handles the global events of the application. The file is optional and is just allowed to have one per application and it must be in the root directory.
Application events:
- Application_BeginRequest - Invoked in each Request
- Application_EndRequest - Invoked at the end of each Request
- Application_Start - Invoked when the application start
- Session_Start - Invoked at the beginning of each session
- Application_Error - Invoked when a not expected exception is thrown
- Session_End - Invoked when a user session ends
- Application_End - Invoked at the end of the application
Configurations
The configurations of an Asp.Net Application are made in a xml file. There are two types of configuration files, the global ones and the local, and each application can use more than one.
Global Configuration Files:
This article was translated from http://pplware.sapo.pt/pessoal/asp-net-%E2%80%93-anatomia-de-uma-aplicacao/
The configurations of an Asp.Net Application are made in a xml file. There are two types of configuration files, the global ones and the local, and each application can use more than one.
Global Configuration Files:
- Location: C:\Windows\Microsoft.Net\Framework\[Version]\config
- All the applications in the server will use that configuration file
Local Configuration Files
- Location: The application root folder
- Specific for the application
Config file elements
responsible for the encription of the Asp.Net applications, session cookies and viewstate protection where you can define some of your application settings, like the quantity of data you want to retrieve for example this is one of the most important elements if not the most, and inside it you can set a lot of configurations such as: - authentication
- compilation
- customErrors
- Membership
- pages
- profile
- sessionstate
- trace
There are a few more elements in the configuration file that are not important for this article.
The Page Class
All the Asp.Net pages inherit the base class Page. This is one of the most important classes in Asp.Net.
It contains 3 important properties:
- Request represents the values and properties of the Http Request that originated the page loading
- Cookies
- Headers and ServerVariables
- IsAuthenticated
- IsLocal
- QueryString
- Response represents the server response to the client
- Cookies
- Redirect()
- Write()
- Server is a utilities class
- MachineName
- GetLastError()
- HtmlEncode() and HtmlDecode()
- MapPath()
- Transfer
Subscribe to:
Posts (Atom)