Example #1
0
        } // Run

        private async Task ProcessAsync(SqlConnection con, string connectionString)
        {
            var changesCount = await OrmDAL.GetRoutineListCntAsync(con, this.MaxRowDate);

            if (changesCount > 0)
            {
                last0Cnt = null;

                // commented out changes line, happens too frequently with just 1 change
                //this.log.Info($"{ changesCount } change(s) found using row date { this.MaxRowDate }");
                this.Status = $"{ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} - { changesCount } change(s) found using rowdate { this.MaxRowDate}";

                var changesList = await GetAndProcessRoutineChangesAsync(con, connectionString, changesCount);

                if (changesList?.Count > 0)
                {
                    // call save for final changes
                    await this.Endpoint.SaveCacheAsync();

                    this.GenerateOutputFiles(this.Endpoint, changesList);
                    // save "settings" to persist JsFile version changes
                    SettingsInstance.SaveSettingsToFile();
                }
            }// if changeCount > 0
            else
            {
                if (last0Cnt == null)
                {
                    last0Cnt = DateTime.Now;
                }

                // only update status if we've been receiving 0 changes for a while
                if (DateTime.Now.Subtract(last0Cnt.Value).TotalSeconds > 30)
                {
                    last0Cnt    = DateTime.Now;
                    this.Status = $"{ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} - no changes found";
                }

                // handle the case where the output files no longer exist but we have also not seen any changes on the DB again
                // TODO: !!!
                // dbSource.JsFiles.forEach(jsFile =>
                // {
                //     let path = dbSource.outputFilePath(jsFile);

                //     if (!fs.existsSync(path))
                //     {
                //         this.progress('Generating ' + jsFile.Filename);
                //         JsFileGenerator.generateJsFile(dbSource, jsFile);

                //         //!this.IsRulesDirty = false;
                //         //!this.IsOutputFilesDirty = false;
                //         dbSource.LastUpdateDate = new Date();
                //     }

                // });
            }
        } // Process
Example #2
0
        private async Task GenerateFmtOnlyResultsetsAsync(string connectionString, CachedRoutine newCachedRoutine)
        {
            try
            {
                // get schema details of all result sets
                (var resultSets, var resultSetError) = await OrmDAL.RoutineGetFmtOnlyResultsAsync(connectionString, newCachedRoutine.Schema, newCachedRoutine.Routine, newCachedRoutine.Parameters);

                if (resultSets != null)
                {
                    var resultSetsDictionary = new Dictionary <string, List <ResultSetFieldMetadata> >();

                    foreach (DataTable dt in resultSets.Tables)
                    {
                        var lst = new List <ResultSetFieldMetadata>();

                        for (var rowIx = 0; rowIx < dt.Rows.Count; rowIx++)
                        {
                            DataRow row = dt.Rows[rowIx];

                            var schemaRow = new ResultSetFieldMetadata()
                            {
                                ColumnName         = (string)row["ColumnName"],
                                DataType           = GetCSharpType(row),
                                DbDataType         = (string)row["DataTypeName"],
                                ColumnSize         = Convert.ToInt32(row["ColumnSize"]),
                                NumericalPrecision = Convert.ToUInt16(row["NumericPrecision"]),
                                NumericalScale     = Convert.ToUInt16(row["NumericScale"])
                            };

                            lst.Add(schemaRow);
                        }

                        resultSetsDictionary.Add(dt.TableName, lst);
                    }

                    newCachedRoutine.ResultSetMetadata = resultSetsDictionary;

                    var resultSetJson = JsonConvert.SerializeObject(resultSetsDictionary);

                    using (var hash = SHA256Managed.Create())
                    {
                        newCachedRoutine.ResultSetHash = string.Concat(hash.ComputeHash(System.Text.Encoding.UTF8
                                                                                        .GetBytes(resultSetJson))
                                                                       .Select(item => item.ToString("x2")));
                    }

                    newCachedRoutine.ResultSetRowver = newCachedRoutine.RowVer;
                    newCachedRoutine.ResultSetError  = resultSetError;
                }
            }
            catch (Exception e)
            {
                newCachedRoutine.ResultSetRowver = newCachedRoutine.RowVer;
                newCachedRoutine.ResultSetError  = e.ToString();
            }
        }