简体   繁体   English

更改代码以通过单击按钮运行将无法正常工作

[英]Changing the code to run by button click won't work

I'm working on a project for astrophotography using plate solving service from http://nova.astrometry.net/ 我正在使用来自http://nova.astrometry.net/的印版求解服务进行天文摄影项目

I found AstrometryNetClient (here: https://github.com/elendil-software/AstrometryNetClient ) I've managed to make it works for me with some changes in code, and it works just fine. 我找到了AstrometryNetClient(在这里: https : //github.com/elendil-software/AstrometryNetClient ),我设法通过一些代码更改使它对我有效,并且很好用。

My problem is when I changed it to run when I click a button it does not work for some reason! 我的问题是,当我单击按钮将其更改为运行时,由于某种原因它不起作用!

It stops at this line: var res = client.Login(); 它在此行停止: var res = client.Login();

I think the problem is in the previous line: var client = new Client(apiKey); 我认为问题出在前一行: var client = new Client(apiKey); , because when I use F11 to check the code it shows "Connected = false" which means that there is something wrong login in to http://nova.astrometry.net/api/ ,因为当我使用F11检查代码时,它显示“ Connected = false”,这意味着登录http://nova.astrometry.net/api/时出现错误

This is the original code: 这是原始代码:

using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using software.elendil.AstrometryNet;
using software.elendil.AstrometryNet.Enum;
using software.elendil.AstrometryNet.Json;

namespace Test
{
  internal static class Program
  {
    private static void Main(string[] args)
    {
      const string apiKey = "astrometrynetapikey";
      const string file = "test.fit";
      try
      {
        var client = new Client(apiKey);
        var res = client.Login();
        Console.WriteLine("Login : " + res.status);
        CancellationTokenSource tokenSource = new 
 CancellationTokenSource();
        CancellationToken token = tokenSource.Token;

        var uploadArguments = new UploadArgs 
     {publicly_visible = Visibility.n};
        var uploadResponse = client.Upload(file, uploadArguments);

        Task<SubmissionStatusResponse> 
submissionStatusResponse = client.GetSubmissionStatus(uploadResponse.subid, token);
        Task<JobStatusResponse> jobStatusResponse = 
client.GetJobStatus(submissionStatusResponse.Result.jobs[0], token);

        if (jobStatusResponse.Result.status.Equals(ResponseJobStatus.success))
        {
          var calibrationResponse = client.GetCalibration(submissionStatusResponse.Result.jobs[0]);
          var objectsInFieldResponse = client.GetObjectsInField(submissionStatusResponse.Result.jobs[0]);

          Console.WriteLine("\nRA : " + calibrationResponse.ra);
          Console.WriteLine("Dec : " + calibrationResponse.dec);
          Console.WriteLine("radius : " + calibrationResponse.radius);
          Console.WriteLine("");
          foreach (string obj in objectsInFieldResponse.objects_in_field)
          {
            Console.WriteLine(obj);
          }
        }
        else
        {
          Console.WriteLine("Status : " + jobStatusResponse.Result.status);
        }
      }
      catch (Exception e)
      {
        Console.WriteLine(e.Message);
      }
      finally
      {
        Console.ReadKey();
      }
    }
  }
}

I think I've found a solution, It seems that I needed to install Newtonsoft.Json and it works just fine now. 我想我已经找到了解决方案,似乎我需要安装Newtonsoft.Json,现在工作正常。 Thanks everybody for your support! 感谢大家的支持!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM