Exemplo n.º 1
0
        private void RemoveExpiredMessages()
        {
            int expiration = PortalConfig.MdsDeleteOlderMoreThan;

            if (expiration > 0)
            {
                SqlScript sqlScript = new SqlScript();

                sqlScript.AppendLine("DELETE FROM [dbo].[cls_Email] WHERE Created < @ExpirationDate");

                sqlScript.AddParameter("@ExpirationDate", DateTime.UtcNow.AddMinutes(-expiration));

                sqlScript.Execute();
            }
        }
Exemplo n.º 2
0
        private static bool ExecuteSqlScript(ConnectionProvider provider, string scriptFile, int batchSize, bool verbose)
        {
            if (!File.Exists(scriptFile))
            {
                cerr.WriteLine($"no input file found : {scriptFile}");
                return(false);
            }

            cout.WriteLine("executing {0}", scriptFile);
            var script = new SqlScript(provider, scriptFile)
            {
                BatchSize = batchSize
            };

            script.Reported += (sender, e) =>
            {
                if (verbose)
                {
                    cout.WriteLine($"processed line:{e.Line} batch:{e.BatchLine}/{e.BatchSize} total:{e.TotalSize}");
                }
            };

            bool hasError = false;

            script.Error += (sender, e) =>
            {
                hasError = true;
                cerr.WriteLine($"line:{e.Line}, {e.Exception.Message}, SQL:{e.Command}");
            };

            Func <bool> stopOnError = () =>
            {
                return(!cin.YesOrNo("are you sure to continue (yes/no)?"));
            };

            script.Execute(stopOnError);
            cout.WriteLine("completed.");

            return(!hasError);
        }
        private void RemoveExpiredMessages()
        {
            int expiration = PortalConfig.MdsDeleteOlderMoreThan;

            if (expiration > 0)
            {
                SqlScript sqlScript = new SqlScript();

                sqlScript.AppendLine("DELETE FROM [dbo].[cls_IbnClientMessage] WHERE Created < @ExpirationDate");

                sqlScript.AddParameter("@ExpirationDate", DateTime.UtcNow.AddMinutes(-expiration));

                sqlScript.Execute();
            }
        }