コード例 #1
0
        public void Post()
        {
            try
            {
                var json = JToken.Parse(Request.ContentString);
                var url  = json["url"].Value <string>();

                var reply = new
                {
                    @result       = SoftwareUpdate.Status.ToString(),
                    @progress     = SoftwareUpdate.Progress,
                    @progress_url = Request.Path + "/progress"
                };

                Request.Response.Header.ContentType = "application/json";
                Request.Response.ContentString      = JToken.FromObject(reply).ToString(Formatting.Indented);
                //Request.Response.FinalizeHeader();

                new Thread(specific =>
                {
                    if (SoftwareUpdate.Download(url) == 0)
                    {
                        SoftwareUpdate.OnUpdateShouldLoad();
                    }
                    return(null);
                }, null)
                {
                    Priority = Thread.eThreadPriority.LowestPriority
                };
            }
            catch (Exception e)
            {
                HandleError(e);
            }
        }
コード例 #2
0
        public override void Get()
        {
            try
            {
                var model = Request.QueryString["model"];
                if (string.IsNullOrEmpty(model))
                {
                    HandleError(400, "Bad Request", "No or invalid model of panel specified");
                    return;
                }

                model = model.ToUpper();

                var version = Request.QueryString["version"];
                if (string.IsNullOrEmpty(version))
                {
                    HandleError(400, "Bad Request", "No or invalid version of file specified");
                    return;
                }

                var fileInfo = SoftwareUpdate.GetPanelUpdates()
                               .FirstOrDefault(
                    f => f["version"].Value <string>() == version && f["model"].Value <string>() == model);

                if (fileInfo == null)
                {
                    HandleError(404, "Not Found", "Update server could not find any files suitable");
                    return;
                }

                Request.Response.Header.ContentType = "application/json";
                Request.Response.ContentSource      = ContentSource.ContentString;
                var files = new List <object>
                {
                    new
                    {
                        @fileUrl     = fileInfo["file_url"].Value <string>(),
                        @fileHashUrl = fileInfo["hash_file_url"].Value <string>(),
                        @fileType    = "project"
                    }
                };

                if (Regex.IsMatch(model, @"TSW-\d{1,2}60"))
                {
                    files.Add(new
                    {
                        @fileUrl =
                            string.Format("http://{0}/updatefiles/tsw-xx60_2.001.0040.001.puf",
                                          SoftwareUpdate.ServerAddress),
                        @fileHashUrl =
                            string.Format("http://{0}/updatefiles/tsw-xx60_2.001.0040.001.puf.hash",
                                          SoftwareUpdate.ServerAddress),
                        @fileType = "firmware"
                    });
                }

                var data = new[]
                {
                    new
                    {
                        @deviceHostname = "*",
                        @deviceModel    = model,
                        @filesToUpdate  = files
                    }
                };
                Request.Response.ContentString = JToken.FromObject(data).ToString(Formatting.Indented);
            }
            catch (Exception e)
            {
                HandleError(e);
            }
        }