|
출처 : https://dotnetcoretutorials.com/2017/01/17/api-versioning-asp-net-core/
|
Install-Package Microsoft.AspNetCore.Mvc.Versioning |
startup.cs
|
public void ConfigureServices(IServiceCollection services) { // ApiVersioning을 추가 services.AddApiVersioning(options => { // 클라이언트에 Api 버전을 통지 options.ReportApiVersions = true; // 이것이 없으면 클라이언트 측에서 에러가 나온다 options.AssumeDefaultVersionWhenUnspecified = true; // Api의 default 버전을 1.0으로 설정 options.DefaultApiVersion = new ApiVersion(1, 0); }); } |
출처에 보면 여러가지 방식(Url Query Based Versioning, URL Path Based Versioning, Http Header Based Versiong) 등이 있으나…
역시 익숙한 방식은
|
[ApiVersion("1.0")] [Route("api/{version:apiVersion}/home")] public class HomeV1Controller : Controller { [HttpGet] public string Get() => "v1"; } [ApiVersion("2.0")] [Route("api/{version:apiVersion}/home")] public class HomeV2Controller : Controller { [HttpGet] public string Get() => "v2"; } |
혹은
|
[ApiVersion("1.0")] [ApiVersion("2.0")] [Route("v{version:apiVersion}/[controller]")] public class HomeController : Controller { [HttpGet] public string Get() => "v1"; // Api 버전을 덮어 쓰기 [HttpGet, MapToApiVersion("2.0")] public string GetV2() => "v2"; } |
/v1/Home, /v2/Home 의 형식으로 call 가능함
ICollection 사용
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
public ICollection<Student> m_listLandSiteDataText { get; set; } protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn<int>( name: "CourseId", table: "Students", nullable: true); migrationBuilder.CreateIndex( name: "IX_Students_CourseId", table: "Students", column: "CourseId"); migrationBuilder.AddForeignKey( name: "FK_Students_Courses_CourseId", table: "Students", column: "CourseId", principalTable: "Courses", principalColumn: "CourseId", onDelete: ReferentialAction.Restrict); } |
Index와 ForeignKey 없이 생성
|
[ForeignKey("Course")] public int CourseId { get; set; } [ForeignKey("CourseId")] public int CourseId { get; set; } protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn<int>( name: "CourseId", table: "Students", nullable: false, defaultValue: 0); } |
virtual 사용시
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
public int CourseId { get; set; } [ForeignKey("CourseId")] public virtual Course m_mvLandSiteDataImage { get; set; } protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn<int>( name: "CourseId", table: "Students", nullable: false, defaultValue: 0); migrationBuilder.CreateIndex( name: "IX_Students_CourseId", table: "Students", column: "CourseId"); migrationBuilder.AddForeignKey( name: "FK_Students_Courses_CourseId", table: "Students", column: "CourseId", principalTable: "Courses", principalColumn: "CourseId", onDelete: ReferentialAction.Cascade); } |
|
SqlConnection conn = new SqlConnection(conStr); SqlCommand cmd = new SqlCommand("sp_getdata", conn); cmd.Parameters.Add("@userIndex", SqlDbType.Int).Value = MemberNo; cmd.CommandType = CommandType.StoredProcedure; conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { Fee = Convert.ToInt32(reader["Fee"].ToString()); } conn.Close(); |
|
@Html.TextBoxFor( model => model.m_modelAccout.m_strExpenseMoney, new { @class = "typeahead", autocomplete = "off", data_provide = "typeahead", data_items = "4", data_source = Model.a } ) |
|
var listevents = new List<string>(); listevents.Add("1111"); listevents.Add("1222"); listevents.Add("1333"); listevents.Add("1234"); listevents.Add("1555"); var events = listevents.ToArray(); var strJson = JsonConvert.SerializeObject(listevents); |
|
private void txtTimeSlice_KeyPress(object sender, KeyPressEventArgs e) { var keyCode = (int)e.KeyChar; if ((keyCode < 48 || keyCode > 57) && keyCode != 8 && keyCode != 46) { e.Handled = true; } } |
출처 http://mainia.tistory.com/412
이벤트로그 쓰기
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
static void Main(string[] args) { WriteEventLogEntry("This is an entry in the event log by daveoncsharp.com"); } private static void WriteEventLogEntry(string message) { // Create an instance of EventLog System.Diagnostics.EventLog eventLog = new System.Diagnostics.EventLog(); // Check if the event source exists. If not create it. if (!System.Diagnostics.EventLog.SourceExists("TestApplication")) { // "Application" 이름이 로그 트리에 나오므로 잘 정의해야 한다. System.Diagnostics.EventLog.CreateEventSource("TestApplication", "Application"); } // Set the source name for writing log entries. eventLog.Source = "TestApplication"; // Create an event ID to add to the event log int eventID = 8; // Write an entry to the event log. eventLog.WriteEntry(message, System.Diagnostics.EventLogEntryType.Error, eventID); // Close the Event Log eventLog.Close(); } |
이벤트 로그 보기
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
static void Main(string[] args) { String machine = "."; // local machine Console.WriteLine("-------------------------------------------------------------n"); if (args.Length == 1) { if (args[0] == "application" || args[0] == "system" || args[0] == "security") { String log = args[0]; EventLog aLog = new EventLog(log, machine); EventLogEntry entry; EventLogEntryCollection entries = aLog.Entries; Stack < EventLogEntry > stack = new Stack < EventLogEntry > (); for (int i = 0; i < entries.Count; i++) { entry = entries[i]; stack.Push(entry); } entry = stack.Pop(); // only display the last record Console.WriteLine("[Index]t" + entry.Index + "n[EventID]t" + entry.InstanceId + "n[TimeWritten]t" + entry.TimeWritten + "n[MachineName]t" + entry.MachineName + "n[Source]t" + entry.Source + "n[UserName]t" + entry.UserName + "n[Message]t" + entry.Message + "n---------------------------------------------------n"); } else { Console.WriteLine("Usage:glog.exe system(application,security)n"); } } else { Console.WriteLine("Usage:glog.exe system(application,security)n"); } Console.WriteLine("end"); Console.ReadLine(); } |
select case
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
static internal ProtoTestRES doHello(ProtoTestASK r_ask) { try { var res = new ProtoTestRES(); var dataContext = new NamuDataClassesDataContext(); var listMember = from itemMember in dataContext.tb_Member where itemMember.fd_Member_nID == 1 select itemMember; foreach(var itemMember in listMember) { res.m_Member_nID = itemMember.fd_Member_nID; res.m_Member_strEmail = itemMember.fd_Member_strEmail; } return res; } catch (Exception ex) { throw new Exception(ex.Message); } } |
insert case
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
static internal ProtoTestRES doHello_Insert(ProtoTestASK r_ask) { using(var tran = new TransactionScope()) { try { var res = new ProtoTestRES(); var dataContext = new NamuDataClassesDataContext(); var itemMember = new tb_Member { fd_Member_strEmail = r_ask.m_Member_strEmail, fd_Member_strPW = r_ask.m_Member_strPW }; dataContext.tb_Member.InsertOnSubmit(itemMember); dataContext.SubmitChanges(); tran.Complete(); return res; } catch (Exception ex) { Transaction.Current.Rollback(); throw new Exception(ex.Message); } } } |
update case
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
static internal ProtoTestRES doHello_Update(ProtoTestASK r_ask) { using(var tran = new TransactionScope()) { try { var res = new ProtoTestRES(); var dataContext = new NamuDataClassesDataContext(); var itemMember = dataContext.tb_Member.SingleOrDefault(r_p => r_p.fd_Member_nID == 1); if (itemMember != null) itemMember.fd_Member_nID = 3; dataContext.SubmitChanges(); tran.Complete(); return res; } catch (Exception ex) { Transaction.Current.Rollback(); throw new Exception(ex.Message); } } } |
delete single case
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
static internal ProtoTestRES doHello_Delete_Single(ProtoTestASK r_ask) { using(var tran = new TransactionScope()) { try { var res = new ProtoTestRES(); var dataContext = new NamuDataClassesDataContext(); var itemMember = dataContext.tb_Member.SingleOrDefault(r_p => r_p.fd_Member_nID == 1); if (itemMember != null) dataContext.tb_Member.DeleteOnSubmit(itemMember); dataContext.SubmitChanges(); tran.Complete(); return res; } catch (Exception ex) { Transaction.Current.Rollback(); throw new Exception(ex.Message); } } } |
delete multi case
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
static internal ProtoTestRES doHello_Delete_Multi(ProtoTestASK r_ask) { using(var tran = new TransactionScope()) { try { var res = new ProtoTestRES(); var dataContext = new NamuDataClassesDataContext(); var itemMember = dataContext.tb_Member.Where(r_p => r_p.fd_Member_nID > 1); dataContext.tb_Member.DeleteAllOnSubmit(itemMember); dataContext.SubmitChanges(); tran.Complete(); return res; } catch (Exception ex) { Transaction.Current.Rollback(); throw new Exception(ex.Message); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
static internal ProtoBufRES doInsert(ProtoBufASK r_ask) { try { var res = new ProtoBufRES(); Mapper.Instance().BeginTransaction(); res.nRet = Mapper.Instance().QueryForObject < int > ("QueryInsert", r_ask); // Insert시에 SELECT SCOPE_IDENTITY()로 키값을 가져오는 방향으로 Mapper.Instance().CommitTransaction(); if (0 >= nRet) { res.m_eResult = ENUM_RESULT.ENUM_NOINSERT; res.m_strMessage = "처리되지 않았습니다."; return res; } else { res.m_eResult = ENUM_RESULT.ENUM_OK; return res; } } catch (Exception ex) { Mapper.Instance().RollBackTransaction(); throw new Exception(ex.Message); } } |
Test
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
static private readonly ILog s_thelog = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); #if DEBUG static public ServiceReference_Solution.ServiceTaxiClient proxy = new ServiceReference_Solution.ServiceTaxiClient(); #else static public ServiceReference_Staging.ServiceTaxiClient proxy = new ServiceReference_Staging.ServiceTaxiClient(); #endif private ProtoBufRES _function(ProtoBufASK r_ask) { s_thelog.Info("> " + GetType().FullName + "." + MethodBase.GetCurrentMethod().Name); var btask = ProtoBuffHelper.Serialize(r_ask); var btres = proxy.function(btask); var res = ProtoBuffHelper.Deserialize < ProtoBufRES > (btres); s_thelog.Debug(string.Format(" {0, -25} : {1}", "m_eResult", res.m_eResult)); if (ENUM_RESULT.ENUM_EXCEPTION == res.m_eResult) { s_thelog.Error(res.m_strMessage); } return res; } [TestMethod] public void function () { var ask = new ProtoBufASK { m_nMemberID = 1, m_nMemberFriendID = 2 }; var res = _function(ask); Assert.AreNotEqual(ENUM_RESULT.ENUM_EXCEPTION, res.m_eResult); } |
Services
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
static public byte[] function (byte[] r_bAsk) { try { var ask = ProtoBuffHelper.Deserialize < ProtoBufASK > (r_bAsk); var res = daoCommunity.doReceiveDeny(ask); return ProtoBuffHelper.Serialize(res); } catch (Exception ex) { var exres = new ProtoBufRES { m_eResult = ENUM_RESULT.ENUM_EXCEPTION, m_strMessage = string.Format("tException function : {0}nt{1}n", Convert.ToBase64String(r_bAsk), ex.Message) }; CCommon.s_thelog(exres.m_strMessage); return ProtoBuffHelper.Serialize(exres); } } |
DAO – insert
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
static internal ProtoBufRES doInsert(ProtoBufASK r_ask) { try { var res = new ProtoBufRES(); Mapper.Instance().BeginTransaction(); res.nRet = Mapper.Instance().QueryForObject < int > ("QueryInsert", r_ask); // Insert시에 SELECT SCOPE_IDENTITY()로 키값을 가져오는 방향으로 Mapper.Instance().CommitTransaction(); if (0 >= nRet) { res.m_eResult = ENUM_RESULT.ENUM_NOINSERT; res.m_strMessage = "처리되지 않았습니다."; return res; } else { res.m_eResult = ENUM_RESULT.ENUM_OK; return res; } } catch (Exception ex) { Mapper.Instance().RollBackTransaction(); throw new Exception(ex.Message); } } |
DAO – update delete
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
static internal ProtoBufRES doUpdate(ProtoBufASK r_ask) { try { var res = new ProtoBufRES(); Mapper.Instance().BeginTransaction(); res.nRet = Mapper.Instance().Delete("QueryDelete", r_ask); Mapper.Instance().CommitTransaction(); if (0 >= nRet) { res.m_eResult = ENUM_RESULT.ENUM_NOUPDATE; res.m_strMessage = "데이터가 처리되지 않았습니다."; return res; } else { res.m_eResult = ENUM_RESULT.ENUM_OK; return res; } } catch (Exception ex) { Mapper.Instance().RollBackTransaction(); throw new Exception(ex.Message); } } |
DAO – select
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
static internal ProtoBufRES doSelect(ProtoBufASK r_ask) { try { var res = Mapper.Instance().QueryForObject < ProtoBufRES > ("QuerySelect", r_ask); if (0 >= res.nRet) { res.m_eResult = ENUM_RESULT.ENUM_NORESULT; res.m_strMessage = "res에 데이터가 없습니다."; return res; } var listMine = Mapper.Instance().QueryForList < ProtoBuf > ("QuerySelect", r_ask); if (0 >= listMine.Count) { res.m_eResult = ENUM_RESULT.ENUM_NORESULT; res.m_strMessage = "list 내에 데이터가 없습니다."; return res; } else { foreach(var itemMine in listMine) { res.m_listMine.Add(itemMine); } res.m_eResult = ENUM_RESULT.ENUM_OK; return res; } } catch (Exception ex) { throw new Exception(ex.Message); } } |
cshap 빌드시에
|
warning "C:Program Files (x86)MSBuildMicrosoftVisualStudiov10.0WebApplicationsMicrosoft.WebApplication.targets"을(를) 다시 가져올 수 없습니다. "##############.csproj (1262,3)"에서 이미 가져왔습니다. 이는 빌드 작성 오류일 가능성이 높으며 이 후속 가져오기는 무시됩니다. |
이 눈에 거슬릴때는 csproj 파일을 열어
|
$(MSBuildExtensionsPath)MicrosoftVisualStudiov10.0WebApplicationsMicrosoft.WebApplication.targets |
이 있는 부분을 찾아 삭제한다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
//양력은 음력으로변환 테스트 private void button1_Click(object sender, EventArgs e) { label1.Text =음력변환(2007, 1, 1); label2.Text = 음력변환(DateTime.Now); } //음력을 양력으로 변환 테스트 private void button2_Click(object sender, EventArgs e) { label2.Text = 양력변환(2006,11,13,false).ToShortDateString(); } private string 음력변환(DateTime dt) { int n윤월; int n음력년, n음력월, n음력일; bool b윤달 = false; System.Globalization.KoreanLunisolarCalendar 음력 = new System.Globalization.KoreanLunisolarCalendar(); n음력년 = 음력.GetYear(dt); n음력월 = 음력.GetMonth(dt); n음력일 = 음력.GetDayOfMonth(dt); if (음력.GetMonthsInYear(n음력년) > 12) //1년이 12이상이면 윤달이 있음.. { b윤달 = 음력.IsLeapMonth(n음력년, n음력월); //윤월인지 n윤월 = 음력.GetLeapMonth(n음력년); //년도의 윤달이 몇월인지? if (n음력월 >= n윤월) //달이 윤월보다 같거나 크면 -1을 함 즉 윤8은->9 이기때문 n음력월--; } return n음력년.ToString() + "-" + (b윤달 ? "*" : "") + n음력월.ToString() + "-" + n음력일.ToString(); } private string 음력변환(int n양력년, int n양력월, int n양력일) { DateTime dTemp = new DateTime(n양력년, n양력월, n양력일); //양력 return 음력변환(dTemp); } private DateTime 양력변환(int n음력년, int n음력월, int n음력일, bool b달) { int n윤월; System.Globalization.KoreanLunisolarCalendar 음력 = new System.Globalization.KoreanLunisolarCalendar(); if (음력.GetMonthsInYear(n음력년) > 12) { n윤월 = 음력.GetLeapMonth(n음력년); if (b달) n음력월++; if (n음력월 > n윤월) n음력월++; } return 음력.ToDateTime(n음력년, n음력월, n음력일, 0, 0, 0, 0); } |
|
|