Sunday, November 17, 2013

Cloud Chat library

Hello,

i am glad to announce my last personal project, Cloud Chat Library.

Cloud chat is a javascript chat library that uses angularjs ( http://angularjs.org/ ) and jquery ( http://jquery.com/ ) for user interface and realtime.co framework ( http://framework.realtime.co ) for messaging and storage.

Authentication is provided by facebook api and google api. Looking forward to add more providers.

The project source code is available at github:

https://github.com/mrshogun/cloudchat

And you can use a the following url to use a online version of the library:

http://dl.dropboxusercontent.com/s/sl5azkks6isi42v/cloudchat.js

You can allways use it in your own blog, if you will need any help with it let me know.

If you want to try it, just login at the top of this blog and let people know what do you think about it.


Thursday, August 29, 2013

Javascript Event Manager singleton with jQuery

When building an SPA (single page application) one of the best patterns to use is the event driven pattern. Below is the implementation of a simple event manager to deal with custom events. Hope it will be usefull.



Thursday, April 18, 2013

Syndication Feed

Reading a feed in C# 4.0

Needed references:

- System.ServiceModel


Realtime.co + GrowlForWindows + SyndicationFeed = RealtimeNotifications

Long time no see :)

But it doens't mean i was doing nothing. In fact lately i was going around with some technologies and how to integrate them between each other. Because it requires some code and not only snippets i created a project in codeplex @ https://realtimenotification.codeplex.com/ where you can download the source code and try. Basically what the project dows for now is a integration between the http://realtime.co technology and GrowlForWindows or rss feeds and GrowlForWindows.

If you dont know GrowlForWindows check it at http://www.growlforwindows.com/gfw/ .

The project strutcture is all based in Notifiers. A Notifier can be a publisher or a subscriber, or both.

Some things are still to be done.

- Custom configuration sections for each type of Notifier, wich are called providers.
- Windows Service with integration between the different technologies.
- MSI with custom action to configure the windows service

Those are the big goals for the next weeks, and after that the creation of providers for different technologies.

To see all this working do the following:

- Install growl for windows
- Open the codeplex project solution
- Run the project with name JF.RealtimeNotifications.Test.Console
- Open http://howdoyouphil.blogspot.pt/ in the browser

After this you should see a growl notification appearing.

Hope this can be usefull for you

Friday, May 25, 2012

Web Application Template html + css

Hello readers,

It passed some time since i wrote something, but i am back :)
Today i am bringing you something about design. When we have a web application usually we want everything to fit in the screen without long scrolls, something like google docs or even gmail. Because i like to learn i created a basic template using only html5 (that can be easily converted to normal html) and css3 (that can be easily converted to normal  css). By the way, it works in all browsers :)



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

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

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:

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

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

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

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):
   < 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

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:




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

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

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:

  • 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:

  • 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 the connections to external systems are defined, such as database or active directory
  •  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

This article was translated from 
http://pplware.sapo.pt/pessoal/asp-net-%E2%80%93-anatomia-de-uma-aplicacao/

Sunday, December 26, 2010

ASP.NET – Introduction and Concepts

What is ASP.NET?


ASP.NET is a server side scripting technology,  this technology allows the programmer to write scripts in a web page that will be executed in server side.

Terminology:
  • ASP, Active Server Pages
  • ASP.NET runs in the IIS server
  • IIS, Internet Information Services, is an internet server built by Microsoft
  • IIS is free of charge and comes with windows, but some features are not supported on client versions, to install you just need to access the turn windows features on or off section in windows.

ASP.NET is compiled and not interpreted:

ASP.NET, as well as all .NET applications, are compiled. Is impossible to run C# or VB code without compiling it.

Fortunately the ASP.NET applications doesn’t need to be compiled every time they are executed, instead the Interpreted Language code is created once and updated just when the source code is change. The files stay in the server cache, in the directory  C:\WINDOWS\MICROSOFT.NET\FRAMEWORK\[VERSION]\TEMPORARY ASP.NET FILES

This statement depends on the type of project you choose. If you will choose a Web Project, the source code is compiled when the project is, otherwise if you choose a Web Site, each page is compiled when the Request is made.

Web Forms


The ASP.NET pages, known as Web Forms, are a vital part of an ASP.NET application, because they provide the browser output after the client Request.


ASP.NET Page:
  • Same as a HTML page
  • Can contain HTML, XML and scripts
  • Scripts are executed in the server
  • ASPX extension
  • All the controls must be contained inside a
    tag
  • The tag must contain the attribute runat=server
  • The attribute runat=server means the form will be processed in server side


How does it work?


  • Applications are executed in server side, so imagine that you have a page that allows users to write comments. The user does this operations in the browser, but to save the comments is needed to make a update in the database, for that the code must run in server side. ASP.NET handles those events using a technique called PostBack, which sends the form when certain operations are executed. When the server receives the page it handles the corresponding events in server side.
  • Web Applications are Stateless, it means they don’t keep the state. When the page is rendered to html, the objects are destroyed and all the client information is discarded. This model is good to increase the scalability and application traffic, but is hard to offer an experience similar to a windows application.
ASP.NET is based in a event model, where the programmer adds a control to the page and choose which event wants to handle.  Each Event Handler is a discrete method that keeps the code clean and tidy.


Events, how do they work:

  1. Page and associated controls are created, initialization code is executed, the html page is rendered and returned to the client and the objects are released from server memory.
  2. At some point the user performs an action that causes a PostBack, such as clicking a button, and every page information is sent to the server.
  3. The server recreates the objects, putting them in the same state as the last time they were sent to the client.
  4. The event that caused the PostBack is handled and the associated code executed.
  5. The modified page is rendered to Html and sent to the client with the new data. The objects are released from server memory.


Page Lifecycle



There are two types of events that cause a PostBack:

  • Immediate Response Events: Executed whenever the user clicks in a button or the javascript function, __DoPostBack() , is used.
  • Change Events: When a control state is changed, like the value of a checkbox or textbox. If the property AutoPostBack is active, the event is executed immediately, otherwise is executed in the next PostBack.
Imagine a page with a submit button and a textbox without the AutoPostBack property active. The user change the text and click in the button, the events execution order is:

  1. Page.Init
  2. Page.Load
  3. TextBox.TextChanged
  4. Button.Click
  5. Page.PreRender
  6. Page.Unload

As for now as introduction this is everything you need to know, the next article will be about Application Anatomy. 


Tuesday, December 14, 2010

No geek

Because today i dont feel like writing about software, i will make a no geek post, and will start with the first thing that will come to my mind.

My girlfriend, i would like to thanks to her all the patience she has with me, when i am moody, when i am childish, when i am stressed and a bunch of other states, also everything she does for me, all the help she give me, even when she is pressuring me to study, because if she would not do it i wouldnt study at all, or at least much less, so thank you very much Moje Kochanie :)

Now coming back to me, just for you not to think i have stopped writing about geek stuff, just wanted to let   you know that i am going to start with a season about asp.net, i will translate some articles from http://www.pplware.com , and i will start also a review about the book Code Complete from Steve McConnel, and of course ill continue with the code snippets that are allways usefull. Probably you will be wondering why im writing direct to you, my readers, but it has a reason, in the last days even if i was talking with some people about it i received more visits than the ones i was expecting, so i decided to do something for you and start writing some set of articles about different subjects, and of course it will allways be a pleasure to have some feedback from you.

Saturday, December 11, 2010

Ubuntu - Magic Mouse

Today i am not writing about Microsoft. For some people it might look like a sin but for me it means i am open to other tecnologies, ideas.
I have been installing ubuntu in my machine today because i heard that the last version supports the Apple Magic Mouse out of the box, so i was curious about it, because i have a Magic Mouse and in Windows 7 the only thing i manage to put to work was the button left and right.

So if you are planning to install ubuntu in dual boot with windows, the only point where you dont have just to press the button forward is when you will need to create the partitions wich are:

Primary 500Mb /boot
Primary Free Space /
Primary 5000Mb swap area

after everything installed you just need to go to the bluetooth symbol and connect to your Magic Mouse, the pin is 0000.

Friday, December 10, 2010

Thinkings - Static Class vs Instance Class

When developing very often a developer wonder if to use a static class or a instance class. It is a decision that really depends on what you are going to do, and i think also from person to person, and because of that i would like you to tell me in wich situations you use each of them.

In my case, for example, if i have to create a business layer, typically i will use static classes. Imagine i have to develop a Content Management System, and i need the methods to write post, delete post, edit post and get posts, so my approach would be to create a static class like the following:

public static class PostsManager
{
    public static void WritePost(String user,String text) {...}
    public static void DeletePost(String user,String text) {...}
    public static void EditPost(String user,String text) {...}
    public static ICollection GetPosts(DateTime begin, DateTime end) {...}
}

and now you are wondering, what is that collection of Post?! That is my instance class, because the method GetPosts will return all the posts between two dates, and because ill need severall instances of Post than i am using a instance class.

public class Post
{
    public Post(String Author, String text) {...}

    public String Author { get; private set; }
    public String Text { get; private set; }

    public String TextTruncated(int size) {...}
}

Code Snippets C# - Strings

Sometimes you want to write a quote inside a string, but if you will write " " " it will not work, so the way to workaround it is writing \" .

Snippet:

String.Format("C:\\TestFiles\\\"{0}\"", fileName)

About MSI - Microsoft Installer

Developing a software application is funny, but more rewarding is to see that it helped someone in its daily work, that its usefull and not superfluous. At this point the developer achieves to a dilemma, how will i distribute my software?

Microsoft provide software developers a component called Microsoft Installer, or MSI to friends, wich contains all the functionalities needed to install, mantain or remove the application from a Windows System.

To start open the context menu of your solution node in the solution explorer dock: Add\New Project. Then you will see the figure shown below:


Now using the setup project context menu you can add several projects outputs and distribute your application.

So this is the basics about MSI, but what i want to write about is Custom Actions and what i learned about it today. So i needed to transfer information between two different custom actions and i thought that i could use the parameter stateSaver from the event install, but it did not workout because it is used to save installation parameters to be shared across all the installation events of the custom action in context. So i questioned my colleague Abel about a idea to solve the problem, and the answer could'nt be more simple, "try to use a static dictionary". With that in mind i created a static class with a property that is a Dictionary and other information, refactored the code to use my new class and went for testing. Result, the test worked out in the first try.

References:
http://en.wikipedia.org/wiki/Windows_Installer
http://devcity.net/Articles/339/3/article.aspx
http://msdn.microsoft.com/en-us/library/aa368066(VS.85).aspx

Thursday, December 9, 2010

How do you Phil?

Yesterday were 30 years since John Lenonn died.
Today is the first day of this blog.

Probably you are wondering what is the relation between those two events, and my answer is:

None.

The thing is that i decided to start writing a blog since some time ago with the objective to archive experiences, lessons learned, ideas, basically some of my life snippets.

Now i should say, i hope you will like what i will write here, but honestly, i am not doing this for you, but for me. The reason why i am sharing this with you is because maybe i will write something that one day can be usefull for you, and i believe that the knowledge should be shared and not keep inside people mind.