Exemple #1
0
        private bool ProcessFile(ChangeScriptWrapper path, Server server)
        {
            string name = path.Description;

            string commandText = null;

            try
            {
                var existingProcedure = _existingChangeScripts.FirstOrDefault(o => o.ChangeNumber == path.ChangeNumber && o.DeltaSet == path.DeltaSet);
                if (existingProcedure != null)
                {
                    _task._logProcessor.Log(Source, $"Skipping {path.DeltaSet} change: {path.ChangeNumber} file: {path.Description} as it was already applied");
                    //path.Info.Delete();
                    return(true);
                }
                commandText    = File.ReadAllText(path.Info.FullName);
                path.StartDate = DateTime.Now;
                server.ConnectionContext.BeginTransaction();
                server.ConnectionContext.ExecuteNonQuery(commandText);

                path.EndDate = DateTime.Now;

                _task._logProcessor.Log(Source, $"Finished processing {path.DeltaSet} change: {path.ChangeNumber} file: {path.Description} in {(path.EndDate - path.StartDate).TotalMilliseconds.ToString("N2")}ms");
                //	path.Info.Delete();
                //	server.ConnectionContext.
                server.ConnectionContext.ExecuteNonQuery(path.InsertStatement);
                server.ConnectionContext.CommitTransaction();
                return(true);
            }
            catch (Exception e)
            {
                path.EndDate = DateTime.Now;
                _task._logProcessor.Log(Source, "failed processing sproc file: " + path.Info.FullName, attachment: e.ToString());
                string errorFile = path.Info.FullName.Replace(".sql", "_error.txt");
                File.WriteAllText(errorFile, e.ToString());
                _task._logProcessor.Log(Source, $"Failed processing {path.DeltaSet} change: {path.ChangeNumber} file: {path.Description} in {(path.EndDate - path.StartDate).TotalMilliseconds.ToString("N2")}ms with message {e.Message}", attachment: commandText);
                return(false);
            }
        }
Exemple #2
0
        private void LoadLocalFiles()
        {
            string[] allSprocs = Directory.GetFiles(_sprocPath, "*.sql", SearchOption.AllDirectories);
            _changeScriptFiles.AddRange(allSprocs.Where(o =>
            {
                var fi = new FileInfo(o);
                return(!fi.Name.StartsWith("output") && fi.Name.StartsWith("0"));
            }).Select(o =>
            {
                ChangeScriptWrapper wrapper = null;
                try
                {
                    wrapper = new ChangeScriptWrapper(o);
                }
                catch (Exception e)
                {
                    _task._logProcessor.Log(Source, $"Error processing file {o}\n{e}");
                }

                return(wrapper);
            }).OrderBy(o => o?.SortString));
        }