Пример #1
0
 public void AddSignal(SignalsInfo signal)
 {
     if (_currentIndex >= bufferSize)
     {
         OnBufferLimitReached?.Invoke(_buffer);
         _buffer = new SignalsInfo[bufferSize];
         _currentIndex = 0;
     }
     _buffer[_currentIndex++] = signal;
 }
Пример #2
0
        static void Main(string[] args)
        {
            bool isSuccess = false;
            try
            {
                SocketOptions options = new SocketOptions();
                options.SetConnectTimeoutMillis(int.MaxValue);
                options.SetReadTimeoutMillis(int.MaxValue);
                options.SetTcpNoDelay(true);

                File.AppendAllText(logFile, "Started pushing data at  " + DateTime.Now);

                if (cassandraUserName != null && cassandraUserName.Length > 0 && cassandraPassword != null && cassandraPassword.Length > 0)
                {
                    cluster = Cluster.Builder().AddContactPoints(new string[] { cassandraIp })
                        .WithPort(cassandraPort)
                        .WithCredentials(cassandraUserName, cassandraPassword)
                        .WithSocketOptions(options)
                        .WithQueryTimeout(int.MaxValue).Build();
                }
                else
                {

                    cluster = Cluster.Builder().AddContactPoints(new string[] { cassandraIp }).WithPort(cassandraPort).WithSocketOptions(options).WithQueryTimeout(int.MaxValue).Build();
                }

                currentSession = cluster.Connect("vegamtagdata");

                eventHubClient = EventHubClient.CreateFromConnectionString(connectionString, eventHubName);

                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 in (#monthyear) and fromtime > #starttime and fromtime < #endtime");
                string cqlCommand = cqlCommandBuilder.ToString();
                signalsBuffer.OnBufferLimitReached += SendDataToAzure;

                IEnumerable<string> signalIdList = File.ReadLines(signalIdListFile);
                SignalsInfo currentSignal;
                int count = 1;
                foreach (var line in signalIdList)
                {
                    Console.WriteLine("Currently processing the line number: " + count++);
                    File.AppendAllText(logFile, "Currently processing the line" + line);
                    string[] items = line.Split(',');

                    isSuccess = long.TryParse(items[2], out long FromTime);

                    if (!isSuccess)
                    {
                        File.AppendAllText(failedCassandraGetTags, line + Environment.NewLine);
                        continue;
                    }
                    var currentCommand = cqlCommand.Replace("#signalid", items[0]);
                    currentCommand = currentCommand.Replace("#monthyear", GetMonthYearBetween(FromTime, SyncEndTime));
                    currentCommand = currentCommand.Replace("#starttime", FromTime.ToString());
                    currentCommand = currentCommand.Replace("#endtime", SyncEndTime.ToString());
                    try
                    {
                        var resultRowSet = currentSession.Execute(currentCommand);
                        var itemcount = 0;
                        //Just some more code changes
                        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"]);
                            signalsBuffer.AddSignal(currentSignal);
                            itemcount++;
                        }
                        Console.WriteLine("Finished processing the line number: " + count + " With a total item count of:" + itemcount);
                        File.AppendAllText(logFile, "Finished processing the line" + line + " With a total item count of:" + itemcount);
                    }
                    catch (Exception)
                    {
                        File.AppendAllText(failedCassandraGetTags, line + Environment.NewLine);
                        continue;
                    }
                }
                signalsBuffer.FlushData();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }