Beispiel #1
0
        private bool Tracking(int level, int[] column)
        {
            if (!IsCanBePlaced(level, column))
            {
                // fail
                Fail?.Invoke(level, column);
                return(false);
            }

            if (level == _size)
            {
                // success
                Success?.Invoke(column);
                return(true);
            }

            // tracking child cases
            for (int i = 1; i <= _size; i++)
            {
                column[level + 1] = i;
                if (Tracking(level + 1, column))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #2
0
 private void Timer_Elapsed(object sender, ElapsedEventArgs e)
 {
     if (m_timeout != -1 && (DateTime.Now - this.m_startTime).TotalMilliseconds > (double)this.m_timeout)
     {
         m_timer.Stop();
         Fail?.Invoke(this, new EventArgs());
     }
     if (m_predicate())
     {
         m_timer.Stop();
         Success?.Invoke(this, new EventArgs());
     }
 }
Beispiel #3
0
        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (m_timeout != System.Threading.Timeout.Infinite && (DateTime.Now - m_startTime).TotalMilliseconds > m_timeout)
            {
                m_timer.Stop();

                Fail?.Invoke(this, new EventArgs());
            }

            if (m_predicate())
            {
                m_timer.Stop();

                Success?.Invoke(this, new EventArgs());
            }
        }
Beispiel #4
0
        public String SendAndRead(String FileName, String OldFileName)
        {
            TcpClient tcpClient    = new TcpClient(_Server, Convert.ToInt32(_Port));
            String    responseData = String.Empty;

            using (FileStream inputStream = File.OpenRead(FileName))
            {
                using (NetworkStream outputStream = tcpClient.GetStream())
                {
                    using (BinaryWriter writer = new BinaryWriter(outputStream))
                    {
                        bool   CloseConnect = false;
                        long   lenght       = inputStream.Length;
                        long   totalBytes   = 0;
                        int    readBytes    = 0;
                        byte[] buffer       = new byte[8192];
                        writer.Write(CloseConnect);
                        writer.Write(SystemArgs.User.Login);
                        writer.Write(OldFileName);
                        writer.Write(SystemArgs.Path.GetFileName(FileName));
                        writer.Write(lenght);
                        do
                        {
                            readBytes = inputStream.Read(buffer, 0, buffer.Length);
                            outputStream.Write(buffer, 0, readBytes);
                            totalBytes += readBytes;
                        } while (tcpClient.Connected && totalBytes < lenght);
                        Byte[]        readingData       = new Byte[256];
                        StringBuilder completeMessage   = new StringBuilder();
                        int           numberOfBytesRead = 0;
                        do
                        {
                            numberOfBytesRead = outputStream.Read(readingData, 0, readingData.Length);
                            completeMessage.AppendFormat("{0}", Encoding.UTF8.GetString(readingData, 0, numberOfBytesRead));
                        }while (outputStream.DataAvailable);
                        responseData = completeMessage.ToString();
                        if (_NeedChecked)
                        {
                            if (AddDecodeSession(responseData.Trim()))
                            {
                                Load?.Invoke(_DecodeSession);
                            }
                            else
                            {
                                Fail?.Invoke(OldFileName);
                            }
                        }
                        else if (responseData.Split('_').Length != 6)
                        {
                            Fail?.Invoke(OldFileName);
                        }
                        else
                        {
                            Rename?.Invoke(responseData, OldFileName);
                        }
                    }
                }
            }
            tcpClient.Close();
            return(responseData);
        }