public void Initialize()
 {
     _testReport = new Report(
        ReportTypeEnum.HighPriority,
        "Test message",
        "40.104669",
        "-88.242254",
        "University of Illinois Campus",
        DateTime.UtcNow,
        new User("test.user"));
     _testReport.CreateReport(null);
 }
  public void TestCreateReportWithNoFile()
  {
      Report report = new Report(
          ReportTypeEnum.HighPriority, 
          "Test message", 
          "40.104669", 
          "-88.242254", 
          "University of Illinois Campus",
          DateTime.UtcNow,
          new User("test.user"));
      string result = report.CreateReport(null);
 
      Assert.IsTrue(result.Equals("success"), result);
  }
        public void TestCreateReport()
        {
            ReportTypeEnum reportTypeId = (ReportTypeEnum)Enum.Parse(
                typeof(ReportTypeEnum),
                TestContext.DataRow["ReportTypeId"].ToString());
            String message = TestContext.DataRow["Message"].ToString();
            String latitude = TestContext.DataRow["Latitude"].ToString();
            String longitude = TestContext.DataRow["Longitude"].ToString();
            String location = TestContext.DataRow["Location"].ToString();
            DateTime dateReported = Convert.ToDateTime(TestContext.DataRow["DateReported"]);
            User user = new User
            {
                UserName = TestContext.DataRow["UserName"].ToString()
            };
            String expectedResult = TestContext.DataRow["Result"].ToString();

            Report report = new Report(reportTypeId, message, latitude,
                longitude, location, dateReported, user);
            string actualResult = report.CreateReport(new TestContentLocator());
            Assert.IsTrue(actualResult.Contains(expectedResult), actualResult);
        }
Пример #4
0
        /// <summary>
        /// Process Request saves the user report including photos,video, and audio given the HttpContext
        /// </summary>
        public void ProcessRequest(HttpContext context)
        {
            HttpRequest request = context.Request;
            HttpResponse response = context.Response;
            String jsonString = String.Empty;
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            try
            {
                HttpPostedFile photo1 = request.Files["photo1"];
                HttpPostedFile photo2 = request.Files["photo2"];
                HttpPostedFile photo3 = request.Files["photo3"];
                HttpPostedFile video = request.Files["video"];
                HttpPostedFile audio = request.Files["audio"];

                Report report = new Report
                {
                    ReportTypeId = (ReportTypeEnum) Int16.Parse(request.Form["reportTypeId"]),
                    Latitude = request.Form["lat"],
                    Longitude = request.Form["lng"],
                    Location = request.Form["location"],
                    DateReported = Convert.ToDateTime(request.Form["timeStamp"]),
                    User = new User(request.Form["userName"]),
                    Message = request.Form["desc"]
                };
                AddMedia(report, photo1, photo2, photo3, video, audio);

                jsonString = serializer.Serialize(
                    new { result = report.CreateReport(new WebContentLocator()) });
            }
            catch (Exception ex)
            {
                jsonString = serializer.Serialize(new { result = ex.Message });
            }
            finally
            {
                response.Write(jsonString);
                response.ContentType = "application/json";
            }
        }
Пример #5
0
        /// <summary>
        /// Gets a list of reports from the database.
        /// </summary>
        /// <returns>The list of Report object.</returns>
        public static List<Report> GetReports()
        {
            SqlDataReader reader = ReportsDAO.GetReports();
            List<Report> reports = new List<Report>();

            try
            {
                int oReportId = reader.GetOrdinal("ReportId");
                int oReportType = reader.GetOrdinal("ReportType");
                int oMarkerImage = reader.GetOrdinal("MarkerImage");
                int oMessage = reader.GetOrdinal("Message");
                int oLatitude = reader.GetOrdinal("Latitude");
                int oLongitude = reader.GetOrdinal("Longitude");
                int oLocation = reader.GetOrdinal("Location");
                int oTimeStamp = reader.GetOrdinal("TimeStamp");
                int oUserName = reader.GetOrdinal("UserName");
                int oFirstName = reader.GetOrdinal("FirstName");
                int oLastName = reader.GetOrdinal("LastName");
                int oGender = reader.GetOrdinal("Gender");
                int oEmail = reader.GetOrdinal("Email");
                int oPhoneNumber = reader.GetOrdinal("PhoneNumber");
                int oAddress = reader.GetOrdinal("Address");
                int oZipCode = reader.GetOrdinal("ZipCode");

                while (reader.Read())
                {
                    Report report = new Report
                    {
                        ReportId = Convert.ToInt32(reader[oReportId]),
                        ReportType = reader[oReportType].ToString(),
                        MarkerImage = reader[oMarkerImage].ToString(),
                        Message = reader[oMessage].ToString(),
                        Latitude = reader[oLatitude].ToString(),
                        Longitude = reader[oLongitude].ToString(),
                        Location = reader[oLocation].ToString(),
                        DateReported = Convert.ToDateTime(reader[oTimeStamp]),
                        User = new User 
                        {
                            UserName = reader[oUserName].ToString(),
                            FirstName = reader[oFirstName].ToString(),
                            LastName = reader[oLastName].ToString(),
                            Gender = reader[oGender].ToString(),
                            Email = reader[oEmail].ToString(),
                            PhoneNumber = reader[oPhoneNumber].ToString(),
                            Address = reader[oAddress].ToString(),
                            ZipCode = reader[oZipCode].ToString()
                        }
                    };

                    for (int i = 1; i <= 5; i++)
                    {
                        String mediaUrl = reader["Media" + i].ToString();
                        if (!String.IsNullOrEmpty(mediaUrl))
                        {
                            report.AddUrlList(mediaUrl);
                        }
                    }
                    reports.Add(report);
                }
            }
            catch (Exception)
            {

            }
            finally
            {
                reader.Close();
            }
            return reports;
        }
Пример #6
0
        /// <summary>
        /// saves the media to Disk
        /// </summary>
        private static void AddMedia(Report report, HttpPostedFile photo1, HttpPostedFile photo2, HttpPostedFile photo3,
            HttpPostedFile video, HttpPostedFile audio)
        {
            if (photo1 != null)
            {
                FileInfo fileInfo = new FileInfo(photo1.FileName);
                report.AddMedia(new Photo
                {
                    Url = "~/Content/uploads/" + DateTime.Now.Ticks + "1_" + fileInfo.Name,
                    File = photo1
                });
            }
            else
            {
                report.AddMedia(null);
            }

            if (photo2 != null)
            {
                FileInfo fileInfo = new FileInfo(photo2.FileName);
                report.AddMedia(new Photo
                {
                    Url = "~/Content/uploads/" + DateTime.Now.Ticks + "2_" + fileInfo.Name,
                    File = photo2
                });
            }
            else
            {
                report.AddMedia(null);
            }

            if (photo3 != null)
            {
                FileInfo fileInfo = new FileInfo(photo3.FileName);
                report.AddMedia(new Photo
                {
                    Url = "~/Content/uploads/" + DateTime.Now.Ticks + "3_" + fileInfo.Name,
                    File = photo3
                });
            }
            else
            {
                report.AddMedia(null);
            }

            if (video != null)
            {
                FileInfo fileInfo = new FileInfo(video.FileName);
                report.AddMedia(new Video
                {
                    Url = "~/Content/uploads/" + DateTime.Now.Ticks + "4_" + fileInfo.Name,
                    File = video
                });
            }
            else
            {
                report.AddMedia(null);
            }

            if (audio != null)
            {
                FileInfo fileInfo = new FileInfo(audio.FileName);
                report.AddMedia(new Audio
                {
                    Url = "~/Content/uploads/" + DateTime.Now.Ticks + "5_" + fileInfo.Name,
                    File = audio
                });
            }
            else
            {
                report.AddMedia(null);
            }
        }
 public void Cleanup()
 {
     _testReport = null;
     ReportsDAO.DeleteReportTest();
 }