You can now find my blog at ShloEmi.com
After almost 7 years at Blogger it's time to grow.
Hope to see you there,
Shlomi.O
Saturday, May 5, 2012
Friday, January 20, 2012
WCF-4 Client/Host quick start/tutorial
For those of you who already know WCF basics and need to start quickly here are guidelines to start a working client-server/service project:
My Quickest Start
Example Host Code
Example Client Code
MSDN's 'Basic Programming Lifecycle'
Please, post comments if you find errors.
I'll fix them ASAP and others can enjoy a cleaner clode.
Hope it helps...
My Quickest Start
- Designing Service Contracts
- Start simple, grow in time.
- Implement the contract
- Host the service - Console (starting simple).
- http://msdn.microsoft.com/en-us/library/ms731758.aspx
- New 'Console Application'
- See 'Example Host Code' below...
- Add Reference.... Select System.ServiceModel
- Reference 'ServiceModel'
- Start the service code
- Using
- Open
- Close
- Disable WcfSvcHost (if needed)
- "Right-click the WCF Service Project in Solution Explorer, choose Properties, and click WCF Options tab. The Start WCF Service Host when debugging another project in the same solution check box is enabled by default."
- CLIENT SIDE - Obtain the Service Contract, Bindings, and Addresses
- Enable the service
- Set the Host as the default startup program and run in without debugger (usually <CTRL>+F5).
- 'Add Service Reference...'
- Past the service address in the 'Address' field and 'Go'.
- Point the service and 'OK' =results=> a new client proxy code will be generated in your client.
- SET YOUR CLIENT APPLICATION AS THE STARTUP PROGRAM :)
- Add service usage code to your client (see 'Example Client Code' below...).
- Run and relax :-).
Code Snippet
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.ServiceModel;
- using System.ServiceModel.Description;
- using MyWcfLib;
- namespace MyServer
- {
- class Program
- {
- static void Main(string[] args)
- {
- Uri baseAddress = new Uri("http://localhost:9090/hello");
- using (ServiceHost host = new ServiceHost(typeof(MyService), baseAddress))
- {
- // Enable metadata publishing.
- ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
- smb.HttpGetEnabled = true;
- smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
- host.Description.Behaviors.Add(smb);
- // Open the ServiceHost to start listening for messages. Since
- // no endpoints are explicitly configured, the runtime will create
- // one endpoint per base address for each service contract implemented
- // by the service.
- host.Open();
- Console.WriteLine("The service is ready at {0}", baseAddress);
- Console.WriteLine("Press <Enter> to stop the service.");
- Console.ReadLine();
- // Close the ServiceHost.
- host.Close();
- }
- }
- }
- }
Example Client Code
Code Snippet
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- var client = new ServiceReference1.MyServiceClient();
- Console.WriteLine(client.GenerateGuid().ToString());
- client.Close();
- Console.ReadLine();
- }
- }
- }
MSDN's 'Basic Programming Lifecycle'
Please, post comments if you find errors.
I'll fix them ASAP and others can enjoy a cleaner clode.
Hope it helps...
Labels:
C#,
Code,
examples,
Programming,
Samples,
Server,
Tips,
Tutorial,
Visual Studio,
WCF
Saturday, January 7, 2012
WPF, XAML: TreeView HierarchicalDataTemplate databinding to unknown XML/DataSource
Problem description
Solution
You need to use and understand these parts:
Usage Example
Just copy paste and start playing / reading each part's help.
XAML
Code behind
Additional files
Performance
I was able to load 100MB of xml data in around ~6 seconds first time, ~4 seconds from the second time.
Testbench station
Results
Resources
Hope it helps.
- I wish to bind my TreeView to a datasource.
- The TreeView should build its child nodes dynamically (unknows childs in datasource).
- Each node should display its data or (if no data) its element name.
Solution
You need to use and understand these parts:
- HierarchicalDataTemplate
- HierarchicalDataTemplate.Triggers
- Binding XPath
Just copy paste and start playing / reading each part's help.
XAML
Code Snippet
- <Window x:Class="TreeViewDataBinding.Window1"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="Window1" Height="300" Width="300">
- <Window.Resources>
- <HierarchicalDataTemplate x:Key="NodeTemplate" >
- <TextBlock x:Name="tbName" Text="?" />
- <HierarchicalDataTemplate.ItemsSource>
- <Binding XPath="child::node()" />
- </HierarchicalDataTemplate.ItemsSource>
- <HierarchicalDataTemplate.Triggers>
- <DataTrigger Binding="{Binding Path=NodeType}" Value="Text">
- <Setter TargetName="tbName" Property="Text" Value="{Binding Path=Value}"/>
- </DataTrigger>
- <DataTrigger Binding="{Binding Path=NodeType}" Value="Element">
- <Setter TargetName="tbName" Property="Text" Value="{Binding Path=Name}"/>
- </DataTrigger>
- </HierarchicalDataTemplate.Triggers>
- </HierarchicalDataTemplate>
- <XmlDataProvider x:Key="xmlDataProvider"/>
- </Window.Resources>
- <StackPanel>
- <Button Click="Button_Click">Reload</Button>
- <TreeView
- ItemsSource="{Binding Source={StaticResource xmlDataProvider}, XPath=*}"
- ItemTemplate="{StaticResource NodeTemplate}" />
- </StackPanel>
- </Window>
Code behind
Code Snippet
- using System.Windows;
- using System.Windows.Data;
- using System;
- namespace TreeViewDataBinding
- {
- public partial class Window1 : Window
- {
- public Window1()
- {
- InitializeComponent();
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- var provider = (XmlDataProvider)this.Resources["xmlDataProvider"];
- provider.Source = new Uri(@"Data\standard.xml", UriKind.Relative);
- }
- }
- }
Additional files
- standard.xml testbenach XML file (100MB !!).
- http://www.xml-benchmark.org/downloads.html
- " For your convenience, we provide a ready-made document for a 100 MB experiment."
Performance
I was able to load 100MB of xml data in around ~6 seconds first time, ~4 seconds from the second time.
Testbench station
- i7 (8 cores) @ 2.80GHz
- 4.00GB RAM
- 64-Bit OS, Win7 Pro.
CPU & memory usage
The CPU was at idle when i started, the RAM was at the base line.
Resources
- http://www.w3schools.com/xpath/xpath_syntax.asp
- http://www.w3schools.com/xpath/xpath_axes.asp
- http://stackoverflow.com/questions/1605062/treeview-bound-to-xmldataprovider-shows-data-in-editor-but-empty-when-run
Hope it helps.
Labels:
examples,
GUI,
Programming,
Samples,
Tips,
UI,
Visual Studio,
WPF,
XAML
Wednesday, December 28, 2011
How to change paypal button image in magento...
Don't even bother finding the solution at Magento Admin Panel or at PayPal :), spent quit a time looking for the solution over there.
Steps
Resources
Steps
- You need to access the file (using ftp...) located here:
- /app/design/frontend/base/default/template/paypal/express/shortcut.phtml
- Edit it:
- find the line that contains "img src=".
- replace the source with your wanted 'Pay with PayPal' image path.
Results
I've managed to change it from this one:
To this one:
Resources
Using PayPal express with magento.
The story
I was asked to give the user the ability to pay using PayPal services.
The site is magento store.
The user will have two option at PayPal:
I was asked to give the user the ability to pay using PayPal services.
The site is magento store.
The user will have two option at PayPal:
- He have an acount and will pay after he logged into his PayPal account.
- He have no account - he is NOT requiered to open a PayPal account to pay, he'll enter his credit credentiols and pay.
Simple, right? :-)
I got into some problems, the community help on this matter is not so obvious, after a day of research and experements, which hopefuly you will avoid, here are the final steps did to satisfy these requierments:
The solution
On Magento Admin Panel
- Magento admin panel => Menu => System => Configuration, click.
- In the left configuration panel => Sales => PayPal, click.
- "Email Associated with PayPal Merchant Account" => enter your PayPal account email.
- "Select a PayPal Solution" => "Express Checkout", checked
- At "Express Checkout Settings" (*2):
- "Payment Action" : Usually Sale .
- "Enable PayPal Guest Checkout" => Yes
- SAVE CONIFG!
- At "API/Integration Settings":
- API Authentication Methods => API Signiture.
- Get Credentials from PayPal, click:
- Entering PayPay... Enter your PayPal credential...
- Just get your API credentials through Profile > My selling tools > API Access > Update > Request API credentials > Request API Signature (*1)
- Enter the API credentioal, appropriattly, to:
- API Username, Password & Signature.
- SAVE CONIFG!
These steps created a fast & secure checout point for my users to buy products without PayPay account.
Hope it helped.
Resources
Saturday, December 24, 2011
MAGENTO: can't "Log in to Admin Panel"
Just solved this problem.
Problem description
I've instaled magento in my local computer and I can't login to the admin panel.
Understanding the problem
Magento doesn't work well with 'localhost' and '127.0.0.1'. After some readings on the net I understood that these addresses won't allow cookies, resolting in admin panel login failure.
Solution
Edit 'host' file located at 'C:\Windows\System32\drivers\etc'.
Add a new line, for example:
127.0.0.1 shloemi.com # Localhost virtual development site.
Usage
You can now acces magento admin pannel using the site shloemi.com.
Example: http://shloemi.com/Magento/index.php/
Problem description
I've instaled magento in my local computer and I can't login to the admin panel.
Understanding the problem
Magento doesn't work well with 'localhost' and '127.0.0.1'. After some readings on the net I understood that these addresses won't allow cookies, resolting in admin panel login failure.
Solution
Edit 'host' file located at 'C:\Windows\System32\drivers\etc'.
Add a new line, for example:
127.0.0.1 shloemi.com # Localhost virtual development site.
Usage
You can now acces magento admin pannel using the site shloemi.com.
Example: http://shloemi.com/Magento/index.php/
WPF: layouts & layout attributes explained.
Found some very good articles that explains layouts & layout attributes...
Alignment, Margins, and Padding Overview
Alignment, Margins, and Padding Overview
WPF controls layout explained
http://www.aspfree.com/c/a/Windows-Scripting/WPF-Control-Layout/
Using the WPF DockPanel http://blogs.objectsharp.com/blogs/dave/archive/2009/03/13/using-the-wpf-dockpanel.aspx
Alignment, Margins, and Padding Overview
Alignment, Margins, and Padding Overview
WPF controls layout explained
http://www.aspfree.com/c/a/Windows-Scripting/WPF-Control-Layout/
Using the WPF DockPanel http://blogs.objectsharp.com/blogs/dave/archive/2009/03/13/using-the-wpf-dockpanel.aspx
WPF: MVVM, Quickstart
Read and follow this GREAT article instructions...
http://www.codeproject.com/KB/WPF/WpfMvvmQuickStart.aspx
http://www.codeproject.com/KB/WPF/WpfMvvmQuickStart.aspx
Background reading that helps
- Data binding refresh - http://msdn.microsoft.com/en-us/magazine/cc163299.aspx
Useful resources
- WPF at CodePlex - http://wpf.codeplex.com/
Labels:
Best practices,
Design Patterns,
Guides,
MVVM,
Programming,
UI,
WPF
Sunday, December 11, 2011
WPF CodePlex toolkit, charting made easy...
Charting made easy: graph, pie, bars, points...
Free, opensource, maintained.
Free, opensource, maintained.
"The WPF Toolkit is a collection of WPF features and components that are being made available outside of the normal .NET Framework ship cycle."
Sources
Saturday, December 10, 2011
MSConfig - System Configuration UI
Very helpfull tool.
(*1) "Some of its functionality varies by Windows versions:
(*1) "Some of its functionality varies by Windows versions:
- In Windows 98 and Windows Me, it can configure advanced troubleshooting settings pertaining to these operating systems. It can also launch common system tools.
- In Windows 98, it can back up and restore startup files.
- In Windows Me, it has also been updated with three new tabs called "Static VxDs", "Environment" and "International". The Static VxDs tab allows users to enable or disable static virtual device drivers to be loaded at startup, the Environment tab allows users to enable or disable environment variables, and the International tab allows users to set international language keyboard layout settings that were formerly set via the real-mode MS-DOS configuration files. A "Cleanup" button on the "Startup" tab allows cleaning up invalid or deleted startup entries.
- In Windows Me and Windows XP versions, it can restore an individual file from the original Windows installation set.
- On Windows NT-based operating systems prior to Windows Vista, it can set various BOOT.INI switches.
- In Windows XP and Windows Vista, it can hide all operating system services for troubleshooting.
- In Windows Vista and later, the tool gained additional support for launching a variety of tools, such as system information, other configuration areas, such as Internet options, and the ability to enable/disable UAC. An update is available for Windows XP and Windows Server 2003 that adds the Tools tab.[1] It also allows configuring various switches for Windows Boot Manager and Boot Configuration Data."
Read more about it here - http://en.wikipedia.org/wiki/MSConfig
To activate it, WIN+R (or Start-->Run), then run 'msconfig'.
Result
Friday, December 9, 2011
WPF: FlowDocument control
Please be aware FlowDocument control in WPF, this can easy your life when needed.
Pictures that say it all
The diagram shows the objects most typically used with flow content.
Sources
Pictures that say it all
Sources
WPF XAML example: Binding FontSize to a Slider
Code snippet
Result
Code Snippet
- <TextBlock Text="Hi there." FontSize="{Binding ElementName=mySlider, Path=Value}" />
- <Slider Minimum="8" Maximum="32" x:Name="mySlider" Value="12" />
Result
WPF XAML example: Rich texted ToolTip with italic, color and more...
Example
In this example I'll demonstrate how to add a ToolTip to a TextBox.
The ToolTip should be colored and italic.
Code snippet
Result
Sources
In this example I'll demonstrate how to add a ToolTip to a TextBox.
The ToolTip should be colored and italic.
Code snippet
Code Snippet
- <TextBox x:Name="SampleText"
- TextWrapping="Wrap">
- <TextBox.ToolTip>
- <TextBlock>
- <Italic Foreground="Red">Instructions: </Italic> Type here to change the preview text.
- </TextBlock>
- </TextBox.ToolTip>
- The quick brown fox jumps over the lazy dog.
- </TextBox>
Result
Sources
WPF XAML TIP: Label with Target + Control composition == Hotkey control
Code snippet
Usage
Press ALT+L to focus the TextBox control 'lastName'.
Result
Code Snippet
- <Border DockPanel.Dock="Top">
- <StackPanel>
- <Label
- Content="_Last Name:"
- Target="{Binding ElementName=lastName}" />
- <TextBox x:Name="lastName" Width="100" HorizontalAlignment="Left"/>
- </StackPanel>
- </Border>
Usage
Press ALT+L to focus the TextBox control 'lastName'.
Result
WPF: TextBox with SpellCheck and ToolTip XAML example
Code snippet
Results
Code Snippet
- <TextBox
- Width="200"
- SpellCheck.IsEnabled="True"
- ToolTip="Tips for this input-box here..." />
Results
WPF: Rich TextBlock XAML example
"The TextBlock was designed specifically for the purpose of showing small amounts of flowing rich text to the user.
It is the perfect element for displaying instructions or summary information."
Have fun...
It is the perfect element for displaying instructions or summary information."
- Quoted from ''Sams Teach Yourself WPF in 24 Hours"
Usage example
I have a program that users can communicate with each other. I wish to add the feature of bold, colored, line-breaking and icons to that chat.
Here is an example I've found to illustrate it:
Example
Code Snippet
- <TextBlock FontSize="10" TextWrapping="Wrap" >
- <Image Stretch="UniformToFill" Width="32" Height="32" Source="http://upload.wikimedia.org/wikipedia/en/b/b0/Avatar-Teaser-Poster.jpg" Margin="2 2 2 2" />
- <Bold><Italic FontSize="12" Foreground="DarkGreen">ShloEmi:</Italic></Bold><LineBreak />
- <Bold><Italic FontSize="14" Foreground="BlueViolet">H</Italic></Bold>ave fun with <Bold>TextBlock's</Bold>.<LineBreak />
- <AccessText Foreground="Blue">It's easy when you have an example </AccessText> <Image Source="http://upload.wikimedia.org/wikipedia/commons/thumb/8/85/Smiley.svg/50px-Smiley.svg.png" Width="16" Height="16"></Image>
- </TextBlock>
Result
Have fun...
Thursday, December 8, 2011
About WPF
Here is my experiance with learning and programming WPF in the last year:
First let me tell you that - WPF IS GREAT!
Simple put - WPF let you do layers of controls and decorators.
This means you can composite anything in easy.
The things I did with WPF were not easy at all in Win32-API and not even in .Net using GDI+.
Usage example
I wish to have a character drawn, later on I wish to add that character a life status, later on - an icon on the top-right to reperesent which guild is he in... and more...
Of course It's solvable using the Decorator-Pattern using the draw to add more pictures, but - you need to BitBlt ... and more complex stuff.
With WPF, however, you layer it all with opacity, or transparency, which is the same solution as before with one exception - you write it declarativly and in 10 min :-).
The learning curve
I already had a very rich epreriance with WinForms/MFC/Win32 GUI + I know Design-Patterns pretty good, so I had a good head-start ==> It was easier to learn, the elements were already in my mind.
First I started with tutorials to feel WPF, and books.
The most used were (recomendation ordered):
First let me tell you that - WPF IS GREAT!
Simple put - WPF let you do layers of controls and decorators.
This means you can composite anything in easy.
The things I did with WPF were not easy at all in Win32-API and not even in .Net using GDI+.
Let's start with a complext WPF sample I've found:
http://10rem.net/blog/2010/10/28/the-present-and-future-of-wpf
http://10rem.net/blog/2010/10/28/the-present-and-future-of-wpf
Usage example
I wish to have a character drawn, later on I wish to add that character a life status, later on - an icon on the top-right to reperesent which guild is he in... and more...
Of course It's solvable using the Decorator-Pattern using the draw to add more pictures, but - you need to BitBlt ... and more complex stuff.
With WPF, however, you layer it all with opacity, or transparency, which is the same solution as before with one exception - you write it declarativly and in 10 min :-).
The learning curve
I already had a very rich epreriance with WinForms/MFC/Win32 GUI + I know Design-Patterns pretty good, so I had a good head-start ==> It was easier to learn, the elements were already in my mind.
First I started with tutorials to feel WPF, and books.
The most used were (recomendation ordered):
- Tutorials:
- WPF Tutorial
- 'Hello WPF' ... http://www.wpftutorial.net/HelloWPF.html
- Books:
- http://www.amazon.com/Sams-Teach-Yourself-WPF-Hours/dp/0672329859
- http://www.amazon.com/2010-NET-Platform-Andrew-Troelsen/dp/1430225491
- The chapters about WPF (Chapter 27).
In between, I started using it in my solutions, strted with simple solutions (traditional GUI programming), used the known and common parts (buttons, labels, textboxes...), practiced and learned the basics.
Bottom line
After touching WPF there is no going back, I'll always prefer WPF over other solutions, unless I have no choice, like - "the OS doesn't support DirectX 9" :-(.
Bottom line
After touching WPF there is no going back, I'll always prefer WPF over other solutions, unless I have no choice, like - "the OS doesn't support DirectX 9" :-(.
Have a good and productive learning - WPF worth it!
Resources
WPF: Radial Panel, custom panel
Here is a cool 'custom panel' I've found that might be very handy...
The Joy Of Programming: A Simple Radial Panel for WPF and SilverLight
Usage examples
Nicer selection menu, Clock digits, dynamic elements in radial presentation rather than list...
Example outputs
source - http://www.codeproject.com/KB/WPF/SpiderControl.aspx
The Joy Of Programming: A Simple Radial Panel for WPF and SilverLight
Usage examples
Nicer selection menu, Clock digits, dynamic elements in radial presentation rather than list...
Example outputs
source - http://www.codeproject.com/KB/WPF/SpiderControl.aspx
WPF: Bulletdecorator XAML example
BulletDecorator is basically like any editor bullet (like MS word's bullet). You can specify how to draw the bullet itself and decorate what ever you need.
Suppose we want to do the following effect in WPF:
And here is the results:
Source - Bulletdecorator in WPF | Controls | w3mentor
Suppose we want to do the following effect in WPF:
- This is a bullet
Here is the source for it:
Code Snippet
- <BulletDecorator>
- <BulletDecorator.Bullet>
- <Polygon Margin=" 2, 0, 0, 0" Points="0, 5 5, 0 10, 5 5, 10" Fill=" Blue" />
- </BulletDecorator.Bullet>
- <TextBlock Margin="10, 0, 0, 0" Text="This is a bullet" />
- </BulletDecorator>
And here is the results:
Source - Bulletdecorator in WPF | Controls | w3mentor
Subscribe to:
Posts (Atom)








