public void Sync()
{
_canceling = false;
var batch = 100;
var count = recipesToSyncIDs.Count();
var total = count;
var parallelList = new List<List<int>>();
//Syns status to DM
TotalItemCount = total;
while (count > 0)
{
if (_canceling)
{
return;
}
var current = recipesToSyncIDs.Take(batch).ToList();
if (count < batch)
batch = count;
recipesToSyncIDs.RemoveRange(0, batch);
count = recipesToSyncIDs.Count();
parallelList.Add(current.Select(i => i.Key).ToList());
}
while (parallelList.Count > 0)
{
if (_canceling)
{
return;
}
Stopwatch sw = new Stopwatch();
sw.Start();
var max = 6;
if (parallelList.Count < max)
max = parallelList.Count;
var tasks = new Task<List<SyncToMakeModel>>[max];
for (int i = 0; i < tasks.Length; i++)
{
if (_canceling)
{
return;
}
var currentCollection = parallelList[0];
tasks[i] = Task.Run(() => CompositeSyncToMakeModel(currentCollection));
parallelList.RemoveAt(0);
}
Task.WaitAll(tasks);
var combinedList = new List<SyncToMakeModel>();
foreach (var task in tasks)
{
combinedList.AddRange(task.Result);
}
combinedList = combinedList.GroupBy(i => i.RecipeUrl).Select(i => i.First()).ToList();
Console.Write("Get:" + sw.ElapsedMilliseconds);
sw.Restart();
ProcessRecipe(combinedList);
total -= combinedList.Count;
Console.WriteLine(" Set:" + sw.ElapsedMilliseconds + " Ct:" + combinedList.Count + " Rm:" + total);
sw.Reset();
//Sync status to DM
CompletedItemCount += combinedList.Count;
}
{
_canceling = false;
var batch = 100;
var count = recipesToSyncIDs.Count();
var total = count;
var parallelList = new List<List<int>>();
//Syns status to DM
TotalItemCount = total;
while (count > 0)
{
if (_canceling)
{
return;
}
var current = recipesToSyncIDs.Take(batch).ToList();
if (count < batch)
batch = count;
recipesToSyncIDs.RemoveRange(0, batch);
count = recipesToSyncIDs.Count();
parallelList.Add(current.Select(i => i.Key).ToList());
}
while (parallelList.Count > 0)
{
if (_canceling)
{
return;
}
Stopwatch sw = new Stopwatch();
sw.Start();
var max = 6;
if (parallelList.Count < max)
max = parallelList.Count;
var tasks = new Task<List<SyncToMakeModel>>[max];
for (int i = 0; i < tasks.Length; i++)
{
if (_canceling)
{
return;
}
var currentCollection = parallelList[0];
tasks[i] = Task.Run(() => CompositeSyncToMakeModel(currentCollection));
parallelList.RemoveAt(0);
}
Task.WaitAll(tasks);
var combinedList = new List<SyncToMakeModel>();
foreach (var task in tasks)
{
combinedList.AddRange(task.Result);
}
combinedList = combinedList.GroupBy(i => i.RecipeUrl).Select(i => i.First()).ToList();
Console.Write("Get:" + sw.ElapsedMilliseconds);
sw.Restart();
ProcessRecipe(combinedList);
total -= combinedList.Count;
Console.WriteLine(" Set:" + sw.ElapsedMilliseconds + " Ct:" + combinedList.Count + " Rm:" + total);
sw.Reset();
//Sync status to DM
CompletedItemCount += combinedList.Count;
}