This blog is subject the DISCLAIMER below.

Wednesday, December 24, 2008

Scripting in JDK6 (JSR 223) Part 2

Its Lunch Time!

After programmer 2 shown programmer 1 how to deal with JSR 223 or JDK6 scripting ( part 1) programmer 2 went for lunch as he didn’t eat anything since yesterday and left programmer 1 to meet his fate.

Programmer 1 began to apply what he learned from programmer 2 and stuff went so bad, after 30 minutes programmer 2 came back.

Programmer 2: Man, how is everything going? (While he was just about to finish his last bite from the sandwich)

Programmer 1: man the performance sucks, it is really really slow and that won’t be good thing, it is bottleneck now

Programmer 2: ok let me see what did you do. (Swallowed his last bite hardly)

The Crime!:

View the whole article

.. more.

Wednesday, December 17, 2008

Requirements Engineering - FCIH Microsoft Club

Header1
Email_Template_04_02
Microsoft-Club Helwan
Requirements Engineering session
JOIN US FOR THIS EXCITING EVENT
Let's start, to share our knowledge and find ways to make a difference.
Let's Start with our First Session with,
"Requirements Engineering session"
(E.g. RE is the branch of software engineering concerned with the real-world goals for functions of, and constraints on software systems).

Come and join us this event @ FCI-H. :)
Agenda:
· Who Am I; a programmer or developer or…?
· What and Why of Analysis..!!!
· The "Others" needs
· Requirements Management
· Requirements Elicitation
· Requirements Analysis
· Requirements Communication
Speaker's Bios:
Marwan Hamad is currently System Analyst in Link Development. In 2004, He started the journey of analysis in ITWorx while he had the honor of working in the enterprise sales field at Microsoft Egypt. Marwan observed the best practice of Business Process Reengineering (BPR) by providing dynamic workflow based on strategic objectives to Vodafone Egypt and New Horizons. Marwan was honored from the Ministry of Youth in 2004 for transferring European Project Management practices to the Egyptian NGO's. Marwan studied Applied Business Computing in the University of Sunderland, UK.

DON'T MISS OUT
2:00 pm – 4:00 pm
Wednesday, December 17, 2008
FCIH main campus, Hall 7 (beside the mosque, 2nd floor)
Faculty of Computers & Information – Helwan University


Hope to see you there!
Microsoft Club – Helwan
Referral Code: Club08

Contact us: msp-helwan@student-partners.com

P. S. RE session mainly for all students, everyone is welcomed.
P. S. If you know anyone else who'd enjoy this event, please forward this email to them now.
Email_Template_04_04
Footer
SubFooter

.. more.

Tuesday, December 16, 2008

DotNetWork.org Dec-08 Gathering


Date:
Saturday, December 27th 2008,
12:00 - 16:30

Attendance is FREE =)

Speaker:
Omar Besiso
Senior Architect - DataCom, Sydney, Australia.

Agenda:

12:00 - 14:00
Building scalable and functional software using dependency and policy injection (Level 200)

14:30 - 16:30
Open Session

Brief (for the open session):

AOP, DDD, TDD, UDD, OO, SilverLight, Azure, DI, IOC, MEF, The Cloud....etc. Tired of all the new hype around a heap of technologies and paradigms? Not sure about your approach in 2009? Come and have a friendly chat with Omar Besiso, a veteran Microsoft architect who lives his life around Microsoft technologies and all their headaches. Omar will be describing the future trends and how as developers and architects design patterns and futuristic architecture paradigms will be used. Whether you’re architecting for retail, corporate, the cloud or just for yourself, this will be your guide into the 2009-2010 explosive years. See you there!
Location:
Canadian International College, @ "El-Tagamo3 El-5ames"

Buses will be available at: Nady El-Sekka (11:00 AM - 11:30 AM)
Please be there before 11:30 coz we will leave on time..


For those who wanna keep tuned with further news about this event & other upcoming events of the dotnetwork.org user group, please check the following links:

Yahoo!Group:
http://tech.groups.yahoo.com/group/dotnetworkorg/

Facebook Event:
http://www.facebook.com/event.php?eid=57316086432
You'd better join the above event if you have a facebook account so we can roughly estimate the attendees count..

Facebook Fan Page:
http://www.facebook.com/pages/netWorkorg/13135685545

Facebook Group:
http://www.facebook.com/group.php?gid=2409268236

Please don't hesitate to contact me if you have any further questions..
See u on the gathering ;)

.. more.

Saturday, December 13, 2008

Scripting in JDK6 (JSR 223) Part 1

Introduction:

For sure most of us (mm guess so) have heard about the Scripting provided in Java 6 (Mustang) or JSR 223, 1st time I saw that (just saw the title) I thought that the Java guys will enable us to compile and run JavaScript scripts and that’s the end, well nope that wasn’t what Scripting in java 6 about but actually it is about enabling scripting languages to access the java platform and get the advantages of using java and the java programmers to use such scripting languages engines and get advantages from that (as we will see ).after I got it I was thinking : oh man if the team who implemented the Scripting engine were living in the dark age and they came up with such idea they will be accused of The practice of witchcraft but thanks God we are open-minded now and they will live and the good thing is that they will continue to practice witchcraft :D
So for now java guys will stay alive and continue to do their voodoo stuff and we will be looking at this nice scripting engine.

for more on this topic check my blog

.. more.

Monday, December 08, 2008

How to increase AIX swap space

"lsps -a"

This will display something like:

Page Space Physical Volume Volume Group Size %Used Active Auto Type
hd6 hdisk0 rootvg 512MB 1 yes yes lv

This means that hd6 is the logical volume used for paging. To increase it, use the following command:

"extendlv hd6 10G"

This will add 10G of space to hd6, now reboot and then re-run "lsps -a" or you can simply use the "topas" command to check the paging space available.

.. more.

Thursday, December 04, 2008

The new Servlets3.0 Specifications

Well, Servlets new specifications 3.0 has be pondered.
The new 3.0 specs changes the servlet technology up-side down the way that EJB3.0 did.

In the new release servlets makes heavy use of annotations to obsolete XML meta data (hell) and to make all its objects as POJOs .

Many changes have added to the new specs such request suspension and allowing servlets to be added to the web app after deployment that all were not allowed in the previous release that held the number 2.4.

you can find more in this interesting article :

http://www.theserverside.com/tt/articles/article.tss?track=NL-461

.. more.

Sunday, November 30, 2008

How to restrict some users to update some tables under some criteria?

Q. How to restrict some users to update some tables under some criteria?

A. If you administer SQL server database, you know that you can grant\deny user updating some tables, but what if you wish to grant\deny user updating some tables when just column equal some value, scenario like that

Table Course (ID, CourseName)

Table Student (ID, Name, CourseID, ….)

Sure, the most common example we give when we teach someone the introduction of databases especially relationships, so if you don’t know it; in brief Student has right to have some courses and the relationship is one-to-many; course-took by- many students.

1

Going on our scenario, data entry1 responsible for insert\update\delete all students take C# course, data entry2 responsible for insert\update\delete all students take Java course

2 3

Clear, isn’t it?

What you should do is to create 2 users dataentry1, and dataentry2 and to create 2 database roles CSharpController, and JavaController.

To create user using SQL Server Management Studio [URL]

To create Database Role using SQL Server Management Studio [URL]

Assign dataentry1 to CSharpController role, and dataentry2 to JavaController, you can assign more users to proper role as you see.

Next step; when user does insert\update\delete operation on Student table, users belong to CSharpController have right if and only if CourseID = 1, and the same for JavaController if and only if CourseID = 2

So, let’s write some code or script; yes, trigger to do those validations

create trigger ManageDML_Student
on student
for insert, delete, update
AS

--here to get column value and assign it variable to check its value later

IF IS_MEMBER ('CSharpController') = 1 && --value == 1--
  commit transaction
else
rollback transaction

Thanks :)


Acknowledge
I'd like to thank Mohamed Abd ALLAH Hewedy, he helped me through this problem

.. more.

Wednesday, November 26, 2008

Enabling Remote Debugging for tomcat

Sometimes your web application just works very fine on your local machine and when you move it to the deployment environment you see a BOOM. If the deployment environment is a Non-GUI machine (which is the common case), it is very hard to debug on that machine. Simply all what you need is to use a remote debugger to connect to the server machine and see what is wrong.

The concept is that you enable the web server to start the JVM in debug mode and start listening on a certain port for remote debuggers to connect, in tomcat, all what you need to do is to add this line to the catalina.sh
you will find at the begining of the file a set of lines started by "#" as they are commented, uncomment the JAVA_OPTS and insert the following line between double qoutes.
"JAVA_OPTS = -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"

-Xdebug: tells the VM to start in debugging mode.
-Xrunjdwp: selects the protocol to use,address: the port,suspend=n: tells the server to start listening even if no debugger is connected, simply, start and dont wait for a debugger to connect.

That's it, tomcat is waiting for a debugger to connect.

.. more.

Tuesday, November 18, 2008

Limitations on using Cookies

Make note of the following limitations when using Cookies (I'm not sure if that applies to all Web-technologies or just Asp.Net, but I've just solved a bug related to this issue using Asp.Net):

  • A cookie size is limited to 4096 bytes. It is not much, so cookies should be used to store small amounts of data. For larger amounts of data
  • Also, number of cookies is limited to 20 per website. If you make new cookie when you already have 20 cookies, browser will delete oldest one.
Quoted from beansoftware.com

.. more.

Saturday, November 08, 2008

dotNetWork.org 9th gathering


Date:
Saturday, November 29th 2008,
12:00 - 16:00

Attendance is FREE =)

Note:
Again (like the last 2 gathering), we are having 2 parallel tracks, but this time we have 4 sessions presented by 4 different speakers.. Waiting for your feed-back about that..


Speakers:

Mohamed Ahmed Meligy
Senior Software Developer, Raya-Software.

Mostafa Mourad
Team Leader, ITWorx.

Hossam El-Deen M. Barakat
Senior Software Developer, Raya-Software.

Hossam Kamel
Senior Software Engineer, ITWorx.
Agenda:

12:00 - 14:00
Applying Domain Driven Design on ASP.NET MVC
by Mohamed Meligy.
Information Architecture
by Mostafa Mourad.
14:30 - 16:30
IIS 7.0
by Hosam Kamel.
BizTalk-SharePoint Integration
by Hossam El-Deen M. Barakat.
Location:


Canadian International College, @ "El-Tagamo3 El-5ames"

Buses will be available at: Nady El-Sekka (11:00 AM - 11:30 AM)
Please be there before 11:30 coz we will leave on time..


For those who wanna keep tuned with further news about this event & other upcoming events of the dotnetwork.org user group, please check the following links:

Yahoo!Group:
http://tech.groups.yahoo.com/group/dotnetworkorg/

Facebook Event:
http://www.facebook.com/event.php?eid=32256529483
You'd better join the above event if you have a facebook account so we can roughly estimate the attendees count..


Facebook Fan Page:
http://www.facebook.com/pages/netWorkorg/13135685545

Facebook Group:
http://www.facebook.com/group.php?gid=2409268236

Please don't hesitate to contact me if you have any further questions..
See u on the gathering ;)

.. more.

Sunday, November 02, 2008

Enabling remote access to Mysql

A very common problem when using Mysql is when you try to remotely connect to the server, the solution is very simple and direct.

Configuration:
1- find a file named "my.cnf", this file contains the server configurations.
2- if you find a line with this syntax "skip-networking", comment it by putting a "#" in the begining of the line.
3- if you find a line with this syntax: bind-address = 127.0.0.1, comment it as well, this line tells mysql to accept connections only from localhost.

Persmissions:
now, you have to tell mysql who is to access the server with what permissions
1- login to mysql(example using root user name) : mysql -uroot -p
2- suppose that the data base we need to make available is named koko, so to make koko available to root with password 'password' at the machine with address 192.168.1.5 we write:
GRANT ALL on koko.* TO 'root'@'192.168.1.5' IDENTIFIED BY 'password';
3- then write : FLUSH PRIVILEGES;

Note: do not forget to restart mysql to reload configurations in the my.cnf file.

.. more.

Monday, October 27, 2008

New .NET Logos announced.

Microsoft announced last friday the new .Net logos.


Source :-
http://blogs.msdn.com/chkoenig/archive/2008/10/24/new-net-logos-announced-today.aspx

.. more.

Sunday, October 19, 2008

dotNetWork.org 8th gathering



Date:

Saturday, October 25th 2008,
12:00 - 16:00

Attendance is FREE =)

Note:
Again (like the last gathering), we are having 2 parallel tracks, but this time we have 5 sessions presented by 5 speakers.. Waiting for your feed-back about that..

Speakers

Ahmed Sidky
Director of Business Technology - X2A Consulting.

Ahmed Bahaa
Principal Technical consultant - CompuPharaohs.

Mohamed Samy
Technical Architect - ITWorx.

Mostafa ElBrarbary
Software Engineer - ITS.

Mohamed Bahaa
CompuPharaohs.

Agenda


12:00 - 13:30
Introduction To Agile Development
by Ahmed Sidky.
14:00 - 15:30
Use cases and requirement analysis
by Mostafa ElBarbary.
12:00 - 13:00
VSTS (Part 1)
by Ahmed Bahaa.
13:30 - 14:30
VSTS (Part 2)
by Mohamed Samy.
15:00 - 16:00
VSTS (Part 3)
by Mohamed Bahaa.


Location:

Canadian International College, @ "El-Tagamo3 El-5ames"

Buses will be available at: Nady El-Sekka (11:00 AM - 11:30 AM)
Please be there before 11:30 coz we will leave on time..


For those who wanna keep tuned with further news about this event & other upcoming events of the dotnetwork.org user group, please check the following links:

Yahoo!Group:
http://tech.groups.yahoo.com/group/dotnetworkorg/

Facebook Event:
http://www.facebook.com/event.php?eid=36111496329
You'd better join the above event if you have a facebook account so we can roughly estimate the attendees count..

Facebook Fan Page:
http://www.facebook.com/pages/netWorkorg/13135685545

Facebook Group:
http://www.facebook.com/group.php?gid=2409268236

.. more.

Sunday, October 12, 2008

Learning Jakarta Struts Project


Struts

The Jakarta Struts Project

The Jakarta Struts project, is an open−source project sponsored by the Apache Software Foundation. The Struts project was designed for creating Web applications that easily separate the presentation layer and allow it to be abstracted from the transaction/data Layers.

Model View Controller

Model : Represents the data objects. The Model is what is being manipulated and presented to the user.

View : Serves as the screen representation of the Model. It is the object that presents the current state of the data objects.

Controller : Defines the interaction between the view and the model .

The MVC (Model-View-Controller) model 2 :

all the views connect to one controller (Servlet) and this servlet works as a dispatcher where it handle all the requests and do whatever it needs in the business layer (Model).

What is Struts?

Struts is a web application framework to force

the user to follow the MVC models.
Struts don't cover the business layer at all (Model)
It concerned only with the controller.
Also Struts support a tag library for the
presentation layer.


life Cycle :

Create new class for each transaction (will call it an action
this class extends Action Class(in Struts Api) and override execute() to handle the business login which this action will perform.
then add struts-config.xml and define each action with his properties in action element.
in web.xml we define the ActionServlet (provided by struts).

How Struts works

· When you Browse http://....../login.do

· The server check web.xml and found the servlet (ActionServlet)

· Then check the actions in struts-config.xml and found this action associated with specific action class.

· The action class Perform the code in execute() and return ActionForward

· ActionForward will give the result url

Struts Main Components:

ActionServlet : The role of the controller.

Action Mapping :

· tells the ActionServlet each request associated with specific Action.

· In Struts-Config.xml you type the element and this translated to java interface called ActionMapping.

Struts-Config.xml

· Three important elements in Struts-Config.xml
{form-bean, ActionMapping , global-forward }


To Be Continued….

.. more.

Tuesday, September 30, 2008

Monday, September 29, 2008

Wine -- Windows Applications On Linux

Wine is a program that runs MS Windows applications on Unix-based systems by providing a compatibility layer by implementing some of the Windows APIs and wrapping the others to call native Unix functions, X server, and OpenGL. Wine implementation is all in userland (outside the kernel and doesn't need special privileges)[1].

Wine was originally short of WINdows Emulator, but I a am not sure about if that's still the case. "Wine" is originally a recursive acronym "Wine Is Not an Emulator"[A]. (Update) Wine is more of a compatibility layer than of an emulator. An emulator usually emulates hardware, like a Playstation emulator (offtopic: I know a good one called pSX).

Wine doesn't only implement Windows system calls, but also most of the DLLs that comes with
Windows. Most notably DirectX (which is one of the top reasons to use Wine; playing Windows games on Linux). If you are a windows license owner you can use some of the native Windows DLLs instead (but others can't be used).

ReactOS[8] is to Windows as Linux is to Unix. A free and open source alternative. It uses Wine code. Several other commercial projects uses Wine too, like TransGaming Cedega and CodeWeavers CrossOver (and others). The former is a fork of Wine specially for gaming, they do NOT send their patches to the main-stream Wine. The latter is both a general-purpose and gaming-purpose dedicated development for Wine. Unlike the former, the latter sends it patches instantly to the main-stream Wine. It relies mostly on support for profit (as for what I understood).

Google have paid CodeWeavers to make Wine able to run Photoshop CS 2 on Linux[2]. CodeWeavers also have acted quickly to to make Wine able to run Google Chrome on Linux, and they made it in 11 days[3]. Google has actively encouraged Wine development through their interns [4] and through student participation during the Summer Of Code 2008 [5].

The only Microsoft acknowledgment about Wine, is to state it is not Genuine Windows and therefore deprived from Windows Genuine Advantage (some downloads). [6] Generously, Microsoft still allows some updates, like Office updates to Wine users. [same source]. (See [7] for instructions how to install Office 2003 on Linux.)

Wine is not small at all. WINE 1.0 have over 1.8 million lines of C code (with blank lines and comments), ~300,000 of which are tests, and ~87000 are related to Direct3D (a subset of DirectX) implementation[original research]. I am not sure how big is the Micorsoft Subsystem for Unix-based Applications (SUA)[9](*1), but I am sure it is much less. That's because what a Unix program assumes to find in a system is much less that what a Windows application assumes to find (which are thousands of Windows APIs[10]).

(Update)
Due to the large amount Wine has to implement, it doesn't implement all of the Windows APIs yet. A program that depends on an unimplemented API might not function correctly. Wine developers try to implement high-priority APIs first. Those are the ones used by the most popular applications. (For a list of which programs are compatible with Wine check Wine AppDB[11])

(Update)
Wine have been in development for more than 16 years (since 1992); even before Linux was born[12]. Wine's still not complete, because it faces the problem with catching up with more recent Windows systems. For example (not saying that this have actually happened), when they completely supported Windows 95 applications, they were struck by XP, and then XP SP 1 and Windows 2000 (just an example, I know there are several editions in the middle). Wine development is indeed much slower than the real development pace of the real Windows (thousands of organized developers vs. hundreds of random contributers - ~700 have contributed to Wine somehow [12]).

(*1)
Wine is binary compatibility layer, which means the binary executable can be executed both on Windows and Linux without modifications. While MS SUA is source compatibility layer, which means the same program will have two executables, compiled differently, but from the same source, in order to run on both platforms.

Wine's web page: http://winehq.org/ .

Other references and links:

[1] Linux Unified Kernel is a project to implement Windows system calls (only, not the entire set of APIs) natively in Linux kernel.
[2] http://apcmag.com/google_behind_photoshops_new_linux_compatibility.htm
[3] http://www.heise-online.co.uk/news/CodeWeavers-bring-Chrome-to-Mac-and-Linux--/111535
[4] http://code.google.com/opensource/wine.html
[5] http://wiki.winehq.org/SummerOfCode
[6] http://www.microsoft.com/genuine/downloads/faq.aspx
[7] http://www.wine-reviews.net/microsoft/running-ms-office-2003-under-linux-with-wine-0952.html
[8] http://www.reactos.org/en/index.html
[9] http://mohnabil.blogspot.com/2008/09/microsoft-subsystem-for-unix-based.html
[10] Unlike Windows system calls (http://www.metasploit.com/users/opcode/syscalls.html), which are less than 400 in Windows Vista, the entire set of the windows APIs are much more (http://www.codase.com/windows.html)
[11] http://appdb.winehq.org/
[12] http://www.winehq.org/site/history
[A] http://wiki.winehq.org/FAQ?action=recall&rev=217#head-8b4fbbe473bd0d51d936bcf298f5b7f0e8d25f2e

.. more.

Saturday, September 20, 2008

Iterative Development – there is a simpler way to work - Part II (finale)

NOTE: This text (part I and part II) is just an introduction to the existence of an alternative, not a guide to use that alternative.

Because I -personally- believe that an example is worth a thousand words, I will tell you my personal experience with iterative development; the story of our graduation project. We only tried iterative development when other ways failed.

Our graduation project was a clustered server for massive multiplayer online games. The entire period for the project to come out was approximately 10 months, overlapping an academic year.

We've spent almost 9 months of them in the design phase; the project turned out to be very big and needed some research and novel techniques. For 5-members team who doesn't know anything about clustering we needed that much time.

Anyways, having only one month left to hand the project, there was no single line of code. We thought that we already have an exhaustive list of classes and functions and it's only a matter of implementation.

Trying to implement the classes we designed, we had no idea how to start, and just -exactly- after 4 functions we totally lost contact with the design and didn't know how to proceed. We were overwhelmed by the complexity and inter-dependencies between modules that it was NOT possible to see anything running before at least thousands of lines of code, which will need even more time to fix (cuz they were not tested).

That seemed inappropriate for the 1-month due time. Our main problem was the inter-dependencies of the modules. That's where iterative development kicked in. (Note that changes in the server and the game affect each others so they have to be done according to each-other step by step).

You will notice in the following sequence that at any point of time we could
A. Hand something that worked, not complete, but works.
B. Features are added incrementally. That means at the dead line we will have N features working, compared to a complete set of features that doesn't work at all.

1- The ping server
The first thing we did is to implement a simple server and test if the game (which was not practically a game then :D) can connect and exchange messages with it. - day 1

2- Simple actions
Then we implemented simple actions to make the game work and players interact - the server is not clustered and there is no state persistence or anything. - day 3
(Starting from here, the server development and game development was going in parallel)

A. Server development

3- Splitting the server
After that we implemented a simple layer above Java Remote Method Invocation (RMI) to be able to split the server on the set of computers in the clusters, and to make debugging easier (that layer could be disabled to run the whole server on a single machine). - day 9

4- Persisting the state
Also, we've developed something we called Object Store to provide transparent persistence using aspect oriented programming. - day 26

5- Work that was not complete until we handed the project
Proper Object Store synchronization between several machines, database replication, security checks, traffic control and traffic load balancing, server peer to peer load balancing, distributed administration.

B. Game development

3- Adding a few actions each day to extend the things the player can do. First walking, then attacking, then riding a car etc. (That's very simple view, the actual actions are numerous and much more complicated than that). - Until we handed the project

Conclusion:
Using iterative development, we've faced the overwhelm we had from the extreme complexity and actually delivered something that was working and people can actually play and enjoy. Compared to waterfall model, nothing would have been delivered in the deadline, and there would have been an implementation paralysis, and an elongated testing phase which might require lots of parts to be reimplemented too.

It's like splitting a big project into smaller projects with limited set of features, and doing that over and over until it's enough or you meet the deadline.

Pros:
Early feedback
More visibility, for the developer and for the client, the client can make changes early (cuz client don't know what they want !
Can deliver at any point of time

Cons:
Adding new features later can result in modifying existing code or removing it, which is the cost tradeoff of using iterative development

.. more.

Tuesday, September 16, 2008

Fun: Linux sudo command

I think it might be nice to send something funny every now and then.

.. more.

Wednesday, August 27, 2008

IoC (Inversion Of Control) and Dependency injection (DI)


Introduction:

Lots of us hear this word and also hear that this container is using IoC (inversion of control) so what is it all about and what does this mean? we will be working using Spring IoC through this article so lets start by checking the formal definition of the Dependency injection:“Dependency injection (DI) in Computer programming refers to the process of supplying an external dependency to a software component. It is a specific form of inversion of control where the concern being inverted is the process of obtaining the needed dependency.”Ho ho sounds little bit confusing, so lets make it more simple so first we need to know what is IoC and what is DI .Well we can say that IoC is a generic term and the DI is a more specific term so this mean that Dependency injection is more specific term than the IoC but still don't understand the IoC thing.


Life Without IoC and DI

In a standard component container,the component themselves ask the container for the resources they want for example lets check this segment of code (which you can find in most of EE application):

Context context=new InitialContext();
DataSoruce dataSource=(DataSource)context.lookup("jdbc/TestingDS");
Connection connection=dataSource.getConnection("yourUser","yourPassword");
Statement statement=connection.CreateStatment();
ResultSet results=statement.executeQuery("select * from users");
.
.
. //i didnt include all the code just the important thing

so in the above code we just initialize a context (JNDI)
and perform a lookup for a resource bounded at jdbc/TestingDS and then get the results and cast it as a DataSource after that we use it and continue with our processing.

oh yea so every time i want to do so i will have to make the lookup thingy to get the data source or any resource i might need.
mmm so i will keep asking my container to give me what i want? yup you will.
well lets see how would the container and the component interact with each other (without IOC)

A Day in the Container's Life !

Component: Hi Mr.Container.
Container:Hi Component.

Component:how is your day?
Container :oh i have been busy serving all other components and don't have time for myself :( .

Component:oh poor you Mr.Component.
Container:ahh what can i do this is my job :) , so how can i serve you ?
Component :oh yea i forgot , i want to you to serve me the resource bounded at bla bla bla
Container:ok sure no problem, just a min. here you are (hehehe now we got what we want :D )
Component:oh many thanks MR.Container, have a nice day.
Container:you too component bye.

so in here as we can see the component keeps asking the container to provide the needed resources.

Hollywood and IoC:

IoC as most of people say it apples Hollywood principle which is :

Component: Hello Mr.Container !Container :don't call Me, I will call you.TEET TEET TEET (the container hanged the phone :S )
Component : Shocked :|

This is what they call: don't call us , we will call you principle.

yup it is what you are thinking in , yes the container will take control over the resources for the
component but without involving the component in that, in other words the control of the resource will be inverted from component to container and its configuration(through XML as most of people do and as i do)


Life With IoC:


what if we want to apply IoC on the previous example?

Ok, so we will just need to modify some stuff (adding a property for the DataSource and also using spring framework)

//class that contains the code for spring IOC
private DataSource dataSource;

public void setDataSource(DataSource ds)
{
dataSource=da;
}

public static void man(String[] args)
{
//so now dataSource is set by Spring IOC
Connection connection=dataSource.getConnection("yourUser","yourPassword");
Statement statement=connection.CreateStatment();
ResultSet results=statement.executeQuery("select * from users");
. . . //i didnt include all the code just the important thing
}

//segments from XML configuration file

<%bean name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">

<%property name="driverClassName" value="youDriverClassName" />

<%property name="url" value="DBUrl" />

<%property name="username" value="yourUsername" />

<%property name="password" value="youPassword" />

<%bean name"ourComponent" class="com.springIoC.IoCTesting">

<%property name="dataSource" ref="dataSource">

<%/bean>


as we can see in the above XML we just stated that we have a bean from class bla bla which has a property named dataSource so spring IoC will just think like that :

mmm (spring IoC thinking...)
oh yea i have a bean named ourComponent .
wait a minute this bean have a property named dataSource! .
this property refers to another bean named dataSource which have some property (url,username,password,driverclassname) .
oh great so now what i need to do is inject this bean property (data source property in the ourComponent ) with the Datasource ,TA DA now it is done.

so we can see here that we didn't make any lookup , so there is zero times component did ask the container about the DataSource.
in this case the control over deciding which DataSource to use is in the container not the component so once the container gets a DataSource it will pass it to the component by calling the setter (SetDataSource).when spring IoC container loads at runtime it will inject the dependency into our component (this is done at runtime by XML configuration as we can see above) so the Data Source will be injected into ourComponent and now we can make anything with this data source (with zero component to container call).

below is a diagram that shows the interaction in case we are using IoC or non IoC Container.

in the first we can see that the component ask the container to provide the resource it need (data source in our case ) but in the second image the container creates and inject the resource into the component































Types Of Injection:
We have seen in the previous sample that spring do the injection through setter (property) thats one way of injection , another way it to inject through the constructor (which spring also support)
this mean that i can inject all resource in the component through a constructor (and that constructor takes all the needed resource through arguments supplied)


so now we know what is Dependency injection and also the IoC concept , there are also some IoC containers other than spring IoC container for example :Pico container and also Avalon framework.

my Blog

.. more.

Monday, August 25, 2008

Playlist creation Mobile App in Python !

This is a simple program i have made for my mobile phone (Nokia N70).

To cut a long story short, i have a a 1GB memory card more than half of them are mp3's, and i wanted a simple program to organize them (Playlist for each folder). At the same time, i wanted to play with something new and non-usual ( ! J2ME), i wanted to write it in python :) , and it turned out to be very easy.



  • At first i needed to install the suitable python runtime for my phone, and found this link (provides some information about your device, including the development platform). Then i had to download it from here . You just need to install it on your cell phone just as any other program.

  • Then i wrote the program in python and tested it on my Ubuntu PC and here is the code. I forgot to mention that playlist files have a ".m3u" extension and are only a text file containing a list of mp3(|| m4a) files separated by a new line character.


    import os
    import sys

    # Test folder
    searchDirectory="/media/sda6/Songs/fdsfsd"

    if not os.path.isdir ( searchDirectory ) :
    print searchDirectory + " is not a directory."
    sys.exit ( 0 )

    m3uFilename = os.path.split ( searchDirectory )[1] + '.m3u'

    # Get all files.
    dirList=os.listdir(searchDirectory)

    fileList = []

    # Get mp3 or m4a files only.
    for fname in dirList:
    if fname.lower().endswith ( '.mp3' ) or fname.lower().endswith ( '.m4a' ) :
    fileList.append ( fname )

    # Begin : Generate the m3u file.
    m3uFile = open( searchDirectory + os.path.normcase('/') + m3uFilename ,'w')

    filesAdded = 0

    for aFile in fileList:
    print 'Adding ' + aFile
    m3uFile.write ( aFile + '\n' )
    filesAdded = filesAdded + 1

    print 'Files Added : ' + str ( filesAdded )

    m3uFile.close()
    # End : Generate the m3u file.

  • Third, I needed a simple control to select the files visually, after a 5 minute googling i found this fileselector control. and I needed to add only two extra lines of code :D , Those -->

    import fileselector
    searchDirectory = fileselector.fileselect()

  • Fourth, Put them on a folder on your memory card, then from your cell phone install fileselector.py (remember you got it from the third step) and install it as a python lib, and install m3ucreator as a script. Then run python on your phone, select options --> Run Script and you will find it as my\m3ucreator.py . When you run it the file selector should open, after you select your folder it will report how many files are added to the playlist. And when you open Nokia Music Manager the next time, you will find it in the list of playlists.

  • Fifth, There is no fifth step :) . I just want to note that there is no code changes from the desktop version except in the folder selection (THIS IS GREAT) . Here is the code listing

    import os
    import sys

    # Begin : Mobile Specific Code.
    import fileselector
    searchDirectory = fileselector.fileselect()
    # End : Mobile Specific Code.

    if not os.path.isdir ( searchDirectory ) :
    print searchDirectory + " is not a directory."
    sys.exit ( 0 )

    m3uFilename = os.path.split ( searchDirectory )[1] + '.m3u'

    # Get all files.
    dirList=os.listdir(searchDirectory)

    fileList = []

    # Get mp3 or m4a files only.
    for fname in dirList:
    if fname.lower().endswith ( '.mp3' ) or fname.lower().endswith ( '.m4a' ) :
    fileList.append ( fname )

    # Begin : Generate the m3u file.
    m3uFile = open( searchDirectory + os.path.normcase('/') + m3uFilename ,'w')

    filesAdded = 0

    for aFile in fileList:
    print 'Adding ' + aFile
    m3uFile.write ( aFile + '\n' )
    filesAdded = filesAdded + 1

    print 'Files Added : ' + str ( filesAdded )

    m3uFile.close()
    # End : Generate the m3u file.

    Enjoy it :)
Note that the code is not displayed properly here. Python code blocks depend on indentation.

.. more.

Introduction To WAP


Introduction:
Through this topic we will work together to understand Technology of Wireless Application Protocol (WAP), also we will take a fast tour about developing WAP Applications using ASP.net.

Technology Description:

Mobile Application :
When First Mobile arrived, it was only smart way for sending and receiving voice calls and after sometime for sending and receiving text messages. But now, it is become the most growing market for services and recreational purposes. It is also being used for accessing internet and multimedia world.

For this reason, a lot of developing and programming concepts changed to become compatible with mobile world, one of these concepts was WAP as a mobile alternative of WEB concepts for regular computers.

What is WAP ؟

From Wikipedia, WAP is an open international standard for application layer network communications in a wireless communication environment. Its main use is to enable access to the Internet (HTTP) from a mobile phone or PDA.

How it Work ؟

The Biggest different between WAP and WEB is that WAP able to work through less capabilities and slow speed in comapre with the configuration of regular computers.

WAP starts since an order come from mobile customer, it is convert HTML page to WML pages that is able to browsing through mobiles.

What is WML ؟

It is description language very similar to HTML tags, it have only some few different:

- The main Tag is <wml> instead of <html>.

- Documents splits to <card></cards>.


Introduction To WML:

This is sample from Wiki about WML document:

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//PHONE.COM//DTD WML 1.1//EN"
"
http://www.phone.com/dtd/wml11.dtd" >
<wml>
   <card id="main" title="First Card">
     <p mode="wrap">This is a sample WML page.</p>
</card>
</wml>

Reading and Writing Variables in WML:

<setvar name="First_Name" value="Ahmed"/>
<setvar name="Age" value="21"/>

Later you can display it like that:

<p>First Name: $(First_Name)</p>

You can also read textbox value with the same way:

<card id="card1" title="Tutorial">
<do type="accept" label="Answer">
<go href="#card2"/>
</do>
<p>
<select name="name">
<option value="HTML">HTML Tutorial</option>
<option value="XML">XML Tutorial</option>
<option value="WAP">WAP Tutorial</option>
</select>
</p>
</card>
<card id="card2" title="Answer">
<p>
You selected: $(name)
</p>
</card>
</wml>

ASP.net Application using WAP:

Do you remember our first WAP Application in this topic?

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//PHONE.COM//DTD WML 1.1//EN"
"
http://www.phone.com/dtd/wml11.dtd" >
<wml>
   <card id="main" title="First Card">
     <p mode="wrap">This is a sample WML page.</p>
</card>
</wml>

If you want to use it through ASP.net, you have to convert it to something like that:

<%@ Page Inherits="System.Mobile.UI.MobilePage" Language="C#" %>
<%@ Register TagPrefix="mobile" Namespace="System.Mobile.UI" %>
<mobile:Form runat="server">
<mobile:Label runat="server">
This is a sample WML page.
</mobile:Label>
</Mobile:Form>

If you want to work through VB.net instead of C#, just modify the first line like that:

<%@ Page Inherits="System.Mobile.UI.MobilePage" Language="C#" %>


And now, if your web site ordered from PC, the response will contain HTML tags, if it is ordered from Mobile, the response will contains WML tags.

.. more.

Forth Arabic Wikipedia Day

.. more.

Sunday, August 24, 2008

.NET Framework 3.5 Service Pack 1 has been released

ASP.NET in the .NET Framework 3.5 Service Pack 1 release includes numerous bug fixes. In addition, it includes features for the following:

  • Enabling high-productivity data scenarios by using ASP.NET Dynamic Data.
  • Supporting the browser navigation in ASP.NET AJAX applications by using ASP.NET AJAX browser history.
  • Increasing the download speed for ASP.NET applications by using ASP.NET AJAX script combining.
More about .NET Framework 3.5 Service Pack 1, Press Here

.. more.

Expression Blend

 

When WPF - the new .net technology- arrived, Microsoft try to provide some tools makes life easy to WPF Developers, one of this tools was Expression Blend, we will try to show some features about it in this topic.

Try to download it form Microsoft web site, then run it and choose new Project - WPF Application (*.exe):

 

You can now choose your name, folder and .net language you want.

Click View-Active Document View then click split view to show both code and design view:

 

In the left side, you will find all tools you need for your design including painting tools such as brushs and pens. You can find also .net components such as commandbuttons. You can also click the link to more item to show all tools:

While you are painting, you will find additional properties for each tool in the right side:

Example:

Add new <canvas>, this will the container of our picture for this example:

<Canvas>
<Canvas x:Name="MainImageCanvas" Canvas.Left="40" Canvas.Top="120">

Add new MediaElement to add a picture:

<MediaElement x:Name="MainImage" Source="c:/example/futex.jpg" Width="300" Height="300" ></MediaElement>

Now we will apply some effects through properties, this is an example of code results from some operations:

<Canvas.RenderTransform><TransformGroup>
<SkewTransform x:Name="MainSkewTransform" AngleY="-19" AngleX="0" CenterX="0" CenterY="0"/> <ScaleTransform x:Name="MainScaleTransform" ScaleY="1" ScaleX = "1" CenterX="0" CenterY="0"/></TransformGroup> </Canvas.RenderTransform></Canvas>

Press F5 now, this is a snap shot of expected results:

Now we will try to apply some shadow to the picture, so we will add <canvas> for a new picture object refer to the same file with new transformation parameters to make the second picture seems to be a shadow:

<Canvas x:Name="ReflectionImageCanvas" Canvas.Left="260" Canvas.Top="640">

<MediaElement x:Name="ReflImage" Source="c:/example/futex.jpg" Width="300" Height="300" Volume="0">

</MediaElement>

<Canvas.RenderTransform>

<TransformGroup>

<SkewTransform x:Name="ReflectionSkewTransform" AngleY="19" AngleX="-41" CenterX="0" CenterY="0" />

<ScaleTransform x:Name="ReflectionScaleTransform" ScaleY="-1" ScaleX="1" CenterX="0" CenterY="0" />

</TransformGroup>

</Canvas.RenderTransform>

</Canvas>

Previous Code Result:

Last topic in this lesson is to add some transparent to the shadow of picture through opacity property, the result XAML maybe like that:

<Canvas x:Name="ReflectionImageCanvas" Canvas.Left="260" Canvas.Top="640">

<MediaElement x:Name="ReflImage" Source="c:/example/futex.jpg" Width="300" Height="300" Volume="0">

</MediaElement>

<Canvas.RenderTransform>

<TransformGroup>

<SkewTransform x:Name="ReflectionSkewTransform" AngleY="19" AngleX="-41" CenterX="0" CenterY="0" />

<ScaleTransform x:Name="ReflectionScaleTransform" ScaleY="-1" ScaleX="1" CenterX="0" CenterY="0" />

</TransformGroup>

</Canvas.RenderTransform>

<Canvas.OpacityMask>

<LinearGradientBrush StartPoint="0.5,0.0" EndPoint="0.5,1.0">

<GradientStop Offset="0.345" Color="#00000000" x:Name="ReflGradientStop1" />

<GradientStop Offset="1.0" Color="#CC000000" x:Name="ReflGradientStop2" />

</LinearGradientBrush>

</Canvas.OpacityMask>

</Canvas>

Now, you have to try to edit the position of shadow by changing top and left manually, the result must be something like that:

Full XAML Code:

<Canvas>
            <Canvas x:Name="MainImageCanvas" Canvas.Left="40" Canvas.Top="120">

                <MediaElement x:Name="MainImage" Source="c:/example/FUTEX.JPG" Width="300" Height="300" >
                </MediaElement>
                <Canvas.RenderTransform>
                    <TransformGroup>
                        <SkewTransform x:Name="MainSkewTransform" AngleY="-19" AngleX="0" CenterX="0" CenterY="0"/>
                        <ScaleTransform x:Name="MainScaleTransform" ScaleY="1" ScaleX = "1" CenterX="0" CenterY="0"/>
                    </TransformGroup>
                </Canvas.RenderTransform>
            </Canvas>
            <Canvas x:Name="ReflectionImageCanvas" Canvas.Left="267" Canvas.Top="645">
                <MediaElement x:Name="ReflImage" Source="c:/example/futex.jpg" Width="300" Height="300" Volume="0">
                </MediaElement>
                <Canvas.RenderTransform>
                    <TransformGroup>
                        <SkewTransform x:Name="ReflectionSkewTransform" AngleY="19" AngleX="-41" CenterX="0" CenterY="0" />
                        <ScaleTransform x:Name="ReflectionScaleTransform" ScaleY="-1" ScaleX="1" CenterX="0" CenterY="0" />
                    </TransformGroup>
                </Canvas.RenderTransform>
                <Canvas.OpacityMask>
                    <LinearGradientBrush StartPoint="0.5,0.0" EndPoint="0.5,1.0">
                        <GradientStop Offset="0.345" Color="#00000000" x:Name="ReflGradientStop1" />
                        <GradientStop Offset="1.0" Color="#CC000000" x:Name="ReflGradientStop2" />
                    </LinearGradientBrush>
                </Canvas.OpacityMask>
            </Canvas>
        </Canvas>

 

Don't forget that MediaElement can accept any type of media, try to attach video and see the result.

Anyway, you can copy this XAML code to a WPF .net solution and the same result will apply to your form.

.. more.

Friday, August 22, 2008

dotNetWork.org 7th gathering


Date:
Saturday, August 30th 2008,
12:00 - 16:00

Attendance is FREE =)

Note: This time we are having 2 parallel tracks, that's 4 sessions presented by 3 speakers.. Waiting for your feed-back about that..

Speakers


Mohamed Ahmed Meligy
Senior Software Engineer - SilverKey Technologies Egypt.

Tamer Mohammad Fathy AL-Khouly
Information Specialist - EDS.

Mohammad Yousri El-Farsi
Senior Software Engineer - ITWorx.

Agenda
12:00 - 13:30:
Design Patterns via C# 3 (Part 1)
by Mohamed Ahmed Meligy.

Tec-Talk Wiz BizTalk (Part 1)
by Tamer Mohammad Fathy AL-Khouly,
Mohammad Yousri El-Farsi.


13:30 - 14:00: Break

14:00 - 15:30:
Design Patterns via C# 3 (Part 2)
by Mohamed Ahmed Meligy.

Tec-Talk Wiz BizTalk (Part 2)
by Tamer Mohammad Fathy AL-Khouly,
Mohammad Yousri El-Farsi.

Location:

Canadian International College, @ "El-Tagamo3 El-5ames"

Buses will be available at: Nady El-Sekka (11:00 AM - 11:30 AM)
Please be there before 11:30 coz we will leave on time..


For those who wanna keep tuned with further news about this event & other upcoming events of the dotnetwork.org user group, please check the following links:

Yahoo!Group:
http://tech.groups.yahoo.com/group/dotnetworkorg/

Facebook Event:
http://www.new.facebook.com/event.php?eid=29202125063
You'd better join the above event if you have a facebook account so we can roughly estimate the attendees count..

Facebook Fan Page:
http://www.facebook.com/pages/netWorkorg/13135685545

Facebook Group:
http://www.facebook.com/group.php?gid=2409268236

Please don't hesitate to contact me if you have any further questions..
See u on the gathering ;)

.. more.

Tuesday, August 19, 2008

When database log file increases incredibly?

Working as DBA, I face problems daily and for the importance of the organization I work for; problems should be solved immediately.  past days I had log file which its size exceeds 70 GB unreasonably... I've low disk space problem, clients access this database denied from doing any operation since log file can't allocate more free space on storage area, really all solutions weren't applied due to some restrictions, one of the solutions is to copy data from this database and transmit it to another database (which you can control  log file growth) this solutions failed because SQL Server needs the new database has a log file its size like the old one aka 70 GB!!!!!

Another is to detach the database and trying attaching it without log file, fails also, since log file not exists.

While searching on this problem I've found someone has big size log file asks this question and I found the solution is to create a new database from the .mdf file of the old one and you shouldn't put the .ldf (log file(s)) besides. because SQL Server searching for the .ldf and if it didn't it creates another one with small size. and now old log file isn't belong to new created database and you can delete it and save more space :)

Code to create database from .mdf file

sql code

.. more.

Friday, August 15, 2008

How to use dataset and adapters with stored procedures?

Q: How to use dataset and adapters with stored procedures?

A: I've asked this question two times today, and for that I thought to do a post and send the link better to answer everyone separately..

Right now, I've be_settings table, its schema (SettingName nvarchar(50) and SettingValue nvarchar(MAX)) what I need is to create stored procedure to get SettingName and SettingValue when the SettingValue = some value

SP  

then let's go to Visual Studio and create windows application and drop DataGridView on the form; press on the smart arow located on its top right, new dialog appears, choose to add new data source->Add project data source->Database

dataconnection

next->next->

databaseobjects

then finish...

Your form should look like

after choosing datasource

in Load data onClick event handler, write this code

code to load data

Just, Ctr + F5 and lets test our work

result

Hope, I answered your question ",)

Tip: if you using Windows Vista you need to run Visual Studio and SQL Server as administrator....

.. more.