public void AddSignal(SignalsInfo signal)
 {
     if (_currentIndex >= bufferSize)
     {
         //System.Threading.Thread.Sleep(Program.BufferDelayForSending);
         OnBufferLimitReached?.Invoke(_buffer);
         _buffer       = new SignalsInfo[bufferSize];
         _currentIndex = 0;
     }
     _buffer[_currentIndex++] = signal;
 }
        static void Main(string[] args)
        {
            try
            {
                SocketOptions options = new SocketOptions();
                options.SetConnectTimeoutMillis(int.MaxValue);
                options.SetReadTimeoutMillis(int.MaxValue);
                options.SetTcpNoDelay(true);

                if (SourceCassandraUserName != null && SourceCassandraUserName.Length > 0 && SourceCassandraPassword != null && SourceCassandraPassword.Length > 0)
                {
                    SourceCluster = Cluster.Builder().AddContactPoints(new string[] { SourceCassandraIp })
                                    .WithPort(SourceCassandraPort)
                                    .WithCredentials(SourceCassandraUserName, SourceCassandraPassword)
                                    .WithSocketOptions(options)
                                    .WithQueryTimeout(int.MaxValue).Build();
                }
                else
                {
                    SourceCluster = Cluster.Builder().AddContactPoints(new string[] { SourceCassandraIp })
                                    .WithPort(SourceCassandraPort)
                                    .WithSocketOptions(options)
                                    .WithQueryTimeout(int.MaxValue)
                                    .Build();
                }
                SourceCurrentSession = SourceCluster.Connect("vegamtagdata");
                Console.WriteLine("Connected to Source Cassandra");

                if (DestinationCassandraUserName != null && DestinationCassandraUserName.Length > 0 && DestinationCassandraPassword != null && DestinationCassandraPassword.Length > 0)
                {
                    DestinationCluster = Cluster.Builder().AddContactPoints(new string[] { DestinationCassandraIp })
                                         .WithPort(DestinationCassandraPort)
                                         .WithCredentials(DestinationCassandraUserName, DestinationCassandraPassword)
                                         .WithSocketOptions(options)
                                         .WithQueryTimeout(int.MaxValue).Build();
                }
                else
                {
                    DestinationCluster = Cluster.Builder().AddContactPoints(new string[] { DestinationCassandraIp })
                                         .WithPort(DestinationCassandraPort)
                                         .WithSocketOptions(options)
                                         .WithQueryTimeout(int.MaxValue)
                                         .Build();
                }

                DestinationCurrentSession = DestinationCluster.Connect("vegamtagdata");

                eventHubClient = EventHubClient.CreateFromConnectionString(connectionString, eventHubName);

                StringBuilder cqlCommandBuilder1 = new StringBuilder();
                cqlCommandBuilder1.Append(" insert into tagdatacentral (signalid, monthyear, fromtime, totime, avg, max, min, readings, insertdate) ");
                cqlCommandBuilder1.Append(" values(?,?,?,?,?,?,?,?,?)");
                insertPreparedStmt = DestinationCurrentSession.Prepare(cqlCommandBuilder1.ToString());

                Console.WriteLine("Connected to Destination Cassandra");
                string        currentSignalId   = "";
                int           currentItemCount  = 0;
                StringBuilder cqlCommandBuilder = new StringBuilder();
                cqlCommandBuilder.Append(" select signalid, monthyear, fromtime, totime, avg, max, min, readings, insertdate ");
                cqlCommandBuilder.Append(" from tagdatacentral where signalid = #signalid and monthyear = #monthyear and fromtime > #starttime and fromtime < #endtime");
                string cqlCommand = cqlCommandBuilder.ToString();

                signalsBuffer.OnBufferLimitReached += On_BufferLimitReached;
                signalsBuffer.OnBufferLimitReached += SendDataToAzure;

                IEnumerable <string> signalIdList = File.ReadLines(TagListFileName);
                SignalsInfo          currentSignal;
                foreach (var line in signalIdList)
                {
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }

                    string[] items = line.Split(',');
                    currentSignalId = items[0];
                    long.TryParse(items[2], out long FromTime);
                    long.TryParse(items[3], out long SyncEndTime);
                    currentItemCount = 0;
                    var currentCommand = cqlCommand.Replace("#signalid", items[0]);
                    currentCommand = currentCommand.Replace("#monthyear", items[1]);
                    currentCommand = currentCommand.Replace("#starttime", FromTime.ToString());
                    currentCommand = currentCommand.Replace("#endtime", SyncEndTime.ToString());


                    try
                    {
                        var resultRowSet = SourceCurrentSession.Execute(currentCommand);
                        foreach (var row in resultRowSet)
                        {
                            currentSignal       = new SignalsInfo();
                            currentSignal.ID    = Convert.ToInt32(row["signalid"]);
                            currentSignal.MYear = row["monthyear"].ToString();
                            currentSignal.FTime = Convert.ToInt64(row["fromtime"]);
                            currentSignal.TTime = Convert.ToInt64(row["totime"]);
                            currentSignal.Avg   = Convert.ToDecimal(row["avg"]);
                            currentSignal.Max   = Convert.ToDecimal(row["max"]);
                            currentSignal.Min   = Convert.ToDecimal(row["min"]);
                            currentSignal.Data  = row["readings"].ToString();
                            currentSignal.CTime = Convert.ToInt64(row["insertdate"]);
                            currentItemCount++;
                            signalsBuffer.AddSignal(currentSignal);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    Console.WriteLine("Completed pushing data for signalId " + currentSignalId + " with count: " + currentItemCount);
                    File.AppendAllText(SuccessFile, currentSignalId + Environment.NewLine);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }