技術者派遣の技術日誌ブログ

July 17, 2009

[ .NET - ASP.NET]マスターページ内の link タグや script タグに記述するパス

Filed under: .NET Framework, Asp.Net — Tags: , , — Sayuri @ 10:39 am

マスターページ内の link タグの href 属性では、チルダ (~) を使った仮想パス形式、もしくはマスターページの配置場所からの相対パス形式で記述しておくと、実行時に適切な相対パスに変換してくれます。(追記:head タグに runat=”server” を記述していない場合は変換されませんので注意してください。)
しかし、script タグの src 属性に関しては、チルダを使った仮想パスや相対パスで記述しても変換が一切行われません。
なので、Control.ResolveClientUrl メソッドVirtualPathUtility.ToAbsolute メソッドを使用して変換する必要があります。幸い、HTML タグの属性値ならば <%= %> が使用できるので (コードのハイライトやインテリセンスは効きませんが) 簡単に対処できます。
Site.Master
<head runat=server>
    <title><asp:Localize runat=server Text=<%$ Resources:CommonResource, SystemName %>“ /></title>
    <link href=Common.css type=text/css rel=stylesheet />
    <link href=Site.css   type=text/css rel=stylesheet />
    <script src=<%= this.ResolveClientUrl(~/Common.js) %>“ type=”text/javascript”></script>
    <script src=<%= this.ResolveClientUrl(~/Site.js) %>“   type=”text/javascript”></script>
    <asp:ContentPlaceHolder ID=HeadPlaceHolder runat=server />
</head>

なお、スタイルシートに関しては Thema 機能を使用すれば link タグを記述する必要はなくなりますが、全てのスタイルシートが読み込まれてしまうため、(スタイルシートの) クラス名の衝突の回避に一工夫必要だったりと管理が複雑化します。テーマの切り替えが不要ならば使用しない方が良いかと思います。

July 7, 2009

Asp.net and c#: Introducing WF4.0: Building Distributed Apps with …

,ASP.NET,JAVASCRIPT,JQUERY

Net Remoting, ADO.net, Authentication, ASP.net Overview, Debugger, Email integration, FTP, Payment Gateway, Performance and Scalability, Security, VS.net 2008, Web controls, Web Parts, WCF , WPF and SQL serve …

Net Remoting, ADO.net, Authentication, ASP.net Overview, Debugger, Email integration, FTP, Payment Gateway, Performance and Scalability, Security, VS.net 2008, Web controls, Web Parts, WCF, WPF and SQL serve …

View post:
Asp.net and c#: Introducing WF4.0: Building Distributed Apps with …

Media Foundation ⑥ WebCam + WPF XAMLとC#の実装

Filed under: ALL — Tags: , , , , — strmozo @ 3:20 pm

それでは XAMLとC#を実装しましょう。次のようにビデオ画像と、スライダーで回転・スケールを行うので、XAMLではD3DImageと2つのスライダー(とラベル)を宣言します。一つのスライダーはD3DImageの回転角度に、もう一つはD3DImageのXScaleとYScaleにバインディングします。

D3DImageはSystem.Windows.Interop名前空間にあるので、名前空間の追加に注意してください。

C#の実装

 

D3DImage チュートリアルとの違いは、初期化時にビデオのサイズを取得していることと、Rendering イベントハンドラーとコールバックを宣言する代わりに、Windows メッセージを処理するためのコールバック(ここではBltVideo)を HWndSourceクラスのAddHookメソッドを使って宣言することです。そのあとで一回目の非同期サンプリング命令(Sample)を呼び出します。

 

 

 

 

private readonly D3DWrapper myD3DScene = new D3DWrapper();
private HwndSource source;
private const int WM_PAINT = 0×000F;
private int videoWidth = 0;
private int videoHeight = 0;

 

 

 

private void StartDXRendering()
{
 if (!myD3DImage.IsFrontBufferAvailable)
  return;
IntPtr scene = myD3DScene.Initialize(
  new WindowInteropHelper(this).Handle,
  ref videoWidth,
  ref videoHeight);
myD3DImage.Lock();
myD3DImage.SetBackBuffer(
D3DResourceType.IDirect3DSurface9, scene);
  myD3DImage.Unlock();
source = HwndSource.FromHwnd(
  new WindowInteropHelper(this).Handle);
source.AddHook(new HwndSourceHook(BltVideo));
myD3DScene.Sample();

}

 

 

 

BltVideo では WM_PAINT メッセージかどうかを確認して、D3DImageの内容を更新します。そのあとで、メッセージの処理完了を示す handled を true にし、次の非同期サンプリング命令を呼び出します。

private IntPtr BltVideo( IntPtr hwnd, int msg, IntPtr wParam, 
                         IntPtr lParam, ref bool handled)
{
  if (msg == WM_PAINT)
  {
    myD3DImage.Lock();
    myD3DImage.AddDirtyRect(
    new Int32Rect(0, 0, videoWidth, videoHeight));
    myD3DImage.Unlock();
    handled = true;
    myD3DScene.Sample();
  }
  return IntPtr.Zero;
}

ソリューションを添付するので、WebCam のついた PC でビルド・実行してみてください。動作環境は以下の通りです。

  • Windows 7 (RC)
  • Windows 7 SDK (RC)
  • Visual Studio 2008 SP1
  • DirectX SDK (Mar 2009)

July 5, 2009

VLINQを使ってフォルダやファイルの情報を集積する

Filed under: LINQ — Tags: , , — Sayuri @ 12:37 am

久しぶりにLINQ(LINQ to Object)ネタです。
ここ2、3日で知り合いの方のBlogに続けてこのような話があがってたもので、ちょっと試したことまとめておこうかと(w

LINQ to Objectで一番重要なのは、操作しようとするデータをいかにしてIEnumerableな形にするか、ということだと思っています。
特にフォルダやファイルといった階層構造のデータを扱う場合、そこさえできてしまえば後はどうにでもなります。
そんな意味で、すごい、と思ったのが@ITの記事に載っていた以下のコードです。

IEnumerable<FileInfo> fileList = Directory.GetFiles(startFolder, “*.*”, SearchOption.AllDirectories).Select(x => new FileInfo(x));

このコード自体Selectメソッドを使ったLINQのコードなのですが、この1行でstartFolderに指定したフォルダ以下の全てのファイルをサブフォルダ配下のものを含めてFileInfoオブジェクトとしてIEnumerableなものにしてしまっています。
FileInfoオブジェクトであればそのファイルのすべての情報にアクセスできますから、あとはここでつくったfileListに対してどのような操作を行うかを考えるだけでよい、ということになります。

ではまず最初に、このコードをベースに、指定したフォルダが使用している容量を計算してみましょう。

—————————————————————————————————————–
using System;
using System.Linq;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        string startFolder = @”c:\temp\”;

        Console.WriteLine(“トータルバイト数:{0}”,
                          Directory.GetFiles(startFolder, “*.*”, SearchOption.AllDirectories)
                              .Select(x => new FileInfo(x)).Sum(f => f.Length));

        Console.Read();
    }
}
—————————————————————————————————————–

先ほどのコードで取り出したすべてのファイルのバイト数(f.Length)をSumメソッドで合計することで容量を計算してます。
実質的に1行で済んでますね。

フォルダ、サブフォルダ毎に情報をまとめたい、といったときにはgroup byを使うと便利です。
フォルダ毎にそこに含まれているファイルを取り出し、作成日順に並べてみましょう。

—————————————————————————————————————–
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        string startFolder = @”c:\temp\”;

        IEnumerable<FileInfo> fileList = Directory.GetFiles(startFolder, “*.*”,
  SearchOption.AllDirectories).Select(x => new FileInfo(x));

        var query = from f in fileList
                    orderby f.CreationTime
                    group f by f.DirectoryName;

        foreach (var item in query)
        {
            Console.WriteLine(“フォルダ名:{0}”, item.Key);
            foreach (var f in item)
            {
                Console.WriteLine(“{0}:{1}”, f.CreationTime, f.Name);
            }
        }
        Console.Read();
    }
}
—————————————————————————————————————–

こんな感じでDirectoryNameを利用してグループ化することでフォルダ毎に情報をまとめることができます。

基本的に、最初の一行のコードの意味がわかっていれば、あとはいろんな応用がききます。
このようなコードを提示してくれた川俣さんにほんと感謝です。

July 4, 2009

Custom SEO friendly paging with ASP.NET Repeater or DataList control

,ASP.NET,JAVASCRIPT,JQUERY

litPaging.Text = GetPagingDone(_thisPage, _totalNumberOfRows, _pageSize,. “/ csharp /paging.aspx”, “”);. } private string GetPagingDone(int thisPageNo, int totalCount, int pageSize, string pageName, string extraQstringToAdd)

litPaging.Text = GetPagingDone(_thisPage, _totalNumberOfRows, _pageSize,. “/csharp/paging.aspx”, “”);. } private string GetPagingDone(int thisPageNo, int totalCount, int pageSize, string pageName, string extraQstringToAdd). {. int pageno = 0; …. First search for “WCF Interview Questions” and Second “C# interview questions”. Both search results gives the result of http://www.dotnetfunda.com/interview/ShowCatQuestion.aspx page but different querystrings value. …

View original post here:
Custom SEO friendly paging with ASP.NET Repeater or DataList control

Powered by WordPress