/// <summary>
        /// Ensures that the necessary data folders on the mobile device exist, creating them if necessary.
        /// </summary>
        /// <param name="rapi"></param>
        /// <param name="rootPath"></param>
        public static void CreateDataFolders(RAPI rapi, string rootPath)
        {
            // Note: Cannot have a trailing backslash when using 'CreateDeviceDirectory'

            try
            {
                // 'rootPath' may have been passed with or without a "Data\" suffix or may just have a "\" suffix
                // Either way, we need to have just the bare root folder name before we can move forward
                if (rootPath.EndsWith(@"\"))
                {
                    rootPath = rootPath.Substring(0, rootPath.Length - 1);
                }
                if (rootPath.ToLower().EndsWith(@"data"))
                {
                    rootPath = rootPath.Substring(0, rootPath.Length - 4);
                }
                if (rootPath.EndsWith(@"\"))
                {
                    rootPath = rootPath.Substring(0, rootPath.Length - 1);
                }

                if (!rapi.DeviceFileExists(rootPath))
                {
                    rapi.CreateDeviceDirectory(rootPath);
                }

                string dataPath = rootPath + @"\Data";

                if (!rapi.DeviceFileExists(dataPath))
                {
                    rapi.CreateDeviceDirectory(dataPath);
                }

                if (!rapi.DeviceFileExists(dataPath + @"\Completed"))
                {
                    rapi.CreateDeviceDirectory(dataPath + @"\Completed");
                }

                if (!rapi.DeviceFileExists(dataPath + @"\Templates"))
                {
                    rapi.CreateDeviceDirectory(dataPath + @"\Templates");
                }
            }

            catch (Exception e)
            {
                if (e.Message.Trim().ToLower() == "could not create directory")
                {
                    string msg = "Could not create data folders for some unknown reason.\n\nPlease reset your mobile device and try again.";
                    Tools.ShowMessage(msg, "Error Creating Data Folders");
                }
                else
                {
                    Tools.ShowMessage(e.Message, "Error Creating Data Folders");
                }
            }
        }
예제 #2
0
    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);
    }
        /// <summary>
        /// Simply makes sure that the "\Temp" folder in main memory exists on the connected mobile device.  This
        /// folder is where the CAB setup files are temporarily copied to before they are executed and then erased.
        /// </summary>
        /// <param name="rapi"></param>
        /// <param name="ExitMsgShown"></param>
        /// <returns></returns>
        public static bool TempFolderExists(RAPI rapi, ref bool ExitMsgShown)
        {
            try
            {
                if (!rapi.DeviceFileExists(@"\Temp"))
                {
                    rapi.CreateDeviceDirectory(@"\Temp");
                }
            }
            catch
            {
                if (!ExitMsgShown)
                {
                    ExitMsgShown = true;
                    Tools.ShowMessage(@"Can't create '\Temp' directory on the mobile device.  Please reset device and try again.", "Error with Mobile Device");
                }
                return(false);
            }

            return(true);
        }
예제 #4
0
 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);
 }
예제 #5
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.");
                    }
                }
            }
        }