/// <summary>
 /// Converts a Yaml value type to a Json value type
 /// </summary>
 /// <param name="sampleYaml">A YAML value type</param>
 /// <returns>A JSON value type</returns>
 private SampleJsonVT ConvertYamlToJsonObject(SampleYamlVT sampleYaml)
 {
     try
     {
         var sampleJson = new SampleJsonVT
         {
             GalleryType      = GALLERYTYPESAMPLE,
             DateCreated      = DateTime.Now.ToLongDateString(),
             Description      = sampleYAML.sample[0].description,
             Id               = Guid.Empty,                      //todo this is either generated, or need to match with an existing one in json file passed in for comparison.
             Languages        = sampleYaml.sample[0].languages,
             LastModifiedBy   = LASTMODIFIEDBY,                  //todo
             LastModifiedDate = DateTime.Now.ToLongDateString(), //todo
             Products         = sampleYaml.sample[0].extensions.products,
             Recommended      = RECOMMENDED,
             Technologies     = sampleYaml.sample[0].technologies,
             Thumbnail        = "",//todo
             Title            = sampleYaml.sample[0].name,
             Scenarios        = sampleYaml.sample[0].extensions.scenarios,
             Url              = sampleYaml.sample[0].path//todo add http protocol
         };
         return(sampleJson);
     }
     catch (Exception e)
     {
         Console.WriteLine("Could not convert YAML to JSON for: " + sampleYaml.sample[0].name);
         Console.WriteLine("   Error message: " + e.Message);
         return(null);
     }
 }
        /// <summary>
        /// add a sample to the file representation. This will check if the sample already exists, and if so just update it.
        /// </summary>
        /// <param name="sampleJSON">The new sample to add</param>
        public void AddSampleToJSON(SampleJsonVT sampleJSON)
        {
            //check if sample already exists searching through existing array of samples
            int loc = IndexOf(sampleJSON.Url);

            if (loc >= -0)
            {
                //update the existing sample
                //Note: this should not set datecreated or ID or URL as these should never change

                //TODO This will not set the LastModifiedBy, LastModifiedDate, or Thumbnail for now
                sample.allSamples[loc].Description      = sampleJSON.Description;
                sample.allSamples[loc].Languages        = sampleJSON.Languages;
                sample.allSamples[loc].Products         = sampleJSON.Products;
                sample.allSamples[loc].Recommended      = sampleJSON.Recommended;
                sample.allSamples[loc].Technologies     = sampleJSON.Technologies;
                sample.allSamples[loc].Title            = sampleJSON.Title;
                sample.allSamples[loc].LastModifiedBy   = sampleJSON.LastModifiedBy;
                sample.allSamples[loc].LastModifiedDate = DateTime.Now.ToString("MM/dd/yyyy h:mm:ss tt");
            }
            else
            {
                //create a new sample
                sampleJSON.Id = Guid.NewGuid(); //new samples need a new guid (otherwise this is all 0000's)
                sample.allSamples.Add(sampleJSON);
            }
        }
        /// <summary>
        /// imports YAML from a file on GitHub and converts to internal representations to store both YAML and JSON for future operations.
        /// </summary>
        /// <param name="org">Name of the org on GitHub (such as "OfficeDev")</param>
        /// <param name="repoName">Name of the repo on GitHub (such as "Add-in-Sample")</param>
        /// <param name="path">Path name of the file on GitHub (such as "/sample.yml")</param>
        public void ImportYAMLFromGitHubFile(string org, string repoName, string path)
        {
            try
            {
                //TODO this should throw an error if the file is not found, or does not have correct YAML
                // string testContent = "### YamlMime:Sample\nsample:\r\n- name: 'Skype for Business: Healthcare app'\r\n  path: HealthcareApp\r\n  description: Skype for Android Healthcare app sample.\r\n  readme: ''\r\n  generateZip: FALSE\r\n  isLive: TRUE\r\n  technologies:\r\n  - Office Add-in\r\n  azureDeploy: ''\r\n  author: JohnAustin-MSFT\r\n  platforms: []\r\n  languages:\r\n  - Java\r\n  extensions:\r\n    products:\r\n    - Skype for Business\r\n    scenarios: []\r\n";

                //get file contents.
                var repoSample = GitHubManager.instance.client.Repository.Content.GetAllContents(org, repoName, path).Result;
                var content    = repoSample[0].Content;

                //deserialize YAML to internal object representation
                var deserializer = new DeserializerBuilder()
                                   .WithNamingConvention(new CamelCaseNamingConvention())
                                   .Build();
                StringReader sr = new StringReader(content);
                sampleYAML = deserializer.Deserialize <SampleYamlVT>(sr);


                //Also store an internal JSON object representation
                sampleJSON     = ConvertYamlToJsonObject(sampleYAML);
                sampleJSON.Url = "https://github.com/" + org + "/" + repoName;
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not import YAML for repo: " + repoName);
                Console.WriteLine("   YAML may be incorrect, or missing.");
                Console.WriteLine("   Error message: " + e.Message);
            }
        }