Console Application using OnTimeApi

93 Views Asked by At

I am trying to make a console application that will read data from our Ontime site, and can then write it to a database.

I have added a reference to OnTimeApi but I'm having difficulties with the writing portion.

Here's a portion of my code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using OnTimeApi;
using System.Net;
using System.IO;
using System.Security.Cryptography;
using System.Configuration;

namespace ConsoleApplication2
{
    class Program
    {

    static void Main(string[] args)
    {
        Settings = new Settings(
        onTimeUrl: ConfigurationManager.AppSettings.Get("OnTimeUrl"),
        clientId: ConfigurationManager.AppSettings.Get("ClientId"),
        clientSecret: ConfigurationManager.AppSettings.Get("ClientSecret")
    );

        var OnTime = new OnTime(Program.Settings);

        OnTime.ObtainAccessTokenFromUsernamePassword(
            username: "************",
            password: "************",
            scope: "read write"
        );

        var result = OnTime.Get<DataResponse<List<Project>>>("v1/projects");
        Console.WriteLine("Testing...");

        foreach (result in OnTime.GetUrl("v1/projects", null))
        {
            Console.WriteLine("{0}", file.Name);
        }
        Console.ReadLine();
        Projects.Clear();
        foreach (var project in result.data)
        {
            Projects.Add(project);
            GetFeatures(project.id);
            GetDefects(project.id);
            GetTasks(project.id);
            GetWork_Logs(project.id);
        }


    }

Trying to get it to loop through each of the different parts so it gets everything. I think it's close but I'm not sure.

1

There are 1 best solutions below

0
On BEST ANSWER

It looks like you used the wrong loop variable name in your first foreach:

    foreach (result in OnTime.GetUrl("v1/projects", null))
    {
        Console.WriteLine("{0}", file.Name);
    }

should be

    foreach (var file in OnTime.GetUrl("v1/projects", null))
    {
        Console.WriteLine("{0}", file.Name);
    }

otherwise you haven't declared file anywhere.