Exemple #1
0
        /// <summary>
        ///     Get the CardId
        /// </summary>
        /// <returns>CardId</returns>
        public string GetCid()
        {
            string command  = $"{AddSlash(Settings.FlashAirUrl)}{CommandPrefix}{(int) CommandIds.Cid}";
            var    contents = new LongRunningWebClient().DownloadString(command);

            return(contents);
        }
Exemple #2
0
        /// <summary>
        /// Set Upload Directory for following uploads
        /// </summary>
        /// <param name="directory">Directory</param>
        /// <returns>Connection State</returns>
        public bool SetUploadDirectory(string directory)
        {
            string command  = $"{AddSlash(Settings.FlashAirUrl)}{UploadPrefix}?WRITEPROTECT=ON&UPDIR={directory}";
            var    contents = new LongRunningWebClient().DownloadString(command);

            return(contents == "SUCCESS");
            //  http://flashair/upload.cgi?UPDIR=/DCIM/101__TSB
        }
Exemple #3
0
        /// <summary>
        ///     Get number of files from a directory
        /// </summary>
        /// <param name="path">directory</param>
        /// <returns>number of files</returns>
        public int GetFileCount(string path)
        {
            int    count;
            string targetUrl  = $"{AddSlash(Settings.FlashAirUrl)}{CommandPrefix}{(int) CommandIds.NumberOfFiles}&DIR={path}";
            var    imageCount = new LongRunningWebClient(10).DownloadString(targetUrl);

            int.TryParse(imageCount, out count);
            return(count);
        }
Exemple #4
0
        /// <summary>
        ///     Get File Informations
        /// </summary>
        /// <param name="path">Directory</param>
        /// <returns>List of Fileinformations</returns>
        public List <FlashAirFileInformation> GetFiles(string path)
        {
            string targetUrl = $"{AddSlash(Settings.FlashAirUrl)}{CommandPrefix}{(int) CommandIds.Files}&DIR={path}";
            var    allFiles  = new LongRunningWebClient().DownloadString(targetUrl);

            if (string.IsNullOrWhiteSpace(allFiles))
            {
                return(null);
            }

            return(allFiles.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Select(file => new FlashAirFileInformation(file)).Where(fileInformation => fileInformation.Filename != null).ToList());
        }
Exemple #5
0
 /// <summary>
 ///     Delete a single file
 /// </summary>
 /// <param name="path">Directory</param>
 /// <param name="filename">File</param>
 /// <returns>Successstatus</returns>
 public bool DeleteFile(string path, string filename)
 {
     //   http: //flashair/upload.cgi?DEL=/DCIM/100__TSB/DSC_100.JPG
     try
     {
         string command     = $"{AddSlash(Settings.FlashAirUrl)}upload.cgi?DEL={AddSlash(path)}{filename}";
         var    returnValue = new LongRunningWebClient(10, 5).DownloadString(command);
         _log.Debug($"Deletion successful for {filename}. Return:{returnValue}");
         return(true);
     }
     catch (Exception ex)
     {
         _log.Error(ex);
         return(false);
     }
 }
Exemple #6
0
 /// <summary>
 ///     Download a single File
 /// </summary>
 /// <param name="directory">Directory</param>
 /// <param name="filename">Filename</param>
 /// <returns>Stream of the file</returns>
 public Stream DownloadFile(string directory, string filename)
 {
     try
     {
         if (directory.StartsWith("/"))
         {
             directory = directory.Substring(1);
         }
         string command = $"{AddSlash(Settings.FlashAirUrl)}{AddSlash(directory)}{filename}";
         var    stream  = new LongRunningWebClient(120, 3).OpenRead(command);
         _log.Debug($"Image {filename} downloaded");
         return(stream);
     }
     catch (Exception ex)
     {
         _log.Error(ex);
         throw;
     }
 }