static void Import(AzureDataCatalog td, string exportedCatalogFilePath)
{
int totalAssetsImportSucceeded = 0;
int totalAssetsImportFailed = 0;
System.IO.StreamReader sr = new StreamReader(exportedCatalogFilePath);
JsonTextReader reader = new JsonTextReader(sr);
StringWriter sw = new StringWriter(new StringBuilder());
JsonTextWriter jtw = new JsonTextWriter(sw);
reader.Read();
if (reader.TokenType != JsonToken.StartObject)
{
throw new Exception("Invalid Json. Expected StartObject");
}
reader.Read();
if ((reader.TokenType != JsonToken.PropertyName) || (!reader.Value.ToString().Equals("catalog")))
{
throw new Exception("Invalid Json. Expected catalog array");
}
reader.Read();
if (reader.TokenType != JsonToken.StartArray)
{
throw new Exception("Invalid Json. Expected StartArray");
}
while (reader.Read())
{
if (reader.TokenType == JsonToken.EndArray)
break;
jtw.WriteToken(reader);
JObject asset = JObject.Parse(sw.ToString());
string id = asset["id"].ToString();
asset.Remove("id");
string[] idInfo = id.Split(new char[] { '/' });
string newid;
string UpdateResponse = td.Update(asset.ToString(), idInfo[idInfo.Length - 2], out newid);
if ((UpdateResponse != null) && (!string.IsNullOrEmpty(newid)))
{
totalAssetsImportSucceeded++;
if (totalAssetsImportSucceeded % 50 == 0)
{
System.Console.WriteLine(totalAssetsImportSucceeded + "Assets Imported Succesfully");
}
}
else
{
totalAssetsImportFailed++;
}
//reset local variables for next iteration
sw = new StringWriter(new StringBuilder());
jtw = new JsonTextWriter(sw);
}
Console.WriteLine("Total Imported Success: " + totalAssetsImportSucceeded);
Console.WriteLine("Total Imported Failed: " + totalAssetsImportFailed);
}