Example #1
0
        /// <summary>
        /// 增加download下载任务(可等待)
        /// </summary>
        public CFTask <DownloadAwaitEventArgs> AwaitAddDownload(string downloadPath, string downloadUri, int priority, object userData)
        {
            if (string.IsNullOrEmpty(downloadPath))
            {
                throw new Exception("Download path is invalid.");
            }

            if (string.IsNullOrEmpty(downloadUri))
            {
                throw new Exception("Download uri is invalid.");
            }

            if (TotalAgentCount <= 0)
            {
                throw new Exception("You must add download agent first.");
            }

            var tcs = new CFTaskCompletionSource <DownloadAwaitEventArgs>();

            DownloadTask downloadTask = DownloadTask.AwaitCreate(downloadPath, downloadUri, priority, m_FlushSize, m_Timeout, userData, (DownloadPath) =>
            {
                try
                {
                    tcs.TrySetResult(DownloadPath);
                }
                catch (Exception e)
                {
                    tcs.TrySetException(new Exception($"Rpc Error: {DownloadPath.GetType().FullName}", e));
                }
            });

            m_TaskPool.AddTask(downloadTask);

            return(tcs.Task);
        }
Example #2
0
        private void SckSAcceptProc()
        {
            Form.CheckForIllegalCrossThreadCalls = false;
            int Scki = SckCIndex;

            SckSs[Scki]     = new VESocket();
            vec[Scki - 1]   = new VEClient();
            sckAccept[Scki] = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            try
            {
                //Socket s = SckSs[Scki].getSck();
                //s = sckAccept.Accept();
                //SckSs[Scki].SckAccept(sckAccept);
                sckAccept[Scki] = sckAccept[0].Accept();
                accumulate++;
                lblAcc.Text = Convert.ToString(accumulate);
                //SckSs[Scki].setSck(s);
                SckSsWaitAccept();
                byte[] clientData = new byte[1024];
                while (true)
                {
                    // if (SckSs[Scki].getSck().Connected == true)
                    if (sckAccept[Scki].Connected == true)
                    {
                        //SckSs[Scki].getSck().Receive(clientData);
                        sckAccept[Scki].Receive(clientData);
                        BinaryFormatter  bf     = new BinaryFormatter();
                        MemoryStream     stream = new MemoryStream(clientData);
                        SQLiteDataReader sqlite_datareader;
                        object           obj = bf.Deserialize(stream);
                        if (obj.GetType() == vec[Scki - 1].GetType())
                        {
                            vec[Scki - 1] = (VEClient)obj;
                            //lblclientComputerName.Text = vec.getComputerName();
                            lblClientIpAddress.Text = vec[Scki - 1].getIpAddress();
                            listBox1.Items.Add(vec[Scki - 1].getComputerName());
                            //讀取SQLite

                            /*SQLiteConnection sqlite_conn = new SQLiteConnection();
                             * SQLiteCommand sqlite_cmd = new SQLiteCommand();
                             *
                             * bool isRepeated = true;
                             #region 檢查重複
                             *
                             * if (vec[Scki - 1].getCommand() == "檢查重複")
                             * {
                             *  sqlite_conn = new SQLiteConnection("Data source=" + SQLitePath.path);
                             *  sqlite_conn.Open();
                             *  sqlite_cmd = sqlite_conn.CreateCommand();
                             *  sqlite_cmd.CommandText = "SELECT * FROM UsersData";
                             *  sqlite_datareader = sqlite_cmd.ExecuteReader();
                             *  while (sqlite_datareader.Read())
                             *  {
                             *      if (sqlite_datareader["User"].ToString() == vec[Scki - 1].getUserName())
                             *      {
                             *          vec[Scki - 1].setCommand("重複");
                             *          Serialize(vec[Scki - 1], Scki);
                             *          isRepeated = true;
                             *          break;
                             *      }
                             *      isRepeated = false;
                             *  }
                             *  if (!isRepeated)
                             *  {
                             *      vec[Scki - 1].setCommand("可用");
                             *      Serialize(vec[Scki - 1], Scki);
                             *  }
                             *  sqlite_datareader.Close();
                             * }
                             #endregion
                             #region 註冊
                             * else if(vec[Scki - 1].getCommand()=="註冊")
                             * {
                             *  sqlite_conn = new SQLiteConnection("Data source=" + SQLitePath.path);
                             *  sqlite_conn.Open();
                             *  sqlite_cmd = sqlite_conn.CreateCommand();
                             *  sqlite_cmd.CommandText = "SELECT * FROM UsersData";
                             *  sqlite_cmd.ExecuteNonQuery();
                             *  sqlite_datareader = sqlite_cmd.ExecuteReader();
                             *  sqlite_cmd.CommandText = "INSERT INTO UsersData (User,Password,Name) VALUES('" + vec[Scki - 1].getUserName() + "','" + vec[Scki - 1].getPassword() + "','" + vec[Scki - 1].getName() + "')";
                             *  sqlite_cmd.ExecuteNonQuery();
                             *  sqlite_datareader.Close();
                             * }
                             #endregion
                             #region 登入
                             * else
                             * {
                             *  sqlite_conn = new SQLiteConnection("Data source=" + SQLitePath.path);
                             *  sqlite_conn.Open();
                             *  sqlite_cmd = sqlite_conn.CreateCommand();
                             *  sqlite_cmd.CommandText = "SELECT * FROM UsersData";
                             *  sqlite_datareader = sqlite_cmd.ExecuteReader();
                             *  bool isCorrceted = true;
                             *  while (sqlite_datareader.Read())
                             *  {
                             *      if (sqlite_datareader["User"].ToString() == vec[Scki - 1].getUserName())
                             *      {
                             *          if (sqlite_datareader["Password"].ToString() == vec[Scki - 1].getPassword())
                             *          {
                             *              vec[Scki - 1].setCommand("正確");
                             *              Serialize(vec[Scki - 1], Scki);
                             *              isCorrceted = true;
                             *              break;
                             *          }
                             *      }
                             *      isCorrceted = false;
                             *
                             *  }
                             *  if (!isCorrceted)
                             *  {
                             *      sckAccept[Scki].Close();
                             *  }
                             *  sqlite_datareader.Close();
                             *
                             * }
                             #endregion*/
                        }
                        else if (obj.GetType() == dlPath.GetType())
                        {
                            dlPath = (DownloadPath)obj;
                            sendMyExcelCollection(dlPath.getPath(), Scki);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                //MessageBox.Show(e.Message);
            }
        }