示例#1
0
 public List <string> GetLocationsUids()
 {
     using (PredixContext context = new PredixContext())
     {
         return(context.Locations.Select(x => x.LocationUid).ToList());
     }
 }
示例#2
0
        private static bool IsStreetSweeping(ParkingRegulation regulation, ParkingEvent parkingEvent,
                                             GeViolation geViolation, PredixContext context, Customer customer)
        {
            bool isVoilation = false;

            if (parkingEvent.EventType.Equals("PKOUT"))
            {
                using (var innerContext = new PredixContext())
                {
                    var inEvent = innerContext.GeViolations.FirstOrDefault(x =>
                                                                           x.ObjectUid == parkingEvent.Properties.ObjectUid &&
                                                                           x.LocationUid == parkingEvent.LocationUid);
                    if (inEvent?.ParkinTime != null)
                    {
                        inEvent.ParkoutTime      = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                        inEvent.EventOutDateTime =
                            parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                        inEvent.ViolationDuration = (long)parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId)
                                                    .Subtract(inEvent.ParkinTime.Value).TotalMinutes;
                        inEvent.StreetSweeping   = true;
                        inEvent.ModifiedDateTime = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                        inEvent.IsException      = true;
                        inEvent.UserAction       = "Missed_Violation";
                        innerContext.SaveChanges();
                        return(true);
                    }
                }
                return(false);
            }
            if (parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId).TimeOfDay >= regulation.StartTime &&
                parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId).TimeOfDay <= regulation.EndTime)
            {
                Commentary.Print("*** StreetWeeping Violation");

                isVoilation = true;
                geViolation.StreetSweeping = true;
                geViolation.ObjectUid      = parkingEvent.Properties.ObjectUid;
                geViolation.LocationUid    = parkingEvent.LocationUid;
                if (parkingEvent.EventType.Equals("PKIN"))
                {
                    geViolation.EventInDateTime =
                        parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                    geViolation.ParkinTime = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                }

                if (parkingEvent.EventType.Equals("PKOUT"))
                {
                    geViolation.EventOutDateTime =
                        parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                    geViolation.ParkoutTime = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                }

                geViolation.RegulationId  = regulation.RegualationId;
                geViolation.ViolationType = regulation.ViolationType;

                context.GeViolations.Add(geViolation);
            }

            return(isVoilation);
        }
示例#3
0
 public List <Boundary> GetBoundaries()
 {
     using (PredixContext context = new PredixContext())
     {
         return(context.Boundaries.Where(x => x.IsActive).ToList());
     }
 }
示例#4
0
        private static void ForceMarkViolation(ParkingEvent parkingEvent, Customer customer)
        {
            Commentary.Print("Force Mark Violation");
            if (parkingEvent.EventType.Equals("PKOUT"))
            {
                using (var innerContext = new PredixContext())
                {
                    var inEvent = innerContext.GeViolations.FirstOrDefault(x =>
                                                                           x.ObjectUid == parkingEvent.Properties.ObjectUid &&
                                                                           x.LocationUid == parkingEvent.LocationUid);
                    if (inEvent?.ParkinTime != null)
                    {
                        inEvent.ParkoutTime      = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                        inEvent.EventOutDateTime =
                            parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                        inEvent.ViolationDuration = (long)parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId)
                                                    .Subtract(inEvent.ParkinTime.Value).TotalMinutes;
                        //inEvent.NoParking = true;
                        inEvent.ModifiedDateTime = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                        inEvent.IsException      = true;
                        inEvent.UserAction       = "Missed_Violation";
                        innerContext.SaveChanges();
                    }
                }

                return;
            }

            GeViolation geViolation = new GeViolation
            {
                NoParking   = true,
                ObjectUid   = parkingEvent.Properties.ObjectUid,
                LocationUid = parkingEvent.LocationUid
            };

            if (parkingEvent.EventType.Equals("PKIN"))
            {
                geViolation.EventInDateTime = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                geViolation.ParkinTime      = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
            }

            if (parkingEvent.EventType.Equals("PKOUT"))
            {
                geViolation.EventOutDateTime = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                geViolation.ParkoutTime      = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
            }

            geViolation.RegulationId  = 81;
            geViolation.ViolationType = ViolationType.FireHydrant;
            using (var context = new PredixContext())
            {
                context.GeViolations.Add(geViolation);
                context.SaveChanges();
            }
        }
示例#5
0
 private async Task SaveAsync(Media media)
 {
     if (media == null)
     {
         return;
     }
     using (PredixContext context = new PredixContext())
     {
         Commentary.Print($"Saving Media Data");
         context.Medias.AddOrUpdate(x => x.ImageAssetUid, media);
         await context.SaveChangesAsync();
     }
 }
示例#6
0
 private void Save(Media media)
 {
     if (media == null)
     {
         return;
     }
     using (PredixContext context = new PredixContext())
     {
         Commentary.Print($"Saving Media Data", true);
         context.Medias.Add(media);
         //context.Medias.AddOrUpdate(x => x.ImageAssetUid, media);
         context.SaveChanges();
     }
 }
示例#7
0
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            //Console.WriteLine("Request:");
            //Console.WriteLine(request.ToString());
            if (request.Content != null)
            {
                //Console.WriteLine(await request.Content.ReadAsStringAsync());
            }
            //Console.WriteLine();

            HttpResponseMessage response = await base.SendAsync(request, cancellationToken);

            //Console.WriteLine("Response:");
            //Console.WriteLine(response.ToString());
            if (response.Content != null)
            {
                //Console.WriteLine(await response.Content.ReadAsStringAsync());
            }
            //Console.WriteLine();

            try
            {
                if (Convert.ToBoolean(ConfigurationManager.AppSettings["Debug"]))
                {
                    using (PredixContext context = new PredixContext())
                    {
                        var activity = new Activity
                        {
                            ProcessDateTime = DateTime.Now,
                            RequestJson     = request.Content?.ReadAsStringAsync().Result,
                            ResponseJson    = response.Content?.ReadAsStringAsync().Result,
                            Type            = request.Method.Method.Equals("get", StringComparison.OrdinalIgnoreCase)
                                ? ActivityType.Get
                                : ActivityType.Post
                        };
                        context.Activities.Add(activity);
                        await context.SaveChangesAsync(cancellationToken);

                        ActivityId = activity.Id;
                    }
                }
            }
            catch (Exception e)
            {
                Commentary.Print($"Failed to log the activity: {e.Message}", true);
            }

            return(response);
        }
示例#8
0
 private void Save(Image image)
 {
     if (image == null)
     {
         return;
     }
     using (PredixContext context = new PredixContext())
     {
         Commentary.Print($"Saving Base64", true);
         context.ImageContents.AddRange(image.Entry.Contents);
         context.Images.Add(image);
         //context.Images.AddOrUpdate(x => x.ImageAssetUid, image);
         context.SaveChanges();
     }
 }
示例#9
0
        //private static DateTime? EpochToDateTime(string epoch)
        //{
        //    if (string.IsNullOrWhiteSpace(epoch))
        //        return null;
        //    return DateTimeOffset.FromUnixTimeMilliseconds(Convert.ToInt64(epoch)).DateTime;
        //    //System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
        //    //dtDateTime = dtDateTime.AddSeconds(Convert.ToInt64(epoch)).ToLocalTime();
        //    //return dtDateTime;
        //}

        private void Save(ParkingEvent parkingEvent, Customer customer)
        {
            if (parkingEvent == null)
            {
                return;
            }
            using (PredixContext context = new PredixContext())
            {
                Commentary.Print("Saving Event Data", true);
                parkingEvent.CreatedDate = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                context.ParkingEvents.Add(parkingEvent);
                //context.ParkingEvents.AddOrUpdate(x => new { x.LocationUid, x.EventType }, parkingEvent);
                context.SaveChanges();
            }
        }
示例#10
0
 public void SaveLocationDetails(List <LocationDetails> locationDetailsList)
 {
     if (!locationDetailsList.Any())
     {
         return;
     }
     using (PredixContext context = new PredixContext())
     {
         //if (Convert.ToBoolean(ConfigurationManager.AppSettings["Debug"]))
         //{
         //    locationKeys.ForEach(x => x.ActivityId = Convert.ToInt32(_globalVariables["ActivityId"]));
         //}
         foreach (var locationDetails in locationDetailsList)
         {
             context.LocationDetails.AddOrUpdate(x => x.LocationUid, locationDetails);
         }
         context.SaveChanges();
     }
 }
示例#11
0
 public List <Tuple <int, string, string> > GetRecentBase64()
 {
     using (PredixContext context = new PredixContext())
     {
         context.Database.CommandTimeout = 1200;
         var results = (from pep in context.ParkingEventProperties
                        join i in context.Images on pep.ImageAssetUid equals i.ImageAssetUid
                        select new
         {
             pep.Id,
             pep.PixelCoordinates,
             i.Base64
         }).Take(5).ToList().Select(f => new Tuple <int, string, string>(
                                        f.Id,
                                        f.PixelCoordinates,
                                        f.Base64
                                        )).ToList();
         return(results);
     }
 }
示例#12
0
        public bool ProcessEvent(IImage imageService, Options options, Customer customer, ParkingEvent parkingEvent)
        {
            try
            {
                Commentary.Print($"Location ID :{parkingEvent.LocationUid}");
                parkingEvent.CustomerId = customer.Id;
                if (parkingEvent.Properties == null)
                {
                    parkingEvent.Properties = new ParkingEventProperties
                    {
                        CreatedDate  = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId),
                        ModifiedDate = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId)
                    }
                }
                ;
                parkingEvent.Properties.LocationUid = parkingEvent.LocationUid;


                var isVoilation = false;
                using (var context = new PredixContext())
                {
                    var anyRecord = context.ParkingEvents.Any(x => x.LocationUid == parkingEvent.LocationUid &&
                                                              x.EventType == parkingEvent.EventType &&
                                                              x.Properties.ObjectUid == parkingEvent.Properties.ObjectUid &&
                                                              x.Properties.ImageAssetUid == parkingEvent.Properties.ImageAssetUid);
                    if (anyRecord)
                    {
                        return(false);
                    }

                    var nodeMasterRegulations =
                        context.NodeMasterRegulations.Join(context.ParkingRegulations,
                                                           node => node.RegulationId,
                                                           regulation => regulation.RegualationId,
                                                           (node, regulation) => new { Node = node, Regulation = regulation })
                        .Where(x => x.Regulation.IsActive && x.Node.LocationUid == parkingEvent.LocationUid)
                        .Select(x => x.Regulation).ToList();

                    //var nodeMasterRegulation =
                    //    nodeMasterRegulations.Where(x => x.LocationUid == parkingEvent.LocationUid)
                    //        .ToList();
                    if (nodeMasterRegulations.Any())
                    {
                        var latLongs           = parkingEvent.Properties.GeoCoordinates.Split(',').ToList();
                        var parkingRegulations = new List <ParkingRegulation>();
                        foreach (var regulation in nodeMasterRegulations)
                        {
                            ViolationPercentage(latLongs, regulation, parkingEvent);
                            if (parkingEvent.MatchRate > 0)
                            {
                                parkingRegulations.Add(regulation);
                            }
                            Commentary.Print(
                                $"Regulation Id: {regulation.RegualationId}, Location Uid: {parkingEvent.LocationUid}, Asset Uid: {parkingEvent.AssetUid}, Match Rate {parkingEvent.MatchRate}",
                                true);
                        }

                        foreach (var regulation in parkingRegulations)
                        {
                            Commentary.Print(
                                $"Location Uid: {parkingEvent.LocationUid}, Asset Uid: {parkingEvent.AssetUid},parkingEvent.Timestamp.ToUtcDateTimeOrNull().DayOfWeek:{parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId).DayOfWeek}, ViolationType: {regulation.ViolationType}",
                                true);
                            if (regulation.DayOfWeek.Split('|').Select(x => x.ToUpper())
                                .Contains(parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId).DayOfWeek.ToString()
                                          .Substring(0, 3).ToUpper()))
                            {
                                GeViolation geViolation = new GeViolation();

                                switch (regulation.ViolationType)
                                {
                                case ViolationType.NoParking:
                                    Commentary.Print(
                                        $"Location Uid: {parkingEvent.LocationUid}, Asset Uid: {parkingEvent.AssetUid}, Checking No Parking",
                                        true);
                                    isVoilation = NoParkingCheck(regulation, parkingEvent, geViolation, context,
                                                                 customer);
                                    break;

                                case ViolationType.StreetSweeping:
                                    Commentary.Print(
                                        $"Location Uid: {parkingEvent.LocationUid}, Asset Uid: {parkingEvent.AssetUid}, Checking Street Sweeping",
                                        true);
                                    isVoilation = IsStreetSweeping(regulation, parkingEvent, geViolation, context,
                                                                   customer);
                                    break;

                                case ViolationType.TimeLimitParking:
                                    Commentary.Print(
                                        $"Location Uid: {parkingEvent.LocationUid}, Asset Uid: {parkingEvent.AssetUid}, Checking Time Limit",
                                        true);
                                    isVoilation = IsTimeLimitExceed(regulation, parkingEvent, geViolation, context,
                                                                    customer);
                                    break;

                                case ViolationType.ReservedParking:
                                    //This is out of scope for now, so we ae skipping this logic
                                    break;

                                case ViolationType.FireHydrant:
                                    Commentary.Print(
                                        $"Location Uid: {parkingEvent.LocationUid}, Asset Uid: {parkingEvent.AssetUid}, Fire Hydrant",
                                        true);
                                    isVoilation = IsFireHydrant(parkingEvent, geViolation, regulation, context,
                                                                customer);
                                    break;
                                }

                                Commentary.Print(
                                    $"Location Uid: {parkingEvent.LocationUid}, Asset Uid: {parkingEvent.AssetUid}, Is Violation: {isVoilation}",
                                    true);
                            }

                            if (isVoilation)
                            {
                                break;
                            }
                        }
                    }

                    context.SaveChanges();
                }

                if (!isVoilation)
                {
                    return(true);
                }
                Save(parkingEvent, customer);
                imageService.MediaOnDemand(parkingEvent, parkingEvent.Properties.ImageAssetUid,
                                           parkingEvent.Timestamp, customer);
                return(false);
            }
            catch (Exception e)
            {
                Commentary.Print("******************************************");
                Commentary.Print(e.ToString());
                return(false);
            }
        }