本文整理汇总了C#中DBManager.DeleteFromDynamicFieldsAsync方法的典型用法代码示例。如果您正苦于以下问题:C# DBManager.DeleteFromDynamicFieldsAsync方法的具体用法?C# DBManager.DeleteFromDynamicFieldsAsync怎么用?C# DBManager.DeleteFromDynamicFieldsAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBManager
的用法示例。
在下文中一共展示了DBManager.DeleteFromDynamicFieldsAsync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RefreshDynamicFieldsAsync
/// <summary>
/// Removes those fields that have been removed from the categories since the last save,
/// and adds those fields that have been added to the categories since the last save.
/// To be sure, we assume the metadata has been changed since the folder was last saved.
/// </summary>
/// <returns></returns>
private static async Task RefreshDynamicFieldsAsync(DBManager dbM, ICollection<DynamicCategory> dynamicCategories, ICollection<DynamicField> dynamicFields, string folderId)
{
if (dbM == null) return;
try
{
var shouldBeFldDscs = new List<FieldDescription>(); // HashSet may be tricky, a List is easier
foreach (var dynCat in dynamicCategories)
{
if (dynCat.Category != null)
{
foreach (var fldDsc in dynCat.Category.FieldDescriptions)
{
if (shouldBeFldDscs.All(fd => fd.Id != fldDsc.Id)) shouldBeFldDscs.Add(fldDsc);
}
}
else
{
await Logger.AddAsync("DynamicCategory " + dynCat.Id + " has Category = null: this must never happen", Logger.ForegroundLogFilename).ConfigureAwait(false);
Debugger.Break(); // this must never happen
}
}
// remove obsolete fields
// LOLLO I create a List, instead of using the IEnumerable, otherwise the following Remove will break the ienumerable and dump!
var obsoleteDynFlds = dynamicFields.Where(dynFld => shouldBeFldDscs.All(fldDsc => fldDsc.Id != dynFld.FieldDescriptionId)).ToList();
foreach (var obsoleteDynFld in obsoleteDynFlds)
{
if (await dbM.DeleteFromDynamicFieldsAsync(obsoleteDynFld).ConfigureAwait(false) && obsoleteDynFld != null)
{
dynamicFields.Remove(obsoleteDynFld);
await obsoleteDynFld.CloseAsync().ConfigureAwait(false);
}
}
var newFldDscs = shouldBeFldDscs.Where(fldDsc => dynamicFields.All(dynFld => dynFld.FieldDescriptionId != fldDsc.Id));
foreach (var newFldDsc in newFldDscs)
{
var dynFld = new DynamicField(dbM, folderId, newFldDsc.Id);
if (await dbM.InsertIntoDynamicFieldsAsync(dynFld).ConfigureAwait(false) && dynFld != null)
{
dynamicFields.Add(dynFld);
await dynFld.OpenAsync().ConfigureAwait(false);
}
}
}
catch (Exception ex)
{
await Logger.AddAsync(ex.ToString(), Logger.ForegroundLogFilename).ConfigureAwait(false);
Debugger.Break();
}
}