private bool DoBlowingEvent(int iIdxInPointLi)
        {
            bool bErg = false;

             try {
            BlowingEvent evBlowing = new BlowingEvent();
            evBlowing.iCnvNr = pointLi[iIdxInPointLi].iCnvNr;
            j = findPoint("O2VOL_TOTAL",pointLi[iIdxInPointLi].iCnvNr);
            if (j >= 0) {
               evBlowing.O2TotalVol = pointLi[j].iDataValue;
               j = findPoint("BLOWING",pointLi[iIdxInPointLi].iCnvNr);
               if (j >= 0) {
                  evBlowing.BlowingFlag = pointLi[j].iDataValue;
                  sLfdEvtMsg = evBlowing.ToString();
                  mainGate.PushEvent(evBlowing);
                  AddLogg(evBlowing.ToString());
                  bErg = true;
                  }
               else {
                  AddLogg("При BlowingEvent не найдена точка K" + pointLi[iIdxInPointLi].iCnvNr + " BLOWING");
                  }
               }
            else {
               AddLogg("При BlowingEvent не найдена точка K" + pointLi[iIdxInPointLi].iCnvNr + " O2VOL_TOTAL");
               }
            }
             catch (Exception eXc) {
            sLfdEvtErr = eXc.Message;
            AddLogg("При BlowingEvent K" + pointLi[iIdxInPointLi].iCnvNr + " Exception: " + eXc.Message);
            }
             return bErg;
        }
 public void Process(BlowingEvent _event)
 {
     try
     {
         this._Module._Heat.BlowingHistory.Add( _event);
     }
     catch {}
 }
 public BaseEvent RestoreEventClass(Type[] assembleTypes)
 {
     BaseEvent be = new BlowingEvent();
     for (int at = 0; at < assembleTypes.Length; at++) {
         if (assembleTypes[at].Name == m_eventClassName) {
             be = (BaseEvent) new SerializeTools().RestoreFromString(m_eventClassJSONData, assembleTypes[at]);
             break;
         }
     }
     return be;
 }
        public static int ReceiveMessage(string message)
        {
            BaseEvent be = new BlowingEvent();
            m_message = new UDPMessage();
            m_message = (UDPMessage) new SerializeTools().RestoreFromString(message, typeof (UDPMessage));
            be = m_message.RestoreEventClass(BaseEvent.GetEvents());

            InstantLogger.log(message, "", InstantLogger.TypeMessage.normal);
            InstantLogger.log(be.ToString(), "", InstantLogger.TypeMessage.normal);
            return 0;
        }
        private static void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            m_vPathIsOutput = !VPathDataIsEqual(HDataList[m_position].Bunkers, m_vPathDataLast);
            if (m_vPathIsOutput) {
                Console.WriteLine(
                    "{17:0000}: {0:00000} > {1:000} | {2:0000.0} | {3:00.0} | {4:00.0} | {5:00.0} | {6:00.0} | {7:00.0} | {8:00.0} " +
                    "| {9:0000} | {10:0000} | {11:0000} | {12:0000} | {13:0000} | {14:0000} | {15:0000} | {16:0000}",
                    m_totalO2,
                    HDataList[m_position].HeightLance,
                    HDataList[m_position].RateO2,
                    HDataList[m_position].H2,
                    HDataList[m_position].O2,
                    HDataList[m_position].CO,
                    HDataList[m_position].CO2,
                    HDataList[m_position].N2,
                    HDataList[m_position].Ar,
                    HDataList[m_position].Bunkers.RB5,
                    HDataList[m_position].Bunkers.RB6,
                    HDataList[m_position].Bunkers.RB7,
                    HDataList[m_position].Bunkers.RB8,
                    HDataList[m_position].Bunkers.RB9,
                    HDataList[m_position].Bunkers.RB10,
                    HDataList[m_position].Bunkers.RB11,
                    HDataList[m_position].Bunkers.RB12,
                    ++m_step
                    );
                m_vPathDataLast = HDataList[m_position].Bunkers;
            }
            else {
                Console.WriteLine(
                    "{9:0000}: {0:00000} > {1:000} | {2:0000.0} | {3:00.0} | {4:00.0} | {5:00.0} | {6:00.0} | {7:00.0} | {8:00.0}",
                    m_totalO2,
                    HDataList[m_position].HeightLance,
                    HDataList[m_position].RateO2,
                    HDataList[m_position].H2,
                    HDataList[m_position].O2,
                    HDataList[m_position].CO,
                    HDataList[m_position].CO2,
                    HDataList[m_position].N2,
                    HDataList[m_position].Ar,
                    ++m_step
                    );
            }
            var le = new LanceEvent();
            le.LanceHeight = HDataList[m_position].HeightLance;
            le.O2Flow = HDataList[m_position].RateO2;
            le.O2TotalVol = (int) m_totalO2;

            var offGA = new OffGasAnalysisEvent();
            offGA.H2 = HDataList[m_position].H2;
            offGA.O2 = HDataList[m_position].O2;
            offGA.CO = HDataList[m_position].CO;
            offGA.CO2 = HDataList[m_position].CO2;
            offGA.N2 = HDataList[m_position].N2;
            offGA.Ar = HDataList[m_position].Ar;

            var fex = new FlexHelper("UDP.OffGasAnalysisEvent");
            fex.AddArg("H2", HDataList[m_position].H2);
            fex.AddArg("O2", HDataList[m_position].O2);
            fex.AddArg("CO", HDataList[m_position].CO);
            fex.AddArg("CO2", HDataList[m_position].CO2);
            fex.AddArg("N2", HDataList[m_position].N2);
            fex.AddArg("Ar", HDataList[m_position].Ar);
            fex.Fire(MainGate);

            var offG = new OffGasEvent();
            offG.OffGasFlow = HDataList[m_position].VOffGas;
            offG.OffGasTemp = (int) Math.Round(HDataList[m_position].TOffGas);

            var bE = new BlowingEvent();
            bE.O2TotalVol = (int) m_totalO2;
            bE.BlowingFlag = 1;

            var vate = new visAdditionTotalEvent();
            vate.RB5TotalWeight = HDataList[m_position].Bunkers.RB5;
            vate.RB6TotalWeight = HDataList[m_position].Bunkers.RB6;
            vate.RB7TotalWeight = HDataList[m_position].Bunkers.RB7;
            vate.RB8TotalWeight = HDataList[m_position].Bunkers.RB8;
            vate.RB9TotalWeight = HDataList[m_position].Bunkers.RB9;
            vate.RB10TotalWeight = HDataList[m_position].Bunkers.RB10;
            vate.RB11TotalWeight = HDataList[m_position].Bunkers.RB11;
            vate.RB12TotalWeight = HDataList[m_position].Bunkers.RB12;

            if ((HDataList[m_position].SublanceC > 0) && !m_sublanceCIsPushed) {
                Int64 reminder = 0;
                Int64 res = Math.DivRem(m_heatNumber, 10000, out reminder);
                Int64 longHN = res*100000 + reminder;
                MainGate.PushEvent(new visSpectrluksEvent() {C = HDataList[m_position].SublanceC, HeatNumber = longHN});
                Console.WriteLine("specroluks push Heat = {0} ", longHN);
                MainGate.PushEvent(new SublanceCEvent() {C = HDataList[m_position].SublanceC});
                m_sublanceCIsPushed = true;
                Console.WriteLine("Carbone pushed C = {0}, heatNumber = {1}", HDataList[m_position].SublanceC, longHN);
            }

            var doge = new DecompressionOffGasEvent();
            m_decompressionOffGas = HDataList[m_position].DecompressionOffGas == Int32.MinValue
                                        ? m_decompressionOffGas
                                        : HDataList[m_position].DecompressionOffGas;
            doge.Decompression = m_decompressionOffGas;

            MainGate.PushEvent(le);
            MainGate.PushEvent(offGA);
            MainGate.PushEvent(offG);
            MainGate.PushEvent(bE);
            MainGate.PushEvent(doge);

            m_totalO2 += HDataList[m_position].RateO2*0.01666666666666666666666666666667;

            if (m_vPathIsOutput) MainGate.PushEvent(vate);

            //Console.WriteLine("m_position -- {0}; HDataList.Count -- {1}", m_position, HDataList.Count);
            if (m_position < HDataList.Count - 1)
                m_position++;
            else {
                Console.WriteLine("Exit 0");
                System.Environment.Exit(0);
                m_timer.Enabled = false;
            }
        }
        private static void transmitter(object state)
        {
            //Console.BackgroundColor = ConsoleColor.Red;
            //Console.ForegroundColor = ConsoleColor.White;
            mainGate = new ConnectionProvider.Client();

            CultureInfo culture = CultureInfo.InvariantCulture;
            System.Threading.Thread.Sleep(1000);
            //mainGate.PushEvent(new comBlowingSchemaEvent()); // после запуска программы листенер пропускает первое сообщение через раз, как временное решение проблемы сообщение с -1
            //mainGate.PushEvent(new HeatChangeEvent() {HeatNumber = 1133});
            //mainGate.PushEvent(new BoundNameMaterialsEvent() {Bunker1MaterialName = "m1", Bunker2MaterialName = "m2", Bunker3MaterialName = "m3"});
            //mainGate.PushEvent(new OPCDirectReadEvent() { EventName = typeof(BoundNameMaterialsEvent).Name });
            //mainGate.PushEvent(new OPCDirectReadEvent() {EventName = typeof(WeighersStateEvent).Name});

            //mainGate.PushEvent(new comAdditionsSchemaEvent());
            //mainGate.PushEvent(new cntWeigher3JobReadyEvent() {Counter = 1137});
            //mainGate.PushEvent(new cntWeigher4JobReadyEvent() { Counter = 1137 });
            //mainGate.PushEvent(new cntWeigher5JobReadyEvent() { Counter = 1137 });
            //mainGate.PushEvent(new cntWeigher6JobReadyEvent() { Counter = 1137 });
            //mainGate.PushEvent(new cntWeigher7JobReadyEvent() { Counter = 1137 });
            //mainGate.PushEvent(new comBlowingSchemaEvent());

            //mainGate.PushEvent(new cntBlowingSchemaEvent() {Counter = 1137});
            //mainGate.PushEvent(new cntO2FlowRateEvent() { Counter = 1137 });
            //var be = new BlowingEvent() {O2TotalVol = 0};
            //int oxyRate = 100;
            //while (true)
            //{
            //    be.O2TotalVol += oxyRate;
            //    mainGate.PushEvent(be);
            //    Thread.Sleep(500);
            //}
            //int ii = 0;
            //while (true)
            //{
            //    mainGate.PushEvent(new HeatChangeEvent() {HeatNumber = ii++});
            //    Thread.Sleep(100);
            //}

            //Console.BackgroundColor = ConsoleColor.Black;
            //Console.ForegroundColor = ConsoleColor.Green;
            /*lock (consoleLock)
            {
                Console.WriteLine("transmitter...................................................................................[started]\n");
            }*/

            var dimm = new int[] {1, 2, 3};

            var fxe = new FlexHelper("TestComplex");

            fxe.AddComplexArg("dimm", dimm);
            fxe.Fire(mainGate);
            Console.WriteLine("Send:");
            Console.WriteLine(fxe.evt);

            //var fex = new FlexHelper("OPC.Flex.Suka");
            //fex.AddArg("val-i2", 1133);
            //fex.AddArg("val-r4", -11.33);
            //fex.AddArg("val-s", "Zalupa");
            //fex.Fire(mainGate);
            //mainGate.PushEvent(new HeatChangeEvent() { HeatNumber = 221111 });

            //mainGate.PushEvent(new visSpectrluksEvent() { HeatNumber = 2201111, C = 0.05 });

            InstantLogger.log("transmitter", "Started", InstantLogger.TypeMessage.important);
            string[] strings;

            try {
                strings = File.ReadAllLines("BlowData.csv");
            }
            catch {
                strings = new string[0];
                //Console.Write("cannot read the file");
                InstantLogger.log("Cannot read the file", "Error", InstantLogger.TypeMessage.error);
                return;
            }
            //Console.Write(strings.ToString() + "\n");

            comBlowingSchemaEvent blowingSchemaEvent = new comBlowingSchemaEvent();
            List<int> O2Vol = new List<int>();
            List<int> LancePosition = new List<int>();
            List<double> O2Flow = new List<double>();
            int O2SchemaNumber = 0;
            O2Vol.Add(-1); // выравнивание чтобы совпадали номера
            LancePosition.Add(-1); // выравнивание чтобы совпадали номера
            O2Flow.Add(-1); // выравнивание чтобы совпадали номера

            for (int i = 1; i < strings.Count(); i++) // в нулевой строке заголовки
            {
                string[] values = strings[i].Split(' ');

                O2SchemaNumber = int.Parse(values[0], culture);
                O2Vol.Add(int.Parse(values[1], culture));
                LancePosition.Add(int.Parse(values[2], culture));
                O2Flow.Add(double.Parse(values[3], culture));
            }
            /* lock (consoleLock)
            {
                Console.BackgroundColor = ConsoleColor.Black;
                Console.ForegroundColor = ConsoleColor.DarkGray;
                Console.WriteLine("transmitter...................................................................................[send]\n");
            }*/
            InstantLogger.log("transmitter", "Send", InstantLogger.TypeMessage.unimportant);

            blowingSchemaEvent.O2SchemaNumber = O2SchemaNumber;
            blowingSchemaEvent.O2VolStep1 = O2Vol.ElementAt(1);
            blowingSchemaEvent.O2VolStep2 = O2Vol.ElementAt(2);
            blowingSchemaEvent.O2VolStep3 = O2Vol.ElementAt(3);
            blowingSchemaEvent.O2VolStep4 = O2Vol.ElementAt(4);
            blowingSchemaEvent.O2VolStep5 = O2Vol.ElementAt(5);
            blowingSchemaEvent.O2VolStep6 = O2Vol.ElementAt(6);
            blowingSchemaEvent.O2VolStep7 = O2Vol.ElementAt(7);
            blowingSchemaEvent.O2VolStep8 = O2Vol.ElementAt(8);
            blowingSchemaEvent.O2VolStep9 = O2Vol.ElementAt(9);
            blowingSchemaEvent.O2VolStep10 = O2Vol.ElementAt(10);
            blowingSchemaEvent.O2VolStep11 = O2Vol.ElementAt(11);
            blowingSchemaEvent.O2VolStep12 = O2Vol.ElementAt(12);
            blowingSchemaEvent.O2VolStep13 = O2Vol.ElementAt(13);
            blowingSchemaEvent.O2VolStep14 = O2Vol.ElementAt(14);
            blowingSchemaEvent.O2VolStep15 = O2Vol.ElementAt(15);
            blowingSchemaEvent.O2VolStep16 = O2Vol.ElementAt(16);
            blowingSchemaEvent.O2VolStep17 = O2Vol.ElementAt(17);
            blowingSchemaEvent.O2VolStep18 = O2Vol.ElementAt(18);
            blowingSchemaEvent.O2VolStep19 = O2Vol.ElementAt(19);
            blowingSchemaEvent.O2VolStep20 = O2Vol.ElementAt(20);
            blowingSchemaEvent.LancePositionStep1 = LancePosition.ElementAt(1);
            blowingSchemaEvent.LancePositionStep2 = LancePosition.ElementAt(2);
            blowingSchemaEvent.LancePositionStep3 = LancePosition.ElementAt(3);
            blowingSchemaEvent.LancePositionStep4 = LancePosition.ElementAt(4);
            blowingSchemaEvent.LancePositionStep5 = LancePosition.ElementAt(5);
            blowingSchemaEvent.LancePositionStep6 = LancePosition.ElementAt(6);
            blowingSchemaEvent.LancePositionStep7 = LancePosition.ElementAt(7);
            blowingSchemaEvent.LancePositionStep8 = LancePosition.ElementAt(8);
            blowingSchemaEvent.LancePositionStep9 = LancePosition.ElementAt(9);
            blowingSchemaEvent.LancePositionStep10 = LancePosition.ElementAt(10);
            blowingSchemaEvent.LancePositionStep11 = LancePosition.ElementAt(11);
            blowingSchemaEvent.LancePositionStep12 = LancePosition.ElementAt(12);
            blowingSchemaEvent.LancePositionStep13 = LancePosition.ElementAt(13);
            blowingSchemaEvent.LancePositionStep14 = LancePosition.ElementAt(14);
            blowingSchemaEvent.LancePositionStep15 = LancePosition.ElementAt(15);
            blowingSchemaEvent.LancePositionStep16 = LancePosition.ElementAt(16);
            blowingSchemaEvent.LancePositionStep17 = LancePosition.ElementAt(17);
            blowingSchemaEvent.LancePositionStep18 = LancePosition.ElementAt(18);
            blowingSchemaEvent.LancePositionStep19 = LancePosition.ElementAt(19);
            blowingSchemaEvent.LancePositionStep20 = LancePosition.ElementAt(20);
            blowingSchemaEvent.O2FlowStep1 = O2Flow.ElementAt(1);
            blowingSchemaEvent.O2FlowStep2 = O2Flow.ElementAt(2);
            blowingSchemaEvent.O2FlowStep3 = O2Flow.ElementAt(3);
            blowingSchemaEvent.O2FlowStep4 = O2Flow.ElementAt(4);
            blowingSchemaEvent.O2FlowStep5 = O2Flow.ElementAt(5);
            blowingSchemaEvent.O2FlowStep6 = O2Flow.ElementAt(6);
            blowingSchemaEvent.O2FlowStep7 = O2Flow.ElementAt(7);
            blowingSchemaEvent.O2FlowStep8 = O2Flow.ElementAt(8);
            blowingSchemaEvent.O2FlowStep9 = O2Flow.ElementAt(9);
            blowingSchemaEvent.O2FlowStep10 = O2Flow.ElementAt(10);
            blowingSchemaEvent.O2FlowStep11 = O2Flow.ElementAt(11);
            blowingSchemaEvent.O2FlowStep12 = O2Flow.ElementAt(12);
            blowingSchemaEvent.O2FlowStep13 = O2Flow.ElementAt(13);
            blowingSchemaEvent.O2FlowStep14 = O2Flow.ElementAt(14);
            blowingSchemaEvent.O2FlowStep15 = O2Flow.ElementAt(15);
            blowingSchemaEvent.O2FlowStep16 = O2Flow.ElementAt(16);
            blowingSchemaEvent.O2FlowStep17 = O2Flow.ElementAt(17);
            blowingSchemaEvent.O2FlowStep18 = O2Flow.ElementAt(18);
            blowingSchemaEvent.O2FlowStep19 = O2Flow.ElementAt(19);
            blowingSchemaEvent.O2FlowStep20 = O2Flow.ElementAt(20);

            SteelMakingPatternEvent steelMakingPatternEvent = new SteelMakingPatternEvent();
            steelMakingPatternEvent.materialsName[0] = "SUKA yana";
            steelMakingPatternEvent.materialsName[1] = "ДОЛОМС";
            steelMakingPatternEvent.materialsName[2] = "3material";
            steelMakingPatternEvent.materialsName[3] = "4material";
            steelMakingPatternEvent.materialsName[4] = "PULSE-CC";
            steelMakingPatternEvent.materialsName[5] = "6material";
            steelMakingPatternEvent.materialsName[6] = "7material";
            steelMakingPatternEvent.materialsName[7] = "8material";
            steelMakingPatternEvent.materialsName[8] = "9material";
            steelMakingPatternEvent.materialsName[9] = "ЯНА";

            steelMakingPatternEvent.steps.Add(new Converter.SteelMakingClasses.Step());
            steelMakingPatternEvent.steps[0].lance.LancePositin = 700;
            steelMakingPatternEvent.steps[0].lance.O2Flow = 450;
            steelMakingPatternEvent.steps[0].O2Volume = 0;

            /*     for (int i = 0; i < 10; i++)
            {
                steelMakingPatternEvent.steps[0].additions.addition[i].MaterialPortionWeight = 0;
            }
             */

            Random rnd1 = new Random();
            int qq = 0;
            for (int step = 1; step <= 25; step++) {
                steelMakingPatternEvent.steps.Add(new Converter.SteelMakingClasses.Step());
                steelMakingPatternEvent.steps[step].lance.LancePositin =
                    steelMakingPatternEvent.steps[step - 1].lance.LancePositin - 25;
                steelMakingPatternEvent.steps[step].lance.O2Flow = 1000;
                steelMakingPatternEvent.steps[step].O2Volume = steelMakingPatternEvent.steps[step - 1].O2Volume + 100;
                //qq = rnd1.Next(10);
                //steelMakingPatternEvent.steps[step].additions.addition[rnd1.Next(10)].MaterialPortionWeight = rnd1.Next(100,1000);
                int weigherid = rnd1.Next(5);
                steelMakingPatternEvent.steps[step].weigherLines[weigherid].PortionWeight = rnd1.Next(100, 1000);
                //steelMakingPatternEvent.steps[step].weigherLines[weigherid].BunkerId = rnd1.Next(8);
                if (weigherid == 0)
                    steelMakingPatternEvent.steps[step].weigherLines[weigherid].BunkerId = rnd1.Next(0, 2);
                if (weigherid == 1)
                    steelMakingPatternEvent.steps[step].weigherLines[weigherid].BunkerId = 2;
                if (weigherid == 2)
                    steelMakingPatternEvent.steps[step].weigherLines[weigherid].BunkerId = 3;
                if (weigherid == 3)
                    steelMakingPatternEvent.steps[step].weigherLines[weigherid].BunkerId = 4;
                if (weigherid == 4)
                    steelMakingPatternEvent.steps[step].weigherLines[weigherid].BunkerId = rnd1.Next(5, 8);

                /* for (int i = 0; i < 10; i++)
                {
                    steelMakingPatternEvent.steps[step].additions.addition[i].MaterialPortionWeight = 1000 + i*100 + i*10 + i;
                }*/

                /*steelMakingPatternEvent.steps[step].additions.addition[0].MaterialPortionWeight = 100;
                steelMakingPatternEvent.steps[step].additions.addition[0].O2VolPortionMateria =
                    steelMakingPatternEvent.steps[step].lance.O2Volume;*/
            }
            /* steelMakingPatternEvent.steps[5].additions.addition[0].MaterialPortionWeight = 50;
            steelMakingPatternEvent.steps[10].additions.addition[0].MaterialPortionWeight = 100;

            steelMakingPatternEvent.steps[7].additions.addition[1].MaterialPortionWeight = 71;
            steelMakingPatternEvent.steps[15].additions.addition[1].MaterialPortionWeight = 151;*/

            /* steelMakingPatternEvent.steps[0].additions.addition[0].MaterialPortionWeight = 100;
            steelMakingPatternEvent.steps[0].additions.addition[0].O2VolPortionMateria = 200;

            steelMakingPatternEvent.steps[0].additions.addition[1].MaterialPortionWeight = 100;
            steelMakingPatternEvent.steps[0].additions.addition[1].O2VolPortionMateria = 200;

            steelMakingPatternEvent.steps[0].additions.addition[2].MaterialPortionWeight = 200;
            steelMakingPatternEvent.steps[0].additions.addition[2].O2VolPortionMateria = 200;

            steelMakingPatternEvent.steps[1].additions.addition[3].MaterialPortionWeight = 200;
            steelMakingPatternEvent.steps[1].additions.addition[3].O2VolPortionMateria = 200;*/

            //steelMakingPatternEvent.steps[0].additions.
            BlowingEvent blowingEvent = new BlowingEvent();
            blowingEvent.O2TotalVol = 0;
            //    mainGate.PushEvent(blowingEvent);

            //   mainGate.PushEvent(steelMakingPatternEvent);

            //blowingEvent.O2TotalVol = 200;
            /*     ComName1MatEvent ssss =new ComName1MatEvent();
            ssss.Name = "TEST";

            ComName2MatEvent cccc = new ComName2MatEvent();
            cccc.Name[0] = (char) 6;
            cccc.Name[1] = (char) 1;
            cccc.Name[3] = (char) 32;*/
            var WSE = new WeighersStateEvent();
            WSE.Weigher3Empty = 1;
            WSE.Weigher3LoadFree = 1;
            WSE.Weigher3UnLoadFree = 1;
            WSE.Weigher4Empty = 1;
            WSE.Weigher4LoadFree = 1;
            WSE.Weigher4UnLoadFree = 1;
            WSE.Weigher5Empty = 1;
            WSE.Weigher5LoadFree = 1;
            WSE.Weigher5UnLoadFree = 1;
            WSE.Weigher6Empty = 1;
            WSE.Weigher6LoadFree = 1;
            WSE.Weigher6UnLoadFree = 1;
            WSE.Weigher7Empty = 1;
            WSE.Weigher7LoadFree = 1;
            WSE.Weigher7UnLoadFree = 1;

            //!!!!!     mainGate.PushEvent(steelMakingPatternEvent);

            //mainGate.PushEvent(new OPCDirectReadEvent() { EventName = "comAdditionsEvent" });
            //int currentStep = 0;
            //while (true)
            //{
            //    if (currentStep > 15)
            //    {
            //        currentStep = 0;
            //    }
            //    else
            //    {
            //        currentStep++;
            //        mainGate.PushEvent(new HeatSchemaStepEvent {Step = currentStep});
            //        Thread.Sleep(1000);
            //    }
            //}

            int cnt = 0;
            int step2 = 0;
            bool stepChange = false;
            /*   while (true)
            {
                         blowingEvent.O2TotalVol +=10;
                mainGate.PushEvent(blowingEvent);
                //mainGate.PushEvent(WSE);
                cnt++;
                if (cnt > 10)
                {
                    //mainGate.PushEvent(steelMakingPatternEvent);
                    //Thread.Sleep(3000);
                    cnt = 0;
                }
               // mainGate.PushEvent(new cntWatchDogPLC01Event());

                //mainGate.PushEvent(WSE);
                if (steelMakingPatternEvent.steps.Count > step2)
                {
                    if (steelMakingPatternEvent.steps[step2].O2Volume < blowingEvent.O2TotalVol)
                    {
                        step2++;
                        stepChange = true;
                    }
                }
                if (steelMakingPatternEvent.steps.Count > step2)
                {
                    if (stepChange)
                    {
                        if (steelMakingPatternEvent.steps[step2].weigherLines[0].PortionWeight > 0)
                        {
                            mainGate.PushEvent(new WeighersStateEvent()
                                                   {Weigher3Empty = 1, Weigher3LoadFree = 1, Weigher3UnLoadFree = 1});
                            stepChange = false;
                            InstantLogger.log("W3 - " +
                                       steelMakingPatternEvent.steps[step2].weigherLines[0].PortionWeight.ToString());
                        }
                        if (steelMakingPatternEvent.steps[step2].weigherLines[1].PortionWeight > 0)
                        {
                            mainGate.PushEvent(new WeighersStateEvent()
                                                   {Weigher4Empty = 1, Weigher4LoadFree = 1, Weigher4UnLoadFree = 1});
                            stepChange = false;
                            InstantLogger.log("W4 - " +
                                       steelMakingPatternEvent.steps[step2].weigherLines[1].PortionWeight.ToString());
                        }
                        if (steelMakingPatternEvent.steps[step2].weigherLines[2].PortionWeight > 0)
                        {
                            mainGate.PushEvent(new WeighersStateEvent()
                                                   {Weigher5Empty = 1, Weigher5LoadFree = 1, Weigher5UnLoadFree = 1});
                            stepChange = false;
                            InstantLogger.log("W5 - " +
                                       steelMakingPatternEvent.steps[step2].weigherLines[2].PortionWeight.ToString());
                        }
                        if (steelMakingPatternEvent.steps[step2].weigherLines[3].PortionWeight > 0)
                        {
                            mainGate.PushEvent(new WeighersStateEvent()
                                                   {Weigher6Empty = 1, Weigher6LoadFree = 1, Weigher6UnLoadFree = 1});
                            stepChange = false;
                            InstantLogger.log("W6 - " +
                                       steelMakingPatternEvent.steps[step2].weigherLines[3].PortionWeight.ToString());
                        }
                        if (steelMakingPatternEvent.steps[step2].weigherLines[4].PortionWeight > 0)
                        {
                            mainGate.PushEvent(new WeighersStateEvent()
                                                   {Weigher7Empty = 1, Weigher7LoadFree = 1, Weigher7UnLoadFree = 1});
                            stepChange = false;
                            InstantLogger.log("W7 - " +
                                       steelMakingPatternEvent.steps[step2].weigherLines[4].PortionWeight.ToString());
                        }
                    }
                }

                Thread.Sleep(1000);
            }*/

            //comO2FlowRateEvent _comO2FlowRateEvent = new comO2FlowRateEvent();
            //BlowingEvent blowingEvent = new BlowingEvent();
            //blowingEvent.O2TotalVol = 1000;

            //_comO2FlowRateEvent.O2TotalVol = 1000;
            //mainGate.PushEvent(_comO2FlowRateEvent);
            // mainGate.PushEvent(new cntO2FlowRateEvent());
            //mainGate.PushEvent(blowingSchemaEvent);
            //mainGate.PushEvent(new cntBlowingSchemaEvent());
            //_comO2FlowRateEvent.iCnvNr = 1;
            /*  while (true)
            {
                _comO2FlowRateEvent.O2TotalVol++;
                blowingEvent.O2TotalVol++;
                mainGate.PushEvent(blowingEvent);
                //mainGate.PushEvent(_comO2FlowRateEvent);
                mainGate.PushEvent(new cntWatchDogPLC01Event());
              //  mainGate.PushEvent(new cntBlowingSchemaEvent());
                //mainGate.PushEvent(new cntWatchDogPLC1Event());
                mainGate.PushEvent(_comO2FlowRateEvent);
                //mainGate.PushEvent(new cntWatchDogPLC1Event());
                Thread.Sleep(1000);
            }*/
            //SteelMakingPatternEvent ss = new SteelMakingPatternEvent();
            //ss.steps.Add(new Converter.SteelMakingClasses.Step() { Period = 777});
            //ss.steps.Add(new Converter.SteelMakingClasses.Step());
            //Console.Write(ss.ToString());
            //Console.Write(ss.steps[0].Period.ToString());
            // mainGate.PushEvent(ss);
            /* while (true)
            {
                lock (mainGate)
                {
                    mainGate.PushEvent(blowingSchemaEvent);
                    blowingSchemaEvent.O2FlowStep20++;
                }
                Thread.Sleep(1000);
            }*/
        }
        private bool ProcessEvent(BlowingEvent _event)
        {
            // Начало главной продувки
            if (_event.BlowingFlag == 1 && !Repositary.ContainsKey("BlowingStartDate"))
            {
                try
                {
                    DBWorker.Instance.Insert((int)HeatPassportOperations.BlowingEvent, _event.Time, m_ConverterNumber, HeatNumber, _event.BlowingFlag, _event.O2TotalVol, 0, 1);
                    Repositary.Add("BlowingStartDate", _event.Time);
                }
                catch { return false; }
            }

            // Конец главной продувки
            if (_event.BlowingFlag == 0 && Repositary.ContainsKey("BlowingStartDate"))
            {
                try
                {
                    DBWorker.Instance.Insert((int)HeatPassportOperations.BlowingEvent, _event.Time, m_ConverterNumber, HeatNumber, _event.BlowingFlag, _event.O2TotalVol,
                        (_event.Time - (DateTime)Repositary["BlowingStartDate"]).TotalSeconds, 1);
                    Repositary.Remove("BlowingStartDate");
                }
                catch { return false; }
            }
            return true;
        }
        private void React(object data)
        {
            var e = data as BaseEvent;
            if (e != null)
            {
                Type eventType = e.GetType();
                Console.WriteLine("Incoming event. Event type is " + eventType);
                if (eventType == typeof(OPCDirectReadEvent))
                {
                    var opcDirectReadEvent = e as OPCDirectReadEvent;
                    if (opcDirectReadEvent != null)
                        Console.WriteLine("OPCDirectReadEvent asking for " + opcDirectReadEvent.EventName);
                    if (opcDirectReadEvent != null &&
                        (opcDirectReadEvent).EventName == typeof(BoundNameMaterialsEvent).Name)
                    {
                        var reaction = new BoundNameMaterialsEvent
                                           {
                                               Bunker5MaterialName = "ДОЛОМС",
                                               Bunker6MaterialName = "ALКонц",
                                               Bunker7MaterialName = "KOKS  ",
                                               Bunker8MaterialName = "ИЗВЕСТ",
                                               Bunker9MaterialName = "ИЗВЕСТ",
                                               Bunker10MaterialName = "ДОЛОМС",
                                               Bunker11MaterialName = "ФОМ   ",
                                               Bunker12MaterialName = "МАХГ  "
                                           };
                        _gate.PushEvent(reaction);
                        //HeatChangeEvent HCE = new HeatChangeEvent();
                        //HCE.HeatNumber = 23989;
                        //_gate.PushEvent(HCE);
                        //Thread.Sleep(3000);
                        Console.WriteLine("BoundNameMaterialsEvent send");
                        var realO = new BlowingEvent() { O2TotalVol = 0 };
                        _gate.PushEvent(realO);
                        for (int i = 1; i < 11; i++)
                        {
                            var additions = new visAdditionTotalEvent
                            {
                                RB5TotalWeight = 100 * i,
                                RB6TotalWeight = 100 * i,
                                RB7TotalWeight = 100 * i,
                                RB8TotalWeight = 100 * i,
                                RB9TotalWeight = 100 * i,
                                RB10TotalWeight = 100 * i,
                                RB11TotalWeight = 100 * i,
                                RB12TotalWeight = 100 * i
                            };
                            _gate.PushEvent(additions);
                            Thread.Sleep(5000);
                        }
                        for (int i = 0; i < 10; i++)
                        {
                            var realO2 = new BlowingEvent() { O2TotalVol = 1 };
                            _gate.PushEvent(realO2);
                            Thread.Sleep(1000);
                        }

                        var realzeroO2 = new BlowingEvent() { O2TotalVol = 0 };
                        _gate.PushEvent(realzeroO2);
                    }
                    if (opcDirectReadEvent != null &&
                        (opcDirectReadEvent).EventName == typeof(ModeVerticalPathEvent).Name)
                    {
                        var reaction = new ModeVerticalPathEvent
                        {
                            VerticalPathMode = 1
                        };
                        _gate.PushEvent(reaction);
                        Console.WriteLine("ModeVerticalPathEvent send");
                    }

                    if (opcDirectReadEvent != null &&
                        (opcDirectReadEvent).EventName == typeof(ModeLanceEvent).Name)
                    {
                        var reaction = new ModeLanceEvent
                        {
                            LanceMode = 3,
                            O2FlowMode = 3
                        };
                        _gate.PushEvent(reaction);
                        Console.WriteLine("ModeLanceEvent send");
                    }

                }
                if (eventType == typeof(SteelMakingPatternEvent))
                {
                    if (_processingHeat)
                    {
                        return;
                    }
                    _processingHeat = true;
                    var steelMakingPatternEvent = e as SteelMakingPatternEvent;
                    if (steelMakingPatternEvent != null)
                    {
                        int stepsCount = steelMakingPatternEvent.steps.Count;
                        for (int i = 0; i < stepsCount; i++)
                        {
                            var reaction = new HeatSchemaStepEvent
                                               {
                                                   Step = i
                                               };
                            var realO2 = new BlowingEvent() { O2TotalVol = 25000 * i / stepsCount };
                            var realLance = new LanceEvent() { LanceHeight = 700 - (700 * i / stepsCount) };
                            _gate.PushEvent(reaction);
                            Console.WriteLine("HeatSchemaStepEvent send");
                            InstantLogger.log(DateTime.Now.ToString() + " Новый шаг, HeatSchemaStepEvent send\r\n");
                            _gate.PushEvent(realO2);
                            Console.WriteLine("BlowingEvent send");
                            _gate.PushEvent(realLance);
                            Console.WriteLine("LanceEvent send");

                            Thread.Sleep(5000);
                        }
                    }
                    //var fex = new FlexHelper("CorrectionCT.RecommendBalanceBlow");
                    //fex.AddArg("CorrectionOxygenT", 18700);
                    //fex.AddArg("CorrectionOxygenC", 18710);
                    //fex.AddArg("CurrentC", 0.432);
                    //fex.AddArg("TargetC", 0.432);
                    //fex.AddArg("CurrentT", 1670);
                    //fex.AddArg("TargetT", 1680);
                    //fex.Fire(_gate);

                    var lastReaction = new HeatSchemaStepEvent
                                           {
                                               Step = -1
                                           };
                    _gate.PushEvent(lastReaction);
                    Console.WriteLine("HeatSchemaStepEvent with stop signal send");
                    _processingHeat = false;
                }
            }
        }