Пример #1
0
 static void Settings_QueryPerformed(DatabaseBase database, string pSql, int records, QueryType pQueryType,
                                     DateTime?pStart, DateTime?pEnd, Exception pException, IsolationLevel pIsolationLevel, int?pResultSize, ulong?transactionId)
 {
     if (pException == null)
     {
         LOG.Debug("End:start:{0:MM-dd-yy HH:mm:ss.fff}, end:{1:MM-dd-yy HH:mm:ss.fff}, rows affected:{2}", pStart, pEnd, records);
     }
     else
     {
         LOG.Error(string.Format("End:start:{0:MM-dd-yy HH:mm:ss.fff}, end:{1:MM-dd-yy HH:mm:ss.fff}, ERROR:{2}", pStart, pEnd, pException.Message), pException);
     }
 }
Пример #2
0
        public static void Generate(GenerateRequest request)
        {
            Debug.Print("Save to folder:" + request.Configurer.DestSourceDir);
            var tables       = request.Tables;
            var configurer   = request.Configurer;
            var providerType = request.ProviderType;

            if (null == tables || tables.Count <= 0 || null == configurer)
            {
                throw new CoooQGenerateException("No tables to generated");
            }
            if (!Directory.Exists(configurer.DestSourceDir))
            {
                try
                {
                    Directory.CreateDirectory(configurer.DestSourceDir);
                }
                catch
                {
                    try
                    {
                        Directory.CreateDirectory(Path.Combine(Application.StartupPath, configurer.DestSourceDir));
                    }
                    catch (Exception e)
                    {
                        throw new CoooQGenerateException("Cannot create destination directory to store code file." + e.Message);
                    }
                }
            }
            //loop each template config to generate to file
            foreach (var templateConfig in configurer.TemplateConfigs)
            {
                Task.Factory.StartNew(() =>
                {
                    try
                    {
                        Debug.Print(String.Format("Start generate for template: {0}", templateConfig.Name));
                        if (!Directory.Exists(templateConfig.DestFolderName))
                        {
                            Directory.CreateDirectory(templateConfig.DestFolderName);
                        }
                        if (templateConfig.IsSingle)
                        {
                            var context = GetContext(configurer, providerType);
                            context.Put("tables", tables);
                            var fileName = Path.Combine(templateConfig.DestFolderName, templateConfig.DestFileName);
                            using (var sw = File.CreateText(fileName))
                            {
                                Engine.Evaluate(context, sw, null, templateConfig.TemplateString);
                            }
                        }
                        else
                        {
                            var tasks = new List <Task>();
                            foreach (var table in tables)
                            {
                                var task = new Task(() =>
                                {
                                    Debug.Print(String.Format("Start generate for template: {0}, table:{1}", templateConfig.Name, table.OriginName));
                                    var t       = table;
                                    var context = GetContext(configurer, providerType);
                                    context.Put("table", t);
                                    var fileName = Path.Combine(templateConfig.DestFolderName,
                                                                templateConfig.DestFileName.Replace("${TABLE}", StringUtils.Capitalize(t.Name)));
                                    using (var sw = File.CreateText(fileName))
                                    {
                                        Engine.Evaluate(context, sw, null, templateConfig.TemplateString);
                                    }
                                    Debug.Print(String.Format("End generate for template: {0}, table:{1}", templateConfig.Name, table.Name));
                                });
                                tasks.Add(task);
                                task.Start();
                            }
                            Task.WaitAll(tasks.ToArray());
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.Print(ex.Message);
                        LOG.Error(ex);
                    }
                    finally
                    {
                        Debug.Print(String.Format("End generate for template:{0}", templateConfig.Name));
                    }
                });
            }
        }