コード例 #1
0
        public static void AddFile(ge_project project, string filename, ge_user user)
        {
            if (File.Exists(filename))
            {
                System.IO.FileInfo fi = new FileInfo(filename);

                project.data.Add(new ge_data
                {
                    createdId       = user.Id,
                    createdDT       = DateTime.Now,
                    filename        = fi.Name,
                    fileext         = fi.Extension,
                    filetype        = "text/plain",
                    filesize        = fi.Length,
                    filedate        = fi.LastWriteTime,
                    encoding        = "ascii",
                    datumProjection = datumProjection.NONE,
                    pstatus         = PublishStatus.Uncontrolled,
                    cstatus         = ConfidentialityStatus.RequiresClientApproval,
                    version         = "P01.1",
                    vstatus         = VersionStatus.Intermediate,
                    qstatus         = QualitativeStatus.AECOMFactual,
                    description     = fi.Name,
                    operations      = "Read;Update;Delete",
                    file            = new ge_data_file {
                        data_string = File.ReadAllText(filename)
                    }
                }
                                 );
            }
        }
コード例 #2
0
ファイル: UserService.cs プロジェクト: simon969/ge_repository
        public async Task UpdateUser(ge_user userToBeUpdated, ge_user user)
        {
            userToBeUpdated.FirstName = user.FirstName;
            userToBeUpdated.LastName  = user.LastName;

            await _unitOfWork.CommitAsync();
        }
コード例 #3
0
ファイル: Index.chtml.cs プロジェクト: simon969/ge_repository
        public async Task <IActionResult> OnGetAsync(string pageFilter, string pageSort, int?pageIndex, int?pageSize, Guid?groupId, Guid?projectId, Constants.PublishStatus?publishStatus)
        {
            base.setPaging(pageFilter, pageSort, pageIndex, pageSize, groupId, projectId, publishStatus);

            user = await GetUserAsync();

            IQueryable <ge_user_ops> var;

            if (IsUserGroupAdmin() || IsUserProjectAdmin())
            {
                var = _context.UserOperationsSearch(null, pageFilter, "", groupId, projectId);
            }
            else
            {
                var = _context.UserOperationsSearch(user.Id, pageFilter, "", groupId, projectId);
            }

            int pTotal;

            user_ops = await var.PagedResult(this.pageIndex, this.pageSize, o => o.createdDT, true, out pTotal).ToListAsync();

            pageTotal = pTotal;

            return(Page());
        }
コード例 #4
0
ファイル: UserService.cs プロジェクト: simon969/ge_repository
        public async Task <ge_user> CreateUser(ge_user newUser)
        {
            await _unitOfWork.User.AddAsync(newUser);

            await _unitOfWork.CommitAsync();

            return(newUser);
        }
コード例 #5
0
        public async Task <string> GetUserIdAsync()
        {
            if (_user == null)
            {
                _user = await GetUserAsync();
            }

            return(_user.Id);
        }
コード例 #6
0
ファイル: ge_groupDAL.cs プロジェクト: simon969/ge_repository
 public void addUser(ge_user u, string operations)
 {
     if (group != null)
     {
         if (group.users != null)
         {
             ge_user_ops os = new ge_user_ops();
             os.user       = u;
             os.operations = operations;
             group.users.Add(os);
         }
     }
 }
コード例 #7
0
        public async Task <IActionResult> OnGetAsync(Guid?groupId, Guid?projectId)
        {
            var CurrentUserId = GetUserIdAsync().Result;

            user = new ge_user();

            user_ops                 = new ge_user_ops();
            user_ops.operations      = "Read;Update;Delete";
            user_ops.user_operations = "Create;Read;Update;Delete";

            if (groupId != null)
            {
                user_ops.group = _context.ge_group
                                 .Where(o => o.Id == groupId).FirstOrDefault();
                if (user_ops.group != null)
                {
                    bool IsUserGroupAdmin = _context.DoesUserHaveOperation(Constants.AdminOperationName, user_ops.group, CurrentUserId);
                    if (!IsUserGroupAdmin)
                    {
                        return(RedirectToPageMessage(msgCODE.GROUP_OPERATION_CREATE_ADMINREQ));
                    }
                    user_ops.groupId = user_ops.group.Id;
                    setViewData();
                    return(Page());
                }
                if (projectId != null)
                {
                    return(RedirectToPageMessage(msgCODE.USER_OPS_CREATE_AMBIGUOUS));
                }
            }

            if (projectId != null)
            {
                user_ops.project = _context.ge_project
                                   .Where(p => p.Id == projectId).FirstOrDefault();
                if (user_ops.project != null)
                {
                    bool IsUserProjectAdmin = _context.DoesUserHaveOperation(Constants.AdminOperationName, user_ops.project, CurrentUserId);
                    if (!IsUserProjectAdmin)
                    {
                        return(RedirectToPageMessage(msgCODE.PROJECT_OPERATION_CREATE_ADMINREQ));
                    }
                    user_ops.projectId = user_ops.project.Id;
                    setViewData();
                    return(Page());
                }
            }

            return(NotFound());
        }
コード例 #8
0
        public async Task <IActionResult> OnGetAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ge_user = await _context.ge_user.FirstOrDefaultAsync(m => m.Id == id);

            if (ge_user == null)
            {
                return(NotFound());
            }
            return(Page());
        }
コード例 #9
0
        public async Task <ge_user> GetUserAsync()
        {
            try {
                if (HttpContext != null)
                {
                    var     claim        = HttpContext.User.Claims.First(c => c.Type == "email");
                    string  emailAddress = claim.Value;
                    ge_user user         = await _userService.GetUserByEmailAddress(emailAddress);

                    return(user);
                }
                return(null);
            } catch {
                return(null);
            }
        }
コード例 #10
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ge_user = await _context.ge_user.FindAsync(id);

            if (ge_user != null)
            {
                _context.ge_user.Remove(ge_user);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
コード例 #11
0
        private async Task <string> EnsureUser(
            string testUserPw,
            string email,
            string firstname,
            string lastname,
            string phonenumber
            )
        {
            var user = await _userManager.FindByNameAsync(email);

            if (user == null)
            {
                user = new ge_user(firstname, lastname, email, phonenumber);
                var resp = await _userManager.CreateAsync(user, testUserPw);
            }

            return(user.Id);
        }
コード例 #12
0
        private async Task <string> ensureUser()
        {
            var u = await _userManager.FindByIdAsync(user.Id);

            if (u == null)
            {
                if (String.IsNullOrEmpty(user.FirstName) ||
                    String.IsNullOrEmpty(user.LastName) ||
                    String.IsNullOrEmpty(user.Email) ||
                    String.IsNullOrEmpty(user.PhoneNumber) ||
                    String.IsNullOrEmpty(_new_user_password)
                    )
                {
                    return(null);
                }

                u = new ge_user(user.FirstName,
                                user.LastName,
                                user.Email,
                                user.PhoneNumber);

                var ir = await _userManager.CreateAsync(u, _new_user_password);

                if (ir != IdentityResult.Success)
                {
                    return(null);
                }

                // var code = await _userManager.GenerateEmailConfirmationTokenAsync(u);
                //     var callbackUrl = Url.Page(
                //         "/Account/ConfirmEmail",
                //         pageHandler: null,
                //         values: new { userId = u.Id, code = code },
                //         protocol: Request.Scheme);

                //     await _emailSender.SendEmailAsync(u.Email, "GE Repository Confirm your email",
                //         $"<p>An account in the Ground Engineering Repository has been created for you. </p>" +
                //         $"<p>Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a></p>" +
                //         $"<p>Your temporary password is [{new_user_password}] please change this when you first login.</p>"
                //         );
            }

            return(u.Id);
        }
コード例 #13
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                var user = new ge_user {
                    UserName    = Input.Email,
                    Email       = Input.Email,
                    PhoneNumber = Input.PhoneNumber,
                    FirstName   = Input.FirstName,
                    LastName    = Input.LastName
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "GE_Repository Confirm your email",
                                                      $"<p>You have successfully created an account in the Ground Engineering Repository</p>" +
                                                      $"<p>Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.</p>");

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(LocalRedirect(returnUrl));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
コード例 #14
0
        private static async Task <string> EnsureUser(IServiceProvider serviceProvider,
                                                      string testUserPw,
                                                      string email,
                                                      string firstname,
                                                      string lastname,
                                                      string phonenumber
                                                      )
        {
            var userManager = serviceProvider.GetService <UserManager <ge_user> >();

            var user = await userManager.FindByNameAsync(email);

            if (user == null)
            {
                user = new ge_user(firstname, lastname, email, phonenumber);
                var resp = await userManager.CreateAsync(user, testUserPw);
            }

            return(user.Id);
        }
コード例 #15
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (!UpdateCreated(group))
            {
                return(Page());
            }

            group.operations         = "Read;Update;Delete";
            group.project_operations = "Create;Read;Update;Delete";

            if (group.datumProjection != Constants.datumProjection.NONE)
            {
                if (!UpdateProjectionLoc(group))
                {
                    return(Page());
                }
            }

            // Add Admin group_user for new group
            ge_user user = await GetUserAsync();

            group.users = new List <ge_user_ops>();
            group.users.Add(new ge_user_ops {
                userId          = user.Id,
                user_operations = "Create;Read;Update;Delete;Approve;Admin",
                createdId       = user.Id,
                createdDT       = DateTime.UtcNow,
                operations      = "Read;Update;Delete"
            }
                            );

            _context.ge_group.Add(group);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
コード例 #16
0
        public async Task <Boolean> DoesUserHaveOperation(string operation, ge_project project, ge_user user)
        {
            var user_ops = await GetByUserIdProjectIdIncludeProject(user.Id, project.Id);

            if (user_ops == null)
            {
                return(false);
            }

            return(user_ops.operations.Contains(operation));
        }
コード例 #17
0
        public async Task <Boolean> DoesUserHaveOperation(string operation, ge_group group, ge_user user)
        {
            var user_ops = await GetByUserIdGroupIdIncludeGroup(user.Id, group.Id);

            if (user_ops == null)
            {
                return(false);
            }

            return(user_ops.operations.Contains(operation));
        }
コード例 #18
0
        private ge_transform_parameters getTransformParameters(Guid transformId,
                                                               Guid?Id,
                                                               Guid?projectId,
                                                               Guid?groupId,
                                                               string[] projects,
                                                               string[] holes,
                                                               string[] tables,
                                                               string[] geols,
                                                               string[] options,
                                                               string arg_vals,
                                                               string flwor,
                                                               string xpath,
                                                               string version)
        {
            ge_transform_parameters transform_params = new ge_transform_parameters();

            if (!String.IsNullOrEmpty(transform.parameters))
            {
                try {
                    transform_params = Newtonsoft.Json.JsonConvert.DeserializeObject <ge_transform_parameters>(transform.parameters);
                } catch (Newtonsoft.Json.JsonReaderException e) {
                    Console.WriteLine(e.Message);
                }
            }

            /* Incase all parameters are passed in first element of parameters array purgeArray for delimiters*/
            string[] delims = new string[] { ",", ";" };

            if (projects.Any())
            {
                projects = projects.purgeArray(delims);
                transform_params.projects = projects;
            }

            if (holes.Any())
            {
                holes    = holes.purgeArray(delims);
                xml_data = getHoles(xml_data, holes);
                transform_params.holes = holes;
            }

            if (tables.Any())
            {
                tables = tables.purgeArray(delims);
                transform_params.tables = tables;
            }

            if (geols.Any())
            {
                geols    = geols.purgeArray(delims);
                xml_data = getGeols(xml_data, geols);
                transform_params.geols = geols;
            }

            if (options.Any())
            {
                options = options.purgeArray(delims);
                transform_params.options = options;
            }

            if (!String.IsNullOrEmpty(arg_vals))
            {
                /* To be added process FLO string */
                transform_params.arg_vals = arg_vals;
            }
            if (!String.IsNullOrEmpty(flwor))
            {
                /* To be added process FLO string */
                transform_params.flwor = flwor;
            }

            if (!String.IsNullOrEmpty(xpath))
            {
                xml_data = getXPath(xml_data, xpath);
                transform_params.xpath = xpath;
            }

            if (transformId != null & transformId != Guid.Empty)
            {
                transform_params.transformId = transformId.ToString();
            }

            if (Id != null & Id != Guid.Empty)
            {
                transform_params.Id = Id.ToString();
            }

            if (projectId != null & projectId != Guid.Empty)
            {
                transform_params.projectId = projectId.ToString();
            }

            if (groupId != null & groupId != Guid.Empty)
            {
                transform_params.groupId = groupId.ToString();
            }

            /* Add current local parameters for passing to stylesheet */
            transform_params.host           = getHostHref();
            transform_params.host_view      = getHostHref() + constHref_transform;
            transform_params.host_file      = getHostHref() + constHref_dataVIEW;
            transform_params.host_download  = getHostHref() + constHref_dataDOWNLOAD;
            transform_params.host_esri      = getHostHref() + constHref_esriFEATURE;
            transform_params.host_logger    = getHostHref() + constHref_Logger;
            transform_params.host_gint      = getHostHref() + constHref_gINT;
            transform_params.host_tablefile = getHostHref() + constHref_TableFile;
            transform_params.host_ags       = getHostHref() + constHref_AGS;
            transform_params.version        = version;
            // transform_params.sessionid = this.Session.Id;
            var user = GetUserAsync();

            if (user != null)
            {
                ge_user u = user.Result as ge_user;
                transform_params.user = u.FirstName + ' ' + u.LastName + '(' + u.Email + ')';
            }

            return(transform_params);
        }
コード例 #19
0
ファイル: UserService.cs プロジェクト: simon969/ge_repository
 public async Task DeleteUser(ge_user user)
 {
     _unitOfWork.User.Remove(user);
     await _unitOfWork.CommitAsync();
 }
コード例 #20
0
        public async Task <IActionResult> CreateXML(Guid Id, string dictionary_file, string data_structure, string options = "")
        {
            if (Id == null)
            {
                // return NotFound();
                return(Json("Id not found"));
            }

            ge_data data = await _dataService.GetDataByIdWithAll(Id);

            Boolean ignore_pflag = options.Contains("ignore_pflag");

            if (data == null)
            {
                // return NotFound();
                return(Json("data not found"));
            }

            if (data.fileext != FileExtension.AGS)
            {
                return(RedirectToPageMessage(msgCODE.AGS_UNKNOWN_FILE));
            }

            if (data.pflag == pflagCODE.PROCESSING && ignore_pflag == false)
            {
                return(RedirectToPageMessage(msgCODE.AGS_PROCESSING_FILE));
            }

            if (_agsConfig == null)
            {
                // return NotFound();
                return(Json("agsConfig not found"));
            }

            ags_config config = _agsConfig.Value;

            if (data_structure != null)
            {
                config.data_structure = data_structure;
            }

            if (dictionary_file != null)
            {
                config.dictionary_file = dictionary_file;
            }

            ge_user user = await GetUserAsync();

            var _OperationRequest = await _userService.GetOperationRequest(user.Id, data);

            if (_OperationRequest.AreProjectOperationsAllowed("Download;Create") == false)
            {
                return(View("OperationRequest", _OperationRequest));
            }

            IAGSConvertXMLService _agsConvertXml = new AGSConvertXMLService(_serviceScopeFactory);

            var resp = _agsConvertXml.NewAGSClientAsync(config, Id, user.Id);

            return(Ok($"AGS Processing File {data.filename} ({data.filesize} bytes), the pflag status will remain as 'Processing' until this workflow is complete"));
        }