'3. Implementation/WPF & Silverlight'에 해당되는 글 9건
- 2014.04.29 Dealing with those pesky WCF CommunicationException “NotFound” errors in Silverlight
- 2014.01.07 How to: Build a Duplex Service for a Silverlight Client
- 2013.12.07 SSH.NET Useful Examples
- 2013.08.04 데이터 바인딩 개요
- 2013.08.04 Prism 4.1 - Developer's Guide to Microsoft Prism
- 2013.08.04 MVVM Training
- 2011.08.09 XAMLPad
- 2010.03.27 발송자(Dispatcher)를 사용하여 응답 성능이 뛰어난 응용 프로그램 작성
- 2010.03.25 [WPF] Screen 영역에 투명한 사각형 그리기
Dealing with those pesky WCF CommunicationException “NotFound” errors in Silverlight

The following links are very helpful to figure out the problem that shows "NotFound" errors in Silverlight.
Dealing with those pesky WCF CommunicationException “NotFound” errors in Silverlight
http://blogs.msdn.com/b/silverlightws/archive/2010/04/15/dealing-with-those-pesky-wcf-communicationexception-notfound-errors-in-silverlight.aspx
Creating and Handling Faults in Silverlight
Configuring WCF SOAP Faults for Use with Silverlight Clients
Receiving SOAP faults is not supported in the default configuration, due to Web browser limitations. When the service does send a fault, an exception is thrown on the client, but it does not specify any information about the fault that has occurred. However, there are two ways to enable SOAP fault consumption:
- Modify the HTTP status code: You can modify your service to return SOAP faults with an HTTP status code of 200, Silverlight 4 so that faults will be processed successfully. How to do this is outlined below. Note that this will make the service non-compliant with the SOAP protocol, because SOAP requires a response code in the 400 or 500 range for faults. If the service is a WCF service, you can create an endpoint behavior that plugs in a message inspector that changes the status code to 200. Then you can create an endpoint specifically for Silverlight consumption, and apply the behavior there. Your other endpoints will still remain SOAP-compliant.
- Use the alternative client HTTP stack: You can register an alternative HTTP stack by using the RegisterPrefix method. See below for an outline of how to do this. Silverlight 4 provides the option of using a client HTTP stack which, unlike the default browser HTTP stack, allows you to process SOAP-compliant fault messages. However, a potential problem of switching to the alternative HTTP stack is that information stored by the browser (such as authentication cookies) will no longer be available to Silverlight, and thus certain scenarios involving secure services might stop working, or require additional code to work. For more information, see HttpCookieContainerBindingElement.
How to: Build a Duplex Service for a Silverlight Client

Do not forget to call Close (CloseAsync in case of Silverlight) of Proxy Service Client!
sl4_wcf_nettcp_duplex_article.zip
References:
- http://www.dotnetcurry.com/showarticle.aspx?ID=726
- http://msdn.microsoft.com/en-us/library/cc645027(v=vs.95).aspx
- http://msdn.microsoft.com/en-us/library/ee844557(v=vs.95).aspx
- http://blogs.msdn.com/b/silverlightws/archive/2010/07/16/pollingduplex-multiple-mode-timeouts-demystified.aspx
- http://blogs.msdn.com/b/silverlightws/archive/2010/04/04/some-known-wcf-issues-in-silverlight-4.aspx
- http://idunno.org/archive/2008/05/29/wcf-callbacks-a-beginners-guide.aspx
- http://msdn.microsoft.com/en-us/library/ee844556(v=vs.95).aspx
SSH.NET Useful Examples

For a few days I was digging how to show the log in real time when running a linux command with SSH.NET. It doesn't look easy but thankfully there is simple way to do that. Here is an example:
client.Connect(); var cmd = client.CreateCommand("ls -l"); // very long list cmd.CommandTimeout = TimeSpan.FromSeconds(30); var asynch = cmd.BeginExecute(); var reader = new StreamReader(cmd.OutputStream); while (!asynch.IsCompleted) { var result = reader.ReadToEnd(); if (string.IsNullOrEmpty(result)) continue; Console.Write(result); } cmd.EndExecute(asynch); client.Disconnect();
Source: https://sshnet.codeplex.com/documentation
Prism 4.1 - Developer's Guide to Microsoft Prism

http://msdn.microsoft.com/en-us/library/gg406140.aspx
Prism provides guidance designed to help you more easily design and build rich, flexible, and easily maintained Windows Presentation Foundation (WPF) desktop applications, Silverlight Rich Internet Applications (RIAs), and Windows Phone 7 applications. Using design patterns that embody important architectural design principles, such as separation of concerns and loose coupling, Prism helps you to design and build applications using loosely coupled components that can evolve independently but which can be easily and seamlessly integrated into the overall application. These types of applications are known as composite applications.
http://compositewpf.codeplex.com/
MVMV Training combines in-depth written guidance with full-featured how-to code examples. MVVM Training is a Visual Studio 2010 Feature Extension and is part of the In the Box training series by Karl Shifflett.
XamlPad (xamlpad.exe) is a basic visual editor for Extensible Application Markup Language (XAML). XAMLPad is installed with Visual Studio 2008 and can be found at Program Files\Microsoft SDKs\Windows\v6.0A\Bin\XAMLPad.
XamlPad is a Windows SDK tool that provides the following features:
Real-time editing and display of XAML content.
XAML markup is automatically saved to the file XamlPad_save.xaml.
Auto parse and refresh modes provide XAML syntax validation and redisplay of content.
Basic text editing commands, including copy, paste, and undo. Also provides find support for simple strings. Invalid XAML displayed in red.
XAML errors are reported in the status bar on bottom left of the main window.
Expansion of XAML content into a visual tree allows you to view property values of content.
You can load an existing XAML file into XamlPad by passing the file name as a command-line argument (there is no File Open available in the menu).
발송자(Dispatcher)를 사용하여 응답 성능이 뛰어난 응용 프로그램 작성

원본 : http://msdn.microsoft.com/ko-kr/magazine/cc163328.aspx
Written by Shawn Wildermuth
DispatcherObject 클래스에는 두 가지 주요 임무가 있으며, 첫 번째는 개체가 연결되어 있는 현재 발송자에 대한 액세스를 제공하는 것이고, 두 번째는 스레드가 개체(DispatcherObject에서 파생)를 액세스할 수 있는지 검사(CheckAccess) 및 확인(VerifyAccess)하는 메서드를 제공하는 것입니다. CheckAccess와 VerifyAccess의 차이점은 CheckAccess는 현재 스레드가 개체를 사용할 수 있는지 여부를 나타내는 부울 값을 반환하는 데 반해 VerifyAccess는 스레드가 개체를 액세스할 수 없으면 예외를 발생시킨다는 것입니다. 이러한 기본 기능이 제공되므로 모든 WPF 개체는 특정 스레드, 특히 UI 스레드에서 개체를 사용할 수 있는지 확인할 수 있게 되었습니다. 컨트롤과 같은 WPF 개체를 직접 작성하는 경우에는 모든 메서드에서 다른 작업을 수행하기 전에 VerifyAccess를 호출해야 합니다. 이렇게 하면 그림 2에서와 같이 개체가 UI 스레드에서만 사용되도록 할 수 있습니다.
public class MyWpfObject : DispatcherObject { public void DoSomething() { VerifyAccess(); // Do some work } public void DoSomethingElse() { if (CheckAccess()) { // Something, only if called // on the right thread } } } |
Figure 3 비 UI 스레드를 사용하여 UI 업데이트 - 잘못된 방법
// The Work to perform on another thread |
Figure 4 UI 업데이트
// The Work to perform on another thread |
// The Work to perform on another thread |
Figure 6 DispatchPriority 우선 순위 지정 수준(우선 순위 순서)
우선 순위 | 설 명 |
---|---|
Inactive | 큐에 저장된 항목이 처리되지 않습니다. |
SystemIdle | 시스템이 유휴 상태일 때만 작업 항목이 UI 스레드로 발송됩니다. 실제로 처리되는 항목의 우선 순위로는 가장 낮은 것입니다. |
ApplicationIdle | 응용 프로그램 자체가 유휴 상태일 때만 작업 항목이 UI 스레드로 발송됩니다. |
ContextIdle | 높은 우선 순위의 작업 항목이 처리된 후에 작업 항목이 UI 스레드로 발송됩니다. |
Background | 모든 레이아웃, 렌더링 및 입력 항목이 처리된 후에 작업 항목이 발송됩니다. |
Input | 작업 항목이 사용자 입력과 동일한 우선 순위로 UI 스레드로 발송됩니다. |
Loaded | 모든 레이아웃 및 렌더링이 처리된 후에 작업 항목이 UI 스레드로 발송됩니다. |
Render | 작업 항목이 렌더링 엔진과 동일한 우선 순위로 UI 스레드로 발송됩니다. |
DataBind | 작업 항목이 데이터 바인딩과 동일한 우선 순위로 UI 스레드로 발송됩니다. |
Normal | 일반적인 우선 순위로 작업 항목을 UI 스레드로 발송합니다. 대부분의 응용 프로그램 작업 항목은 이 우선 순위로 발송되어야 합니다. |
Send | 우선 순위가 가장 높은 작업 항목부터 UI 스레드로 발송합니다. |
앞 서 사용했던 예와 같이 UI의 모양을 업데이트하는 작업 항목의 우선 순위는 일반적으로 항상 DispatcherPriority.Normal을 사용해야 합니다. 그러나 다른 우선 순위를 사용해야 하는 경우가 있습니다. 특히 관심을 끄는 세 가지 유휴 우선 순위(ContextIdle, ApplicationIdle 및 SystemIdle)가 있습니다. 이러한 우선 순위를 사용하여 매우 낮은 작업 부하에서만 실행될 작업 항목을 지정할 수 있습니다.
Figure 7 WPF에서 BackgroundWorker 사용
BackgroundWorker _backgroundWorker = new BackgroundWorker(); |
Figure 8 DispatcherTimer 클래스 사용
// Create a Timer with a Normal Priority |
DispatcherTimer 클래스는 발송자에 연결되어 있으므로 DispatcherPriority는 물론 사용할 발송자까지 지정할 수 있습니다. DispatcherTimer 클래스는 기본적으로 현재 발송자와 마찬가지로 Normal 우선 순위를 사용하지만 이러한 값은 다시 정의할 수 있습니다.
_timer = new DispatcherTimer( |
응용 프로그램의 응답 성능을 개선하기 위해 작업자 프로세스에 대한 계획을 마련하는 노력은 충분한 가치가 있습니다. 약간의 초기 연구를 수행한다면 계획을 더욱 성공적으로 수행할 수 있습니다. 시작하기 전에 "WPF 스레딩 리소스" 보충 기사에서 언급한 사이트 중 일부를 확인해 보기를 권장합니다. 응답 성능이 뛰어난 응용 프로그램을 개발하기 위해 이 기사에서 얻은 내용을 보강하는 기본 정보를 얻을 수 있을 것입니다.
Shawn Wildermuth는 Microsoft MVP, MCSD.NET, MCT이며 Wildermuth Consulting Services의 설립자이고, Pragmatic ADO.NET(Addison-Wesley, 2002)의 저자이자 Microsoft Certification Training Kits와 향후 출판 예정인 Prescriptive Data Architectures의 공동 저자이기도 합니다. 문의 사항이 있으면 그의 웹 사이트인 wildermuthconsulting.com으로 연락하십시오.
[WPF] Screen 영역에 투명한 사각형 그리기

GDI 또는 GDI+ 를 이용하는 방법인데,
GDI + 는 다중 모니터를 사용하는 경우에 Graphics 개체가 제대로 동작하지 않는걸 확인하였고,
GDI 를 직접 이용하는 것은 투명 처리등과 같은 복잡한 구현을 직접 해야 하는 번거로움이 있다.
이때 WPF 를 이용하면 굉장히 쉽게 구현할 수 있다.
투명한 윈도우를 만들고, 투명 윈도우를 전체 화면 영역의 크기로 변경한다. xaml 은 다음과 같다.
1. 투명처리를 하기 위해서 Background 와 AllowsTransparency, WindowStyle 을 각각 Transparent, True, None 으로 설정해야 한다.
2. 그리고 투명한 윈도우가 최상위 윈도우가 도도록 TopMost 속성을 True 로 하고, 위치를 Left=0, Top=0 으로 설정한다.
3. ShowIniTaskbar를 False 로 설정하여 태스크바에 목록에 추가되지 않도록 한다.
4. DockPanel 과 Rectangle 을 추가한다.
<Window x:Class="WpfApplication2.Window2" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window2" Height="100" Width="200" WindowStyle="None" Left="0" Top="0" AllowsTransparency="True" Background="Transparent" Topmost="True" ShowInTaskbar="False" Margin="0,0,0,0" > <DockPanel LastChildFill="True" > <Rectangle Stroke="Red" StrokeThickness="3" /> </DockPanel> </Window> |
클래스는 다음과 같이 구현한다.
초기화싱 윈도우의 위치와 크기를 지정하였는데, 이것은 필요할 때 변경하면 된다.
namespace WpfApplication2 { /// <summary> /// Window2.xaml에 대한 상호 작용 논리 /// </summary> public partial class Window2 : Window { public Window2() { InitializeComponent(); // 원하는 위치로 이동시키고, 크기를 조절한다. this.Left = 2000; this.Top = 500; this.Width = 100; this.Height = 100; } } } |
아래는 소스.