Esempio n. 1
0
 public upgradeTask()
 {
     intitDeafault();
     for (int i = 0; i < 8; i++)
     {
         info[i] = new updateInfo();
     }
     srcFilePath = null;
     srcFileName = null;
 }
Esempio n. 2
0
        public void uprgdFinishTaskTrack()
        {
            updateInfo uInfo = new updateInfo();

            while ((numberOfActiveUgradeTask - numberOfFailedUgradeTask) > 0)
            {
                Thread.Sleep(1000);
            }
            uInfo.actOn  = actionOnControl.PROCESS_COMPLETED;
            uInfo.dEntry = null;
            cbPb(uInfo);
        }
Esempio n. 3
0
 public upgradeTask()
 {
     //denty = new deviceEntry();
     listIndex = 0;
     mainW     = null;
     for (int i = 0; i < 8; i++)
     {
         info[i] = new updateInfo();
     }
     srcFilePath = null;
     srcFileName = null;
 }
Esempio n. 4
0
 public upgradeTask(callback_ProgressBar pb)
 {
     listIndex = 0;
     mainW     = null;
     for (int i = 0; i < 8; i++)
     {
         info[i] = new updateInfo();
     }
     cbPb        = pb;
     srcFilePath = null;
     srcFileName = null;
 }
Esempio n. 5
0
        private int dumy(updateInfo info)
        {
            /* progress bar update*/
            info.pbMax = 20;
            //reset progress bar and other information @ startup
            info.pbMin = 0;
            info.pbVal = 0;
            info.actOn = actionOnControl.PROGRESS_BAR;
            cbPb(info);

            for (int i = 0; i < 20; i++)
            {
                info.pbVal += 1;
                /* update progress bar */
                cbPb(info);
                Thread.Sleep(1000);
            }
            return(0);
        }
        public void updateProgressBar_Callback(updateInfo pbInfo)
        {
            Action cmd;

            try
            {
                if (pbInfo.actOn == actionOnControl.NO_ACTION)
                {
                    return;
                }

                if (pbInfo.winControlIndex == 0xFF)
                {
                    Console.WriteLine("Progress bar is uninitialized ");
                }
                if (pbInfo.actOn == actionOnControl.PROGRESS_BAR)
                {
                    if (pbInfo.pbVal == 0)
                    {
                        cmd = () => updateWin.pb[pbInfo.winControlIndex].Maximum = pbInfo.pbMax;
                        Application.Current.Dispatcher.Invoke(cmd);

                        cmd = () => updateWin.pb[pbInfo.winControlIndex].Minimum = pbInfo.pbMin;
                        Application.Current.Dispatcher.Invoke(cmd);

                        // IP address lebel clean up
                        cmd = () => updateWin.lb[pbInfo.winControlIndex].Content = " ";
                        Application.Current.Dispatcher.Invoke(cmd);
                    }
                    else
                    {
                        cmd = () => updateWin.lb[pbInfo.winControlIndex].Content = pbInfo.serverIpAddress;
                        Application.Current.Dispatcher.Invoke(cmd);
                    }

                    cmd = () => updateWin.pb[pbInfo.winControlIndex].Value = pbInfo.pbVal;
                    Application.Current.Dispatcher.Invoke(cmd);
                }
                else if (pbInfo.actOn == actionOnControl.DATA_GRID)
                {
                    cmd = () => updateWin.grdUpdateList.Items.Add(pbInfo.dEntry);
                    Application.Current.Dispatcher.Invoke(cmd);
                }
                else if (pbInfo.actOn == actionOnControl.PROCESS_COMPLETED)
                {
                    int lstCnt = 0;

                    cmd = () => lstCnt = grdUpdateList.Items.Count;
                    Application.Current.Dispatcher.Invoke(cmd);
                    /* clean old entry*/

                    for (int i = 0; i < lstCnt; i++)
                    {
                        cmd = () => grdUpdateList.Items.RemoveAt(0);
                        Application.Current.Dispatcher.Invoke(cmd);
                    }
                    /* add new entry*/
                    int j = 0;
                    for (int i = 0; i < upgradedDeviceListCnt; i++)
                    {
                        cmd = () => grdUpdateList.Items.Add(upgradedDeviceList[i]);
                        Application.Current.Dispatcher.Invoke(cmd);
                    }
                    // enbale start button
                    cmd = () => btStart.IsEnabled = true;
                    Application.Current.Dispatcher.Invoke(cmd);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 7
0
        private int PostDatatoDevice(updateInfo info)
        {
            // updateInfo info = new updateInfo();
            int retVal       = -1;
            int ftpFrameSize = 1400;

            // Read the source file into a byte array.
            byte[] dataToSend = new byte[ftpFrameSize];
            byte[] fileContain;
            int    bytesToSend;
            int    remainbyte;
            Uri    myUri = new Uri("ftp://" + info.serverIpAddress + "/fw/" + info.fileName);

            byte[]        fileContents = new byte[1400];
            FtpWebRequest request      = (FtpWebRequest)WebRequest.Create(myUri);


            try
            {
                request.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.CacheIfAvailable);
                request.Method      = WebRequestMethods.Ftp.UploadFile;
                request.UseBinary   = true;
                request.Credentials = new NetworkCredential("pcfactory", "pcfactory");
                lock (ftpFileLock)
                {
                    FileInfo fInfo = new FileInfo(info.filePath);
                    remainbyte = (int)fInfo.Length;
                    BinaryReader bread = new BinaryReader(File.Open(info.filePath, FileMode.Open));
                    fileContain = new byte[remainbyte];
                    /* read complete file same time To give access for other thread*/
                    fileContain = bread.ReadBytes(remainbyte);
                    /* file operation closed*/
                    bread.Close();
                }
                /* progress bar update*/
                info.pbMax = (remainbyte / ftpFrameSize) + 1; // atleast 1 frame
                //reset progress bar and other information @ startup
                info.pbMin = 0;
                info.pbVal = 0;
                //reset progress bar and other information @ startup
                info.actOn = actionOnControl.PROGRESS_BAR;
                cbPb(info);


                /* ftp Operation start*/
                Stream requestStream = request.GetRequestStream();
                int    dataIndex     = 0;
                while (remainbyte > 0)
                {
                    bytesToSend = ((remainbyte > ftpFrameSize) ? ftpFrameSize : remainbyte);
                    //dataToSend = bread.ReadBytes(bytesToSend);
                    request.ContentLength = bytesToSend;
                    Buffer.BlockCopy(fileContain, dataIndex, dataToSend, 0, bytesToSend);
                    requestStream.Write(dataToSend, 0, bytesToSend);
                    dataIndex  += bytesToSend;
                    info.pbVal += 1;
                    Console.WriteLine(info.pbVal.ToString());
                    /* update progress bar */
                    info.actOn = actionOnControl.PROGRESS_BAR;
                    cbPb(info);
                    remainbyte = remainbyte - bytesToSend;
                    Thread.Sleep(10);
                }
                /*FTP Close */
                requestStream.Close();

                FtpWebResponse response = (FtpWebResponse)request.GetResponse();
                Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);

                response.Close();
                retVal = 0;
                info.dEntry.upgradeStatus = "Successfull";
            }
            catch (WebException e)
            {
                Console.WriteLine(e.Message.ToString());
                String status = ((FtpWebResponse)e.Response).StatusDescription;
                Console.WriteLine(status);
                numberOfFailedUgradeTask++;
                info.dEntry.upgradeStatus = "Failed";
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message.ToString());
                numberOfFailedUgradeTask++;
                info.dEntry.upgradeStatus = "Failed";
            }

            return(retVal);
        }
Esempio n. 8
0
        // public void updateThread(int deviceId)
        public void updateThread(deviceEntry dEntry)
        {
            updateInfo uInfo = new updateInfo();

            Console.WriteLine("upgrade task invoked and waiting from sema");
            semaUpdate.WaitOne();
            int i = 0;

            lock (thislock)
            {
                for (i = 0; i < 8; i++)
                {
                    if (info[i].winControlIndex == 0xFF)
                    {
                        uInfo = info[i];
                        break;
                    }
                }
                if (i < 8)
                {
                    uInfo.winControlIndex = i;
                }
            }
            if (i > 8) // somthing is worng in memory allocation process did't able get windows resources
            {
                return;
            }
            uInfo.serverIpAddress = dEntry.deviceIP;
            uInfo.fileName        = srcFileName;
            uInfo.filePath        = srcFilePath;
            int rTry = 0;

            do
            {   // send file to device and retry for 3 time in case fail
                if (PostDatatoDevice(uInfo) == -1)
                // if (dumy(uInfo) == -1)
                {
                    uInfo.actOn = actionOnControl.PROGRESS_BAR;
                    uInfo.pbVal = 0;
                    cbPb(uInfo);
                    rTry++;
                    Thread.Sleep(1000);
                }
                else
                {
                    break;
                }
            }while(rTry < 3);
            // Successful only within 3 time retry
            if (rTry < 3)
            {
                dEntry.upgradeStatus = "Successful";
            }
            else
            {
                //denty[deviceId].upgradeStatus = "Failed";
                dEntry.upgradeStatus = "Failed";
            }
            uInfo.actOn  = actionOnControl.DATA_GRID;
            uInfo.dEntry = dEntry;
            cbPb(uInfo);
            lock (thislock)
            {
                info[i].winControlIndex = 0xFF;
            }

            numberOfActiveUgradeTask--;
            // release the semaphore for other task
            semaUpdate.Release();
        }