예제 #1
0
        public void UpisiUBazu(Logger l)
        {
            lock (obj)
            {
                if (File.Exists(file))
                {
                    try
                    {
                        using (StreamWriter sw = new StreamWriter(file, true))
                        {
                            foreach (var podatak in DeadbandList)
                            {
                                string c1 = $"{podatak.Item1.Code} {podatak.Item1.Value}";
                                string c2 = $"{podatak.Item2.Code} {podatak.Item2.Value}";

                                sw.WriteLine($"{c1} {c2}");
                            }
                            DeadbandList.Clear();
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("The file could not be read:");
                        Console.WriteLine(e.Message);
                    }
                }
                else if (Buffer.Count != 0)
                {
                    using (StreamWriter sw = new StreamWriter(file, true))
                    {
                        foreach (var podatak in Buffer)
                        {
                            string c1 = $"{podatak.Item1.Code} {podatak.Item1.Value}";
                            string c2 = $"{podatak.Item2.Code} {podatak.Item2.Value}";

                            sw.WriteLine($"{c1} {c2}");
                        }
                        Buffer.Clear();
                    }
                }
                string log = String.Format("{0}: ReaderCSCM upisuje u bazu\n", DateTime.Now);
                l.Upisi(log);
            }
        }
예제 #2
0
        public void Deadband(Logger l)
        {
            lock (obj)
            {
                if (File.Exists(file))
                {
                    try
                    {
                        string[] allText = File.ReadAllLines(file);
                        foreach (string line in allText)
                        {
                            if (!String.IsNullOrWhiteSpace(line))
                            {
                                string[] niz   = line.Split(' ');
                                string   code1 = niz[0];
                                int      code1Value;
                                Int32.TryParse(niz[1], out code1Value);
                                string code2 = niz[2];
                                int    code2Value;
                                Int32.TryParse(niz[3], out code2Value);
                                foreach (var podatak in Buffer)
                                {
                                    if (code1 == podatak.Item1.Code.ToString())
                                    {
                                        if (podatak.Item1.Value < code1Value * 0.98 ||
                                            podatak.Item1.Value > code1Value * 1.02 &&
                                            podatak.Item2.Value < code2Value * 0.98 ||
                                            podatak.Item2.Value > code2Value * 1.02)
                                        {
                                            if (!DeadbandList.Contains(podatak))
                                            {
                                                DeadbandList.Add(podatak);
                                            }
                                        }
                                    }
                                    if (code1 == podatak.Item2.Code.ToString())
                                    {
                                        if (podatak.Item1.Value < code2Value * 0.98 ||
                                            podatak.Item1.Value > code2Value * 1.02 &&
                                            podatak.Item2.Value < code1Value * 0.98 ||
                                            podatak.Item2.Value > code1Value * 1.02)
                                        {
                                            if (!DeadbandList.Contains(podatak))
                                            {
                                                DeadbandList.Add(podatak);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        Buffer.Clear();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("The file could not be read:");
                        Console.WriteLine(e.Message);
                    }

                    string log = String.Format("{0}: ReaderCSCM vrsi deadband proveru\n", DateTime.Now);
                    l.Upisi(log);
                }
            }
        }
예제 #3
0
        public void Deadband(Logger l)
        {
            lock (obj)
            {
                if (System.IO.File.Exists(File))
                {
                    try
                    {
                        string[] allText = System.IO.File.ReadAllLines(File);
                        foreach (string line in allText)
                        {
                            if (!string.IsNullOrWhiteSpace(line))
                            {
                                string[] niz   = line.Split(' ');
                                string   code1 = niz[0];
                                int      code1Value;
                                int.TryParse(niz[1], out code1Value);
                                string code2 = niz[2];
                                int    code2Value;
                                int.TryParse(niz[3], out code2Value);
                                for (int i = 0; i < buffer.Count; i++)
                                {
                                    if (code1 == buffer[i].Item1.Code.ToString())
                                    {
                                        if (buffer[i].Item1.Value <code1Value * 0.98 ||
                                                                   buffer[i].Item1.Value> code1Value * 1.02 &&
                                            buffer[i].Item2.Value <code2Value * 0.98 ||
                                                                   buffer[i].Item2.Value> code2Value * 1.02)
                                        {
                                            //if (!DeadbandList.Contains(buffer[i]))
                                            //{
                                            //    DeadbandList.Add(buffer[i]);
                                            //}
                                        }
                                        else
                                        {
                                            buffer.Remove(buffer[i]);
                                            i--;
                                        }
                                    }
                                    else if (code1 == buffer[i].Item2.Code.ToString())
                                    {
                                        if (buffer[i].Item1.Value <code2Value * 0.98 ||
                                                                   buffer[i].Item1.Value> code2Value * 1.02 &&
                                            buffer[i].Item2.Value <code1Value * 0.98 ||
                                                                   buffer[i].Item2.Value> code1Value * 1.02)
                                        {
                                            //if (!DeadbandList.Contains(buffer[i]))
                                            //{
                                            //    DeadbandList.Add(buffer[i]);
                                            //}
                                        }
                                        else
                                        {
                                            buffer.Remove(buffer[i]);
                                            i--;
                                        }
                                    }
                                }
                            }
                        }
                        foreach (var podatak in buffer)
                        {
                            if (!DeadbandList.Contains(podatak))
                            {
                                DeadbandList.Add(podatak);
                            }
                        }
                        Buffer.Clear();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("The file could not be read:");
                        Console.WriteLine(e.Message);
                    }

                    string log = string.Format("{0}: ReaderCCCL vrsi deadband proveru\n", DateTime.Now);
                    l.Upisi(log);
                }
            }
        }