Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            var dateTime = loadCpu.ReadDatetime(Convert.ToInt32(startByteAdrSettings.Text));

            if (dateTime != null)
            {
                dateTimeSettingsLabel.Text = dateTime.DateTime.ToString();
            }
        }
Beispiel #2
0
        public WorkCpu()
        {
            LoadCpu loadCpu = new LoadCpu();

            while (true)
            {
                // STOP
                if (Form1.stopThreadAll)
                {
                    return;
                }

                workCpuStatus = true;

                // Makes the status, for a long time there was no connection with the CPU
                NoConnectionTimeSec(loadCpu);

                // select limits---------------
                LimitsCpu limitsCpu = loadCpu.ReadLimits();
                if (limitsCpu == null)
                {
                    continue;   // error connect
                }
                if ((limitsCpu.PositionRead < limitsCpu.PositionMin) ||
                    (limitsCpu.PositionRead > limitsCpu.PositionMax))
                {
                    loadCpu.WritePositionLimitsCpu(limitsCpu.PositionMin);   // write PositionRead
                    continue;
                }
                //------------------------------

                writeIndex = limitsCpu.PositionWrite;
                readIndex  = limitsCpu.PositionRead;


                // new PositionRead + 1
                int newIndexDb = LocationIndexDb(loadCpu, limitsCpu);
                // if there isn't data
                if (newIndexDb < limitsCpu.PositionMin)
                {
                    FindMaxIdFromSql();
                    continue;
                }
                else
                {
                    // loading data all CPU--------
                    Model_dateTime modelDTBase = loadCpu.ReadDatetime(newIndexDb);
                    if (modelDTBase == null)
                    {
                        continue;   // error connect
                    }
                    if (modelDTBase.Id_DateTime == -1)
                    {
                        loadCpu.WritePositionLimitsCpu(newIndexDb);   // write PositionWrite (+1)
                        continue;
                    }
                    //------------------------------

                    idMaxSql = modelDTBase.Id_DateTime;  // save ID to static

                    // ok <<< Write id and DateTime to SQL
                    WriteDateTimeToSql(loadCpu, modelDTBase, newIndexDb);
                }

                if (Form1.stopThreadAll)
                {
                    return;                         // STOP
                }
                Thread.Sleep(Properties.Settings.Default.timerWorkCycle);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Write перегнал Read (1 цикл)
        /// </summary>
        /// <returns>
        /// false - продолжать с Read (+2)
        /// true - продолжать с Write (+2)
        /// </returns>
        private bool CheckDateTimeCpu(LoadCpu loadCpu, LimitsCpu limitsCpu)
        {
            //----------------------------------------------------------------
            // loading data all CPU
            var tempDtRead  = loadCpu.ReadDatetime(limitsCpu.PositionRead);
            var tempDtWrite = loadCpu.ReadDatetime(limitsCpu.PositionWrite);

            if ((tempDtRead == null) || (tempDtWrite == null))
            {
                return(false);
            }
            long dtRead  = tempDtRead.Id_DateTime;
            long dtWrite = tempDtWrite.Id_DateTime;

            // no connections > 1 hour
            if ((!isNoConnectionTimeSec) && (dtRead < dtWrite))
            {
                // after (перегнал)
                return(false);
            }
            //----------------------------------------------------------------
            long dtdtReadAfterWrite;

            if ((limitsCpu.PositionWrite + addPositionIndex > limitsCpu.PositionMax) || (limitsCpu.PositionWrite < limitsCpu.PositionMin))
            {
                var tempDtdtReadAfterWrite = loadCpu.ReadDatetime(limitsCpu.PositionMin);
                if (tempDtdtReadAfterWrite == null)
                {
                    return(false);
                }
                else
                {
                    dtdtReadAfterWrite = tempDtdtReadAfterWrite.Id_DateTime;
                }
            }
            else
            {
                var tempDtdtReadAfterWrite = loadCpu.ReadDatetime(limitsCpu.PositionWrite + addPositionIndex);
                if (tempDtdtReadAfterWrite == null)
                {
                    return(false);
                }
                else
                {
                    dtdtReadAfterWrite = tempDtdtReadAfterWrite.Id_DateTime;
                }
            }

            if (dtdtReadAfterWrite == 0)
            {
                // before
                return(false);
            }

            // no connections > 1 hour
            if (isNoConnectionTimeSec)
            {
                // after (перегнал)
                if ((dtRead < dtWrite) && (dtRead > dtdtReadAfterWrite))
                {
                    // true - Is present to SQL (dtdtReadAfterWrite)
                    if (!IsCheckPresent(dtdtReadAfterWrite))
                    {
                        return(true);
                    }
                }
            }
            // before
            return(false);
        }