>> 원문 : http://msdn.microsoft.com/msdnmag/issues/02/07/NetSmartClients/default.asp
1. Application Download
- virtual directory
2. Versioning
// Strong naming is required when versioning
[assembly: AssemblyKeyFileAttribute("wahoo.key")]
[assembly: AssemblyVersionAttribute("1.2.3.4")]
3. Related Files
- GAC
- download cache
string appbase = AppDomain.CurrentDomain.BaseDirectory;
private void InitializeComponent() {
System.Resources.ResourceManager resources =
new System.Resources.ResourceManager(typeof(MainForm));
...
this.game.BackgroundImage = ((System.Drawing.Bitmap)
(resources.GetObject("game.BackgroundImage")));
...
}
public MainForm() {
// Let the Designer-generated code run
InitializeComponent();
// Init culture-neutral properties
this.game.BackgroundImage = new Bitmap(typeof(MainForm),
"sblogo.gif"); // WARNING: Case sensitive
}
[assembly: NeutralResourcesLanguageAttribute("en-US")]
.config 파일이 캐시된 후에는 신버전이 있더라도 다시 다운로드하지 않는다!
4. Security Zones
using System.Security;
using System.Security.Policy;
SecurityZone zone = Zone.CreateFromUrl(appbase).SecurityZone;
5. Isolated Storage
- 생성/조회
private IsolatedStorageFileStream CreateSettingsStream() {
IsolatedStorageFile store =
IsolatedStorageFile.GetUserStoreForDomain();
return new IsolatedStorageFileStream("settings.txt",
FileMode.Create, store);
}
private IsolatedStorageFileStream OpenSettingsStream() {
IsolatedStorageFile store =
IsolatedStorageFile.GetUserStoreForDomain();
return new IsolatedStorageFileStream("settings.txt",
FileMode.Open, store);
}
- 저장
private void LoadSettings() {
try {
using( Stream stream = OpenSettingsStream() )
using( StreamReader reader = new StreamReader(stream) ) {
Location = (Point)ReadSetting(reader, typeof(Point));
ClientSize = (Size)ReadSetting(reader, typeof(Size));
}
}
catch {
// If there's nothing to read,
// put the form in the center of the screen
StartPosition = FormStartPosition.CenterScreen;
}
}
private void SaveSettings() {
// Restore so we don't store a zero size or location
WindowState = FormWindowState.Normal;
// Save the window location
using( Stream stream = CreateSettingsStream() )
using( StreamWriter writer = new StreamWriter(stream) ) {
WriteSetting(writer, Location);
WriteSetting(writer, ClientSize);
}
}
- Type Conversions functions
private object ReadSetting(StreamReader reader, Type type) {
TypeConverter converter = TypeDescriptor.GetConverter(type);
return converter.ConvertFromString(reader.ReadLine());
}
private void WriteSetting(StreamWriter writer, object obj) {
Type type = obj.GetType();
TypeConverter converter = TypeDescriptor.GetConverter(type);
writer.WriteLine(converter.ConvertToString(obj));
}
6. Web Service와 통신
WahooScoresService GetService() {
WahooScoresService service = new WahooScoresService();
try {
string appbase = AppDomain.CurrentDomain.BaseDirectory;
// Set URL to server where this came from
string site =
System.Security.Policy.Site.CreateFromUrl(appbase).Name;
service.Url = service.Url.Replace("//localhost/",
"//" + site + "/");
}
catch( ArgumentException ) { }
return service;
}
void GetHighScores() {
// Get scores
WahooScoresService service = GetService();
WahooScore[] scores = service.GetScores();
// Show high scores...
}
7. Reading and Writing Files
SaveFileDialog dlg = new SaveFileDialog();
dlg.DefaultExt = ".txt";
dlg.Filter = "Text Files (*.txt)|*.txt|All files (*.*)|*.*";
// NOTE: Not allowed unless we have FileIOPermission
//dlg.AddExtension = true;
//dlg.FileName = "somefile.txt";
if( dlg.ShowDialog() == DialogResult.OK ) {
// NOTE: Not allowed to call dlg.FileName
using( Stream stream = dlg.OpenFile() )
using( StreamWriter writer = new StreamWriter(stream) ) {
writer.Write("...");
}
}
- Check Permission
// Check permission helper
bool HavePermission(IPermission perm) {
try { perm.Demand(); }
catch( SecurityException ) { return false; }
return true;
}
void SaveHighScore(string name, int score) {
IPermission perm =
new FileDialogPermission(FileDialogPermissionAccess.Save);
if( !HavePermission(perm) ) {
MessageBox.Show("Doh!");
return;
}
...
}
8. 접근권한
- 제한된 어셈블리로부터 호출될 수 있는 권한
[assembly: AllowPartiallyTrustedCallersAttribute]
9. IEExec
Usage: ieexec.exe url flags [securityZone] [domainId]
url Assembly to launch, e.g. http://localhost/foo.exe
flags Flags to control execution. Values that can be
added together are:
0: no flags
1: create evidence for the zone
2: create evidence for the site
securityZone If evidenceFlags != 0, sets the security zone.
Values can be {0, 1, 2, 3} for
{MyComputer, Intranet, Trusted, Internet}
domainId If evidenceFlags != 0, unused hex-encoded bytes.
Use 00.
- 디버그 모드
Start Application : IEExec.exe의 전체경로
Command Line Arguments : url 및 옵션
- 커맨드 라인
C:\> ieexec.exe file://c:\wahoo\deploy\wahoo.exe 3 3 00
'Tech: > .NET·C#' 카테고리의 다른 글
.NET Framework을 복구할 때 (0) | 2008.06.26 |
---|---|
C# - P/Invoke 호출 예제 (0) | 2008.06.26 |
웹 서비스 사용시 공식 네임스페이스 (0) | 2008.06.26 |
유용한 Regular Expression (0) | 2008.06.26 |
.NET Enterprise Service에 사용되는 도구들 (0) | 2008.06.26 |