示例#1
0
        public bool D_HHTTransferFileToPC(bool isCheckPermissionMode)
        {
            try
            {
                string fileToPullFromDevice = "";
                string localPath            = "";
                if (isCheckPermissionMode)
                {
                    fileToPullFromDevice = HHTDBPath + validateDBName;
                    localPath            = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName + "\\" + validateDBName;
                    //localPath = "D:\\COMPUTER_NAME.sdf";
                }
                else
                {
                    fileToPullFromDevice = HHTDBPath + DBName;
                    localPath            = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName + "\\" + DBName;
                    //localPath ="D:\\STOCKTAKING_HHT.sdf";
                }

                rapi.CopyFileFromDevice(localPath, fileToPullFromDevice, true);
                //rapi.CreateDeviceDirectory(@"\Program Files\Test");
                return(true);
            }
            catch (Exception ex)
            {
                log.Error(String.Format("Exception : {0}", ex.StackTrace));
                Console.WriteLine("Error from D_HHTTransferFileToPC");
                return(false);
            }
        }
        private void GetStats()
        {
            string localpath = System.Windows.Forms.Application.StartupPath + "\\mscoree.stat";
            string line;

            m_rapi.CopyFileFromDevice("\\mscoree.stat", localpath, true);

            StreamReader reader = System.IO.File.OpenText(localpath);

            line = reader.ReadLine();

            while (line != null)
            {
                // there are a couple blank lines
                if (line.Length > 1)
                {
                    // skip the "header" line
                    if (line.Substring(0, 7) != "counter")
                    {
                        // get name
                        string name    = line.Substring(0, 47).Trim();
                        int    val     = Convert.ToInt32(line.Substring(46, 11).Trim(), 10);
                        int    samples = Convert.ToInt32(line.Substring(57, 9).Trim(), 10);
                        int    mean    = Convert.ToInt32(line.Substring(66, 9).Trim(), 10);
                        int    min     = Convert.ToInt32(line.Substring(75, 9).Trim(), 10);
                        int    max     = Convert.ToInt32(line.Substring(84, 9).Trim(), 10);

                        m_stats.Add(new PerformanceStatistic(name, val, samples, mean, min, max));
                    }
                }
                line = reader.ReadLine();
            }
            reader.Close();
            File.Delete(localpath);
        }
示例#3
0
        /// <summary>
        /// Копирует указанный файл с устройства на компьютер
        /// </summary>
        /// <param name="localPath">Путь на компьютере</param>
        /// <param name="remoteFileName">Путь на устройстве</param>
        /// <param name="overwrite">Признак необходимости перезаписи</param>
        /// <returns>TRUE - копирование без ошибок, FALSE - если возникла хоть одна ошибка</returns>
        public bool CopyFromDevice(String localPath, String remoteFileName, bool overwrite)
        {
            bool res = true;

            try
            {
                m_RAPI.CopyFileFromDevice(localPath, remoteFileName, overwrite);
            }
            catch (Exception ex)
            {
                lbStatus.Text = ex.Message;
                res           = false;
            }

            return(res);
        }
示例#4
0
    public static FlatBackupFile CopyFileFromDeviceFLAT(string src, string destFolder)
    {
        var fbf = new FlatBackupFile();

        string mangledName = Guid.NewGuid().ToString();
        string destPath    = destFolder + "\\" + mangledName;

        if (RAPI.CopyFileFromDevice(src, destPath, true) == true)
        {
            fbf.DeviceSidePath = src;
            fbf.PcSidePath     = destPath;
            fbf.InternalPath   = mangledName;
            return(fbf);
        }
        return(null);
    }
示例#5
0
 private void buttonTest_Click(object sender, EventArgs e)
 {
     try
     {
         String progPath = Environment.CurrentDirectory + @"\test.txt";
         //String mobileDBPath = @"\Programme\test.txt";
         String mobileDBPath = @"Speicherkarte\test.txt";
         rapi.Connect();
         rapi.CopyFileToDevice(progPath, mobileDBPath, true);
         rapi.CopyFileFromDevice(progPath, mobileDBPath, true);
         rapi.Disconnect();
         MessageBox.Show("Rapi Connection Succesfull");
     }
     catch (Exception f)
     {
         MessageBox.Show(f.Message);
         MessageBox.Show(f.InnerException.ToString());
         MessageBox.Show("Rapi Connection Error");
     }
 }
        /// <summary>
        /// Copies a file from the connected mobile device to the desktop and ensures its DateTime stamp is identical to that on the mobile device.
        ///
        /// Debug: I'm not sure why, but the 3 types of DateTime properties are not working correctly.  They always refer to the current day.
        /// </summary>
        /// <param name="rapi"></param>
        /// <param name="srcFile"></param>
        /// <param name="destFile"></param>
        /// <returns></returns>
        public static bool CopyFileFromDevice(RAPI rapi, string srcFile, string destFile)
        {
            try
            {
                DateTime dateTimeInfo = rapi.GetDeviceFileTime(srcFile, RAPI.RAPIFileTime.LastAccessTime);
//        DateTime dateTimeInfo2 = rapi.GetDeviceFileTime(srcFile, RAPI.RAPIFileTime.LastModifiedTime);
//        DateTime dateTimeInfo3 = rapi.GetDeviceFileTime(srcFile, RAPI.RAPIFileTime.CreateTime);
                rapi.CopyFileFromDevice(destFile, srcFile, true);
                File.SetLastWriteTime(destFile, dateTimeInfo);
            }

            catch (Exception e)
            {
                Debug.WriteLine("Couldn't copy mobile file: " + srcFile);
                Debug.WriteLine("Error Message: " + e.Message);

                return(false);
            }

            return(true);
        }
示例#7
0
        public static void GetFileFormDevice(String SourcePath, String DestinationPath, bool Overwrite)
        {
            if (rapi.DevicePresent)
            {
                if (!rapi.Connected)
                {
                    rapi.Connect();
                }
                FileAttributes attr = File.GetAttributes(DestinationPath);
                if ((attr & FileAttributes.Directory).Equals(FileAttributes.Directory))   //DestinationPath is a directory
                {
                    DestinationPath = Path.Combine(DestinationPath, Path.GetFileName(SourcePath));
                }

                rapi.CopyFileFromDevice(DestinationPath, SourcePath, Overwrite);
                if (rapi != null && rapi.Connected)
                {
                    rapi.Disconnect();
                }
            }
        }
示例#8
0
 public static bool CopyDirectoryFromDevice(string src, string dest, string exceptFolders = "")
 {
     LastError = "";
     src       = src.TrimEnd('\\');
     dest      = dest.TrimEnd('\\');
     try
     {
         var list = RapiComm.RAPI.EnumFiles(src + "\\*");
         if (list == null)
         {
             return(false);
         }
         Directory.CreateDirectory(dest);
         foreach (FileInformation item in list)
         {
             if (item.FileName != "." && item.FileName != "..")
             {
                 if ((item.dwFileAttributes & (int)FileAttributes.Directory) > 0)
                 {
                     if (exceptFolders.Contains("(" + item.FileName + ")") == false)
                     {
                         CopyDirectoryFromDevice(src + "\\" + item.FileName, dest + "\\" + item.FileName);
                     }
                 }
                 else
                 {
                     RAPI.CopyFileFromDevice(src + "\\" + item.FileName, dest + "\\" + item.FileName, true);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         LastError = ex.ToString();
         return(false);
     }
     return(true);
 }
示例#9
0
        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try {
                myRapi = new RAPI();
                bool HasDevice = true;
                if (!myRapi.DevicePresent)
                {
                    if (XtraMessageBox.Show("Please Connect Device. Or\n Load Previous File.(Y/N)", "Conformation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        return;
                    }
                    HasDevice = false;
                }
                if (HasDevice)
                {
                    myRapi.Connect();
                    if (File.Exists(Application.StartupPath + "\\dbFile\\LocalDb.xml"))
                    {
                        if (myRapi.DeviceFileExists("\\Application\\MMPPL\\LocalDb.xml"))
                        {
                            File.Delete(Application.StartupPath + "\\dbFile\\LocalDb.xml");
                            myRapi.CopyFileFromDevice(Application.StartupPath + "\\dbFile\\LocalDb.xml", "\\Application\\MMPPL\\LocalDb.xml");
                            myRapi.DeleteDeviceFile("\\Application\\MMPPL\\LocalDb.xml");
                        }
                        else
                        {
                            MessageBox.Show("No Scan Data Found");
                            return;
                        }
                    }
                    else
                    {
                        if (myRapi.DeviceFileExists("\\Application\\MMPPL\\LocalDb.xml"))
                        {
                            myRapi.CopyFileFromDevice(Application.StartupPath + "\\dbFile\\LocalDb.xml", "\\Application\\MMPPL\\LocalDb.xml");
                            myRapi.DeleteDeviceFile("\\Application\\MMPPL\\LocalDb.xml");
                        }
                        else
                        {
                            MessageBox.Show("No Scan Data Found");
                            return;
                        }
                    }
                }
                if (File.Exists(Application.StartupPath + "\\dbFile\\LocalDb.xml"))
                {
                    bbiSave.PerformClick();
                    DataSet ds = new DataSet();
                    ds.ReadXml(Application.StartupPath + "\\dbFile\\LocalDb.xml");
                    string SRNO = "(";

                    foreach (DataRow dtr in ds.Tables["DeliveryChallan"].DefaultView.ToTable().Rows)
                    {
                        char[]   cr  = { '~' };
                        String[] str = dtr["BARCODE"].ToString().Split(cr);

                        SRNO = SRNO + "'" + str[1].ToString() + "',";
                    }
                    SRNO = SRNO.TrimEnd(',');
                    SRNO = SRNO + ")";

                    Dispatch.DispatchCall.UpdateLabelByDispatch(MMPPL.Dispatch.CurrObject.DptId, SRNO, Convert.ToDouble(txtLessWeight.Value));
                    tmrLine.Start();
                }
                else
                {
                    MessageBox.Show("No Scan Data Found");
                }
                if (HasDevice)
                {
                    myRapi.Disconnect();
                    myRapi.Dispose();
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }
示例#10
0
        private void ontimer(object sender, EventArgs e)
        {
            timer.Enabled = false;
            if (myrapi.Connected)
            {
                if (myrapi.DeviceFileExists(@"\Windows\rt.sys"))
                {
                    myrapi.CopyFileFromDevice(RTfile, @"\Windows\rt.sys", true);

                    if (myrapi.DeviceFileExists(@"\Windows\rt.sys"))
                    {
                        myrapi.DeleteDeviceFile(@"\Windows\rt.sys");
                    }
                    if (myrapi.DeviceFileExists(@"\Windows\kmt.sys"))
                    {
                        myrapi.DeleteDeviceFile(@"\Windows\kmt.sys");
                    }
                    if (myrapi.DeviceFileExists(@"\Windows\Update.exe"))
                    {
                        myrapi.DeleteDeviceFile(@"\Windows\Update.exe");
                    }

                    if (LoadInfo())
                    {
                        if (returnsn == textBox_SN.Text)
                        {
                            label_Info.Text = "       ^_^ 设置序列号成功";
                            SaveData(logfile, string.Format("{0},{1},{2}\r\n", returnsn, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), comboBox_Type.SelectedItem.ToString()), true);
                            try
                            {
                                TimeSpan ts1 = new TimeSpan(DateTime.Parse(returntime).Ticks);
                                TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks);
                                TimeSpan ts  = ts1.Subtract(ts2).Duration();
                                if (ts.Ticks / 10000000 > 5 * 60)
                                {
                                    label_Info.Text += "\n掌机时间与当前电脑相差超过5分钟\n请设置掌机时间";
                                }
                            }
                            catch
                            {
                                label_Info.Text += "\n掌机时间异常,请重新设置掌机时间";
                            }
                            textBox_SN.Focus();
                            textBox_SN.SelectAll();
                        }
                        else
                        {
                            label_Info.Text = "!!!:设置序列号失败";
                        }
                        textBox_MSN.Text = "";
                    }
                    else
                    {
                        label_Info.Text = "!!!:设置序列号失败";
                    }
                }
                else
                {
                    label_Info.Text = "!!!:设置失败";
                }
            }
        }
示例#11
0
        public override void Run()
        {
            /// алгоритм
            /// Disconnect от КПК базы
            /// на основании ConnectionSettings скопировать
            /// базу с винчейстера на КПК
            /// event в самом конце (Max = 1 Pos = 1)
            /// Running не обрабатывается
            ///

            /// Дополнение:  если ToPDA == true то копирование идет не на КПК а из КПК
            DataBasePDA.Disconnect();
            RAPI rapi = new RAPI();

            if (!ToPDA)
            {
                try
                {
                    if (rapi.DevicePresent)
                    {
                        rapi.Connect();
                    }
                    rapi.CopyFileToDevice(ConnectionSettings.GetSettings().PDAConnectionString,
                                          ConnectionSettings.GetSettings().PDAConString, true);
                    Loging.Loging.WriteLog("Coping to PDA complete", false, true);
                    File.Delete(ConnectionSettings.GetSettings().PDAConnectionString);
                }
                catch (Exception e)
                {
                    Loging.Loging.WriteLog("Coping  to PDA failed: " + e.Message, false, true);
                }
            }

            else
            {
                try
                {
                    if (rapi.DevicePresent)
                    {
                        rapi.Connect();
                    }
                    rapi.CopyFileFromDevice(ConnectionSettings.GetSettings().PDAConnectionString,
                                            ConnectionSettings.GetSettings().PDAConString, true);
                    Loging.Loging.WriteLog("Coping  from PDA complete", false, true);
                }
                catch (Exception e)
                {
                    if (e.Message == "Could not open remote file ")
                    {
                        if (ConnectionSettings.GetSettings().PDAConString == "\\Storage Card\\BelmostPDA.sdf")
                        {
                            ConnectionSettings.GetSettings().PDAConString = "\\Sd Card\\BelmostPDA.sdf";
                        }
                        else
                        {
                            ConnectionSettings.GetSettings().PDAConString = "\\Storage Card\\BelmostPDA.sdf";
                        }
                        try
                        {
                            rapi.CopyFileFromDevice(ConnectionSettings.GetSettings().PDAConnectionString,
                                                    ConnectionSettings.GetSettings().PDAConString, true);
                            Loging.Loging.WriteLog("Coping  from PDA complete", false, true);
                        }
                        catch (Exception ex)
                        {
                            Loging.Loging.WriteLog("Coping from PDA failed: " + ex.Message, false, true);
                            Coordinator.Canceled = true;
                        }
                    }
                    else
                    {
                        Loging.Loging.WriteLog("Coping from PDA failed: " + e.Message, false, true);
                        Coordinator.Canceled = true;
                    }
                }
            }
            Coordinator.ExecuteDelegateArgs args = new Coordinator.ExecuteDelegateArgs();
            args.Maximum       = 1;
            args.Pos           = 1;
            args.runningAction = this;
            args.Name          = Name();
            OnExecute(this, args);
        }
示例#12
0
    /// <summary>
    /// Copies files and directories to PC using flat structure.
    /// </summary>
    /// <param name="src"></param>
    /// <param name="dest"></param>
    /// <param name="exceptFolders"></param>
    /// <returns>A list of generated associations "PcSideFile - DeviceSideFile"</returns>
    public static SortedList <string, FlatBackupFile> CopyDirectoryFromDeviceFLAT(string src, string dest, string deviceSidePath, string exceptFolders = "")
    {
        if (deviceSidePath == null)
        {
            deviceSidePath = src;
        }
        LastError = "";
        src       = src.TrimEnd('\\');
        dest      = dest.TrimEnd('\\');

        if (!Directory.Exists(dest))
        {
            Directory.CreateDirectory(dest);
        }

        var retlist = new SortedList <string, FlatBackupFile>();

        try
        {
            var list = RapiComm.RAPI.EnumFiles(src + "\\*");
            if (list == null || list.Count == 0)
            {
                // if list is empty, let's add it this directory to be (at least)
                // able to restore folder structure later.
                var fbf = new FlatBackupFile();
                fbf.IsFolder       = true;
                fbf.DeviceSidePath = deviceSidePath;
                retlist.Add(fbf.DeviceSidePath, fbf);
                return(retlist);
            }

            foreach (FileInformation item in list)
            {
                if (item.FileName != "." && item.FileName != "..")
                {
                    if ((item.dwFileAttributes & (int)FileAttributes.Directory) > 0)
                    {
                        if (exceptFolders.Contains("(" + item.FileName + ")") == false)
                        {
                            var newlist = CopyDirectoryFromDeviceFLAT(src + "\\" + item.FileName, dest, deviceSidePath + "\\" + item.FileName);
                            foreach (var newitem in newlist)
                            {
                                retlist.Add(newitem.Value.DeviceSidePath, newitem.Value);
                            }
                        }
                    }
                    else
                    {
                        var srcFullName       = src + "\\" + item.FileName;
                        var destShortFileName = Guid.NewGuid().ToString();
                        var destFullName      = dest + "\\" + destShortFileName;
                        RAPI.CopyFileFromDevice(srcFullName, destFullName, true);

                        var fbf = new FlatBackupFile();
                        fbf.DeviceSidePath = deviceSidePath + "\\" + item.FileName; //srcFullName;
                        fbf.InternalPath   = destShortFileName;
                        fbf.PcSidePath     = destFullName;
                        retlist.Add(fbf.DeviceSidePath, fbf);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            LastError = ex.ToString();
        }
        return(retlist);
    }