Cancel() public abstract méthode

public abstract Cancel ( ) : void
Résultat void
Exemple #1
0
 public override void Cancel()
 => _wrappedCommand.Cancel();
        private void timer1_Tick(object sender, System.Timers.ElapsedEventArgs e)
        {
            timer1.Enabled = false;
            CustomBase.Rec rec = new CustomBase.Rec();
            CustomServiceBase s;
            if (usingRegistery)
            {
                s = base.GetInstanceService("Security Manager Sender");
            }
            else
            {
                s = base.GetInstanceService("Security Manager Remote Recorder");
            }

            L.Log(LogType.FILE, LogLevel.INFORM, "Service Started");

            try
            {
                // Fill the record fileds with necessary parameters
                //readQuery = "SELECT UPPER(HOST_NAME) AS HOST_NAME FROM NODE WHERE LAST_UPDATED < (getdate() - CONVERT(datetime,'" + respond_hour + ":" + respond_time + ":0',108)) ORDER BY LAST_UPDATED DESC";
                L.Log(LogType.FILE, LogLevel.INFORM, "Starting the timer");
                if (!reg_flag)
                {
                    if (usingRegistery)
                    {
                        if (!Read_Registry())
                        {
                            L.Log(LogType.FILE, LogLevel.ERROR, "Error on Reading the Registry ");
                            return;
                        }
                    }

                        if (!Initialize_Logger())
                        {
                            L.Log(LogType.FILE, LogLevel.ERROR, "Error on Intialize Logger on Incident Access Recorder functions may not be running");
                            return;
                        }
                    reg_flag = true;
                }

                L.Log(LogType.FILE, LogLevel.DEBUG, " last dbname is: " + dbName);

                if (begining)
                {
                    max_rec_send2 = max_record_send;
                    begining = false;
                }

                int i = 0;      //okunan row sayisi

                //get date and repeat number separetly
                splitDate();
                /*
                * date max_record_send sayisindan fazla repeat ederse sonsuz loopa giriyor
                * onu onlemek icin repeat sayisi max_recordu gecerse
                * max record sayisina repeat sayisini ekliyorum
                * daha sonra eski haline tekrar getiriyorum
                * */
                if (repeat_recordnum >= max_record_send)
                {
                    max_record_send += repeat_recordnum;
                }
                else
                {
                    max_record_send = max_rec_send2;

                }
                if(dates == "" ||dates == null ||dates == " ")
                {
                    dates = DateTime.MinValue.ToString().Substring(0, 19);
                }
                //query must be reorganize, scan id filter must be added (last scan id)
                readQuery = "SELECT TOP " + max_record_send + " [_DateTime],[Message],FileName,VirusIncident,State,ScanJobDeleted,VirusIncidentsDeleted,ID,SenderName,SenderAddress,RecipientNames,RecipientAddresses,ccNames,ccAddresses,bccNames,bccAddresses from "
                            + Table_name + " where [_DateTime] > CDATE(\"" + dates + "\") order by [_DateTime] asc";

                L.Log(LogType.FILE, LogLevel.DEBUG, " Query is " + readQuery);
                string connectionString = "";
                OleDbConnection conn = null;
                OleDbCommand cmd = null;
                try
                {
                    connectionString = "Provider=Microsoft.JET.OLEDB.4.0;data source=" + location;

                    conn = new OleDbConnection(connectionString);
                    cmd = new OleDbCommand(readQuery, conn);
                    conn.Open();
                    readReader = cmd.ExecuteReader();
                }
                catch (Exception rr)
                {
                    L.LogTimed(LogType.FILE, LogLevel.ERROR, "Readreader is not working properly" + rr.ToString());
                }
                L.Log(LogType.FILE, LogLevel.DEBUG, "Finish executing the query");

                //en son tarihten kac kez okunmus
                repeat = repeat_recordnum;
            #region read Query
                while (readReader.Read())
                {
                    L.Log(LogType.FILE, LogLevel.DEBUG, "read reader");
                    if (repeat == 0)
                    {
                        try
                        {
                            L.Log(LogType.FILE, LogLevel.DEBUG, "Setting rec's variables");
                            rec.LogName = "IncidentAccess Recorder";
                            try
                            {
                                dates = readReader.GetDateTime(0).ToString("yyyy/MM/dd HH:mm:ss.fff");
                                rec.Datetime = readReader.GetDateTime(0).AddMinutes(zone).ToString("yyyy/MM/dd HH:mm:ss.fff");
                            }
                            catch
                            {
                                L.Log(LogType.FILE, LogLevel.ERROR, "Convertion failure in DateTime : " + readReader.GetValue(0).ToString());
                            }
                            rec.CustomStr2 = readReader.GetString(1).ToString();
                            rec.Description = readReader.GetString(2).ToString();
                            rec.EventType = readReader.GetValue(3).ToString();
                            rec.EventCategory = readReader.GetString(4).ToString();
                            try
                            {
                                rec.CustomInt1 = Convert.ToInt32(readReader.GetValue(5).ToString());
                            }
                            catch (Exception e1) { L.Log(LogType.FILE, LogLevel.DEBUG, e1.Message); }
                            try
                            {
                                rec.CustomInt2 = Convert.ToInt32(readReader.GetValue(6).ToString());
                            }
                            catch (Exception e2) { L.Log(LogType.FILE, LogLevel.DEBUG, e2.Message); }
                            rec.EventId = Convert.ToInt64(readReader.GetValue(7).ToString());
                            rec.CustomStr4 = readReader.GetString(8).ToString();
                            rec.CustomStr3 = readReader.GetString(9).ToString();
                            rec.CustomStr1 = readReader.GetString(10).ToString();
                            if (readReader.GetValue(11).ToString().Length > 899 && readReader.GetValue(11).ToString().Length < 1800)
                            {
                                rec.CustomStr5 = readReader.GetString(11).ToString().Substring(0, 899);
                                rec.CustomStr7 = readReader.GetString(11).ToString().Substring(900, 1799);
                            }
                            else if (readReader.GetValue(11).ToString().Length < 899 )
                                rec.CustomStr5 = readReader.GetString(11).ToString();

                            rec.CustomStr6 = readReader.GetString(12).ToString();
                            rec.CustomStr8 = readReader.GetString(13).ToString();
                            rec.CustomStr9 = readReader.GetString(14).ToString();
                            rec.CustomStr10 = readReader.GetString(15).ToString();
                        }
                        catch (Exception bd)
                        {
                            L.Log(LogType.FILE, LogLevel.ERROR, "Bad data recieved" + bd.ToString());
                            continue;
                        }
                        //eyer tarih bir onceki tarih ile ayni ise repeat numberi artir
                        dates = dates.Substring(0, 19);
                        L.Log(LogType.FILE, LogLevel.DEBUG, "Lastrecord : " + dates );
                        repeat_recordnum = 0;
                        L.Log(LogType.FILE, LogLevel.DEBUG, "Start sending Data");
                        if (usingRegistery)
                        {
                            s.SetData(rec);     //datayi gonder
                        }
                        else
                        {
                            s.SetData(Dal,Virtualhost,rec);     //datayi gonder
                        }
                        L.Log(LogType.FILE, LogLevel.DEBUG, "Finish Sending Data");
                        //bakilan en son record
                        lastRecordDate = dates + "%" + repeat_recordnum.ToString();
                        L.Log(LogType.FILE, LogLevel.DEBUG, "Record Number is " + lastRecordDate);
                        //2007/12/18 14:54:15.000
                        dates = rec.Datetime.Substring(0, 19);
                        i++;
                        if (i > max_record_send)
                        {
                            L.Log(LogType.FILE, LogLevel.INFORM, "Reached MAX RECORD SEND number");
                            //son bakilan recordu registerye kaydet
                            cmd.Cancel();
                            dates = rec.Datetime.Substring(0, 19);
                            Set_Registry(lastRecordDate, rec.Datetime.Substring(0, 19));
                            //  lastRecordDate += "%" + repeat_recordnum.ToString();
                            return;
                        }
                    }//end of if
                    else
                    {
                        repeat -= 1;
                    }
                }
            #endregion
                ////son bakilan recordu registerye kaydet
                //lastRecordDate += "%" + repeat_recordnum.ToString();
                L.Log(LogType.FILE, LogLevel.DEBUG, "Set last date to registery");
                //Set_Registry(lastRecordDate,rec.Datetime);
                conn.Close();
                readReader.Close();
            }
            catch (Exception er)
            {
                L.LogTimed(LogType.FILE, LogLevel.ERROR, er.ToString());
                L.Log(LogType.FILE, LogLevel.ERROR, "Line could not parsed : " + readReader.GetValue(0) + " "  + readReader.GetValue(1) + " "  + readReader.GetValue(2));
            }
            finally
            {
                timer1.Enabled = true;
                L.Log(LogType.FILE, LogLevel.INFORM, "Service Stopped");
                s.Dispose();
            }
        }