public void findAllCommentsArroundTest()
 {
     Locations location = new Locations();
     Codes code = new Codes();
     Comments comment = new Comments();
     List<Comments> comments = new List<Comments>();
     location.id = 20;
     location.latitude = 25;
     location.longitude = 20;
     code.code = "7DE352BC35E966716789926415D69D96";
     code.id = 5;
     comment.archiveDescription = "archive";
     comment.description = "descr";
     comment.id = 30;
     comment.isText = true;
     comment.locationsId = 23;
     comment.userId = 10;
     comments.Add(comment);
     iLocationServices.Setup(m => m.findLocationByLatAndLng(It.IsAny<string>(), It.IsAny<string>())).Returns(location);
     iCommentServices.Setup(m => m.findCommentByIdLocation(It.IsAny<int>())).Returns(comments);
     iCodeServices.Setup(m => m.findFirstCode()).Returns("code");
     CommentsWebServicesController target = new CommentsWebServicesController(iCodeServices.Object, iLocationServices.Object, iCommentServices.Object);
     string actual = target.findAllCommentsArround(null, "3", "7DE352BC35E966716789926415D69D96");
     Assert.IsNull(actual);
 }
        public string searchLocations(string location, string radius, string windowsPhoneId, string code)
        {
            string firstCode =  codeServices.findFirstCode();
            Locations locationPassed = new Locations();
            List<Locations> locationsResult = new List<Locations>();
            string locationsResultJson = "";
            if (code == firstCode)
            {
                locationPassed = serializer.Deserialize<Locations>(location);

                locationsResult = locationServices.findLocationsAround(locationPassed.latitude.ToString(), locationPassed.longitude.ToString(), Convert.ToDouble(radius));
                try
                {
                    locationsResultJson = serializer.Serialize(locationsResult);
                }
                catch
                {

                }
                userLocationWebServices.addUserLocation("0", windowsPhoneId, locationPassed.latitude.ToString(), locationPassed.longitude.ToString(), code);

                return locationsResultJson;
            }
            return null;
        }
        public string addCommentoToLocation(string location, string comment, string code)
        {
            string firstCode = codeServices.findFirstCode();
            Locations locationPassed = new Locations();
            Locations locationSearch = new Locations();
            Comments commentPassed = new Comments();

            if (code == firstCode)
            {
                locationPassed = serializer.Deserialize<Locations>(location);
                commentPassed = serializer.Deserialize<Comments>(comment);
                locationSearch = locationServices.findLocationByLatAndLng(locationPassed.latitude.ToString(), locationPassed.longitude.ToString());
                if (locationPassed == null || locationPassed.id == 0)
                {
                    locationServices.addLocations(locationPassed);
                    commentPassed.locationsId = locationPassed.id;
                    commentPassed.isText = true;
                }
                else
                {
                    commentPassed.locationsId = locationSearch.id;
                    commentPassed.isText = true;
                }
                commentServices.addComment(commentPassed);
                return "1";

            }
            return "0";
        }
        public ActionResult showComments(int idLocation)
        {
            Locations location = new Locations();
            string lat, lng;
            try
            {
                if (location.currentLocation != null)
                {
                    lat = location.currentLocation.latitude.ToString();
                    lng = location.currentLocation.longitude.ToString();
                    location.currentLocation = locationServices.findLocationByLatAndLng(lat, lng);
                    idLocation = location.currentLocation.id;
                }
            }
            catch (Exception)
            {
            }

            List<Comments> comments = new List<Comments>();
            comments = commentServices.findCommentByIdLocation(idLocation);
            byte[] bytes;
            foreach (Comments comment in comments)
            {
                bytes = convertStringToBytes(comment.sound);
            }
            ViewData["locationId"] = idLocation;
            ViewData["comments"] = comments;
            return View();
        }
 public void addLocations(string location, string code)
 {
     string firstCode = codeServices.findFirstCode();
     Locations locationPassed = new Locations();
     if (code == firstCode)
     {
         locationPassed = serializer.Deserialize<Locations>(location);
         locationServices.addLocations(locationPassed);
     }
 }
 public void currentLocation(string lat, string lng)
 {
     Locations location = new Locations();
     location.latitude = Convert.ToDouble(lat);
     location.longitude = Convert.ToDouble(lng);
     try
     {
         location.currentLocation = location;
     }
     catch (Exception)
     {
     }
 }
 public void locationsOfTest()
 {
     List<Locations> locations = new List<Locations>();
     List<Locations> expected = locations;
     Locations location = new Locations();
     location.latitude = 10;
     location.longitude = 20;
     location.id = 20;
     locations.Add(location);
     iLocationServices.Setup(m => m.findLocationsAround(It.IsAny<String>(), It.IsAny<String>(), It.IsAny<Double>())).Returns(locations);
     LocationsController target = new LocationsController(iLocationServices.Object,iCommentServices.Object);
     List <Locations> actual = target.locationsOf("10", "20");
     Assert.AreEqual(expected, actual);
 }
 public void searchLocationsTest()
 {
     Locations location = new Locations();
     List<Locations> locations = new List<Locations>();
     location.id = 1;
     location.latitude = 1.2;
     location.longitude = 1.3;
     locations.Add(location);
     iCodeServices.Setup(m => m.findFirstCode()).Returns("code");
     iUserLocationServices.Setup(m => m.addUserLocation(It.IsAny<UserLocations>()));
     iLocationServices.Setup(m=>m.findLocationsAround(It.IsAny<string>(),It.IsAny<string>(),It.IsAny<double>())).Returns(locations);
     LocationsWebServicesController target = new LocationsWebServicesController(iLocationServices.Object, iCodeServices.Object, iUserLocationServices.Object, iCommentServices.Object);
     string locationString = "{'id':'1','longitude':'1','latitude':'1'}";
     string radius = "1";
     string windowsPhoneId = "teste";
     string code = "code";
     var actual = target.searchLocations(locationString, radius, windowsPhoneId, code);
     Assert.IsNotNull(actual, "");
 }
 public void addLocationsTest()
 {
     iCodeServices.Setup(m => m.findFirstCode()).Returns("code");
     iLocationServices.Setup(m => m.addLocations(It.IsAny<Locations>()));
     LocationsWebServicesController target = new LocationsWebServicesController(iLocationServices.Object, iCodeServices.Object, iUserLocationServices.Object, iCommentServices.Object);
     Locations location = new Locations();
     string locationString;
     try
     {
         locationString = serializer.Serialize(location);
     }
     catch
     {
         locationString = "{'id':'1','longitude':'1','latitude':'1'}";
     }
     string code = "code";
     target.addLocations(locationString, code);
     Assert.IsTrue(true);
 }
        //
        // GET: /Maps/
        public ActionResult index()
        {
            try
            {
                if (user.currentLocation == null)
                {
                    Locations location = new Locations();
                    location.latitude = 42.345573;
                    location.longitude = -71.098326;
                    user.currentLocation = location;
                }
            }
            catch
            {
            }

            /*EXEMPLO REQUESICAO EXTERNA !!!! */
            /*string result2;
            Stream result;
            Locations locationsUser = user.currentLocation;
            locationsUser.currentLocation = null;
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            ConnectController connectController = new ConnectController();
            dynamic userLocation = serializer.Serialize(locationsUser);
            dynamic result4 = speechWebServicesController.sendLastCommentFromIdLocation("18", "wonders");
            result2 = connectController.getJson("http://ec2-177-71-137-221.sa-east-1.compute.amazonaws.com/smartaudiocityguide/SpeechWebServices/sendLastCommentFromIdLocation?idLocation=18&code=wonders");
            */
            /*List<Locations> test = serializer.Deserialize<List<Locations>>(result2);
            user.currentLocation = locationsUser;
            */

            List<string> list = new List<string>();
            list.Add("Normal Mode");
            list.Add("Exploration Mode");
            ViewData["selectList"] = new SelectList(list);

            return View();
        }
        public void addCommentToLocation(string streamOfComment, string latitude , string longitude)
        {
            SpeechAudioFormatInfo audioType = new SpeechAudioFormatInfo(1000,AudioBitsPerSample.Sixteen,AudioChannel.Mono);
            SpeechSynthesizer speech = new SpeechSynthesizer("SmartAudioCityGuide", "Lz+vYpOFm6NTP83A9y0tPoX6ByJa06Q6yxHvoBsD0xo=");
            byte[] streamString;
            Locations location = new Locations();
            byte[] buffer = new byte[10];
            MemoryStream stream = new MemoryStream();
            using (SpeechRecognitionEngine speechRecongnizeEngine = new SpeechRecognitionEngine())
            {
                location.latitude = Convert.ToDouble(latitude);
                location.longitude = Convert.ToDouble(longitude);
                locationsServices.addLocations(location);

                streamString = serializer.Deserialize<byte[]>(streamOfComment);
                buffer = new byte[streamString.Count()];

                stream.Write(buffer, 0, buffer.Length);

                // Add a handler for the LoadGrammarCompleted event.
                speechRecongnizeEngine.LoadGrammarCompleted +=
                  new EventHandler<LoadGrammarCompletedEventArgs>(speechRecongnizeEngine_LoadGrammarCompleted);

                // Add a handler for the SpeechRecognized event.
                speechRecongnizeEngine.SpeechRecognized +=
                new EventHandler<SpeechRecognizedEventArgs>(speechRecongnizeEngine_SpeechRecognized);

                speechRecongnizeEngine.LoadGrammar(new DictationGrammar());
                speechRecongnizeEngine.SetInputToAudioStream(stream, audioType);
                speechRecongnizeEngine.RecognizeAsync(RecognizeMode.Multiple);
            }
            using (SpeechRecognizer recognizer = new SpeechRecognizer())
            {

                // Create SemanticResultValue objects that contain cities and airport codes.
                SemanticResultValue chicago = new SemanticResultValue("Chicago", "ORD");
                SemanticResultValue boston = new SemanticResultValue("Boston", "BOS");
                SemanticResultValue miami = new SemanticResultValue("Miami", "MIA");
                SemanticResultValue dallas = new SemanticResultValue("Dallas", "DFW");

                // Create a Choices object and add the SemanticResultValue objects, using
                // implicit conversion from SemanticResultValue to GrammarBuilder
                Choices cities = new Choices();
                cities.Add(new Choices(new GrammarBuilder[] { chicago, boston, miami, dallas }));

                // Build the phrase and add SemanticResultKeys.
                GrammarBuilder chooseCities = new GrammarBuilder();
                chooseCities.Append("I want to fly from");
                chooseCities.Append(new SemanticResultKey("origin", cities));
                chooseCities.Append("to");
                chooseCities.Append(new SemanticResultKey("destination", cities));

                // Build a Grammar object from the GrammarBuilder.
                Grammar bookFlight = new Grammar(chooseCities);
                bookFlight.Name = "Book Flight";

                // Add a handler for the LoadGrammarCompleted event.
                recognizer.LoadGrammarCompleted +=
                  new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);

                // Add a handler for the SpeechRecognized event.
                recognizer.SpeechRecognized +=
                  new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
                // Attach event handlers for recognition events.
                recognizer.SpeechRecognized +=
                  new EventHandler<SpeechRecognizedEventArgs>(
                    SpeechRecognizedHandler);
                recognizer.EmulateRecognizeCompleted +=
                  new EventHandler<EmulateRecognizeCompletedEventArgs>(
                    EmulateRecognizeCompletedHandler);
                // Load the grammar object to the recognizer.
                recognizer.LoadGrammarAsync(bookFlight);
            }
        }
 public void addLocations(Locations location)
 {
     db.locations.Add(location);
     db.SaveChanges();
 }
 public void showCommentsTest()
 {
     List<Locations> locations = new List<Locations>();
     Locations location = new Locations();
     Comments comment = new Comments();
     List<Comments> comments = new List<Comments>();
     comment.archiveDescription = "Teste";
     comment.description = "Teste";
     comment.id = 256;
     comment.isText = true;
     comment.locationsId = 20;
     comment.userId = 20;
     comment.sound = "1;0;1;0;1;1;1;1;1;0;0;0";
     comments.Add(comment);
     location.latitude = 10;
     location.longitude = 20;
     location.id = 20;
     locations.Add(location);
     iLocationServices.Setup(m => m.findLocationsAround(It.IsAny<String>(), It.IsAny<String>(), It.IsAny<Double>())).Returns(locations);
     iCommentServices .Setup(m => m.findCommentByIdLocation(location.id)).Returns(comments);
     int idLocation = 20;
     LocationsController target = new LocationsController(iLocationServices.Object, iCommentServices.Object);
     ViewResult res;
     res = target.showComments(idLocation) as ViewResult;
     ViewDataDictionary tempData = res.ViewData as ViewDataDictionary;
     Assert.AreEqual(20, tempData["locationid"]);
     Assert.AreEqual(comments, tempData["comments"]);
     Assert.IsNotNull(res);
 }
        public string findAllCommentsArround(string location, string radius, string code)
        {
            string firstCode = codeServices.findFirstCode();
            Locations locationPassed = new Locations();
            Locations location1 = new Locations();
            List<Comments> commentsResult = new List<Comments>();
            string commentsResultJson;
            if (code == firstCode)
            {
                locationPassed = serializer.Deserialize<Locations>(location);

                location1 = locationServices.findLocationByLatAndLng(locationPassed.latitude.ToString(), locationPassed.longitude.ToString());
                commentsResult = commentServices.findCommentByIdLocation(location1.id);

                commentsResultJson = serializer.Serialize(commentsResult);
                return commentsResultJson;
            }
            return null;
        }
        public ActionResult tellAboutLocation(string lat, string lng)
        {
            Locations location = new Locations();

            try
            {
                if (location.currentLocation != null)
                {
                    lat = location.currentLocation.latitude.ToString();
                    lng = location.currentLocation.longitude.ToString();
                }

                location.currentLocation = locationServices.findLocationByLatAndLng(lat, lng);
                return RedirectToActionPermanent("showComments", new { idLocation = location.currentLocation.id });
            }
            catch (Exception)
            {
                return null;
            }
        }