public void InvokeDiscoverCallback(DataNode node)
 {
     if (_sender != null && DiscoverCallback != null)
     {
         _sender.BeginInvoke(DiscoverCallback, new object[] { node });
     }
 }
Exemple #2
0
        public void AutoAddTask()
        {
            //读取所有分类,然后根据分类加载任务
            cTaskClass xmlTClass = new cTaskClass();
            cTaskIndex xmlTasks;

            //获取共有多少个任务分类
            int TClassCount = xmlTClass.GetTaskClassCount();

            for (int i = 0; i < TClassCount; i++)
            {
                xmlTasks = new cTaskIndex();

                //获取此分类下工有过少个任务
                xmlTasks.GetTaskDataByClass(xmlTClass.GetTaskClassName(i));

                int count = xmlTasks.GetTaskClassCount();

                cTask t;

                ListViewItem Litem;

                for (int j = 0; j < count; j++)
                {
                    t = new cTask();
                    try
                    {
                        t.LoadTask(xmlTClass.GetTaskClassPathByName(xmlTClass.GetTaskClassName(i)) + "\\" + xmlTasks.GetTaskName(j) + ".xml");
                        t = null;
                    }
                    catch (cSoukeyException)
                    {
                        Litem = new ListViewItem();

                        Litem.ImageIndex = 0;
                        Litem.Text       = "等待升级";
                        Litem.SubItems.Add(xmlTasks.GetTaskName(j));
                        Litem.SubItems.Add(t.TaskVersion.ToString());
                        Litem.SubItems.Add(xmlTClass.GetTaskClassName(i));
                        Litem.SubItems.Add(xmlTClass.GetTaskClassPathByName(xmlTClass.GetTaskClassName(i)));
                        Litem.SubItems.Add("");
                        //更新进度条信息
                        m_sender.BeginInvoke(m_senderDelegate, new object[] { TClassCount + count, j + i, Litem, false });

                        Application.DoEvents();
                    }
                    catch (System.Exception ex)
                    {
                    }
                }

                //更新进度条信息
                m_sender.BeginInvoke(m_senderDelegate, new object[] { TClassCount, i, null, false });
            }

            m_sender.BeginInvoke(m_senderDelegate, new object[] { TClassCount, TClassCount, null, true });

            xmlTClass = null;
        }
        /// <summary>
        /// Local Method for the actual work.
        /// </summary>
        private void LocalRunProcess()
        {
            int i = 0;

            for (; i < _totalMessages; i++)
            {
                Thread.Sleep(50);
                _sender.BeginInvoke(_senderDelegate, new object[] { _totalMessages, i, false });
            }
            _sender.BeginInvoke(_senderDelegate, new object[] { _totalMessages, i, true });
        }
Exemple #4
0
        private void DownloadSoft()
        {
            Gather.cGatherWeb gData = new Gather.cGatherWeb();

            //增加采集的标志
            Task.cWebpageCutFlag c;

            c           = new Task.cWebpageCutFlag();
            c.id        = 0;
            c.Title     = "版本";
            c.DataType  = (int)cGlobalParas.GDataType.File;
            c.StartPos  = "<a href=\"";
            c.EndPos    = "\"";
            c.LimitSign = (int)cGlobalParas.LimitSign.NoLimit;
            gData.CutFlag.Add(c);
            c = null;


            DataTable dGather = gData.GetGatherData("http://www.yijie.net/user/soft/updatesoukey.html", cGlobalParas.WebCode.utf8, "", "", "", Program.getPrjPath(), false);

            dGather = null;
            gData   = null;

            m_sender.BeginInvoke(m_senderDelegate, new object[] { true });
        }
        public static void InvokeIfRequired(ContainerControl target, Action del)
        {
            if (null == target)
            {
                throw new ArgumentNullException("target");
            }
            if (null == del)
            {
                throw new ArgumentNullException("del");
            }

            if (target.InvokeRequired && (!target.Disposing) && (!target.IsDisposed))
            {
                try
                {
                    target.BeginInvoke(del);
                }
                catch (Exception ex)
                {
                    Log.Info("Could not invoke method", ex);
                }
            }
            else
            {
                del();
            }
        }
Exemple #6
0
 /// <summary>
 /// Thiết lập contextMenu và khởi động hàm hiển thị cột của Grid. Hàm này được chạy ngầm tránh ảnh hưởng đến việc LoadForm
 /// </summary>
 public void StartUp()
 {
     do
     {
         IntPtr IR = _Container.Handle;
         _IAr = _Container.BeginInvoke(new StartUpCallBack(SetContextMenu));
         ControlHasCreadted = true;
     } while (!ControlHasCreadted);
 }
 /// <summary>
 /// Sets the binding context.
 /// </summary>
 /// <param name="control">The control.</param>
 /// <param name="value">The value.</param>
 public static void SetBindingContext(this ContainerControl control, BindingContext value)
 {
     if (control.InvokeRequired)
     {
         control.BeginInvoke(new MethodInvoker(() => control.SetBindingContext(value)));
     }
     else
     {
         control.BindingContext = value;
         control.Refresh();
     }
 }
 /// <summary>
 /// Sets the automatic scale dimensions.
 /// </summary>
 /// <param name="control">The control.</param>
 /// <param name="value">The value.</param>
 public static void SetAutoScaleDimensions(this ContainerControl control, SizeF value)
 {
     if (control.InvokeRequired)
     {
         control.BeginInvoke(new MethodInvoker(() => control.SetAutoScaleDimensions(value)));
     }
     else
     {
         control.AutoScaleDimensions = value;
         control.Refresh();
     }
 }
 /// <summary>
 /// Sets the automatic validate.
 /// </summary>
 /// <param name="control">The control.</param>
 /// <param name="value">The value.</param>
 public static void SetAutoValidate(this ContainerControl control, AutoValidate value)
 {
     if (control.InvokeRequired)
     {
         control.BeginInvoke(new MethodInvoker(() => control.SetAutoValidate(value)));
     }
     else
     {
         control.AutoValidate = value;
         control.Refresh();
     }
 }
 /// <summary>
 /// Sets the active control.
 /// </summary>
 /// <param name="control">The control.</param>
 /// <param name="value">The value.</param>
 public static void SetActiveControl(this ContainerControl control, Control value)
 {
     if (control.InvokeRequired)
     {
         control.BeginInvoke(new MethodInvoker(() => control.SetActiveControl(value)));
     }
     else
     {
         control.ActiveControl = value;
         control.Refresh();
     }
 }
Exemple #11
0
        //线程处理函数
        private void threadWorkAppIcon(object o)
        {
            ImageData pv    = (ImageData)o;
            int       index = 0;

            while (index < pv.imageDataLenght.Count)
            {
                int    widht            = pv.imageDataLenght[index];
                string BackFunctionFile = ReduceImage(pv.fileName, widht, widht);
                m_pForm.BeginInvoke(new MyDelegateData(UpdateAddListView), BackFunctionFile);
                index++;
            }
        }
Exemple #12
0
 private void LocalRunProcess()
 {
     try
     {
         m_sender.BeginInvoke(m_senderDelegate);
     }
     catch (System.InvalidOperationException)
     {
         Thread.CurrentThread.Abort();
     }
     catch
     {
         Thread.CurrentThread.Abort();
     }
 }
 private void ReportProgress(int progressPercentage, string message)
 {
     _sender.BeginInvoke(_senderDelegate, new object[] { progressPercentage, message });
 }
        public void Worker()
        {
            bool bSoundOn   = false;
            bool bLimitDone = false;


            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.SoundLocation = "fuel_pump_operating.wav";
            while (true)
            {
                if (b888 && count888 > 0)
                {
                    bLimitDone = false;
                    SetUpdateData(true);
                    m_sender.BeginInvoke(m_senderDelegate, data);
                    count888--;
                    if (count888 == 0)
                    {
                        b888       = false;
                        data.vol   = 0.0;
                        data.money = 0.0;
                    }
                    Thread.Sleep(100);
                    continue;
                }
                if (ps == PumpStatus.InUse && !bLimit)
                {
                    data.vol += (dFlow / 600);
                    data.vol  = Math.Round(data.vol, 2);
                    SetUpdateData(false);
                    double valuetocheck = 0.0;
                    if (type == "Money")
                    {
                        valuetocheck = data.money;
                    }
                    else
                    {
                        valuetocheck = data.vol;
                    }
                    if (valuetocheck > limit)
                    {
                        bLimit = true;
                        if (type == "Money")
                        {
                            data.money = limit;
                            //make sure no over flow - we calcualte display by vol
                            if (nozz == 1)
                            {
                                data.vol = data.money / PPV1;
                            }
                            else
                            {
                                data.vol = data.money / PPV2;
                            }
                        }
                        else
                        {
                            data.vol = limit;
                        }
                        if (bSoundOn)
                        {
                            player.Stop();
                            bSoundOn = false;
                        }
                    }

                    SetUpdateData(false);

                    m_sender.BeginInvoke(m_senderDelegate, data);
                    if (!bSoundOn && !bLimit)
                    {
                        bSoundOn = true;
                        player.PlayLooping();
                        //player.Play();
                    }
                }
                else
                {
                    if (bSoundOn)
                    {
                        player.Stop();
                        bSoundOn = false;
                    }
                }
                Thread.Sleep(100);
            }
        }
Exemple #15
0
        //导出Excel
        private void ExportExcel1()
        {
            // 定义要使用的Excel 组件接口
            // 定义Application 对象,此对象表示整个Excel 程序

            Interop.Excel.Application excelApp = null;
            Interop.Excel.Workbook    workBook = null;
            Interop.Excel.Worksheet   ws       = null;
            Interop.Excel.Range       r;
            int row   = 1;
            int cell  = 1;
            int i     = 0;
            int Count = 0;

            try
            {
                //初始化 Application 对象 excelApp
                excelApp = new Interop.Excel.Application();
                workBook = excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
                ws       = (Worksheet)workBook.Worksheets[1];

                // 命名工作表的名称为 "Task Management"
                ws.Name = "Soukey导出数据";


                // 遍历数据表中的所有列
                for (i = 0; i < m_pData.Columns.Count; i++)
                {
                    ws.Cells[row, cell] = m_pData.Columns[i].ColumnName;
                    r = (Range)ws.Cells[row, cell];
                    ws.get_Range(r, r).HorizontalAlignment = Interop.Excel.XlVAlign.xlVAlignCenter;

                    cell++;
                }

                Count = m_pData.Rows.Count;

                // 创建行,把数据视图记录输出到对应的Excel 单元格
                for (i = 0; i < m_pData.Rows.Count; i++)
                {
                    for (int j = 0; j < m_pData.Columns.Count; j++)
                    {
                        ws.Cells[i + 2, j + 1] = m_pData.Rows[i][j];
                        Range rg = (Range)ws.get_Range(ws.Cells[i + 2, j + 1], ws.Cells[i + 2, j + 1]);
                        rg.EntireColumn.ColumnWidth = 20;
                        rg.NumberFormatLocal        = "@";
                    }

                    //更新进度条信息
                    m_sender.BeginInvoke(m_senderDelegate, new object[] { Count, i, false });
                }

                workBook.SaveCopyAs(m_FileName);
                workBook.Saved = true;
            }
            catch (System.Exception)
            {
                return;
            }
            finally
            {
                excelApp.UserControl = false;
                excelApp.Quit();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(ws);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(workBook);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
                GC.Collect();

                //更新进度条为完成,并传递参数表示导出任务完成
                m_sender.BeginInvoke(m_senderDelegate, new object[] { Count, i, true });
            }

            return;
        }
Exemple #16
0
        public void Worker()
        {
            string c = "";

            while (true)
            {
                try
                {
                    Thread.Sleep(5);
                    if (FoundCard)
                    {
                        myLog.Log("Invoked found card");
                        FoundCard = false;
                        int ep = Card.IndexOf('=');
                        if (ep != -1)
                        {
                            c = Card.Substring(0, Card.IndexOf('='));
                        }
                        else
                        {
                            c = Card;
                        }

                        stat.carddata = c;
                        myLog.Log("Valid card, update GUI: " + c);
                        stat.msg = MsgLogType.MSRRead;
                        m_sender.BeginInvoke(m_senderDelegate, stat);


                        Thread.Sleep(50);
                        stat.msg = MsgLogType.MSRRequestAuth;
                        m_sender.BeginInvoke(m_senderDelegate, stat);
                        Thread.Sleep(1000);

                        myLog.Log("Going to request auth: " + c);
                        //get auth
                        var myBinding = new BasicHttpBinding();
                        // DisableDecompression(myBinding);

                        myBinding.Security.Mode = BasicHttpSecurityMode.None;
                        var myEndpointAddress = new EndpointAddress(conf.MSRService);
                        LoyaltyService.LoyaltyServiceClient s = new LoyaltyService.LoyaltyServiceClient(myBinding, myEndpointAddress);


                        myBinding.MessageEncoding = WSMessageEncoding.Text;


                        LoyaltyService.AuthResult res = new LoyaltyService.AuthResult();
                        try
                        {
                            res = s.GetAuth(c, GetStationCode());
                        }
                        catch (Exception ex)
                        {
                            myLog.Log("Error GetAuth - server down.");
                            stat.msg = MsgLogType.MSRCommError;
                            m_sender.BeginInvoke(m_senderDelegate, stat);
                            continue;
                        }
                        //MessageBox.Show(res.DriverName + " " + res.Limit.ToString() + " " + res.ProductsCode[0].ToString());
                        myLog.Log("Got auth replay: " + res.Allowed.ToString() + ":" + res.DriverName + ":" + res.ErrorDesc);
                        stat.ErrorDesc = res.ErrorDesc;
                        stat.carddata  = c;

                        try
                        {
                            stat.Reference     = res.Reference;
                            stat.CPassRequired = res.cPassRequired;
                            stat.PINRequired   = res.PINRequired;
                            stat.PIN           = res.PinCode;
                            if (res.DriverName != null)
                            {
                                stat.DriverName = res.DriverName;
                            }
                        }
                        catch (Exception ex)
                        {
                            //ignor
                        }

                        if (res.Allowed)
                        {
                            //copy product locally
                            stat.ProductsList = new List <MyProductItem>();
                            foreach (ForeFuelSimulator.LoyaltyService.ProductItem item in res.ProductsList)
                            {
                                stat.ProductsList.Add(new MyProductItem(item.Code, item.Discount, item.DiscountType));
                            }
                            //check correct product

                            bool found = false;
                            foreach (MyProductItem item in stat.ProductsList)
                            {
                                if (item.Code == ProductCode)
                                {
                                    found = true;
                                    break;
                                }
                            }
                            if (!found && ProductCode != 0)
                            {
                                stat.msg = MsgLogType.MSRWrongProduct;
                            }
                            else
                            {
                                stat.msg      = MsgLogType.MSRAuth;
                                lastReference = res.Reference;
                            }

                            stat.Limit     = res.Limit;
                            stat.LimitType = res.LimitType;
                        }
                        else
                        {
                            stat.msg = MsgLogType.MSRReject;
                        }

                        m_sender.BeginInvoke(m_senderDelegate, stat);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Exemple #17
0
 private void UpdateMessage(string msg, bool done)
 {
     m_sender.BeginInvoke(m_senderDelegate, new object[] { msg, done, -1 });
 }
Exemple #18
0
        public void Worker()
        {
            StatusData stat = new StatusData();

            stat.status   = -1;     //error
            stat.carddata = "";
            int laststatus1 = 0x30; //no data

            stat.status2   = -1;    //error
            stat.carddata2 = "";
            int laststatus2 = 0x30; //no data
            int count       = 0;

            while (true)
            {
                if (tcpClient == null || !tcpClient.Connected)
                {
                    try
                    {
                        tcpClient = new TcpClient();
                        //tcpClient.BeginConnect(_Host, _Port, new AsyncCallback(ConnectCallback1), tcpClient);
                        tcpClient.Connect(_Host, _Port);
                        //if (connectDone.WaitOne())
                        {
                            /*
                             * myLog.Log("network connection failed!");
                             * bConnected = false;
                             * stat.carddata = "";
                             * stat.status = -1;
                             * laststatus1 = -1; //no data
                             * stat.carddata2 = "";
                             * stat.status2 = -1;
                             * laststatus2 = -1; //no data
                             * m_sender.BeginInvoke(m_senderDelegate, stat);
                             * continue;
                             */

                            bConnected   = true;
                            stat.status  = 0x30;
                            stat.status2 = 0x30;
                            m_sender.BeginInvoke(m_senderDelegate, stat);
                        }
                    }
                    catch (SocketException e)
                    {
                        Console.WriteLine(e.Message);
                        tcpClient.Close();
                        tcpClient      = null;
                        bConnected     = false;
                        stat.status    = -1;
                        laststatus1    = -1; //no data
                        stat.carddata  = "";
                        stat.status2   = -1;
                        laststatus2    = -1; //no data
                        stat.carddata2 = "";
                        m_sender.BeginInvoke(m_senderDelegate, stat);
                        Thread.Sleep(5000);
                        continue;
                    }

                    catch (Exception exp)
                    {
                        myLog.Log(exp.Message);
                        tcpClient.Close();

                        tcpClient      = null;
                        bConnected     = false;
                        laststatus1    = -1; //no data
                        stat.status    = -1;
                        stat.carddata  = "";
                        laststatus2    = -1; //no data
                        stat.status2   = -1;
                        stat.carddata2 = "";
                        m_sender.BeginInvoke(m_senderDelegate, stat);
                        Thread.Sleep(5000);
                        continue;
                    }
                } //!bConnected
                try
                {
                    Stream stream = tcpClient.GetStream();
                    stream.ReadTimeout = 5000;
                    MakePollMessage();

                    myLog.Log("SEND: " + GetString(_Msg, 10));
                    stream.Write(_Msg, 0, 10);

                    if (((count = Recv(tcpClient, _Msg)) == -1) || _Msg[3] != 0x01)
                    {
                        if (count == -1)
                        {
                            myLog.Log("RECV: Error in read: ");
                        }
                        else
                        {
                            laststatus1 = laststatus2 = -1; // 0x00; //reset
                            myLog.Log("RECV: Error in read: " + GetString(_Msg, count));
                        }
                        continue;
                    }

                    myLog.Log("RECV: " + GetString(_Msg, count));


                    int Chann2Stat = _Msg[8];

                    //check status of the 1st channel - we check on same data - will get on second poll
                    if (((_Msg[7] == 0x35 || _Msg[7] == 0x34) && (laststatus1 == 0x30 || laststatus1 == -1)) ||
                        (_Msg[7] == 0x34 && laststatus1 == 0x35) || (_Msg[7] == 0x35 && laststatus1 == 0x34)) //only if we did not have any thing before
                    {
                        laststatus1 = _Msg[7];                                                                //save it
                        MakeGetDataMessage(1);
                        myLog.Log("SEND: " + GetString(_Msg, 10));
                        stream.Write(_Msg, 0, 10);

                        if (((count = Recv(tcpClient, _Msg)) == -1) || _Msg[3] != 0x22)
                        {
                            tcpClient.Close();
                            if (count == -1)
                            {
                                myLog.Log("Error in read");
                            }
                            else
                            {
                                myLog.Log("RECV: Error in read: " + GetString(_Msg, count));
                            }
                            continue;
                        }
                        myLog.Log("RECV: " + GetString(_Msg, count));

                        int i1 = System.Text.Encoding.Default.GetString(_Msg).IndexOf("?;");
                        int i2 = System.Text.Encoding.Default.GetString(_Msg).IndexOf("=");
                        if (i2 <= i1)
                        {
                            if (i2 == 0xc) //other type?
                            {
                                stat.carddata =
                                    System.Text.Encoding.Default.GetString(_Msg).Substring(i2 + 1, 16);
                            }
                            else
                            {
                                myLog.Log("Bad card format = did not find track2 card number.");
                                stat.carddata = "";    //no data
                            }
                        }
                        else
                        {
                            stat.carddata =
                                System.Text.Encoding.Default.GetString(_Msg).Substring(i1 + 2, i2 - i1 - 2);
                        }


                        stat.status = laststatus1;
                    }
                    else
                    {
                        // myLog.Log("What did we got");
                    }

                    if ((laststatus1 == 0x35 || laststatus1 == 0x34) && _Msg[7] == 0x30) //no data after we had some
                    {
                        laststatus1   = 0x30;
                        stat.status   = laststatus1;
                        stat.carddata = "";
                        stat.nozz     = 1;
                    }

                    //second chan
                    //check status of the 1st channel - we check on same data - will get on second poll
                    if (((Chann2Stat == 0x35 || Chann2Stat == 0x34) && (laststatus2 == 0x30 || laststatus2 == -1)) ||
                        (Chann2Stat == 0x34 && laststatus2 == 0x35)) //only if we did not have any thing before
                    {
                        laststatus2 = Chann2Stat;                    //save it
                        MakeGetDataMessage(2);
                        myLog.Log("SEND: " + GetString(_Msg, 10));
                        stream.Write(_Msg, 0, 10);

                        if (((count = Recv(tcpClient, _Msg)) == -1) || _Msg[3] != 0x22)
                        {
                            if (count == -1)
                            {
                                myLog.Log("Error in read");
                            }
                            else
                            {
                                myLog.Log("RECV: Error in read: " + GetString(_Msg, count));
                            }
                            continue;
                        }
                        myLog.Log("RECV: " + GetString(_Msg, count));

                        int i1 = System.Text.Encoding.Default.GetString(_Msg).IndexOf("?;");
                        int i2 = System.Text.Encoding.Default.GetString(_Msg).IndexOf("=");
                        if (i2 <= i1)
                        {
                            myLog.Log("Bad card format = did not find track2 card number.");
                            stat.carddata2 = "";    //no data
                        }
                        else
                        {
                            stat.carddata2 =
                                System.Text.Encoding.Default.GetString(_Msg).Substring(i1 + 2, i2 - i1 - 2);
                        }


                        stat.status2 = laststatus2;
                    }

                    if ((laststatus2 == 0x35 || laststatus2 == 0x34) && Chann2Stat == 0x30) //no data after we had some
                    {
                        laststatus2    = 0x30;
                        stat.status2   = laststatus2;
                        stat.carddata2 = "";
                        stat.nozz2     = 2;
                    }
                    //second chan


                    m_sender.BeginInvoke(m_senderDelegate, stat);

                    Thread.Sleep(200);
                }
                catch (Exception exp)
                {
                    myLog.Log(exp.Message);
                    tcpClient.Close();
                    tcpClient      = null;
                    bConnected     = false;
                    laststatus1    = -1; //no data
                    stat.status    = -1;
                    stat.carddata  = "";
                    laststatus2    = -1; //no data
                    stat.status2   = -1;
                    stat.carddata2 = "";
                    m_sender.BeginInvoke(m_senderDelegate, stat);
                    Thread.Sleep(5000);
                    continue;
                }
            }
        }