Skip to content

Instantly share code, notes, and snippets.

@sommereder
Created July 31, 2017 07:54
Show Gist options
  • Select an option

  • Save sommereder/d55d0fed403bf1e788418acc5f7f407d to your computer and use it in GitHub Desktop.

Select an option

Save sommereder/d55d0fed403bf1e788418acc5f7f407d to your computer and use it in GitHub Desktop.

Revisions

  1. Mario Hofer created this gist Jul 31, 2017.
    30 changes: 30 additions & 0 deletions EggPlantTaskRunner.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    public string RunTasksAndGetResponse(int pNumTasks = 0)
    {
    if (mRequestJson != null && mResponseJson != null) // check for necessary files
    {
    string lResponseString = "{\"ActionResult\":{\"Result\": \"ERROR: Timeout reached while executing eggPlant task(s).\",\"Expected\":[],\"Received\":[],\"Screenshots\":[]}}";

    Stopwatch lRequestStopwatch = Stopwatch.StartNew();
    TimeSpan lRequestTimeout = TimeSpan.FromSeconds((pNumTasks > 1 ? 5 : 10) * 60 * pNumTasks);

    string lCampaignId = CreateCampaign(mRequestJson, mResponseJson); // create campaign by requesting the API
    string lCampaignStatus = GetCampaignStatus(lCampaignId); // update campaign status

    while (lCampaignStatus != "finished" && lRequestStopwatch.Elapsed < lRequestTimeout) // while campaign not finished and timeout not reached
    {
    Console.WriteLine(lRequestStopwatch);
    lCampaignStatus = GetCampaignStatus(lCampaignId); // update campaign status
    Thread.Sleep(5 * 1000); // rest for five seconds
    }

    if (lCampaignStatus == "finished")
    {
    SaveCampaignResult(lCampaignId, mTargetFolder); // save campaign results into target folder
    lResponseString = SeparateResultFilesAndGetResponse(); // separate result and return response file as string
    }

    return lResponseString;
    }

    return null; // return null if not all requirements are met
    }