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); } } }
/// <summary> /// Creates a <see cref="T:OctoprintClient.OctoprintConnection"/> /// </summary> /// <param name="eP">The endpoint Address like "http://192.168.1.2/"</param> /// <param name="aK">The Api Key of the User account you want to use. You can get this in the user settings</param> public OctoprintConnection(string eP, string aK) { SetEndPointDirty(eP); ApiKey = aK; Position = new OctoprintPosTracker(this); Files = new OctoprintFileTracker(this); Jobs = new OctoprintJobTracker(this); Printers = new OctoprintPrinterTracker(this); //source = new CancellationTokenSource(); //token = source.Token; var canceltoken = CancellationToken.None; WebSocket = new ClientWebSocket(); WebSocket.ConnectAsync(new Uri("ws://" + EndPoint.Replace("https://", "").Replace("http://", "") + "sockjs/websocket"), canceltoken).GetAwaiter().GetResult(); // //Correct format should be // WebSocket.ConnectAsync(new Uri("ws://192.168.1.41:5000/sockjs/websocket"), canceltoken).GetAwaiter().GetResult(); }