コード例 #1
0
 RAPI m_objRAPI; //= new RAPI();
 private void StartTheThread()
 {
     try
     {
         try
         {
             m_objRAPI.Connect();
             if (m_objRAPI.DevicePresent)
             {
                 if (PublicClass.currentInstrument == "Impaq-Benstone")
                 {
                     m_objRAPI.CopyFileToDevice(PathToUpLoad, @"\Storage Card\ImpaqElite" + CValues.SCONSTDCD + PublicClass.routename + CValues.SCONSTDBF, true);
                 }
                 else
                 {
                     m_objRAPI.CopyFileToDevice(PathToUpLoad, @"\Storage Card\FieldpaqII" + CValues.SCONSTDCD + PublicClass.routename + CValues.SCONSTDBF, true);
                 }
             }
         }
         catch (Exception ex)
         {
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.Message, ex.StackTrace);
     }
 }
コード例 #2
0
 public bool D_PCTransferFileToHHT()
 {
     try
     {
         string fileToPushToDevice = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName + "\\" + DBName;
         //string fileToPushToDevice = "D:\\TestDB1.sdf";
         string remotePath = HHTDBPath + DBName;
         rapi.CopyFileToDevice(fileToPushToDevice, remotePath, true);
         return(true);
     }
     catch (Exception ex)
     {
         log.Error(String.Format("Exception : {0}", ex.StackTrace));
         Console.Error.WriteLine("Error from D_PCTransferFileToHHT");
         return(false);
     }
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: radtek/pdaexport
        public static void Copy(String path)
        {
            RAPI r = new RAPI();

            try
            {
                if (r.DevicePresent)
                {
                    r.Connect();
                    Consoler("Copying database to PDA. Wait...");
                    r.CopyFileToDevice(path, path2device, true);
                    FileDeleter(pathbase);
                }
                else
                {
                    Consoler("No Device Connected");
                    Log("No Device Connected", logpath);
                }
            }
            catch (Exception e)
            {
                if (e.Message == "Could not create remote file ")
                {
                    path2device = "\\Sd Card\\BelmostPDA.sdf";
                }
                try
                {
                    Consoler("Copying database to PDA. Wait...");
                    r.CopyFileToDevice(path, path2device, true);
                    FileDeleter(pathbase);
                }
                catch (Exception ex)
                {
                    Consoler(ex.Message);
                    Log(ex.Message, logpath);
                }
            }
        }
コード例 #4
0
        private void CopyTest_Click(object sender, EventArgs e)
        {
            // Perform the copy.
            string name            = textBox1.Text;
            string CopyDestination = textBox2.Text;

            try
            {
                rapi.CopyFileToDevice(name, CopyDestination, true);
                MessageBox.Show("Ваш файл скопирован.", "Copy Success");
            }

            // Handle any errors that might occur.
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка подключения" + " - " + ex.Message,
                                "Copy Error");
            }
        }
コード例 #5
0
ファイル: RapiComm.cs プロジェクト: dynamics7/wpbackup
    public static bool CopyFileToDeviceFLAT(SortedList <string, FlatBackupFile> list, string fileName, string destFileName = null)
    {
        string temp = fileName.ToLower();

        foreach (var item in list)
        {
            var file = item.Value;
            if (file.DeviceSidePath.ToLower().StartsWith(temp))
            {
                if (destFileName == null)
                {
                    destFileName = file.DeviceSidePath;
                }
                RAPI.CopyFileToDevice(file.PcSidePath, destFileName, true);
                return(true);
            }
        }
        return(false);
    }
コード例 #6
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");
     }
 }
コード例 #7
0
ファイル: MainForm.cs プロジェクト: DenSamara/CopyFileRAPI
        public bool CopyToDevice(String localFileName, String remoteFileName)
        {
            bool res = true;

            try
            {
                m_RAPI.CopyFileToDevice(localFileName, remoteFileName, true);
            }
            catch (FileNotFoundException)
            {
                lbStatus.Text = "файл не найден: " + localFileName;
                res           = false;
            }
            catch (Exception ex)
            {
                lbStatus.Text = ex.Message;
                res           = false;
            }
            return(res);
        }
コード例 #8
0
ファイル: RapiComm.cs プロジェクト: dynamics7/wpbackup
    public static bool CopyDirectoryToDeviceFLAT(SortedList <string, FlatBackupFile> list, string folderPath, string dest, string exceptFolders = "")
    {
        LastError = "";

        try
        {
            RAPI.CreateDeviceDirectory(dest);
            foreach (var item in list)
            {
                var file = item.Value;
                if (file.DeviceSidePath.ToLower().StartsWith(folderPath.ToLower()))
                {
                    if (String.IsNullOrEmpty(dest))
                    {
                        dest = folderPath;
                    }
                    else
                    {
                        dest = dest.TrimEnd('\\');
                    }
                    if (file.IsFolder)
                    {
                        RAPI.CreateDeviceDirectory(dest);
                    }
                    else
                    {
                        folderPath = folderPath.TrimEnd('\\');
                        var relativePath = file.DeviceSidePath.Substring(folderPath.Length);
                        RAPI.CopyFileToDevice(file.PcSidePath, dest + relativePath, true);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            LastError = ex.ToString();
            Console.WriteLine(ex.ToString() + "\n");
            return(false);
        }
        return(true);
    }
コード例 #9
0
 public static void CopyFileToDevice(String SourcePath, String DestinationPath, bool Overwrite)
 {
     try
     {
         if (rapi.DevicePresent)
         {
             if (!rapi.Connected)
             {
                 rapi.Connect();
             }
             try
             {
                 RAPI.RAPIFileAttributes rattr = rapi.GetDeviceFileAttributes(DestinationPath);
                 if ((rattr & RAPI.RAPIFileAttributes.Directory).Equals(RAPI.RAPIFileAttributes.Directory))   //if destination path exist and it's a directory
                 {
                     FileAttributes attr = File.GetAttributes(SourcePath);
                     if (!(attr & FileAttributes.Directory).Equals(FileAttributes.Directory))                   //if source path is not a directory.
                     {
                         DestinationPath = DestinationPath.TrimEnd('\\') + '\\' + Path.GetFileName(SourcePath); //Append the file name after the destination directory
                     }
                 }
             }
             catch
             {
                 //if destination path is a non-existing file, it's a normal situation, do nothing.
             }
             rapi.CopyFileToDevice(SourcePath, DestinationPath, Overwrite);
             if (rapi != null && rapi.Connected)
             {
                 rapi.Disconnect();
             }
         }
     }
     catch (Exception ex)
     {
         System.Windows.Forms.MessageBox.Show(ex.Message + " ; \r\n" + ex.StackTrace);
     }
 }
コード例 #10
0
ファイル: RapiComm.cs プロジェクト: dynamics7/wpbackup
 public static bool CopyDirectoryToDevice(string src, string dest, string exceptFolders = "")
 {
     LastError = "";
     src       = src.TrimEnd('\\');
     dest      = dest.TrimEnd('\\');
     try
     {
         RAPI.CreateDeviceDirectory(dest);
         var files = Directory.GetFiles(src);
         foreach (var file in files)
         {
             string shortName = file;
             if (shortName.Contains("\\"))
             {
                 shortName = shortName.Substring(shortName.LastIndexOf("\\") + 1);
             }
             RAPI.CopyFileToDevice(file, dest + "\\" + shortName, true);
         }
         var folders = Directory.GetDirectories(src);
         foreach (var folder in folders)
         {
             string shortName = folder;
             if (shortName.Contains("\\"))
             {
                 shortName = shortName.Substring(shortName.LastIndexOf("\\") + 1);
             }
             RAPI.CreateDeviceDirectory(dest + "\\" + shortName);
             CopyDirectoryToDevice(folder, dest + "\\" + shortName);
         }
     }
     catch (Exception ex)
     {
         LastError = ex.ToString();
         Console.WriteLine(ex.ToString() + "\n");
         return(false);
     }
     return(true);
 }
コード例 #11
0
        /// <summary>
        /// Testing of rapi.CopyFileToDevice revealed that if the connection is broken that a subsequent attempt, without first shutting
        /// down this application, will cause rapi.CopyFileToDevice to fail because of a locking problem with the source file.
        /// This method resolves this problem.  It's also possible that the destination file already exists and is locked.
        ///
        /// Note: Code has been introduced to explicitly set the time of the copied file to be identical to that on the desktop
        ///       but it doesn't seem to work correctly, with the time equivalent to GMT-8.  This must be a bug within RAPI.
        /// </summary>
        /// <param name="rapi"></param>
        /// <param name="srcPath"></param>         // The path on the desktop
        /// <param name="fileName"></param>
        /// <param name="destPath"></param>        // The path on the mobile device
        /// <param name="ExitMsgShown"></param>    // A flag in DataXfer that prevents multiple message boxes from being shown
        /// <returns></returns>
        public static bool CopyFileToDevice(RAPI rapi, string srcPath, string fileName, string destPath, ref bool ExitMsgShown)
        {
            srcPath  = Tools.EnsureFullPath(srcPath);
            destPath = Tools.EnsureFullPath(destPath);
            string tmpPath = SysInfo.Data.Paths.Temp; // {Temp Directory} + AppFilename

            try
            {
                DateTime dateTimeInfo = File.GetLastWriteTime(srcPath + fileName);

                if (CheckSourceFileAccess(srcPath + fileName))
                {
                    // There appear to be no problems copying file directly
                    rapi.CopyFileToDevice(srcPath + fileName, destPath + fileName, true); // Copy file to device, overwriting if necessary
                }
                else // File is definitely locked (to RAPI copy function) so use more complex approach
                {
                    // First see if we can just copy the locked file directly to Temp directory
                    if (!File.Exists(tmpPath + fileName))
                    {
                        File.Copy(srcPath + fileName, tmpPath + fileName);
                        rapi.CopyFileToDevice(tmpPath + fileName, destPath + fileName, true); // Copy file to device, overwriting if necessary
                    }
                    else // This file is locked too so find a free filename we can use
                    {
                        int    sepCharPos = fileName.LastIndexOf(".");
                        string origName   = fileName.Substring(0, sepCharPos);
                        string origExt    = fileName.Substring(sepCharPos);
                        string newName    = "";

                        int i = 1;
                        do
                        {
                            if (!File.Exists(tmpPath + origName + i.ToString() + origExt))
                            {
                                newName = origName + i.ToString() + origExt;
                            }
                            else
                            {
                                i++;
                            }
                        } while (newName == "");

                        File.Copy(srcPath + fileName, tmpPath + newName);

                        if (rapi.DeviceFileExists(destPath + fileName))
                        {
                            rapi.DeleteDeviceFile(destPath + fileName);
                        }

                        rapi.CopyFileToDevice(tmpPath + newName, destPath + fileName, true); // Copy file to device, overwriting if necessary
                    }
                }

                // If there's an error setting the device filetime then handle separately
                try
                {
                    // Note: One would think that these next 2 statements would set the correct time of the file on the mobile device but they don't appear to. :-(
                    //       The datestamp on the device file seems to be in a different time zone.
                    rapi.SetDeviceFileTime(destPath + fileName, RAPI.RAPIFileTime.CreateTime, dateTimeInfo);
                    rapi.SetDeviceFileTime(destPath + fileName, RAPI.RAPIFileTime.LastModifiedTime, dateTimeInfo);
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Error setting device filetime.  Message: " + e.Message);
                }
            }

            catch (Exception e)
            {
                if (!ExitMsgShown)
                {
                    ExitMsgShown = true;
                    string msg = "Error copying file to mobile device" + "\n" + e.Message;
                    msg += "\n\nSource Path: " + srcPath;
                    msg += "\nDest Path: " + destPath;
                    msg += "\nFilename: " + fileName;
                    msg += "\n\nPlease reconnect and try again!";

                    Debug.WriteLine(msg);
                    Tools.ShowMessage(msg, SysInfo.Data.Admin.AppName);
                }
                return(false);
            }

            return(true);
        }
コード例 #12
0
        private void textBox_SN_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
            case Keys.Enter:
                Cursor          = Cursors.WaitCursor;
                label_Info.Text = "";
                try
                {
                    if ((6 < textBox_MSN.Text.Length) && (textBox_MSN.Text.Equals(textBox_SN.Text)) /*&& IsNumberic(textBox_SN.Text)*/)
                    {
                        string sType = "";
                        switch (comboBox_Type.SelectedItem.ToString())
                        {
                        case "K36掌机":
                            sType = Convert.ToString(1300 << 16, 16);
                            break;

                        case "K25全能终端":
                            sType = Convert.ToString(1100 << 16, 16);
                            break;

                        case "P31全能终端":
                            sType = Convert.ToString(1200 << 16, 16);
                            break;

                        case "P31抄表终端":
                            sType = Convert.ToString(1201 << 16, 16);
                            break;

                        case "P31用电检查终端":
                            sType = Convert.ToString(1202 << 16, 16);
                            break;

                        case "P31计量维护终端":
                            sType = Convert.ToString(1203 << 16, 16);
                            break;

                        case "P31应急处理终端":
                            sType = Convert.ToString(1204 << 16, 16);
                            break;

                        default:
                            break;
                        }
                        SaveData(SNfile, string.Format("{0},{1},{2},{3},{4},{5}\r\n",
                                                       System.DateTime.Now.ToString("yyyy-MM-dd"), //"2011-06-15",//strDate,
                                                       textBox_MSN.Text,                           //strSN,
                                                       "WinCE",                                    //strDescription,
                                                       sType,                                      //strVer,
                                                       "30.40",                                    //"24.32",//strZB,
                                                       "80.21"                                     //"80.20"//strFB
                                                       ), false);
                        if (!myrapi.Connected)
                        {
                            ActiveSync_Active();
                        }
                        System.Threading.Thread.Sleep(100);
                        if (myrapi.Connected)
                        {
                            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");
                            }

                            myrapi.CopyFileToDevice(SNfile, @"\Windows\kmt.sys", true);
                            myrapi.CopyFileToDevice(Runfile, @"\Windows\Update.exe", true);
                            myrapi.CreateProcess(@"\Windows\Update.exe", "");


                            timer.Enabled = true;
                        }
                        else
                        {
                            label_Info.Text = "!!!:设备未连接";
                        }
                    }
                    else
                    {
                        label_Info.Text = "!!!:输入不正确";
                        textBox_MSN.Focus();
                        textBox_MSN.SelectAll();
                    }
                }
                catch
                {
                    label_Info.Text = "!!!:运行异常";
                }

                Cursor = Cursors.Default;
                break;
            }
        }
コード例 #13
0
ファイル: ActionDeploy.cs プロジェクト: radtek/pdaexport
        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);
        }
コード例 #14
0
        private void saveGoogleMapToDevice()
        {
            if (this.deviceMapDirectory != null)
            {
                Object[] obj = new Object[2];
                obj[0] = (Object)deviceWidth;
                obj[1] = (Object)deviceHeight;

                HtmlDocument doc = webBrowserMap.Document;
                Object       url = webBrowserMap.Document.InvokeScript("loadImageWithParam", obj);

                StringBuilder builder = new StringBuilder();
                builder.Append(this.textBoxFileName.Text);
                builder.Append(".png");
                String localFileName = builder.ToString();

                if (this.DownloadFile(url.ToString(), localFileName) > 0)
                {
                    builder = new StringBuilder();
                    builder.Append(this.textBoxFileName.Text);
                    builder.Append(".xml");

                    ImageOptions iOpt = new ImageOptions();
                    iOpt.Name        = this.textBoxFileName.Text.Trim();
                    iOpt.Description = this.textBoxFileDescription.Text.Trim();

                    if (webBrowserMap.Document != null)
                    {
                        doc = webBrowserMap.Document;
                        Object temp;
                        temp       = doc.InvokeScript("getSWLatitude");
                        iOpt.SWLat = float.Parse(temp.ToString());
                        iOpt.SELat = float.Parse(temp.ToString());

                        temp        = doc.InvokeScript("getSWLongitude");
                        iOpt.SWLong = float.Parse(temp.ToString());

                        temp       = doc.InvokeScript("getNELatitude");
                        iOpt.NELat = float.Parse(temp.ToString());

                        temp        = doc.InvokeScript("getNELongitude");
                        iOpt.NELong = float.Parse(temp.ToString());
                        iOpt.SELong = float.Parse(temp.ToString());

                        temp           = doc.InvokeScript("getZoomLevel");
                        iOpt.ZoomLevel = int.Parse(temp.ToString());
                    }

                    this.writeSettingsToXML(builder.ToString(), iOpt);

                    try
                    {
                        if (!rapi.DeviceFileExists(this.deviceMapDirectory))
                        {
                            rapi.CreateDeviceDirectory(this.deviceMapDirectory);
                        }
                        rapi.CopyFileToDevice(localFileName, this.deviceMapDirectory + @"\" + localFileName, true);
                        rapi.CopyFileToDevice(builder.ToString(), this.deviceMapDirectory + @"\" + localFileName, true);
                        File.Delete(localFileName);
                        File.Delete(builder.ToString());
                        this.textBoxFileDescription.Clear();
                        this.textBoxFileName.Clear();
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("DirectCopy Not Succesfull. You need To copy manually.");
                    }
                }
            }
        }