/// <summary> /// Save the changes denoted by the selected nodes. /// </summary> /// <param name="selectedNodes">The changes to persist</param> /// <param name="kustoQueryEngine">Pass a connection to Kusto if the target is Kusto</param> private void PersistChanges(IEnumerable <TreeNode> selectedNodes, QueryEngine kustoQueryEngine = null) { void WriteToTarget(IKustoSchema schema) { if (spcTarget.SourceSelection == SourceSelection.FilePath()) { schema.WriteToFile(spcTarget.SourceFilePath); } else { schema.WriteToKusto(kustoQueryEngine); } } void DeleteFromTarget(IKustoSchema schema) { if (spcTarget.SourceSelection == SourceSelection.Kusto()) { schema.DeleteFromKusto(kustoQueryEngine); } else { schema.DeleteFromFolder(spcTarget.SourceFilePath); } } foreach (SchemaDifference difference in selectedNodes.Select(node => (SchemaDifference)node.Tag)) { switch (difference.Schema) { case IKustoSchema update when difference.Difference is Modified || difference.Difference is OnlyInSource: WriteToTarget(update); break; case IKustoSchema delete when difference.Difference is OnlyInTarget: DeleteFromTarget(delete); break; default: throw new InvalidOperationException("Unhandled type supplied."); } } }
public IReadOnlyDictionary <SourceSelection, Action <bool> > Choose(Action <bool> chooseFilePath, Action <bool> chooseKusto) => new Dictionary <SourceSelection, Action <bool> >() { [SourceSelection.FilePath()] = chooseFilePath, [SourceSelection.Kusto()] = chooseKusto, };