예제 #1
0
 public LogScope(ILogModel logModel, WriteLogDelegate writeLogDelegate)
 {
     this.logModel = logModel;
     this.writeLogDelegate = writeLogDelegate;
     this.stopwatch = new Stopwatch();
     stopwatch.Start();
 }
예제 #2
0
        public void WriteLogDelegateCanPointToMethod() //delegate
        {
            WriteLogDelegate log = ReturnMessage;

            //log = new WriteLogDelegate(ReturnMessage);
            log += ReturnMessage; //means line above
            log += IncrementCount;
            var result = log("Hi");

            Assert.Equal(3, count);
            //Assert.Equal("Hi", result);
        }
예제 #3
0
        public void WriteLogDeleageCantPointToMethod()
        {
            WriteLogDelegate log = ReturnMessage;

            //points to return message and can point to more than one method
            log += ReturnMessage;
            log += IncrementCount;
            var result = log("Hello");

            Assert.Equal("Hello", result);
            AssemblyLoadEventArgs.Equals(3, count);
        }
예제 #4
0
        public void WriteLogDelegateCanPointToMethod()
        {
            WriteLogDelegate Log = ReturnMessage;

            Log += ReturnMessage;
            Log += ReturnMessage;

            var result = Log("Hello");

            Assert.Equal(3, count);
            Assert.Equal("Hello", result);
        }
        public void WriteLogDelegateCanPointToMethod()
        {
            WriteLogDelegate log;

            log  = new WriteLogDelegate(ReturnMessage); // or just log = ReturnMessage;
            log += ReturnMessageToLower;                // we can add more functions to log with +=
            log += ReturnMessage;                       // add more!

            var result = log("Hello");

            Assert.Equal("Hello", result);
        }
        public void WriteLogDelegateCanPointToMethod()
        {
            WriteLogDelegate log;

            log = new WriteLogDelegate(ReturnMessage); // ei invoke, vaan et delegate osoittaa returnmessage funktioon
            // log = ReturnMessage ois shorthand.
            // log += ReturnMessage; voi invokata monia metodeja kun tuolleen lisää.

            var result = log("Hello!");

            Assert.Equal("Hello!", result);
        }
예제 #7
0
        public void WriteLogDelegateCanPointToMethod()
        {
            //Delegates are useful because you can take a variable and treat it like a method
            //Delegates can invoke one or more methods, as long as the return type and the parameters match
            WriteLogDelegate log = ReturnMessage;

            log += ReturnMessage;
            log += IncrementCount;
            var result = log("Hello");

            Assert.Equal("Hello", result);
        }
예제 #8
0
        public void WriteLogDelegateCanPointToMethod()
        {
            //Given
            WriteLogDelegate log;

            log = new WriteLogDelegate(ReturnMessage);
            // log = ReturnMessage;
            var result = log("hello");

            //Then
            Assert.Equal("hello", result);
        }
예제 #9
0
        public void WriteLogDelegateCanPointToMethod()
        {
            WriteLogDelegate log = ReturnMessage;

            //log = new WriteLogDelegate(ReturnMessage);
            log += ReturnMessage; // C# can assume this
            log += IncrementCount;

            var result = log("Hello!");

            Assert.Equal(3, count);
        }
예제 #10
0
        public void WriteLogMultiCastDelegate()
        {
            WriteLogDelegate log = ReturnMessage;

            log += this.ReturnMessage;
            log += this.IncrementCount;

            var result = log("Hello!");

            Assert.Equal("hello!", result);
            Assert.Equal(3, this.count);
        }
예제 #11
0
        public void WriteLogDelegateCanPointToMethod()
        {
            WriteLogDelegate log = ReturnMsg;

            // log = new WriteLogDelegate(ReturnMsg);
            // OR
            log += ReturnMsg;
            log += IncrementCount;
            var result = log("Hello!");

            Assert.Equal(3, count);
        }
예제 #12
0
        public void WriteLogDelegateCanPointToMe()
        {
            WriteLogDelegate log = ReturnMessage;

            log += ReturnMessage;
            log += IncrementCount;


            var result = log("Hello");

            Assert.Equal(3, count);
        }
예제 #13
0
        public void WriteLogDelegateCanPointToMethod()
        {
            WriteLogDelegate log = ReturnMessage;

            log += new WriteLogDelegate(ReturnMessage);
            log += IncrementCount;
            // can also be initialized: log = ReturnMesage;

            var result = log("Hello!");

            Assert.Equal(3, count);
        }
예제 #14
0
        [Fact] void WriteLogDelegatePointToMethod()
        {
            WriteLogDelegate log = ReturnMessage;

            log += ReturnMessage;
            log += IncrementCount;

            var result = log("Hello");

            System.Console.WriteLine(result);
            Assert.Equal("Hello Hello hello", result);
        }
예제 #15
0
        public void WriteLogDelegateCanPointToMethod()
        {
            WriteLogDelegate log;

            log = new WriteLogDelegate(ReturnMessage);

            log += ReturnMessage;

            var result = log("hi");

            Assert.Equal("hi", result);
        }
예제 #16
0
        public void WriteLogDelegateCanPointToMethod()
        {
            WriteLogDelegate log = ReturnMessage;

            log += ReturnMessage;
            log += IncrementCount;
            var result = log("Hello!");

            Assert.Equal(count, 3);
            //    Assert.Equal(count, 0);
            // Assert.Equal(result, "Hello!");
        }
예제 #17
0
        public void DelegateCanPointToMetod()
        {
            WriteLogDelegate logDelegate = new WriteLogDelegate(ReturnMessage);

            logDelegate += ReturnMessage;
            logDelegate += IncrementCount;

            var result = logDelegate("Hello!");

            Assert.Equal("hello!", result);
            Assert.Equal(3, count);
        }
예제 #18
0
        public void WriteLogDelegateCanPointToMethod()
        {
            WriteLogDelegate log = ReturnMessage; // initialize delegate

            log += ReturnMessage;
            log += IncrementCount; // point delegate to method.  We could possibly both write to console and file

            var result = log("Hello!");

            Assert.Equal("Hello!", result);
            Assert.Equal(3, count);
        }
예제 #19
0
        public void WriteLogDelegateCanPointToMethod()
        {
            WriteLogDelegate log = ReturnMessage;

            //log=new WriteLogDelegate(ReturnMessage);//Long way to intialize deligate short way is down
            //this needs to be done because we should invoke the method
            log += ReturnMessage;
            log += IncrimentcountMessage;
            var result = log("Hello");

            Assert.Equal(1, count);
        }
예제 #20
0
        public void WriteLogDelegateCanPointToMethod()
        {
            // Section 1: Arrange
            WriteLogDelegate log = ReturnMessage;

            log += ReturnMessage;
            log += IncrementCount;
            // Section 2: Act
            var result = log("Hello!");

            // Section 3: Assert
            Assert.Equal(3, count);
        }
예제 #21
0
        public void WriteLogDelegateCanPointToMethod()
        {
            WriteLogDelegate log = ReturnMessage;

            log += ReturnMessage;
            log += IncreamentCount;
            log += IncreamentCount;


            var result = log("Hello Bryan");

            Assert.Equal(4, count);
        }
예제 #22
0
파일: TypeTests.cs 프로젝트: naheemnoah/C-
        public void writeLogDelegateCanPointToMethod()
        {
            // declare delegate method
            WriteLogDelegate log = ReturnMessage;

            //initialize delegate method
            log += ReturnMessage;
            log += IncrementCount;

            var result = log("Hello!");

            Assert.Equal(3, count);
        }
예제 #23
0
 /// <summary>
 /// 写日志
 /// </summary>
 private void WriteLog(string msg)
 {
     if (this.InvokeRequired)
     {
         WriteLogDelegate d   = new WriteLogDelegate(WriteLog);
         object           arg = msg;
         this.Invoke(d, arg);
     }
     else
     {
         WriteLog1(msg);
     }
 }
예제 #24
0
        public void WriteLogDelegateCanPointToMethod()
        {
            WriteLogDelegate log = ReturnMessage;

            // log = new WriteLogDelegate(ReturnMessage);
            // These two lines are equivalent
            log += ReturnMessage;
            log += IncrementCount;

            var result = log("Hello");

            Assert.Equal(3, count);
        }
예제 #25
0
        public void WriteLogDelegateCanPointToMethod()
        {
            WriteLogDelegate log = ReturnMessage;

            //log = new WriteLogDelegate(ReturnMessage); kan skrivas som nedan:
            log += ReturnMessage; // log = ReturnMessage från början;
            log += IncrementCount;

            var result = log("Hello");

            //Assert.Equal("Hello", result);
            Assert.Equal(3, count);
        }
예제 #26
0
        public NetworkHelper(string ip, int port, string username, string password, WriteLogDelegate callbackMethod)
        {
            this.IP       = ip;
            this.Port     = port;
            this.Username = username;
            this.Password = password;

            this.WriteLog = callbackMethod;

            settings.Username    = username;
            settings.PreferredIP = ip;
            settings.Save();
        }
예제 #27
0
        public void WriteLogDelegate_Call_CanPointToMethod()
        {
            //Given
            WriteLogDelegate log = ReturnMessage;

            log += ReturnMessageToLower;
            //When
            var result = log("Hello!");

            //Then

            Assert.Equal(2, count);
        }
예제 #28
0
        public void WriteLogDelegateCanPointToMethod()
        {
            WriteLogDelegate log = ReturnMessage;

            //log = new WriteLogDelegate(ReturnMessage); - alternative syntax (what happens under the hood)
            log += ReturnMessage;
            log += IncrementCount;

            var result = log("Hello!");

            //Assert.Equal("Hello!", result);
            Assert.Equal(3, count);
        }
예제 #29
0
        public void WriteLogDelegateCanPointToMethod()
        {
            WriteLogDelegate log = ReturnMessage;

            log += ReturnMessage;
            log += IncrementCount;

            // log = new WriteLogDelegate(ReturnMessage);

            var result = log("Hello!");

            AssemblyTraitAttribute.Equals(3, count);
        }
예제 #30
0
        public void WriteLogDelegateCanPointToAMethod()
        {
            WriteLogDelegate log = ReturnMessage;

            log += ReturnMessage;
            // also add and invoke IncrementCount;
            log += IncrementCount;
            var result = log("Hello");

            // check count;
            Assert.Equal(3, count);
            // Assert.Equal("Hello", result); // since adding multiple delegates dont need to assert here
        }
예제 #31
0
        public void WriteLogDelegateReturnMessage()
        {
            //initiate the delegate
            WriteLogDelegate logDelegate = ReturnMessage;

            // assign delegate
            logDelegate += ReturnMessage;
            logDelegate += IncrementCount;

            var result = logDelegate("Elsie");

            Assert.Equal(3, count);
        }
예제 #32
0
파일: ts2qsv.cs 프로젝트: tydk27/ts2qsv
        /// <summary>
        /// エンコードスレッドメイン処理
        /// </summary>
        private void mainTask()
        {
            WriteProcessDelegate process_dlg = new WriteProcessDelegate(WriteProcess);
            WriteLogDelegate log_dlg = new WriteLogDelegate(WriteLog);
            
            try
            {
                this.nowEncodeFileLabel.Text = "";
                this.nowEncodeProcessLabel.Text = "";

                string filePath = "";
                string[] address = this.encodeList.Items.Cast<string>().ToArray();

                DateTime dtNow;
                dtNow = DateTime.Now;

                int encodeFilesCount = address.Length;

                for (int i = 0; i < encodeFilesCount; ++i)
                {
                    this.Invoke(process_dlg, new object[] { i, encodeFilesCount });
                    filePath = address[i];
                    EncodeProcess ep = new EncodeProcess();
                    ep.startEndoceProcess(filePath, dtNow.ToString("yyyyMMdd"));
                }
                this.Invoke(process_dlg, new object[] { encodeFilesCount, encodeFilesCount });
            }
            catch (Exception)
            {
                MessageBox.Show("異常終了しました", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally
            {
                this.Invoke(log_dlg, new object[] { "全ての処理を終了しました" });

                if (ini["use", "shutdown"] == "true")
                {
                    ShutDownProcess sdp = new ShutDownProcess();
                    sdp.StartShutDown();
                }
            }
        }
예제 #33
0
 /// <summary>
 /// ��������
 /// </summary>
 /// <param name="strMsg">��־��Ϣ</param>
 public static void Fatal(string strMsg)
 {
     WriteLogDelegate wld = new WriteLogDelegate(WriteLog);
     IAsyncResult ar = wld.BeginInvoke(LogLevel.Fatal, "", "", strMsg, new AsyncCallback(CallBackMethod), wld);
 }
예제 #34
0
 /// <summary>
 /// һ�����
 /// </summary>
 /// <param name="strClassName">����</param>
 /// <param name="strMethodName">������</param>
 /// <param name="strMsg">��־��Ϣ</param>
 public static void Error(string strClassName, string strMethodName, string strMsg)
 {
     WriteLogDelegate wld = new WriteLogDelegate(WriteLog);
     IAsyncResult ar = wld.BeginInvoke(LogLevel.Error, strClassName, strMethodName, strMsg, new AsyncCallback(CallBackMethod), wld);
 }
예제 #35
0
파일: MainForm.cs 프로젝트: kos811/Spydee2
 public void LOG(string text)
 {
     WriteLogDelegate wtlg = new WriteLogDelegate(WriteTortbLog);
     rtbLog.Invoke(wtlg, text);
 }
예제 #36
0
        private void WriteToLog(string msg)
        {
            if (InvokeRequired)
            {
                var d = new WriteLogDelegate(WriteToLog);
                Invoke(d, msg);
                return;
            }

            if (!_shown)
                return;

            txtLog.AppendText(string.Format("[{0}] {1}\r\n", DateTime.Now.ToString("hh:mm:ss.ffff tt"), msg));
        }