Exemplo n.º 1
0
        //Create Parking Spot with DLL service
        public static void CreateParkingSpotDLL(string parkingSpotInfo)
        {
            dll.Stop();

            //ParkId;SpotId;Timestamp;ParkingSpotStatus;BatteryStatus
            string[] info = parkingSpotInfo.Split(';');

            Console.WriteLine("--------------- CREATE PARKING SPOT DATA CONTRACT ------------------");

            #region CreateParkingSpotDataContract
            bool batteryStatus = false, spotStatus = false;

            int batteryStatusInt = Convert.ToInt32(info[4], NumberFormatInfo.InvariantInfo);
            int spotStatusInt    = Convert.ToInt32(info[3], NumberFormatInfo.InvariantInfo);

            if (batteryStatusInt == 1)
            {
                batteryStatus = true;
            }

            if (spotStatusInt == 1)
            {
                spotStatus = true;
            }

            ParkingSpot newParkingSpot = new ParkingSpot
            {
                BatteryStatus = batteryStatus,
                Location      = null,
                ParkId        = info[0],
                SpotId        = info[1],
                Status        = new Status
                {
                    Timestamp = DateTime.Parse(info[2]),
                    Value     = spotStatus
                },
                Type = ServiceReferenceParkingSpots.Type.ParkingSpot
            };
            #endregion

            Console.WriteLine("--------------- CREATE PARKING SPOT XML ------------------");

            #region CreateParkingSpotXML
            XmlDocument doc = new XmlDocument();
            // Create the XML Declaration, and append it to XML document
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);
            doc.AppendChild(dec); //dec é o header do doc XML

            HandlerXML handlerXML = new HandlerXML(m_strFilenameParkingSpotXML, m_strFilenameParkingSpotXSD);

            string parkingSpotXML = handlerXML.CreateParkingSpotXML(newParkingSpot);
            doc.InnerXml += parkingSpotXML;
            doc.Save(m_strFilenameParkingSpotXML);

            if (!handlerXML.ValidateXML())
            {
                Console.WriteLine(handlerXML.ValidationMessage);
                return;
            }
            Console.WriteLine("SUCCESS: Parking spot XML file created.");
            #endregion

            Console.WriteLine("--------------- SHOW PARKING SPOT XML ------------------");
            Console.WriteLine("Parking Spot Xml (DLL): " + parkingSpotXML);

            string endpoint = dll.ToString();

            JoinData("DLL", newParkingSpot, parkingSpotXML, endpoint);

            dll.DoWork();
        }
Exemplo n.º 2
0
        public static void JoinData(string connectionType, ParkingSpot parkingSpot, string parkingSpotXML, string endpoint)
        {
            Console.WriteLine("-------------- GET PARKING SPOT LOCATION -----------------");

            #region UpdateLocation

            string filename = GetGeoLocationFilename(parkingSpot.ParkId);

            if (filename == null)
            {
                Console.WriteLine("ERROR: No filename information attached on the requested parking spot");
            }
            else
            {
                Console.WriteLine("GeoLocationFilename: " + filename);
            }

            string str_pathExcelFile = m_strPathApp + "\\" + filename;

            int[] cell = GetSpotCellFromExcelFile(str_pathExcelFile, parkingSpot.SpotId);

            if (cell == null)
            {
                Console.WriteLine("ERROR: Parking Spot not found on the file.");
                return;
            }
            else
            {
                Console.WriteLine("Cell: " + cell[0].ToString() + "," + cell[1].ToString());
            }

            string location = GetLocationFromExcelFile(str_pathExcelFile, cell[0], cell[1]);

            if (location == null)
            {
                Console.WriteLine("ERROR: No corresponding GeoLocation of the parking spot on the file.");
                return;
            }
            else
            {
                Console.WriteLine("Location: " + location);
            }
            #endregion

            Console.WriteLine("------- UPDATE CONFIG FILE WITH NEW PARKING SPOT, LOCATION AND ENDPOINT ----------");

            #region UpdateConfigFile
            if (!UpdateConfigFile(parkingSpotXML, parkingSpot.ParkId, parkingSpot.SpotId, location, connectionType, endpoint))
            {
                Console.WriteLine("ERROR: Configuration file not updated with new parkingSpot.");
                return;
            }
            else
            {
                Console.WriteLine("SUCCESS: Configuration file updated with new parking spot data.");
            }
            #endregion

            Console.WriteLine("----------------------- VALIDATE CONFIG FILE ---------------------------");

            #region ValidateConfigFile
            HandlerXML handlerXML = new HandlerXML(m_strFilenameParkingNodesXML, m_strFilenameParkingNodesXSD);

            if (!handlerXML.ValidateXML())
            {
                Console.WriteLine("ERROR: Configuration file validation failed");
            }
            else
            {
                Console.WriteLine("SUCCESS: Configuration file validation succeded");
            }
            #endregion
        }