示例#1
0
        public HttpResponseMessage RequestPointDetails(decimal latitude,
                                                       decimal longitude,
                                                       int identifier,
                                                       decimal zoomLevel,
                                                       string username,
                                                       string datasetName,
                                                       PointsSource pointsSource)
        {
            DomainInstance databaseInteractionHandler = new DomainInstance();

            //*zoomLevel is not required anymore
            var point = databaseInteractionHandler.RequestPointDetails(datasetName,
                                                                       username,
                                                                       new PointBase()
            {
                Latitude  = latitude,
                Longitude = longitude,
                Number    = identifier
            },
                                                                       pointsSource
                                                                       );
            var response = new HttpResponseMessage();

            response.Content = new StringContent(point.JSONSerialize());
            response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

            return(response);
        }
示例#2
0
        public ActionResult Login(string username, string password)
        {
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                return(RedirectToAction("Index"));
            }

            DomainInstance databseHandler = new DomainInstance();

            if (databseHandler.GetUser(username, false) == null)
            {
                return(RedirectToAction("Index", new { LoginErrorMessage = TextDictionary.LLoginWrongUsernameOrPasswordMessage }));
            }

            var signInManager = HttpContext.GetOwinContext().Get <SignInManager>();
            var userManager   = HttpContext.GetOwinContext().Get <UserManager>();

            var signInStatus = signInManager.PasswordSignIn(username, password, true, false);

            if (!userManager.IsEmailConfirmedAsync(username).Result)
            {
                return(RedirectToAction("Index", new { LoginErrorMessage = TextDictionary.LLoginActivateAccountMessage }));
            }

            if (signInStatus == SignInStatus.Success)
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                return(RedirectToAction("Index", new { LoginErrorMessage = TextDictionary.LLoginWrongUsernameOrPasswordMessage }));
            }
        }
示例#3
0
        /// <summary>
        /// Use this api method to check if a username is valid or not for registration
        /// </summary>
        /// <param name="username">Username which must be checked</param>
        /// <returns></returns>
        public HttpResponseMessage ValidateUsername(string username)
        {
            var response = new HttpResponseMessage();

            response.Content = null;

            DomainInstance handler = new DomainInstance();

            if (handler.GetUser(username, false) != null)
            {
                response.Content = new StringContent(new RegisterValidationResult()
                {
                    IsValid = false,
                    Message = Resources.text.TextDictionary.LRegisterInvalidUsernameInputMessage
                }.JSONSerialize());
            }

            if (response.Content == null)
            {
                response.Content = new StringContent(new RegisterValidationResult()
                {
                    IsValid = true
                }.JSONSerialize());
            }

            response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
            return(response);
        }
示例#4
0
        public void SelectUser()
        {
            DomainInstance handler = new DomainInstance();

            //            bool response = handler.ValidateUser("woofwoofa", "andrei1234");

            Assert.IsTrue(true);
        }
        public void InsertUser()
        {
            DomainInstance handler = new DomainInstance();

            //bool response = handler.U("test45", "andrei", "andrei", "woofwoof");

            Assert.IsTrue(true);
        }
示例#6
0
        public HttpResponseMessage GetDatasetLimits(string username, string datasetName)
        {
            var databaseInteractionHandler = new DomainInstance();
            var response = new HttpResponseMessage();


            response.Content = new StringContent(databaseInteractionHandler.GetDataSet(username, datasetName).JSONSerialize());
            response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

            return(response);
        }
示例#7
0
        public HttpResponseMessage GetColorPalette(string username, string paletteName)
        {
            DomainInstance databaseInteractionHandler = new DomainInstance();
            string         serializedColorPalete      = databaseInteractionHandler.GetColorPaletteSerialization(username, paletteName);

            var response = new HttpResponseMessage();

            response.Content = new StringContent(serializedColorPalete);
            response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

            return(response);
        }
示例#8
0
        public HttpResponseMessage ValidateGeoserverStyle(string datasetName, string datasetUsername, string paletteName, string paletteUsername)
        {
            DomainInstance databaseInteractionHandler = new DomainInstance();

            bool validationResult = databaseInteractionHandler.ValidateGeoserverLayer(datasetName, datasetUsername, paletteName, paletteUsername);

            var response = new HttpResponseMessage();

            response.StatusCode = validationResult ? System.Net.HttpStatusCode.OK : System.Net.HttpStatusCode.Conflict;

            return(response);
        }
示例#9
0
        public HttpResponseMessage GetUsers(int pageIndex, int itemsPerPage)
        {
            DomainInstance     handler = new DomainInstance();
            IEnumerable <User> users   = handler.GetUsers(null, pageIndex, itemsPerPage);

            var response = new HttpResponseMessage();

            response.Content = new StringContent(users.JSONSerialize());
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            return(response);
        }
示例#10
0
        public HttpResponseMessage GetUserAssociatedDatasetsCount(string username)
        {
            DomainInstance handler = new DomainInstance();

            var datasetsCount = new { count = handler.GetUsersAssociatedDatasetsCount(username) };

            var response = new HttpResponseMessage();

            response.Content = new StringContent(datasetsCount.JSONSerialize());
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            return(response);
        }
示例#11
0
        public HttpResponseMessage UploadFileChunk()
        {
            var databaseInteractionHandler = new DomainInstance();

            string directoryName = $"{ConfigurationManager.AppSettings["PointsDatasetsCheckpointFolder"]}\\{RouteConfig.CurrentUser.Username}";

            if (!Directory.Exists(directoryName))
            {
                Directory.CreateDirectory(directoryName);
            }


            foreach (string file in HttpContext.Current.Request.Files)
            {
                var FileData = HttpContext.Current.Request.Files[file];

                string[] checkoutData = FileData.FileName.Split(new char[] { '_' }, 2, StringSplitOptions.RemoveEmptyEntries);

                //fileFolderName represents the path to the folder where the dataset will be stored
                string fileFolderName = $"{directoryName}\\{checkoutData[0]}";

                //If the directory for the requested file doesnt has an entry in databse, create one
                if (!Directory.Exists(fileFolderName))
                {
                    Directory.CreateDirectory(fileFolderName);
                    databaseInteractionHandler.CreateDataSet(
                        checkoutData[0],
                        RouteConfig.CurrentUser.Username,
                        PointsSource.Cassandra
                        );
                }


                if (FileData?.ContentLength > 0)
                {
                    using (var fileStream = File.Create($"{fileFolderName}\\{checkoutData[1]}"))
                        FileData.InputStream.CopyTo(fileStream);
                }
            }

            return(new HttpResponseMessage()
            {
                StatusCode = System.Net.HttpStatusCode.OK,
                Content = new StringContent("Chunk uploaded")
            });
        }
示例#12
0
        public HttpResponseMessage GetColorPaletteList(int pageIndex)
        {
            var databaseInteractionHandler = new DomainInstance();
            var response = new HttpResponseMessage();


            List <Tuple <ColorMapFilters, string> > filters = buildFilters <ColorMapFilters>(Request.GetQueryNameValuePairs());

            response.Content = new StringContent(
                databaseInteractionHandler.GetColorPaletes(
                    filters,
                    pageIndex,
                    ChosePaletteViewModel.ColorPalettesPerPage
                    )?.JSONSerialize());
            response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

            return(response);
        }
        public HttpResponseMessage UploadGeoserverLayer([FromBody] JObject data)
        {
            DomainInstance handler = new DomainInstance();


            var insertResult = handler.CreateDataSet(
                datasetName: data["name"].ToObject <string>(),
                username: RouteConfig.CurrentUser.Username,
                pointsSource: PointsSource.Geoserver,
                serviceUrl: data["apiUrl"].ToObject <string>(),
                colorPaletteName: data["defaultColorPaletteName"].ToObject <string>(),
                colorPaletteUser: data["defaultColorPaletteUser"].ToObject <string>());


            if (insertResult == Domain.ViewModel.CreateDatasetResultCode.Ok)
            {
                handler.UpdateDatasetStatus(data["name"].ToObject <string>(),
                                            DatasetStatus.Generated,
                                            RouteConfig.CurrentUser.Username);

                return(new HttpResponseMessage()
                {
                    StatusCode = System.Net.HttpStatusCode.OK,
                    Content = new StringContent(MessageBoxBuilder.Create(TextDictionary.OverlayMFSuccesTitle,
                                                                         TextDictionary.OverlayMFSuccesText,
                                                                         true))
                });
            }

            //Log a warning message
            Core.CoreContainers.LogsRepository.LogWarning($"Failed to insert geoserver layer ( ({ insertResult.ToString()} ) with data provided: {data}", Core.Database.Logs.LogTrigger.Controllers);

            return(new HttpResponseMessage()
            {
                StatusCode = System.Net.HttpStatusCode.OK,
                Content = new StringContent(MessageBoxBuilder.Create(
                                                insertResult == Domain.ViewModel.CreateDatasetResultCode.GeoserverError ?
                                                TextDictionary.OverlayCDGeoserverFailTitle :
                                                TextDictionary.OverlayCDFailTitle,
                                                insertResult == Domain.ViewModel.CreateDatasetResultCode.GeoserverError ?
                                                string.Format(TextDictionary.OverlayCDGeoserverFailText, data["name"].ToObject <string>()) :
                                                TextDictionary.OverlayCDFailText))
            });
        }
        public void RequestDataPoints(decimal latitudeFrom,
                                      decimal longitudeFrom,
                                      decimal latitudeTo,
                                      decimal longitudeTo,
                                      int zoomLevel,
                                      string[] cachedRegions,
                                      string username,
                                      string datasetName)
        {
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(datasetName))
            {
                return;
            }

            DomainInstance databaseInteractionHandler = new DomainInstance();

            Action <IEnumerable <PointBase>, string> callback = (pointsData, regionKey) =>
            {
                Clients.Caller.ProcessPoints(new
                {
                    pointsData,
                    regionKey
                }.JSONSerialize());
            };

            try
            {
                databaseInteractionHandler.RequestDomainPointsRegions(new Tuple <decimal, decimal>(latitudeFrom, longitudeFrom),
                                                                      new Tuple <decimal, decimal>(latitudeTo, longitudeTo),
                                                                      zoomLevel,
                                                                      username,
                                                                      datasetName,
                                                                      cachedRegions,
                                                                      callback);
            }
            catch (Exception exception)
            {
                CoreContainers.LogsRepository.LogError(exception, Core.Database.Logs.LogTrigger.Controllers);
            }
            finally
            {
                Clients.Caller.PointsProcessedNotification();
            }
        }
示例#15
0
        public HttpResponseMessage RemoveDatasetFromUser([FromBody] JObject data)
        {
            DomainInstance handler = new DomainInstance();

            return(handler.ChangeUserAssociatedDataset(
                       data["username"].ToString(),
                       data["datasetName"].ToString(),
                       data["datasetUser"].ToString(),
                       false) ?
                   new HttpResponseMessage()
            {
                StatusCode = System.Net.HttpStatusCode.OK
            }
                :
                   new HttpResponseMessage()
            {
                StatusCode = System.Net.HttpStatusCode.InternalServerError
            });
        }
示例#16
0
        public HttpResponseMessage AddDatasetToUser([FromBody] JObject data)
        {
            DomainInstance handler = new DomainInstance();

            return(handler.ChangeUserAssociatedDataset(
                       data["username"].ToString(),
                       data["datasetName"].ToString(),
                       data["datasetUser"].ToString(),
                       true) ?
                   new HttpResponseMessage()
            {
                StatusCode = System.Net.HttpStatusCode.OK
            }
                :
                   new HttpResponseMessage()
            {
                StatusCode = System.Net.HttpStatusCode.InternalServerError
            });
            //todo: add a better message here
        }
        public HttpResponseMessage GetDatasets(int pageIndex, int itemsPerPage)
        {
            DomainInstance handler  = new DomainInstance();
            var            datasets = handler.GetDataSets(string.Empty, true, null, pageIndex, itemsPerPage)?.Select(dataset => new
            {
                dataset.Name,
                dataset.ID,
                dataset.Username,
                Status = dataset.Status.GetEnumString(),
                dataset.IsValid,
                Source = dataset.PointsSource.ToString()
            });

            var response = new HttpResponseMessage();

            response.Content = new StringContent(datasets.JSONSerialize());
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            return(response);
        }
示例#18
0
        /// <summary>
        /// Use this api method to check if a email is valid or not for registration
        /// </summary>
        /// <param name="username">Username which must be checked</param>
        /// <returns></returns>
        public HttpResponseMessage ValidateEmail(string email)
        {
            var response = new HttpResponseMessage();

            Func <HttpResponseMessage, HttpResponseMessage> setContentType = (httpResponse) => {
                httpResponse.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
                return(httpResponse);
            };

            if (!new EmailAddressAttribute().IsValid(email))
            {
                response.Content = new StringContent(new RegisterValidationResult()
                {
                    IsValid = false,
                    Message = TextDictionary.LRegisterInvalidEmailFormatInputMessage
                }.JSONSerialize());

                return(setContentType(response));
            }

            DomainInstance handler = new DomainInstance();

            if (handler.GetUser(email, true) != null)
            {
                response.Content = new StringContent(new RegisterValidationResult()
                {
                    IsValid = false,
                    Message = Resources.text.TextDictionary.LRegisterInvalidEmailInputMessage
                }.JSONSerialize());

                return(setContentType(response));
            }


            response.Content = new StringContent(new RegisterValidationResult()
            {
                IsValid = true
            }.JSONSerialize());

            return(setContentType(response));
        }
示例#19
0
        public HttpResponseMessage GetDatasetsList(int pageIndex, int itemsPerPage = -1)
        {
            if (itemsPerPage == -1)
            {
                itemsPerPage = ChoseDatasetViewModel.DataPointsPerPage;
            }

            var databaseInteractionHandler = new DomainInstance();
            var response = new HttpResponseMessage();

            bool isAnonymous = User.IsInRole(UserRoles.Anonymous.GetEnumString());

            List <Tuple <DataSetsFilters, string> > filters = buildFilters <DataSetsFilters>(Request.GetQueryNameValuePairs());

            //if is anonymous, only source filter should be considered
            if (isAnonymous)
            {
                filters = filters.Where(item => item.Item1 == DataSetsFilters.Source).ToList();
                filters.Add(new Tuple <DataSetsFilters, string>(DataSetsFilters.IsDemo, "1"));
            }

            var model = databaseInteractionHandler.GetDataSets(
                RouteConfig.CurrentUser.Username,
                isAnonymous,
                filters,
                pageIndex,
                itemsPerPage
                )?.Select(dataset => new
            {
                dataset.Name,
                dataset.ID,
                dataset.Username,
                Status = dataset.Status.GetEnumString(),
                dataset.IsValid
            });

            response.Content = new StringContent(model?.JSONSerialize());
            response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

            return(response);
        }
示例#20
0
        public ActionResult GetColorPalettePage()
        {
            try
            {
                DomainInstance databaseInteractionHandler = new DomainInstance();

                return(View("~/Views/Home/Points Settings Content/ChosePalette.cshtml",
                            new ChosePaletteViewModel(databaseInteractionHandler.GetColorPaletes(
                                                          new List <Tuple <Core.Database.ColorMapFilters, string> >()
                {
                    new Tuple <Core.Database.ColorMapFilters, string>(Core.Database.ColorMapFilters.None, string.Empty)
                },
                                                          0,
                                                          ChosePaletteViewModel.ColorPalettesPerPage
                                                          ))));
            }
            catch
            {
                return(View());
            }
        }
示例#21
0
        public HttpResponseMessage RequestRegionsKeys(decimal latitudeFrom,
                                                      decimal longitudeFrom,
                                                      decimal latitudeTo,
                                                      decimal longitudeTo,
                                                      int zoomLevel,
                                                      string username,
                                                      string datasetName)
        {
            DomainInstance databaseInteractionHandler = new DomainInstance();
            var            keys = databaseInteractionHandler.RequestPointsRegionsKeys(
                new Tuple <decimal, decimal>(latitudeFrom, longitudeFrom),
                new Tuple <decimal, decimal>(latitudeTo, longitudeTo),
                zoomLevel,
                username,
                datasetName);

            var response = new HttpResponseMessage();

            response.Content = new StringContent(keys.JSONSerialize());
            response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

            return(response);
        }
示例#22
0
 public ActionResult GetChoseDatasetPage()
 {
     try
     {
         DomainInstance databaseInteractionHandler = new DomainInstance();
         return(View("~/Views/Home/Points Settings Content/ChoseDataset.cshtml",
                     new ChoseDatasetViewModel(databaseInteractionHandler.GetDataSets(
                                                   RouteConfig.CurrentUser?.Username,
                                                   false,
                                                   new List <Tuple <DataSetsFilters, string> >()
         {
             new Tuple <DataSetsFilters, string>(
                 DataSetsFilters.None,
                 string.Empty)
         },
                                                   ChoseDatasetViewModel.DataPointsPerPage
                                                   ))));
     }
     catch (Exception e)
     {
         return(View());
     }
 }
示例#23
0
        public HttpResponseMessage SaveColorsPalette(ColorMap colorMap)
        {
            DomainInstance handler = new DomainInstance();
            bool           success = handler.InsertColorPalette(RouteConfig.CurrentUser.Username, colorMap);


            var response = new HttpResponseMessage();

            response.Content = new StringContent(MessageBoxBuilder.Create(success ? TextDictionary.OverlayCPSuccesTitle
                                                                                 : TextDictionary.OverlayCPFailedTitle,
                                                                          success ? TextDictionary.OverlayCPSuccesText
                                                                                 : TextDictionary.OverlayCPFailedText,
                                                                          success));

            //Log a warning message if insert fails
            if (!success)
            {
                Core.CoreContainers.LogsRepository.LogWarning($"Failed to insert color palette { colorMap.Name } (main color criteria: { colorMap.MainColorCriteria }) for user {RouteConfig.CurrentUser.UserName}", Core.Database.Logs.LogTrigger.Controllers);
            }

            response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");

            return(response);
        }