Beispiel #1
0
        public static async Task <T> RunUntilCancelled <T>(this IMenuUserInterface userInterface, Func <CancellationToken, Task <T> > backgroundTaskFactory)
        {
            var cancellation = new CancellationTokenSource();

            var backgroundTask = Task.Run(async() =>
            {
                try
                {
                    return(await backgroundTaskFactory(cancellation.Token));
                }
                catch (TaskCanceledException)
                {
                    return(default);
        public void Run(IMenuUserInterface c)
        {
            var dbType = DatabaseType.SqLite;

            DomainSqlHelper.AddCommonReadConn(dbType, "Data Source=Z:\\FT-water-zone.sqlite;");
            DomainSqlHelper.AddCommonWriteConn(dbType, "Data Source=Z:\\FT-water-zone.sqlite;");

            var domains = new[]
            {
                typeof(Book),
                typeof(BuyingRecord),
                typeof(Person),
                typeof(Publisher)
            };
            var option = new DomainSqlConfig();

            foreach (var domain in domains)
            {
                var array = new List <object>();
                if (typeof(Person) == domain)
                {
                    array = GetPersonDefaultData();
                }
                else if (typeof(Publisher) == domain)
                {
                    array = GetPublisherDefaultData();
                }
                var domainSql = DomainSqlHelper.Build(domain, dbType, array.ToArray());
                option.SqlMap.Add(domainSql.TypeName, domainSql);
            }

            var s    = $"..{Path.DirectorySeparatorChar}";
            var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, s, s, s, $"config{Path.DirectorySeparatorChar}", "DomainSqlConfig.yaml");

            if (!File.Exists(path))
            {
                c.Error($"文件不存在:{path}");
            }
            c.Debug(path);
            using (var tw = new StreamWriter(path))
            {
                var serializer = new Serializer();
                serializer.Serialize(tw, option);
            }
        }