2013. 3. 18. 10:01

아래와 같이 하면 Enum으로 데이터를 선언하고 실제 소스에서는 enum 형식으로 비교하고 UI에서는 Description 내용으로 보여줄 수 있다.


    public enum eGameInfo

    {

        [Description("사과")]

        Apple = 1,

        [Description("오렌지")]

        Orange = 2,

        [Description("망고")]

        Mango = 3,

    }


    public class HtmlHelper

    {

        public static string GetComboBoxHtml<TEnum>(string id, string style, TEnum eValue, bool isAll, string allText, string allValue, string[] exceptValues)

        {

            string html = "";


            string[] names = Enum.GetNames(typeof(TEnum));

            Array values = Enum.GetValues(typeof(TEnum));


            html += string.Format("<select id=\"{0}\">", id);

            for (int i = 0; i <= names.Length - 1; i++)

            {

                string value = Convert.ToInt32(values.GetValue(i)).ToString();

                string text = names[i];

                string name = HtmlHelper.GetDescriptName<TEnum>(text);

                if (!string.IsNullOrEmpty(name)) text = name;


                if (exceptValues.Where(code => code.Equals(value)).Count() == 0)

                {                    

                    html += string.Format("    <option value=\"{0}\" {2}>{1}</option>", value, text, eValue.ToString().Equals(values.GetValue(i).ToString()) ? "selected=\"selected\"" : "");

                }

            }

            html += string.Format("</select>");


            return html;

        }


        public static string GetDescriptName<T>(string memberName)

        {

            string name = string.Empty;

            var type = typeof(T);


            foreach (System.Reflection.MemberInfo member in type.GetMember(memberName))

            {

                object[] attributes = member.GetCustomAttributes(false);


                if (attributes.Length != 0)

                {

                    foreach (object attr in attributes)

                    {

                        DescriptionAttribute descAttr = attr as DescriptionAttribute;


                        if (descAttr != null)

                        {

                            name = descAttr.Description;

                            break;

                        }

                    }

                }

            }

            return name;

        }

    }

Posted by CoolDragon
2013. 1. 29. 23:00

1. 윈도우즈 버전 다운로드


2. 서비스로 구동하기 위하여 NSSM(the Non-Sucking Service Manager) 사이트에서 프로그램을 다운로드 받음

    2.1 다운로드 받은 파일을 압축을 풀고 아래와 같이 실행을 한다.

   ※ 주의 : 서비스를 생성할 때 되도록이면 c:\Program Files 경로에서 생성하지 말길 바란다.  서비스는 생성되지만 공백이 있어 

               그런지 정상적으로 실행되지 않는다. 따라서 경로를 바꿔서 하는게 정신 건강에 좋을 것 같다.

3. 실행코드

var http = require('http');

http.createServer(function (req, res) {

  res.writeHead(200, {'Content-Type': 'text/plain'});

  res.end('Hello World\n');

}).listen(1337, '127.0.0.1');

console.log('Server running at http://127.0.0.1:1337/');

4. 실행결과




Posted by CoolDragon
2012. 12. 11. 19:23


JSON 메시지 생성 (출처 : http://code.google.com/p/aspjson/)

JSON_2.0.4.asp

JSON_UTIL_0.1.1.asp

<!-- #include virtual="JSON_2.0.4.asp" -->

<!-- #include virtual="JSON_UTIL_0.1.1.asp" -->

<%

Dim json

Dim person, people(4)


For i = 0 To 4

Set person = jsObject()

person("name") = "park"

person("age") = 20

person("sex") = "male"

Set people(i) = person

Next


Set json = jsObject()

json("count") = Ubound(people)

json("people") = people


Response.Write toJSON(json)

' 결과

{"count":4,"people":[{"name":"park","age":20,"sex":"male"},{"name":"park","age":20,"sex":"male"},{"name":"park","age":20,"sex":"male"},{"name":"park","age":20,"sex":"male"},{"name":"park","age":20,"sex":"male"}]}

%>


JSON 메시지 파싱 (https://github.com/nagaozen/asp-xtreme-evolution/blob/master/lib/axe/classes/Parsers/json2.asp)

json2.asp

<!-- #include virtual="json2.asp" -->


dim Info : set Info = JSON.parse(join(array( _
    "{", _
    " ""firstname"": ""Fabio"",", _
    " ""lastname"": ""長尾"",", _
    " ""alive"": true,", _
    " ""age"": 27,", _
    " ""nickname"": ""nagaozen"",", _
    " ""fruits"": [", _
    " ""banana"",", _
    " ""orange"",", _
    " ""apple"",", _
    " ""papaya"",", _
    " ""pineapple""", _
    " ],", _
    " ""complex"": {", _
    " ""real"": 1,", _
    " ""imaginary"": 2", _
    " }", _
    "}" _
)))

Response.write(Info.firstname & vbNewline) ' prints Fabio
Response.write(Info.alive & vbNewline) ' prints True
Response.write(Info.age & vbNewline) ' prints 27
Response.write(Info.fruits.get(0) & vbNewline) ' prints banana
Response.write(Info.fruits.get(1) & vbNewline) ' prints orange
Response.write(Info.complex.real & vbNewline) ' prints 1
Response.write(Info.complex.imaginary & vbNewline) ' prints 2

Posted by CoolDragon
2012. 12. 11. 17:40



ASP 방식

Function BytesToStr(bytes)
    Dim Stream
    Set Stream = Server.CreateObject("Adodb.Stream")
        Stream.Type = 1 'adTypeBinary
        Stream.Open
        Stream.Write bytes
        Stream.Position = 0
        Stream.Type = 2 'adTypeText
        Stream.Charset = "iso-8859-1"
        BytesToStr = Stream.ReadText
        Stream.Close
    Set Stream = Nothing
End Function
If Request.TotalBytes > 0 Then
    Dim lngBytesCount
        lngBytesCount = Request.TotalBytes
    Response.Write BytesToStr(Request.BinaryRead(lngBytesCount))
End If


ASP.NET 방식

string jsonMessage = string.Empty;
System.IO.Stream inputStream = HttpContext.Current.Request.InputStream;
byte[] inputBuffer = new byte[inputStream.Length];
inputStream.Read(inputBuffer, 0, inputBuffer.Length);

try
{
	jsonMessage = System.Text.Encoding.UTF8.GetString(inputBuffer);
}
catch (Exception ex)
{
	throw ex;
}

return jsonMessage;

Posted by CoolDragon
2012. 10. 22. 17:39

첨부파일 참조..



MyBitis.zip


Posted by CoolDragon
2012. 10. 22. 17:31

<?xml version="1.0" encoding="utf-8" ?>

<sqlMap namespace="UserInfo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://ibatis.apache.org/mapping">

  <alias>

    <typeAlias alias="MyUser"  type="MainApp.MyUser" />

  </alias>


  <statements>

    <!-- 동적 테이블 생성 -->

    <statement id='Create_Login_Log'>

      IF NOT EXISTS (SELECT 'X' FROM sysobjects where xtype = 'U' and name = 'Login_Log$yyyymm$')

      BEGIN

      create table Login_Log$yyyymm$

      (

      id int identity(1,1),

      name nvarchar(100)

      );

      END;


      IF NOT EXISTS (SELECT 'X' FROM sysobjects where xtype = 'U' and name = 'Login_Log2_$yyyymm$')

      BEGIN

      create table Login_Log2_$yyyymm$

      (

      id int,

      name nvarchar(100)

      );

      END;

    </statement>


    <!-- 동적 생성 테이블 데이터 Insert  -->

    <insert id="Insert_Login_Log" resultClass="int" >

      INSERT INTO Login_Log$yyyymm$ (name)

      VALUES (#name#);

      <selectKey resultClass="int" property="id" type="post" >

        SELECT @@IDENTITY AS VALUE;

      </selectKey>

    </insert>


    <!-- 동적 생성 테이블 데이터 Insert  -->

    <insert id="Insert_Login_Log2" resultClass="int" >

      INSERT INTO Login_Log2_$yyyymm$ (id, name)

      VALUES (#id#, #name#);

    </insert>


    <!-- 동적 테이블 데이터 조회 -->

    <select id="Select_Login_Log">

      SELECT *

      FROM Login_Log$yyyymm$ a inner join Login_Log2_$yyyymm$ b on a.id = b.id

      WHERE b.id = #id#;

    </select>

  </statements>

</sqlMap>

Posted by CoolDragon
2012. 10. 22. 17:25

1) iBatis.Net 프레임워크 다운로드

    http://blog.mybatis.org/


2) .NET 프로젝트 생성


3) iBatis.Net DLL 참조


4) config 파일 설정

 - provider 파일

 - sqlmap 파일

 - query 파일

Posted by CoolDragon
2012. 10. 4. 15:24

[닷넷용 Driver 다운로드]

 - http://github.com/mongodb/mongo-csharp-driver/downloads


[어셈블리 참조]

 - MongoDB.Bson.dll

 - MongoDB.Driver.dll


[샘플 코드]

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;


using MongoDB.Bson;

using MongoDB.Driver;

using MongoDB.Driver.Builders;



namespace ConsoleApplication1

{

    public class Entity

    {

        public ObjectId Id { get; set; }

        public string Name { get; set; }

    }


    class Program

    {

        static void Main(string[] args)

        {

            var connectionString = "mongodb://localhost/?safe=true";

            var server = MongoServer.Create(connectionString);

            var database = server.GetDatabase("test");

            var collection = database.GetCollection<Entity>("entities");


            var entity = new Entity { Name = "Tom" };

            collection.Insert(entity);

            var id = entity.Id;


            var query = Query.EQ("_id", id);

            entity = collection.FindOne(query);


            entity.Name = "Dick";

            collection.Save(entity);


            var update = Update.Set("Name", "Harry");

            collection.Update(query, update);


            collection.Remove(query);

        }

    }

}


출처:http://www.mongodb.org/display/DOCS/CSharp+Driver+Quickstart

Posted by CoolDragon
2012. 10. 4. 11:50

// 사용중인 DB 리스트 조회

show dbs;


// 선택 데이터베이스 사용

use [databasename];


// 사용중인 컬렉션 리스트 조회

show collections;


Index관련

// 인덱스 설정 (j열 인덱스 설정)

db.[collectionname].ensureIndex({j:1});
// 컬렉션에 설정된 인덱스 정보 조회

db.[collectionname].getIndexes();


// 선택 컬렉션 전체 조회

db.[collectionname].find();

// 선택 컬렉션에 조건식을 지정하여 조회

db.[collectionname].find({a:1});

// 선택 컬렉션의 결과를 배열형태로 조회

db.[collectionname].find().toArray();

// 선택 컬렉션의 결과 개수

db.[collectionname].find().count();


// 선택 컬렉션의 전체 삭제

db.[collectionname].remove();

// 선택 컬렉션에 조건식을 지정하여 삭제

db.[collectionname].remove({a:1});


// 선택 컬렉션 제거

db.[collectionname].drop();


// 선택 데이터 베이스 제거

db.dropDatabase();

Posted by CoolDragon
2012. 10. 2. 15:42

memCached 관련


[서비스]

 - 32bit : http://blog.couchbase.com/memcached-144-windows-32-bit-binary-now-available

 - 64bit : http://mnshankar.wordpress.com/2011/03/25/memcached-on-64-bit-windows/

 - 서비스 등록 및 실행


[.NET용 어셈블리 참조]

 - MemcachedProviders.dll

 - Enyim.Caching.dll

 - log4net.dll


[Config 작성은 첨부된 pdf파일 참조]

Using Memcached Cached Provider 1.2.pdf


[샘플]

TestmemCached.zip



Posted by CoolDragon