datamapping.cs

来自「经典游戏程序设计:visual c++ 上的杀人游戏源代码」· CS 代码 · 共 65 行

CS
65
字号
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace DAL
{
    partial class DataMappingDataContext
    {
        private static StreamWriter sw = new StreamWriter(Path.Combine(Directory.GetCurrentDirectory(), "log.txt"), true);

        /**/
        /// <summary>
        /// Try to create DataContext with log. 
        /// </summary>
        /// <param name="withLog"></param>

        public DataMappingDataContext(bool withLog)
            : this(Provider.ConnectionString)
        {
            OnCreated();
            if (withLog)
            {
                if (sw == null)
                {
                    sw = new StreamWriter(Path.Combine(Directory.GetCurrentDirectory(), "log.txt"), true);
                }
                this.Log = sw;
            }
        }

        /**/
        /// <summary>
        /// try to close streamwriter
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
            sw.Flush();

        }

    }

    internal static class Provider
    {
        internal static string ConnectionString
        {
            get
            {
                //string path = Directory.GetCurrentDirectory();
                //path = Path.Combine(path, "killperson.sdf");
                //return "Data Source = " + path;
                return DAL.Properties.Settings.Default.KillingGameConnectionString;
            }
        }
    }
    public partial class PlayerEntity : Player
    {
        public string IP { get; set; }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?