Ejemplo n.º 1
0
 void IncrementProgressbar(ProgressBar control)
 {
     if (control.InvokeRequired)
     {
         DelegateProgress d = new DelegateProgress(IncrementProgressbar);
         control.Invoke(d, new object[] { control });
     }
     else
     {
         control.Value++;
     }
 }
Ejemplo n.º 2
0
        public void Progress_manager_can_be_created_from_an_existing_instance_of_IProgress()
        {
            // Arrange
            var reportedValues = new List <double>();
            var progress       = new DelegateProgress <double>(reportedValues.Add);

            var manager   = progress.Wrap();
            var operation = manager.CreateOperation();

            // Act
            operation.Report(0.1);
            operation.Report(0.3);
            operation.Dispose();

            // Assert
            reportedValues.Should().Equal(0.1, 0.3, 0);
        }
Ejemplo n.º 3
0
        private void btnRecive_Click(object sender, EventArgs e)
        {
            try
            {
                oradb = Program.oradb;
                //   if (oradb != "")
                if (true)
                {
                    // OracleConnection conn = new OracleConnection(oradb);
                    //  conn.Open();
                    // conn.Dispose();
                    gpsTimer.Start();
                    showTimer.Start();
                    //异步委托
                    DelegateProgress wtGps   = new DelegateProgress(gpsDataHandler);
                    IAsyncResult     syncGps = wtGps.BeginInvoke(null, null);
                    DelegateProgress wtVio   = new DelegateProgress(vioDataHandler);
                    IAsyncResult     syncVio = wtVio.BeginInvoke(null, null);
                    DelegateProgress wtDev   = new DelegateProgress(devDataHandler);
                    IAsyncResult     syncDev = wtDev.BeginInvoke(null, null);

                    DelegateProgress wtDuiJiangJi   = new DelegateProgress(DuiJiangJiDataHandler);
                    IAsyncResult     syncDuiJiangJi = wtDuiJiangJi.BeginInvoke(null, null);

                    //队列插入
                    DelegateProgress wtQueue  = new DelegateProgress(QueueInsert);
                    IAsyncResult     synQueue = wtQueue.BeginInvoke(null, null);
                    //if (threadStatus == ThreadState.Unstarted || threadStatus == ThreadState.Stopped)
                    //{
                    //    ReceiveThread.Start();
                    //    threadStatus = ThreadState.Running;
                    //}
                }
                else
                {
                    WriteLog("oracle数据库连接未设置");
                    MessageBox.Show("请先进行远程数据库的设置。");
                }
            }
            catch (Exception ex)
            {
                //WriteLog(ex.Message);
                MessageBox.Show("远程数据库连接不成功。");
            }
        }
Ejemplo n.º 4
0
    public static System.Collections.IEnumerator Extract(string inFile, string outDir, DelegateProgress progress, DelegateFinish finish,
                                                         System.Collections.Generic.List <string> skipList = null)
    {
        UnityEngine.Debug.Log(inFile + "->" + outDir);
        bool bFail = false;

        if (System.IO.File.Exists(inFile))
        {
            System.IO.FileStream fin = System.IO.File.OpenRead(inFile);
            //UnityEngine.Debug.Log("Open " + inFile + " = " + fin);
            if (fin != null)
            {
                System.IO.BinaryReader fbr = new System.IO.BinaryReader(fin);

                if (!System.IO.Directory.Exists(outDir))
                {
                    System.IO.Directory.CreateDirectory(outDir);
                }
                int nFiles = fbr.ReadInt32();
                for (int i = 0; i < nFiles; ++i)
                {
                    yield return(1);

                    int    nameLen  = fbr.ReadInt32();
                    string fileName = System.Text.Encoding.UTF8.GetString(fbr.ReadBytes(nameLen));
                    int    byteLen  = fbr.ReadInt32();

                    long fileSize = 0;
                    if (skipList != null && skipList.Contains(fileName))
                    {
                        UnityEngine.Debug.Log("Skip: " + fileName + " Length: " + byteLen);
                        fbr.ReadBytes(byteLen);
                    }
                    else
                    {
                        UnityEngine.Debug.Log("Extract: " + fileName + " Length: " + byteLen);
                        byte[] nbytes = null;
                        try {
                            if (byteLen > 0)
                            {
                                nbytes = Decompress(fbr.ReadBytes(byteLen));
                            }
                            else
                            {
                                throw new System.IndexOutOfRangeException("ZeroLength");
                            }
                        } catch (System.Exception e) {
                            UnityEngine.Debug.LogError(e.Message);
                            fileSize = -1;
                            bFail    = true;
                        }

                        if (nbytes != null)
                        {
                            fileSize = nbytes.LongLength;
                            System.IO.FileStream fs = System.IO.File.Create(outDir + "/" + fileName);
                            fs.Write(nbytes, 0, nbytes.Length);
                            fs.Close();
                        }
                    }
                    if (progress != null)
                    {
                        progress(i + 1, nFiles, fileName, fileSize);
                    }
                    if (bFail)
                    {
                        break;
                    }
                }
                fbr.Close();
                fin.Close();
            }
            else
            {
                UnityEngine.Debug.LogError("Open " + inFile + " = " + fin);
            }
        }
        if (finish != null && !bFail)
        {
            finish(inFile);
        }
    }
Ejemplo n.º 5
0
    static public System.Collections.IEnumerator Unpack(PackInfo pack, string outDir, DelegateProgress progress, DelegateFinish finish, string record)
    {
        string inFile = pack.packName;

        UnityEngine.Debug.Log(inFile + "->" + outDir);
        bool bFail = false;

        if (System.IO.File.Exists(inFile))
        {
            System.IO.FileStream fin = System.IO.File.OpenRead(inFile);
            if (fin != null)
            {
                System.IO.BinaryReader fbr = new System.IO.BinaryReader(fin);

                if (!System.IO.Directory.Exists(outDir))
                {
                    System.IO.Directory.CreateDirectory(outDir);
                }
                int nFiles = Math.Max(fbr.ReadInt32(), pack.nTotal);
                fbr.ReadBytes(pack.offset);
                UnityEngine.Debug.Log(string.Format("Unpack Begin: {0}/{1}, Offset: {2}", pack.nCurrent, nFiles, pack.offset));
                for (int i = pack.nCurrent; i < nFiles; ++i)
                {
                    int    nameLen  = fbr.ReadInt32();
                    string fileName = System.Text.Encoding.UTF8.GetString(fbr.ReadBytes(nameLen));
                    int    byteLen  = fbr.ReadInt32();
                    long   fileSize = 0;

                    yield return(1);

                    //UnityEngine.Debug.Log("Unpack: " + fileName + " Length: " + byteLen);
                    byte[] nbytes = fbr.ReadBytes(byteLen);
                    fileSize = nbytes.Length;
                    System.IO.FileStream fs = System.IO.File.Create(System.IO.Path.Combine(outDir, fileName));
                    fs.Write(nbytes, 0, nbytes.Length);
                    fs.Close();

                    pack.offset += sizeof(System.Int32) + nameLen + sizeof(System.Int32) + byteLen;
                    if (!string.IsNullOrEmpty(record))
                    {
                        System.IO.File.WriteAllText(record, string.Format("{0}|{1}|{2}", nFiles, i + 1, pack.offset));
                    }

                    if (progress != null)
                    {
                        progress(i + 1, nFiles, fileName, fileSize);
                    }
                    if (bFail)
                    {
                        break;
                    }
                }
                fbr.Close();
                fin.Close();
                UnityEngine.Debug.Log(string.Format("Unpack End: {0}, Size: {1}", nFiles, pack.offset));
            }
            else
            {
                UnityEngine.Debug.LogError("Open " + inFile + " = " + fin);
            }
        }
        if (finish != null && !bFail)
        {
            finish(inFile);
        }
    }