Beispiel #1
0
        public void UpdateLog(List<LogItem> logs)
        {
            if (this.logs.InvokeRequired) {
                var del = new updateLog(UpdateLog);
                this.logs.Invoke(del, new object[] { logs });
            } else {
                var newlogs = new List<LogItem>();
                foreach (var log in logs) newlogs.Add(log);

                //this.logs.DataSource = typeof(List<LogItem>);
                this.logs.DataSource = newlogs;
                if(this.logs.Rows.Count > 0)this.logs.CurrentCell = this.logs[0, this.logs.Rows.Count - 1];
            }
        }
Beispiel #2
0
        void worker_DoWork(Object sender, DoWorkEventArgs e)
        {
            int currentFileCount = 0;
            int currentCodeCount;
            updateLog updateLogDelegate = new updateLog(updateLogMethod);
            System.Windows.Threading.DispatcherOperation updateLogBox = txtLog.Dispatcher.BeginInvoke(updateLogDelegate, System.Windows.Threading.DispatcherPriority.Normal,"Reading files");
            foreach (Files file in sourceFiles)
            {
                currentCodeCount = 0;
                if (worker.CancellationPending == true)
                {
                    e.Cancel = true;
                    break;
                }

                if (isWhitelisted(file.extension.ToUpper()))
                {
                    if (!turbo)
                        Thread.Sleep(50);

                    currentFileCount++;
                    System.Windows.Threading.DispatcherOperation updateProgressText = tbxLoc.Dispatcher.BeginInvoke(new progressTextUpdater(progressTextUpdateMethod), System.Windows.Threading.DispatcherPriority.Normal, file.fullname);
                    System.Windows.Threading.DispatcherOperation updateProgressBar = progress.Dispatcher.BeginInvoke(new progressBarUpdater(progressBarUpdateMethod), System.Windows.Threading.DispatcherPriority.Normal, currentFileCount);

                    try
                    {
                        using (TextReader reader = new StreamReader(file.fullname))
                        {
                            while (reader.ReadLine() != null)
                            {
                                currentCodeCount++;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        updateLogBox = txtLog.Dispatcher.BeginInvoke(updateLogDelegate, System.Windows.Threading.DispatcherPriority.Normal, "Exception: " + ex.Message);
                    }

                    loc += currentCodeCount;

                    if (CodeBreakup.ContainsKey(file.extension.ToLower()))
                    {
                        CodeBreakup[file.extension.ToLower()] += currentCodeCount;
                    }
                    else
                    {
                        CodeBreakup.Add(file.extension.ToLower(), currentCodeCount);
                    }

                    System.Windows.Threading.DispatcherOperation updateLocCounter = progress.Dispatcher.BeginInvoke(new updateLOCCounter(LocCounterUpdateMethod), System.Windows.Threading.DispatcherPriority.Normal);
                }
                else
                {
                    currentFileCount++;
                    updateLogBox = txtLog.Dispatcher.BeginInvoke(updateLogDelegate, System.Windows.Threading.DispatcherPriority.Normal, "Skipping file: " + file.fullname);
                }
            }
        }
Beispiel #3
0
        // Send out converted data to remote server
        private void TransmitData(string data)
        {
            try
            {
                _outputLog.OutputDateTime = System.DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff");

                _tcpOutputStream = _tcpClient.GetStream();

                UnicodeEncoding encoder = new UnicodeEncoding();
                byte[] tmp = encoder.GetBytes(String.Format("{0}", data));
                byte[] buffer = new byte[tmp.Length / 2];
                for (int i = 0, j = 0; i < tmp.Length; i += 2, j++)
                {
                    buffer[j] = tmp[i];
                }

                _tcpOutputStream.Write(buffer, 0, buffer.Length);
                _tcpOutputStream.Flush();
                _outputLog.Status = "Y";
                stulblSoftware.Text = "Software Listening-Sending";
                stulblSoftware.Image = _imgRun;
                _tmpUILog = String.Format("Transmit: {0}", data);
                _isSoftwareError = false;
                updateLog method = new updateLog(this.UpdateLog);
                this.txtLog.Invoke(method);
            }
            catch (Exception ex)
            {
                if (_isSoftwareError != true)
                {
                    bgWorker.RunWorkerAsync();
                }
            }
        }
Beispiel #4
0
        public void AcceptCallback(IAsyncResult ar)
        {
            bool flag;
            Socket asyncSocket = ((Socket)ar.AsyncState).EndAccept(ar);
            if ((asyncSocket == null) || !asyncSocket.Connected)
            {
                return;
            }
            asyncSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 1000);
            asyncSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 1000);
            asyncSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, 512);
            string str = "";
            string responseData = "";
            string str3 = "";
            while (true)
            {
                if (asyncSocket.Connected)
                {
                    if (_clientConnected)
                    {
                        stulblSoftware.Text = "Software Listening-Sending";
                    }
                    else
                    {
                        stulblSoftware.Text = "Software Listening";
                    }
                    stulblSoftware.Image = _imgRun;
                }

                _outputLog = new LogFormat();
                flag = false;
                int count = 0;
                str3 = "";
                byte[] bytes = new byte[512];
                try
                {
                    count = asyncSocket.Receive(bytes);
                }
                catch (SocketException ex)
                {
                    if ((ex.ErrorCode == 10060) || (ex.ErrorCode == 10035))
                    {
                        _isSoftwareError = false;
                        continue;
                    }
                    //else // 判斷 Client 是否斷線
                    //{
                    //    if (_isSoftwareError != true)
                    //    {
                    //        if (_fileName == "")
                    //        {
                    //            _fileName = String.Format("{0}_{1}", _jobId, System.DateTime.Now.ToString("yyyyMMddHHmmss"));
                    //        }
                    //        stulblSoftware.Text = "Software Error";
                    //        stulblSoftware.Image = _imgStop;
                    //        _outputLog.InputDateTime = System.DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff");
                    //        _outputLog.InputData = String.Format("Software Error,{0},,,", ex.Message);
                    //        _outputLog.OutputData = ",,";
                    //        WriteHelper.Log(_outputLog, _fileName);
                    //        _isSoftwareError = true;
                    //    }
                    //}
                    this.Listen();
                    return;
                }
                if (count <= 0)
                {
                    //stulblSoftware.Text = "Software Error";
                    //stulblSoftware.Image = _imgStop;
                    if (true)
                    {
                        this.Listen();
                        return;
                    }
                }
                else
                {
                    string str4 = Encoding.Unicode.GetString(bytes, 0, count);
                    if (str.Length > 0)
                    {
                        str4 = str + str4;
                        str = "";
                    }
                    if (str4.Length > 0)
                    {
                        int num2 = str4.LastIndexOf("\r");
                        if (num2 == -1)
                        {
                            str = str4;
                            str4 = "";
                        }
                        else if (num2 < (str4.Length - 1))
                        {
                            str = str4.Substring(num2 + 1);
                            str4 = str4.Remove(num2 + 1, (str4.Length - num2) - 1);
                        }
                        foreach (string str7 in str4.Split(new char[] { '\r' }))
                        {
                            if (str7.Length >= 1)
                            {
                                _receiveData.Add(str7);
                            }
                        }
                    }
                    while (_receiveData.Count > 0)
                    {
                        string str8 = (string)_receiveData[0];
                        _receiveData.RemoveAt(0);
                        str3 = String.Format("Receive: {0}", str8);
                        _outputLog.InputDateTime = System.DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff");
                        if (str8.CompareTo("GetStatus") == 0)
                        {
                            responseData = "Device_OK\r";
                            flag = true;
                        }
                        else if (str8.CompareTo("Rdy4_Xmit?") == 0)
                        {
                            responseData = "Send_New\r";
                            _clearLog = true;
                            flag = true;
                        }
                        if (flag)
                        {
                            bytes = Encoding.Unicode.GetBytes(responseData);
                            int responseDataLength = 0;
                            try
                            {
                                responseDataLength = asyncSocket.Send(bytes);
                            }
                            catch (SocketException exception2)
                            {
                                if ((exception2.ErrorCode == 10060) || (exception2.ErrorCode == 10035))
                                {
                                    continue;
                                }
                                this.Listen();
                                break;
                            }
                            if (responseDataLength > 0)
                            {
                                str3 = String.Format("Response: {0}", responseData.Substring(0, responseData.Length - 1));
                            }
                        }
                        lock (_memLock)
                        {
                            _tmpUILog = str3;
                        }
                        updateLog method = new updateLog(this.UpdateLog);
                        this.txtLog.Invoke(method);

                        if (flag)
                        {
                            break;
                        }

                        string convertedData = ConvertData(str8);

                        if (_clientConnected && flag != true)
                        {
                            TransmitData(convertedData);
                        }

                        if (_createNewLog)
                        {
                            _fileName = String.Format("{0}_{1}", _jobId, System.DateTime.Now.ToString("yyyyMMddHHmmss"));
                            _createNewLog = false;
                        }

                        string[] splitReceiveData = _outputLog.InputData.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                        string[] splitConvertedData = convertedData.Split(new char[] { '\r' }, StringSplitOptions.RemoveEmptyEntries);
                        for (int i = 0; i < splitReceiveData.Length; i++)
                        {
                            _outputLog.InputData = splitReceiveData[i];
                            //if (_clientConnected && flag != true)
                            //{
                                _outputLog.OutputData = splitConvertedData[i].Replace(";", ",");
                            //}
                            WriteHelper.Log(_outputLog, _fileName);
                        }
                    }
                }
            }
        }
Beispiel #5
0
        void worker_DoWork(Object sender, DoWorkEventArgs e)
        {
            int       currentFileCount = 0;
            int       currentCodeCount;
            updateLog updateLogDelegate = new updateLog(updateLogMethod);

            System.Windows.Threading.DispatcherOperation updateLogBox = txtLog.Dispatcher.BeginInvoke(updateLogDelegate, System.Windows.Threading.DispatcherPriority.Normal, "Reading files");
            foreach (Files file in sourceFiles)
            {
                currentCodeCount = 0;
                if (worker.CancellationPending == true)
                {
                    e.Cancel = true;
                    break;
                }

                if (isWhitelisted(file.extension.ToUpper()))
                {
                    if (!turbo)
                    {
                        Thread.Sleep(50);
                    }

                    currentFileCount++;
                    System.Windows.Threading.DispatcherOperation updateProgressText = tbxLoc.Dispatcher.BeginInvoke(new progressTextUpdater(progressTextUpdateMethod), System.Windows.Threading.DispatcherPriority.Normal, file.fullname);
                    System.Windows.Threading.DispatcherOperation updateProgressBar  = progress.Dispatcher.BeginInvoke(new progressBarUpdater(progressBarUpdateMethod), System.Windows.Threading.DispatcherPriority.Normal, currentFileCount);

                    try
                    {
                        using (TextReader reader = new StreamReader(file.fullname))
                        {
                            while (reader.ReadLine() != null)
                            {
                                currentCodeCount++;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        updateLogBox = txtLog.Dispatcher.BeginInvoke(updateLogDelegate, System.Windows.Threading.DispatcherPriority.Normal, "Exception: " + ex.Message);
                    }

                    loc += currentCodeCount;

                    if (CodeBreakup.ContainsKey(file.extension.ToLower()))
                    {
                        CodeBreakup[file.extension.ToLower()] += currentCodeCount;
                    }
                    else
                    {
                        CodeBreakup.Add(file.extension.ToLower(), currentCodeCount);
                    }

                    System.Windows.Threading.DispatcherOperation updateLocCounter = progress.Dispatcher.BeginInvoke(new updateLOCCounter(LocCounterUpdateMethod), System.Windows.Threading.DispatcherPriority.Normal);
                }
                else
                {
                    currentFileCount++;
                    updateLogBox = txtLog.Dispatcher.BeginInvoke(updateLogDelegate, System.Windows.Threading.DispatcherPriority.Normal, "Skipping file: " + file.fullname);
                }
            }
        }