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 <float?>("estimatedPrintTime") ?? 0;

                        JToken filament = gcodeanalysis.Value <JToken>("filament");
                        if (filament != null)
                        {
                            JToken tool0 = filament.Value <JToken>("tool0");
                            if (tool0 != null)
                            {
                                file.GcodeAnalysis.FilamentLength = tool0.Value <int?>("length") ?? -1;
                                file.GcodeAnalysis.FilamentVolume = tool0.Value <int?>("volume") ?? -1;
                            }
                        }

                        JToken dimensions = gcodeanalysis.Value <JToken>("dimensions");
                        if (dimensions != null)
                        {
                            file.GcodeAnalysis.Dimensions_Depth  = dimensions.Value <float?>("depth") ?? -1f;
                            file.GcodeAnalysis.Dimensions_Height = dimensions.Value <float?>("height") ?? -1f;
                            file.GcodeAnalysis.Dimensions_Width  = dimensions.Value <float?>("width") ?? -1f;
                        }
                    }
                    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);
                }
            }
        }
Exemple #2
0
        /// <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 OctoprintConnectionUWP(string eP, string aK) : base(eP, aK)
        {
            Position = new OctoprintPos(this);
            Files    = new OctoprintFileTracker(this);
            Jobs     = new OctoprintJobTracker(this);
            Printer  = new OctoprintPrinter(this);

            WebSocket = new WebSocket(GetWebsocketurl());
            WebSocket.ConnectAsync();
            WebSocket.OnMessage += webSocket_OnMessage;
        }
Exemple #3
0
        /// <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();
        }
Exemple #4
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);
         }
     }
 }