예제 #1
0
        private static bool HandleWarning(ref Current current)
        {
            WarningCoords wc = new WarningCoords();

            wc.OrientationIndex = current.OrientationIndex;
            wc.Postion          = current.Postion;
            bool warningRecieved = StoreWarningCoords.CheckWarningCoords(wc);

            return(warningRecieved);
        }
        public static bool CheckWarningCoords(WarningCoords wc)
        {
            List <WarningCoords> deserializedWarningCoords = new List <WarningCoords>();
            bool alreadyInList = false;

            if (!Directory.Exists(@"C:\Dev"))
            {
                throw new Exception(@"Directory Does Not Exist Please add C:\Dev");
            }

            if (File.Exists(@"C:\Dev\store.xml"))
            {
                using (FileStream fs = new FileStream(@"C:\Dev\store.xml", FileMode.Open))
                {
                    XmlSerializer _xSer             = new XmlSerializer(typeof(List <WarningCoords>));
                    var           listWarningCoords = (List <WarningCoords>)_xSer.Deserialize(fs);

                    // Upgrade to c# 7.3 to allow Tuple match in this context...
                    alreadyInList             = listWarningCoords.Any(item => item.OrientationIndex == wc.OrientationIndex && item.Postion.Item1 == wc.Postion.Item1 && item.Postion.Item2 == wc.Postion.Item2);
                    deserializedWarningCoords = listWarningCoords;
                }

                if (!alreadyInList)
                {
                    deserializedWarningCoords.Add(wc);
                    SerializeAndWriteList(deserializedWarningCoords);
                }
            }
            else
            {
                var listWarningCoords = new List <WarningCoords>();

                listWarningCoords.Add(wc);
                StoreWarningCoords.SerializeAndWriteList(listWarningCoords);
            }

            return(alreadyInList);
        }