예제 #1
0
        /// <summary>
        /// Gets certain file informations
        /// </summary>
        /// <returns>The file Informations.</returns>
        /// <param name="path">The path to the Folder or File.</param>
        public OctoprintFolder GetFiles(string path)
        {
            string jobInfo = "";

            try
            {
                jobInfo = Connection.Get("api/files" + path);
            }
            catch (WebException e)
            {
                switch (((HttpWebResponse)e.Response).StatusCode)
                {
                case HttpStatusCode.NotFound:
                    Debug.WriteLine("searched for a file that wasn't there at " + path);
                    return(null);
                }
            }
            JObject         data   = JsonConvert.DeserializeObject <JObject>(jobInfo);
            OctoprintFolder folder = new OctoprintFolder(data, this)
            {
                Name = data.Value <String>("name") ?? "", Path = data.Value <String>("path") ?? "", Type = "folder"
            };

            return(folder);
        }
예제 #2
0
        /// <summary>
        /// Gets all the files on the Server
        /// </summary>
        public OctoprintFolder GetFiles()
        {
            string          jobInfo    = Connection.Get("api/files");
            JObject         data       = JsonConvert.DeserializeObject <JObject>(jobInfo);
            OctoprintFolder rootfolder = new OctoprintFolder(data, this)
            {
                Name = "root", Path = "/", Type = "root"
            };

            return(rootfolder);
        }
예제 #3
0
 public OctoprintFolder(JObject data, OctoprintFileTracker t)
 {
     octoprintFolders = new List <OctoprintFolder>();
     octoprintFiles   = new List <OctoprintFile>();
     foreach (JObject filedata in data["files"])
     {
         if ((string)filedata["type"] == "folder")
         {
             OctoprintFolder folder = t.GetFiles((string)filedata["path"]);
             octoprintFolders.Add(folder);
         }
         else
         {
             OctoprintFile file = new OctoprintFile(filedata);
             JToken        refs = filedata.Value <JToken>("refs");
             if (refs != null)
             {
                 file.Refs_resource = refs.Value <String>("resource") ?? "";
                 file.Refs_download = refs.Value <String>("download") ?? "";
             }
             JToken gcodeanalysis = filedata.Value <JToken>("gcodeAnalysis");
             if (gcodeanalysis != null)
             {
                 file.GcodeAnalysis_estimatedPrintTime = gcodeanalysis.Value <int?>("estimatedPrintTime") ?? 0;
                 JToken filament = gcodeanalysis.Value <JToken>("filament");
                 if (filament != null)
                 {
                     file.GcodeAnalysis_filament_length = filament.Value <int?>("length") ?? -1;
                     file.GcodeAnalysis_filament_volume = filament.Value <int?>("volume") ?? -1;
                 }
             }
             JToken print = filedata.Value <JToken>("print");
             if (print != null)
             {
                 file.Print_failure = print.Value <int?>("failure") ?? -1;
                 JToken last = print.Value <JToken>("last");
                 if (last != null)
                 {
                     file.Print_last_date    = last.Value <int>("date");
                     file.Print_last_success = last.Value <bool>("success");
                 }
             }
             octoprintFiles.Add(file);
         }
     }
 }