Пример #1
0
        private static void timer_park_information_and_update(object stateInfo)
        {
            mutex.WaitOne();
            Console.WriteLine("######################Update Excel Information###########################");
            foreach (LocationExcel locationExcel in locationCampus)
            {
                locationExcel.updateIfNeedUpdate();
            }
            Console.WriteLine("####################END-Update Excel Information#########################");

            Console.WriteLine("######################Park Information###########################");
            //List<Provider> providersLocal = (List<Provider>)stateInfo;
            XmlDocument    doc = new XmlDocument();
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);

            doc.AppendChild(dec);
            XmlElement listNote = doc.CreateElement("list");

            foreach (Provider provider in providers)
            {
                ParkingInformation parkingInformation = new ParkingInformation(provider.parkInfoID, provider.parkInfoDescription, provider.parkInfoNumberOfSpots, provider.parkInfoNumberOfSpecialSpots, provider.parkInfoOperatingHours);
                listNote.AppendChild(parkingInformation.ToXML(doc));
            }

            doc.AppendChild(listNote);

            Console.WriteLine(FunctionHelper.formatXmlToUnminifierString(doc));

            Console.WriteLine("Sending information...");
            Mosquitto.publishMosquitto(mClient, new string[] { "ParkDACE\\" }, doc.OuterXml);
            Console.WriteLine("######################END-Park Information#####################\n\n");
            mutex.ReleaseMutex();
        }
Пример #2
0
        public JsonResult Get(int id)
        {
            if (id != 750)
            {
                return(new JsonResult(String.Empty));
            }

            var json = System.IO.File.ReadAllText("ParkingInfo.json");

            ParkingInformation parkInfo = JsonSerializer.Deserialize <ParkingInformation>(json);

            // Sign into parking app
            // Save Screenshot
            // Send email to recipient
            var result = ParkingService.ParkMyCar(parkInfo);

            // Send email
            if (result.Success)
            {
                var emailInfoJson = System.IO.File.ReadAllText("EmailInfo.json");
                var emailInfo     = JsonSerializer.Deserialize <EmailInformation>(emailInfoJson);
                var emailResult   = gmailService.SendEmail(result.ParkingPassLocation, emailInfo);
                return(new JsonResult(emailResult));
            }
            else
            {
                return(new JsonResult(result));
            }
        }
Пример #3
0
        private static void updatePark(ParkingInformation park)
        {
            SqlConnection conn = new SqlConnection(connectionString);

            conn.Open();
            SqlCommand sql = new SqlCommand("Select description, operating_hours, number_spots, number_special_spots From Parks Where id = @id", conn);

            sql.Parameters.AddWithValue("@id", park.id);
            SqlDataReader reader = sql.ExecuteReader();

            if (reader.Read())
            {
                if (park.description.Equals(reader["description"]) && park.operatingHours.Equals(reader["operating_hours"]) && park.numberOfSpots == Convert.ToInt32(reader["number_spots"]) && park.numberOfSpecialSpots == Convert.ToInt32(reader["number_special_spots"]))
                {
                    reader.Close();
                    conn.Close();
                    return;
                }
            }
            reader.Close();
            SqlCommand cmd = new SqlCommand("UPDATE Parks SET description = @description, operating_hours = @operatingHours, number_spots = @numberSpots, number_special_spots = @numberSpecialSpots WHERE Id = @id", conn);

            cmd.Parameters.AddWithValue("@description", park.description);
            cmd.Parameters.AddWithValue("@operatingHours", park.operatingHours);
            cmd.Parameters.AddWithValue("@numberSpots", park.numberOfSpots);
            cmd.Parameters.AddWithValue("@numberSpecialSpots", park.numberOfSpecialSpots);
            cmd.Parameters.AddWithValue("@id", park.id);
            int i = cmd.ExecuteNonQuery();

            conn.Close();
        }
Пример #4
0
        public ParkingResult ParkMyCar(ParkingInformation parkInfo)
        {
            var parkingAttemptResult = new ParkingResult();

            try
            {
                this.driver = new ChromeDriver(options);
                driver.Manage().Window.Size = new Size(iPhoneXWidth, iPhoneXHeight);
                var visitResult   = VerifyMyVisit(parkInfo.PhoneNumber, parkInfo.ApartmentNumber);
                var detailsResult = EnterVehicleDetails(parkInfo.PlateNumber, parkInfo.PlateState, parkInfo.CarMake, parkInfo.CarModel, parkInfo.CarColor, parkInfo.CarYear);
                var confirmResult = ConfirmRules();

                var ssLocation = Path.GetFullPath(GetPass());
                Console.WriteLine(ssLocation);

                parkingAttemptResult.Success             = (visitResult.Success && detailsResult.Success && confirmResult.Success);
                parkingAttemptResult.ParkingPassLocation = ssLocation;
            }
            catch (Exception e)
            {
                parkingAttemptResult.Success      = false;
                parkingAttemptResult.ErrorMessage = $"{e.Message} ::: {e.StackTrace}";
            }
            finally
            {
                driver.Quit();
                this.driver = null;
            }
            return(parkingAttemptResult);
        }
Пример #5
0
        /// <summary>
        /// Park the Vehicle
        /// </summary>
        /// <param name="Info"></param>
        /// <returns></returns>
        public bool ParkVehicle(Information Info)
        {
            try
            {
                bool parkingtype = Enum.TryParse <Parkingtype>(Info.ParkingType, true, out Parkingtype Parkingtype);
                if (parkingtype != true)
                {
                    throw new Exception("Invalid Parking Type");
                }
                string VehicalNo  = Info.VehicalNumber;
                var    Validation = dBContext.ParkingInfo.Where(u => u.VehicalNo == Info.VehicalNumber).FirstOrDefault();

                if (Validation != null)
                {
                    throw new Exception("User Already Exist ");                     //throw exception when user exist
                }
                int ParkingSlotNo = AllotcateSlot();
                if (ParkingSlotNo == 0)
                {
                    throw new Exception("Parking is Full ");
                }
                ParkingInformation data = new ParkingInformation
                {
                    EntryTime     = DateTime.Now,
                    VehicalNo     = Info.VehicalNumber,
                    VehicalBrand  = Info.VehicalBrand,
                    VehicalColor  = Info.VehicalColor,
                    ParkingType   = Info.ParkingType,
                    ParkingSlotNo = ParkingSlotNo,
                    ParkStatus    = true
                };

                var Result = dBContext.ParkingInfo.Add(data);

                if (Result != null)
                {
                    dBContext.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        public void ParkingCarInLot_ReturnsBadRequest()
        {
            ParkingInformation details = new ParkingInformation()
            {
                VehicleOwnerName = "Sahil",
                VehicalBrand     = "Toyota",
                VehicalColor     = "Black",
                DriverName       = "Anurag"
            };

            // Act
            var badRequest = parkingController.ParkingCarInLot(details);

            // Assert
            Assert.IsType <BadRequestObjectResult>(badRequest);
        }
        /*
         * //Method to Add car park details
         * public ParkingLotDetails ParkingCarInLot(ParkingLotDetails details)
         * {
         *  try
         *  {
         *      var data = parkingLotRL.ParkingCarInLot(details);
         *      if(data == null)
         *      {
         *          throw new Exception();
         *      }
         *      else
         *      {
         *          return data;
         *      }
         *  }
         *  catch(Exception exception)
         *  {
         *      throw new Exception(exception.Message);
         *  }
         * }
         */

        public ParkingLotDetails ParkingCarInLot(ParkingInformation Details)
        {
            try
            {
                var data = parkingLotRL.ParkingCarInLot(Details);
                if (data == null)
                {
                    throw new Exception();
                }
                else
                {
                    return(data);
                }
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message);
            }
        }
Пример #8
0
        public static string newParking(ParkingInformation park)
        {
            String response = "";

            try
            {
                if (!parkExists(park.id))
                {
                    response = insertNewPark(park);
                }
                else
                {
                    Thread thread = new Thread(() => updatePark(park));
                    thread.Start();
                    response = "UPDATED";
                }
            } catch (Exception ex)
            {
                throw new ParkNotInsertedException(ex.Message);
            }
            return(response);
        }
Пример #9
0
        /// <summary>
        /// Get Car Details by Vehicle Number
        /// </summary>
        /// <param name="VehicleNo"></param>
        /// <returns></returns>
        public object GetCarDetailsByVehicleNumber(string VehicleNo)
        {
            ParkingInformation detail = new ParkingInformation();

            detail.VehicalNo = VehicleNo;
            try
            {
                if (dBContext.ParkingInfo.Any(x => x.VehicalNo == VehicleNo))
                {
                    return((from Details in dBContext.ParkingInfo
                            where Details.VehicalNo == VehicleNo
                            select Details).ToList());
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Пример #10
0
        private static string insertNewPark(ParkingInformation park)
        {
            SqlConnection conn = new SqlConnection(connectionString);

            conn.Open();
            SqlCommand cmd = new SqlCommand("INSERT INTO Parks (id, description, operating_hours, number_spots, number_special_spots) VALUES (@id, @description, @operatingHours, @numberSpots, @numberSpecialSpots)", conn);

            cmd.Parameters.AddWithValue("@id", park.id);
            cmd.Parameters.AddWithValue("@description", park.description);
            cmd.Parameters.AddWithValue("@operatingHours", park.operatingHours);
            cmd.Parameters.AddWithValue("@numberSpots", park.numberOfSpots);
            cmd.Parameters.AddWithValue("@numberSpecialSpots", park.numberOfSpecialSpots);
            int i = cmd.ExecuteNonQuery();

            conn.Close();

            if (i < 1)
            {
                throw new ParkNotInsertedException("ERROR: Park could not be inserted");
            }

            return("INSERTED");
        }
        public IActionResult ParkingCarInLot(ParkingInformation Details)
        {
            try
            {
                string cacheKey = "parking";
                var    data     = parkingLotBusiness.ParkingCarInLot(Details);
                var    count    = parkingLotBusiness.ParkingLotStatus();

                if (data == null)
                {
                    return(Ok(new { success = false, message = "Parking Lot is Full" }));
                }
                else
                {
                    distributedCache.Remove(cacheKey);
                    return(Ok(new { success = true, message = "Car parked successfully", Data = data }));
                }
            }
            catch (Exception e)
            {
                return(BadRequest(new { success = false, message = e.Message }));
            }
        }
Пример #12
0
        public static void mClientPark_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e) //Recebe tudo independentement que park pretence
        {
            mutex.WaitOne();
            Console.WriteLine("#######################New Park########################################");
            Console.WriteLine("mClientPark-->> Topic: " + e.Topic);
            List <ParkingInformation> parkingsInformationsLocal = new List <ParkingInformation>();
            List <string>             parkingsNameLocal         = new List <string>();
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(Encoding.UTF8.GetString(e.Message));
            if (!FunctionHelper.ValidXML(doc, "ParkInformation.xsd"))
            {
                Console.WriteLine("##############################END New Park#################################");
                mutex.ReleaseMutex();
                return;
            }
            Console.WriteLine("XML is valid!");
            Boolean newTopics = false;

            foreach (XmlNode parkingInformationNode in doc.SelectNodes("/list/parkingInformation"))
            {
                ParkingInformation parkingInformation = new ParkingInformation(parkingInformationNode.OuterXml);
                parkingsInformationsLocal.Add(parkingInformation);
                if (parkingsNameSubscribed.Count == 0 || !parkingsNameSubscribed.Exists(topicList => topicList.Equals(parkingInformation.id)))
                {
                    Console.Write(newTopics?"": "New topics subscribed: \n");
                    newTopics = true;
                    string topic = topicsParkDACE[0] + "" + parkingInformation.id;
                    Console.WriteLine("\t\t|" + topic);
                    parkingsNameSubscribed.Add(parkingInformation.id);
                    Mosquitto.subscribedMosquitto(mClient, topic);
                }
            }
            Console.WriteLine();


            //Verificar e unsubscribe os que já não existem
            if (parkingsNameSubscribed.Count > 0)
            {
                List <string> auxList = parkingsNameLocal.Except(parkingsNameSubscribed).ToList();
                if (auxList.Count > 0)
                {
                    Console.WriteLine("Old topics Unsubscribed: ");
                    foreach (string aux in auxList)
                    {
                        Console.WriteLine("\t\t|" + topicsParkDACE[0] + "" + aux);
                        Mosquitto.unsubscribeMosquitto(mClient, new string[] { topicsParkDACE[0] + "" + aux });
                        parkingsNameSubscribed.Remove(aux);
                    }
                }
            }

            /////// Send data to BD
            string response = "";

            foreach (ParkingInformation park in parkingsInformationsLocal)
            {
                try
                {
                    response = DatabaseHelper.newParking(park);
                }
                catch (ParkNotInsertedException ex)
                {
                    response = ex.Message;
                }
                Console.WriteLine("\t\t\t" + park.id + ":" + response);
            }

            Console.WriteLine("##############################END New Park#################################");
            mutex.ReleaseMutex();
        }
Пример #13
0
        //Method to Add parking details
        public ParkingLotDetails ParkingCarInLot(ParkingInformation Details)
        {
            var condition = dataBase.ParkingLotDetails.Where(parkingDetails => parkingDetails.Status == "Park").Count();

            //check if parking lot is full or empty
            if (!condition.Equals(Limit.TotalParkingLimit))
            {
                try
                {
                    ParkingLotDetails details = new ParkingLotDetails();
                    details.VehicleOwnerName    = Details.VehicleOwnerName;
                    details.VehicleNumber       = Details.VehicleNumber;
                    details.VehicalBrand        = Details.VehicalBrand;
                    details.VehicalColor        = Details.VehicalColor;
                    details.DriverName          = Details.DriverName;
                    details.ParkingUserCategory = Details.ParkingUserCategory;

                    // Conditions
                    bool condition1 = dataBase.ParkingLotDetails.Any(parkingDetails => parkingDetails.VehicleNumber == details.VehicleNumber);
                    //bool condition2 = dataBase.ParkingLotDetails.Any (parkingDetails => parkingDetails.VehicleNumber == details.VehicleNumber && parkingDetails.Status == "UnPark");
                    var condition2 = (from parkingDetails in dataBase.ParkingLotDetails where parkingDetails.VehicleNumber == details.VehicleNumber select parkingDetails.Status == "UnPark").LastOrDefault();
                    // Check Same Data Available Or Not By Vehicale Number
                    if (!condition1)
                    {
                        details.ParkingDate         = DateTime.Now;
                        details.Status              = "Park";
                        details.ParkingSlot         = checkValidParkingSlot(details.ParkingSlot);
                        details.ParkingUserCategory = ParkingCategory(details.ParkingUserCategory);
                        if (details.ParkingUserCategory == "Handicap")
                        {
                            details.ParkingSlot = checkPakingSlotForHandicap(details.ParkingSlot);
                        }
                        dataBase.Add(details);
                        dataBase.SaveChanges();
                        // Return Data
                        return(details);
                    }
                    else if (condition2)  // Check Second Condition The Data Avaliable With UnPark And Last Data Of That Vehical Number
                    {
                        // Current Date And Time
                        details.ParkingDate = DateTime.Now;
                        details.Status      = "Park";
                        dataBase.Add(details);
                        dataBase.SaveChanges();
                        // Return Data
                        return(details);
                    }
                    else
                    {
                        // If Data Avaliable With Park Status Return This Message

                        throw new Exception(details.VehicleNumber + "  Vehical Number already parked in the Lot ");
                    }
                }
                catch (Exception exception)
                {
                    throw new Exception(exception.Message);
                }
            }
            else
            {
                throw new Exception("ParkingLot Is Full");
            }
        }