Exemple #1
0
        /// <summary>
        /// This method is subscribed to the mousedown event for the pushpin, and opens the socialMediaDialogue, with the information of the pushpin
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void Pushpin_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Offence offence = (sender as Pushpin).GetOffence();

            new Scraper(offence).UpdateSocialMediaMessages();
            new DelictDialog(offence).Show();
        }
Exemple #2
0
        /// <summary>
        /// Creates a grid containing the information of an offence.
        /// </summary>
        /// <param name="maxWidth">maximum item width</param>
        /// <returns></returns>
        private Grid CreateOffencePanel(double maxWidth)
        {
            Grid grid = new Grid {
                Width = maxWidth, Margin = new Thickness(0, 0, 0, 8)
            };
            Offence offence = wpfDelict.DataContext as Offence;

            for (int i = 0; i < 4; i++)
            {
                grid.RowDefinitions.Add(new RowDefinition {
                    Height = GridLength.Auto
                });
            }

            grid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = GridLength.Auto
            });
            grid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = GridLength.Auto
            });
            grid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });

            AddTextRow(grid, 0, "Datum en tijd", offence.DateTime.ToString());
            AddTextRow(grid, 1, "Delict nummer", $"{offence.ID}");
            AddTextRow(grid, 2, "Categorie", $"{offence.Category}");
            AddTextRow(grid, 3, "Omschrijving", offence.Description);

            grid.Measure(new Size(maxWidth, double.PositiveInfinity)); // Required to calculate if items fit on the page
            return(grid);
        }
Exemple #3
0
        public void RetrieveWitnessMessages(Offence offence)
        {
            OffenceController offenceController = new OffenceController();
            Scraper           WitnessScraper    = new Scraper(offence, true, offenceController.Hashtag(offence));

            WitnessScraper.UpdateSocialMediaMessages(1);
        }
Exemple #4
0
 /// <summary>
 /// Gets the pushpin of the offence
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public static Pushpin GetPushpin(this Offence value)
 {
     if (!_pushpins.ContainsKey(value))
     {
         _pushpins.Add(value, CreatePushpin(value));
     }
     return(_pushpins[value]);
 }
Exemple #5
0
 public AskForWitnessWindow(Offence offence)
 {
     InitializeComponent();
     _witnessController     = new WitnessController(offence, this);
     _SendMessageController = new SendMessageController();
     txtb_omschrijving.Text = offence.Description;
     ShowDialog();
 }
Exemple #6
0
 /// <summary>
 /// Creates a pushpin
 /// </summary>
 /// <param name="offence"></param>
 /// <returns></returns>
 private static Pushpin CreatePushpin(Offence offence) => new Pushpin
 {
     Location = new Microsoft.Maps.MapControl.WPF.Location
     {
         Latitude  = offence.Location.Latitude,
         Longitude = offence.Location.Longitude
     },
     Background = ColorDefault
 };
Exemple #7
0
        public override string ToString()
        {
            return($@"Off:{
				StringUtils.PadLeft(4, Offence.ToString())
				} Def:{
				StringUtils.PadLeft(4, Defence.ToString())
				} Tot:{
				StringUtils.PadLeft(4, Total().ToString())
				}"                );
        }
Exemple #8
0
        /// <summary>
        /// Adds an offence to the list of offences for this window.
        /// </summary>
        /// <param name="description">offence description</param>
        /// <param name="category">offence Categorie(enum value)</param>
        /// <param name="dateTime">offence date and time</param>
        /// <param name="location">offence location</param>
        public static void AddOffence(string description, OffenceCategories category, DateTime dateTime, Location location)
        {
            OffenceController offenceController = new OffenceController();
            Offence           offence           = new Offence(dateTime, description, location, category);

            offence.ID = offenceController.SetOffence(offence);

            new Scraper(offence).SetSocialMediaMessages();

            _offences.Add(offence);
        }
Exemple #9
0
        /// <summary>
        /// Performs parsing operations and constructs a list of Coordinate objects as the result.
        /// </summary>
        /// <param name="fileName">The path to the file containing the XML information to parse.</param>
        /// <param name="crimes">The list of Crime objects to serialise the XML information into.</param>
        protected override void OnParse(string fileName, List <Crime> crimes)
        {
            OutputStreams.WriteLine($"Parsing {SA} data...");

            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load(fileName);

            State state = DataProvider.StateRepository.GetStateByAbbreviatedName(SA);
            List <LocalGovernmentArea> localGovernmentAreas = DataProvider.LocalGovernmentAreaRepository.GetLocalGovernmentAreasByStateID(state.ID);

            Dictionary <string, Offence> offences = new Dictionary <string, Offence>();

            DataProvider.OffenceRepository.GetOffences().ForEach(m => offences.Add(m.Name.ToUpper(), m));

            XmlNodeList workSheetXmlNodeList = xmlDocument.SelectNodes("/Workbook/Worksheet");

            foreach (XmlNode workSheetXmlNode in workSheetXmlNodeList)
            {
                string localGovernmentAreaName = workSheetXmlNode.Attributes["Name"].Value;
                if (localGovernmentAreaName.Contains("(") == true)
                {
                    localGovernmentAreaName = localGovernmentAreaName.Substring(0, localGovernmentAreaName.IndexOf("(")).Trim();
                }

                LocalGovernmentArea localGovernmentArea = localGovernmentAreas.Where(m => (m.Name.EqualsIgnoreCase(localGovernmentAreaName) == true)).FirstOrDefault();

                XmlNodeList xmlNodeList = workSheetXmlNode.SelectNodes("Table/Row[count(Cell) = 6]");

                foreach (XmlNode xmlNode in xmlNodeList)
                {
                    string offenceName = xmlNode.ChildNodes[0].InnerText.ToUpper();
                    if ((String.IsNullOrEmpty(offenceName) == false) && (offenceName.StartsWith("-") == true))
                    {
                        offenceName = offenceName.Substring(offenceName.IndexOf("-") + 1).Trim();

                        Offence offence = null;
                        if ((String.IsNullOrEmpty(offenceName) == false) && (offences.ContainsKey(offenceName) == true))
                        {
                            offence = offences[offenceName];
                        }

                        for (int i = 1, j = 2009; i < 6; i++, j++)
                        {
                            int count = Convert.ToInt32(xmlNode.ChildNodes[i].InnerText);

                            crimes.Add(new Crime(count, localGovernmentArea.ID, 1, offence.ID, j));
                        }
                    }
                }
            }

            base.OnParse(fileName, crimes);
        }
    private void InsertUpdate()
    {
        Offence objOffence = new Offence();

        objOffence.OffenceId   = ID;
        objOffence.OffenceName = tbxName.Text;
        objOffence.Description = tbxDescription.Text;
        new bllOffence().InsertUpdate(objOffence);
        new bllAudit().Insert("Setup", "InsertUpdate Offence", "Offence: " + tbxName.Text, User.Identity.Name);
        MessageController.Show("Saved successfully.", MessageType.Information, Page);
    }
Exemple #11
0
 public void ChangeRating(User user, Offence offence)
 {
     if (user.Rating - offence.Cost < 0)
     {
         user.Rating = 0;
     }
     else
     {
         user.Rating = user.Rating - offence.Cost;
     }
 }
Exemple #12
0
        public ActionResult Offence(uint id)
        {
            OffenceModel offenceModel = null;
            Offence      offence      = DataProvider.OffenceRepository.GetOffenceByID((int)(id));

            if (offence != null)
            {
                offenceModel = new OffenceModel(offence.DateCreatedUtc, offence.DateUpdatedUtc, offence.ID, offence.IsDeleted, offence.IsVisible, offence.Name, offence.OffenceCategoryID);
            }

            return(View(offenceModel));
        }
Exemple #13
0
        /// <summary>
        /// The method executes a LINQ search on the List items and finds the offencelistItem with the same pin.
        /// </summary>
        /// <returns>The method returns the offence that has the same pin</returns>
        public static Offence RetrieveOffence(double latitude, double longitude)
        {
            Offence offence = null;
            IEnumerable <Offence> offenceQuerry =
                from OffenceItem in _offences
                where OffenceItem.Location.Latitude == latitude &&
                OffenceItem.Location.Longitude == longitude
                select OffenceItem;

            offence = offenceQuerry.First();
            return(offence);
        }
Exemple #14
0
 public int SaveOffence(Offence entity)
 {
     if (entity.OffenceId == default)
     {
         context.Entry(entity).State = Microsoft.EntityFrameworkCore.EntityState.Added;
     }
     else
     {
         context.Entry(entity).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
     }
     context.SaveChanges();
     return(entity.OffenceId);
 }
Exemple #15
0
        /// <summary>
        /// Change the hastag for the given offence in the database
        /// </summary>
        /// <param name="offence">the offence that needs to be changed</param>
        public void UpdateHashtag(Offence offence)
        {
            SqlCommand query = new SqlCommand("UPDATE Offence SET Hashtag = @Hashtag WHERE ID = @OffenceID");

            //prepare values in statement
            query.Parameters.Add("@OffenceID", System.Data.SqlDbType.Int);
            query.Parameters.Add("@Hashtag", System.Data.SqlDbType.NVarChar);

            query.Parameters["@Hashtag"].Value   = $"Delict{offence.ID}";
            query.Parameters["@OffenceID"].Value = offence.ID;

            _dbContext.ExecuteQuery(query);
        }
Exemple #16
0
        /// <summary>
        /// Insert the sended messages into the SendMessage Table
        /// </summary>
        /// <param name="offence">the offence needed for the offence ID</param>
        /// <param name="message">the message that has to be inserted</param>
        public void SetSendMessage(Offence offence, String message)
        {
            SqlCommand insertMessage = new SqlCommand("INSERT INTO SendMessage (OffenceID, Message) OUTPUT INSERTED.ID" +
                                                      " VALUES (@OffenceID, @Message)");

            insertMessage.Parameters.Add("@OffenceID", System.Data.SqlDbType.Int);
            insertMessage.Parameters.Add("@Message", System.Data.SqlDbType.NVarChar);

            insertMessage.Parameters["@OffenceID"].Value = offence.ID;
            insertMessage.Parameters["@Message"].Value   = message;

            _dbContext.ExecuteInsertQuery(insertMessage);
        }
Exemple #17
0
        /// <summary>
        /// Performs parsing operations and constructs a list of Coordinate objects as the result.
        /// </summary>
        /// <param name="fileName">The path to the file containing the XML information to parse.</param>
        /// <param name="crimes">The list of Crime objects to serialise the XML information into.</param>
        protected override void OnParse(string fileName, List <Crime> crimes)
        {
            OutputStreams.WriteLine($"Parsing {NSW} data...");

            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load(fileName);

            XmlNodeList xmlNodeList = xmlDocument.SelectNodes("/Workbook/Worksheet/Table/Row[position() > 1]");
            int         year        = 1995;

            State state = DataProvider.StateRepository.GetStateByAbbreviatedName(NSW);
            List <LocalGovernmentArea>   localGovernmentAreas = DataProvider.LocalGovernmentAreaRepository.GetLocalGovernmentAreasByStateID(state.ID);
            Dictionary <string, Offence> offences             = new Dictionary <string, Offence>();

            DataProvider.OffenceRepository.GetOffences().ForEach(m => offences.Add(m.Name.ToUpper(), m));

            foreach (XmlNode xmlNode in xmlNodeList)
            {
                string localGovernmentAreaName = xmlNode.ChildNodes[0].InnerText.Trim();
                string offenceName             = xmlNode.ChildNodes[1].InnerText.Trim().ToUpper();
                string suboffenceName          = xmlNode.ChildNodes[2].InnerText.Trim().ToUpper();

                Offence             offence             = null;
                LocalGovernmentArea localGovernmentArea = localGovernmentAreas.Where(m => (m.Name.EqualsIgnoreCase(localGovernmentAreaName) == true)).FirstOrDefault();

                if ((String.IsNullOrEmpty(offenceName) == false) && (offences.ContainsKey(offenceName) == true))
                {
                    offence = offences[offenceName];
                }

                if ((String.IsNullOrEmpty(suboffenceName) == false) && (offences.ContainsKey(offenceName) == true))
                {
                    offence = offences[suboffenceName];
                }

                DateTime dateTime = new DateTime(year, 1, 1);

                for (int i = 3; i < xmlNode.ChildNodes.Count; i++)
                {
                    int count = Convert.ToInt32(xmlNode.ChildNodes[i].InnerText);

                    crimes.Add(new Crime(count, localGovernmentArea.ID, dateTime.Month, offence.ID, dateTime.Year));

                    dateTime = dateTime.AddMonths(1);
                }
            }

            base.OnParse(fileName, crimes);
        }
Exemple #18
0
        /// <summary>
        /// Searches the Event-Guardian database for an Offence record with a specified Offence ID.
        /// </summary>
        /// <param name="id">Identification number for the Offence record</param>
        /// <returns>An Offence record with the specified ID, or null if no matches were found</returns>
        public Offence GetOffenceByID(int id)
        {
            Offence offence = null;

            using (SqlConnection sqlConnection = SqlConnectionFactory.NewSqlConnetion())
            {
                offence = SqlMapper
                          .Query(sqlConnection, "Crime.spGetOffenceByID", new { ID = id }, commandType: CommandType.StoredProcedure)
                          .Select(m => new Offence(m.DateCreatedUtc, m.DateUpdatedUtc, m.ID, m.IsDeleted, m.IsVisible, m.Name, m.OffenceCategoryID))
                          .FirstOrDefault();
            }

            return(offence);
        }
Exemple #19
0
        /// <summary>
        /// Performs parsing operations and constructs a list of Coordinate objects as the result.
        /// </summary>
        /// <param name="fileName">The path to the file containing the XML information to parse.</param>
        /// <param name="crimes">The list of Crime objects to serialise the XML information into.</param>
        protected override void OnParse(string fileName, List <Crime> crimes)
        {
            OutputStreams.WriteLine($"Parsing {ACT} data...");

            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load(fileName);

            XmlNodeList xmlNodeList = xmlDocument.SelectNodes("/Workbook/Worksheet/Table");

            State state = DataProvider.StateRepository.GetStateByAbbreviatedName(ACT);
            List <LocalGovernmentArea>   localGovernmentAreas = DataProvider.LocalGovernmentAreaRepository.GetLocalGovernmentAreasByStateID(state.ID);
            Dictionary <string, Offence> offences             = new Dictionary <string, Offence>();

            DataProvider.OffenceRepository.GetOffences().ForEach(m => offences.Add(m.Name.ToUpper(), m));

            foreach (XmlNode xmlNode in xmlNodeList)
            {
                XmlNode             localGovermentAreaXmlNode = xmlNode.SelectSingleNode("Row[position() = 1]");
                string              localGovernmentAreaName   = localGovermentAreaXmlNode.InnerText.Trim();
                LocalGovernmentArea localGovernmentArea       = localGovernmentAreas.Where(m => (m.Name.EqualsIgnoreCase(localGovernmentAreaName) == true)).FirstOrDefault();

                List <DateTime> dateTimeList     = new List <DateTime>();
                XmlNodeList     datesXmlNodeList = xmlNode.SelectNodes("Row[position() = 3]/Cell");
                datesXmlNodeList.OfType <XmlNode>().ToList().ForEach(m => dateTimeList.Add(DateTime.Parse(m.InnerText)));

                XmlNodeList offenceXmlNodeList = xmlNode.SelectNodes("Row[position() > 3]");
                foreach (XmlNode offenceXmlNode in offenceXmlNodeList)
                {
                    Offence offence     = null;
                    string  offenceName = offenceXmlNode.ChildNodes[0].InnerText.Trim().ToUpper();

                    if ((String.IsNullOrEmpty(offenceName) == false) && (offences.ContainsKey(offenceName) == true))
                    {
                        offence = offences[offenceName];
                    }

                    for (int i = 0, j = 1; j < offenceXmlNode.ChildNodes.Count; i++, j++)
                    {
                        int      count    = Convert.ToInt32(offenceXmlNode.ChildNodes[j].InnerText);
                        DateTime dateTime = dateTimeList[i];

                        crimes.Add(new Crime(count, localGovernmentArea.ID, dateTime.Month, offence.ID, dateTime.Year));
                    }
                }
            }

            base.OnParse(fileName, crimes);
        }
Exemple #20
0
 /// <summary>
 /// The Delete
 /// </summary>
 /// <param name="entity">The entity<see cref="Offence"/></param>
 /// <returns>The <see cref="ServiceResult"/></returns>
 public ServiceResult Delete(Offence entity)
 {
     try
     {
         _repository.Delete(entity);
         return(new ServiceResult(true));
     }
     catch (Exception ex)
     {
         return(new ServiceResult(false)
         {
             Error = ex.ToString()
         });
     }
 }
Exemple #21
0
        public IActionResult OffenceAdd(string cost, string name)
        {
            Offence model = new Offence();

            if (cost.All(char.IsDigit) && name != "")
            {
                model.Name       = name;
                model.Cost       = Int32.Parse(cost);
                model.Owner      = User.Identity.Name;
                model.CreateDate = DateTime.Now;
                offenceRepository.SaveOffence(model);
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Index"));
        }
Exemple #22
0
        /// <summary>
        /// Performs parsing operations and constructs a list of Coordinate objects as the result.
        /// </summary>
        /// <param name="fileName">The path to the file containing the XML information to parse.</param>
        /// <param name="crimes">The list of Crime objects to serialise the XML information into.</param>
        protected override void OnParse(string fileName, List <Crime> crimes)
        {
            OutputStreams.WriteLine($"Parsing {VIC} data...");

            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load(fileName);

            XmlNodeList xmlNodeList = xmlDocument.SelectNodes("/Workbook/Worksheet/Table/Row[position() > 1]");

            //	The dataset I'm working with has a single year - 2014
            int year = 2014;

            State state = DataProvider.StateRepository.GetStateByAbbreviatedName(VIC);
            List <LocalGovernmentArea>   localGovernmentAreas = DataProvider.LocalGovernmentAreaRepository.GetLocalGovernmentAreasByStateID(state.ID);
            Dictionary <string, Offence> offences             = new Dictionary <string, Offence>();

            DataProvider.OffenceRepository.GetOffences().ForEach(m => offences.Add(m.Name.ToUpper(), m));

            foreach (XmlNode xmlNode in xmlNodeList)
            {
                string localGovernmentAreaName = xmlNode.ChildNodes[2].InnerText.Trim();
                string offenceName             = xmlNode.ChildNodes[3].InnerText.Trim().ToUpper();
                string suboffenceName          = xmlNode.ChildNodes[4].InnerText.Trim().ToUpper();
                int    count = Convert.ToInt32(xmlNode.ChildNodes[5].InnerText);

                LocalGovernmentArea localGovernmentArea = localGovernmentAreas.Where(m => (m.Name.EqualsIgnoreCase(localGovernmentAreaName) == true)).FirstOrDefault();
                Offence             offence             = null;

                if ((String.IsNullOrEmpty(offenceName) == false) && (offences.ContainsKey(offenceName) == true))
                {
                    offence = offences[offenceName];
                }

                if ((String.IsNullOrEmpty(suboffenceName) == false) && (offences.ContainsKey(offenceName) == true))
                {
                    offence = offences[suboffenceName];
                }

                //	We only have crime data per year, so it will always be added in on 01/01/YYYY
                crimes.Add(new Crime(count, localGovernmentArea.ID, 1, offence.ID, year));
            }

            base.OnParse(fileName, crimes);
        }
Exemple #23
0
        /// <summary>
        /// Checks the database for Offence records based on a specified ID value.
        /// </summary>
        /// <param name="value">The ID value for the Offence record.</param>
        /// <returns>true if the Offence exists; otherwise false.</returns>
        public override bool IsValid(object value)
        {
            bool isValid = false;

            if (value != null)
            {
                int id = 0;

                if (Int32.TryParse(value.ToString(), out id) == true)
                {
                    Offence offence = DataProvider.OffenceRepository.GetOffenceByID(id);

                    isValid = (offence != null);
                }
            }

            return(isValid);
        }
Exemple #24
0
        /// <summary>
        /// gets called when a offence in the list is clicked/selected.
        /// </summary>
        /// <param name="sender">the publisher</param>
        /// <param name="e">arguments for retrieving the selected item</param>
        private void wpfLBSelection_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count <= 0)
            {
                return;
            }

            Offence item = e.AddedItems[0] as Offence;

            wpfMapMain.Center    = item.GetPushpin().Location;
            wpfMapMain.ZoomLevel = 16;
            item.GetPushpin().Background = MainWindowController.ColorSelected;

            for (int i = 0; i < e.RemovedItems.Count; i++)
            {
                Offence removed = e.RemovedItems[i] as Offence;
                removed.GetPushpin().Background = MainWindowController.ColorDefault;
            }
        }
Exemple #25
0
        /// <summary>
        /// Create a Search hashtag fot the offence
        /// </summary>
        /// <param name="offence">the offence for the search hastag</param>
        /// <returns></returns>
        public string Hashtag(Offence offence)
        {
            SqlCommand query = new SqlCommand("SELECT Hashtag FROM Offence WHERE ID = @OffenceID");

            query.Parameters.Add("@OffenceID", System.Data.SqlDbType.Int);
            query.Parameters["@OffenceID"].Value = offence.ID;
            List <object[]> rows = _dbContext.ExecuteSelectQuery(query);

            if (rows.Count == 1 && rows[0].GetValue(0).ToString().Length > 0)
            {
                string text = rows[0].GetValue(0).ToString();
                return(text);
            }

            else
            {
                return($"#Delict{offence.ID}");
            }
        }
Exemple #26
0
        /// <summary>
        /// instantiates the window
        /// </summary>
        /// <param name="offence">data to be shown</param>
        public DelictDialog(Offence offence)
        {
            InitializeComponent();
            _controller        = new DelictDialogController();
            _messageController = new SocialMediaMessageController();

            wpfDelict.DataContext = offence;
            _controller.DisplayMessages(offence, wpfLVMessages);
            _controller.RetrieveWitnessMessages(offence);
            _controller.DisplayMessages(offence, WitnessMessages, 1);

            foreach (SocialMediaMessage message in wpfLVMessages.ItemsSource)
            {
                foreach (SocialMediaImage image in message.Media)
                {
                    _images.Add(image.URL, new Image {
                        Source = new BitmapImage(new Uri(image.URL))
                    });
                }
            }
        }
Exemple #27
0
        /// <summary>
        /// The Save
        /// </summary>
        /// <param name="entity">The entity<see cref="Offence"/></param>
        /// <returns>The <see cref="ServiceResult"/></returns>
        public ServiceResult Save(Offence entity)
        {
            try
            {
                if (entity.Identifier.Equals(""))
                {
                    _repository.Add(entity);
                }
                else
                {
                    _repository.Update(entity);
                }

                return(new ServiceResult(true));
            }
            catch (Exception ex)
            {
                return(new ServiceResult(false)
                {
                    Error = ex.ToString()
                });
            }
        }
Exemple #28
0
        /// <summary>
        /// saves an offence and its location when location.id == 0
        /// </summary>
        /// <param name="offence">offence obj that needs saving</param>
        /// <returns> returns the ID of the inserted Offence</returns>
        public int SetOffence(Offence offence)
        {
            if (offence.Location.ID == 0)
            {
                offence.Location.ID = new LocationController().SetLocation(offence.Location);
            }
            SqlCommand query = new SqlCommand("INSERT INTO Offence (DateTime, Description, LocationID, Category) " +
                                              "OUTPUT INSERTED.ID " +
                                              "VALUES(@DateTime, @Description, @LocationID, @Category)");

            //set values we want to insert
            query.Parameters.Add("@DateTime", System.Data.SqlDbType.DateTime);
            query.Parameters.Add("@Description", System.Data.SqlDbType.VarChar);
            query.Parameters.Add("@LocationID", System.Data.SqlDbType.Int);
            query.Parameters.Add("@Category", System.Data.SqlDbType.VarChar);

            query.Parameters["@DateTime"].Value    = offence.DateTime.ToString("yyyy-MM-dd HH:mm:ss.fff");
            query.Parameters["@Description"].Value = offence.Description;
            query.Parameters["@LocationID"].Value  = offence.Location.ID;
            query.Parameters["@Category"].Value    = offence.Category.ToString();

            return(_dbContext.ExecuteInsertQuery(query));
        }
 /// <summary>
 /// Creates a scraper, can use a search on a text with or without additionel parameters.
 /// </summary>
 /// <param name="offence">the offence needed for parameter information</param>
 /// <param name="OnlyHastag">true or false to toggle additionel parameters.</param>
 /// <param name="text">the text for searching.</param>
 public Scraper(Offence offence, bool OnlyHastag = false, string text = " ")
 {
     Offence = offence;
     if (!OnlyHastag)
     {
         _searchParameters = new SearchTweetsParameters(text)
         {
             GeoCode = new GeoCode(offence.Location.Latitude, offence.Location.Longitude, 1, DistanceMeasure.Kilometers),
             Lang    = LanguageFilter.Dutch,
             MaximumNumberOfResults = 10,
             Until = new DateTime(offence.DateTime.Year, offence.DateTime.Month, offence.DateTime.Day).AddDays(1),
             Since = new DateTime(offence.DateTime.Year, offence.DateTime.Month, offence.DateTime.Day, offence.DateTime.Hour, offence.DateTime.Minute, offence.DateTime.Second).AddHours(-1)
         };
     }
     else
     {
         _searchParameters = new SearchTweetsParameters(text)
         {
             Since = new DateTime(offence.DateTime.Year, offence.DateTime.Month, offence.DateTime.Day).AddDays(-1),
             Until = DateTime.Now
         };
     }
 }
Exemple #30
0
        /// <summary>
        /// Performs parsing operations and constructs a list of Coordinate objects as the result.
        /// </summary>
        /// <param name="fileName">The path to the file containing the XML information to parse.</param>
        /// <param name="crimes">The list of Crime objects to serialise the XML information into.</param>
        protected override void OnParse(string fileName, List <Crime> crimes)
        {
            OutputStreams.WriteLine($"Parsing {QLD} data...");

            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load(fileName);

            XmlNode qldXmlNode = xmlDocument.SelectSingleNode("/Workbook/Worksheet/Table/Row[position() = 1]");

            State state = DataProvider.StateRepository.GetStateByAbbreviatedName(QLD);
            List <LocalGovernmentArea>   localGovernmentAreas = DataProvider.LocalGovernmentAreaRepository.GetLocalGovernmentAreasByStateID(state.ID);
            Dictionary <string, Offence> offences             = new Dictionary <string, Offence>();

            DataProvider.OffenceRepository.GetOffences().ForEach(m => offences.Add(m.Name.ToUpper(), m));

            List <string> offenceNames = new List <string>();

            qldXmlNode.ChildNodes.OfType <XmlNode>().Skip(2).ToList().ForEach(m => offenceNames.Add(m.InnerText));

            XmlNodeList xmlNodeList = xmlDocument.SelectNodes("/Workbook/Worksheet/Table/Row[position() > 1]");

            foreach (XmlNode xmlNode in xmlNodeList)
            {
                string localGovernmentAreaName = xmlNode.ChildNodes[0].InnerText.Trim();
                string dateTimeValue           = xmlNode.ChildNodes[1].InnerText.Trim();

                DateTime dateTime = DateTime.MinValue;

                if (DateTime.TryParse(dateTimeValue, out dateTime) == false)
                {
                    //	Can't really use this, but should the whole thing fall over because of it?

                    throw new Exception($"Date time parse choked: {dateTimeValue}");
                }

                for (int i = 0, j = 2; i < offenceNames.Count; i++, j++)
                {
                    string offenceName = offenceNames[i].ToUpper();
                    double countDouble = 0;
                    int    count       = 0;

                    //	These must be some kind of averaged data - you can't have half a crime for example.
                    if (Double.TryParse(xmlNode.ChildNodes[j].InnerText, out countDouble) == true)
                    {
                        count = Convert.ToInt32(countDouble);
                    }

                    LocalGovernmentArea localGovernmentArea = localGovernmentAreas.Where(m => (m.Name.EqualsIgnoreCase(localGovernmentAreaName) == true)).FirstOrDefault();
                    Offence             offence             = null;

                    if ((String.IsNullOrEmpty(offenceName) == false) && (offences.ContainsKey(offenceName) == true))
                    {
                        offence = offences[offenceName];
                    }

                    crimes.Add(new Crime(count, localGovernmentArea.ID, dateTime.Month, offence.ID, dateTime.Year));
                }
            }

            base.OnParse(fileName, crimes);
        }