Ejemplo n.º 1
0
        public async Task <IActionResult> GetFiles(string projectName, Guid?projectId, string changeRequestName, Guid entityId,
                                                   int projectNumber, int changeRequestNumber)
        {
            if (!projectId.HasValue || projectId.Value == Guid.Empty)
            {
                return(BadRequest());
            }

            Result refreshUserToken = await _mediatorFactory.Execute(new RefreshCurrentUserTokenCommand()
            {
                ExternalProvider = ExternalProviders.OneDrive
            });

            var dto = new OneDriveTabDto()
            {
                ExternalProvider = ExternalProviders.OneDrive,
                Paths            = new List <string>
                {
                    "drive/special/approot:/PM/" + "Projects/" + projectName + projectId.Value + "/"
                    + "Requests/" + (changeRequestName?.ReplaceSpecialCharacters('_') ?? string.Empty) + entityId,
                    "drive/special/approot:/PM/" + "Projects/" + $"P{projectNumber.ToString().PadLeft(8, '0')}" + "/"
                    + "Requests/" + $"R{changeRequestNumber.ToString().PadLeft(8, '0')}"
                },
                FolderName = "   "
            };

            if (refreshUserToken.IsSuccess)
            {
                var model = new OneDriveListViewModel()
                {
                    Paths      = dto.Paths,
                    FolderName = dto.FolderName,
                    MetaData   = new List <CloudMetaData>()
                };

                try
                {
                    foreach (var path in model.Paths)
                    {
                        model.MetaData.AddRange(await Mediator.Send(new GetChildrenQuery()
                        {
                            ExternalProvider = dto.ExternalProvider, FilePath = path
                        }));
                    }
                }
                catch (Exception e)
                {
                    throw new InvalidOperationException("Catch this: " + e.Message);
                }

                ViewBag.Name = "Projects/" + projectName + projectId.Value + "/Requests/" +
                               (changeRequestName?.ReplaceSpecialCharacters('_') ?? string.Empty) + entityId;
                return(PartialView("_OneDriveFilesForChangeRequest", model));
            }

            throw new InvalidOperationException("Catch this: ");
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetFiles(string name, Guid?id)
        {
            if (!id.HasValue || id.Value == Guid.Empty)
            {
                return(BadRequest());
            }

            Result refreshUserToken = await _mediatorFactory.Execute(new RefreshCurrentUserTokenCommand()
            {
                ExternalProvider = ExternalProviders.OneDrive
            });

            var dto = new OneDriveTabDto()
            {
                ExternalProvider = ExternalProviders.OneDrive,
                Paths            = new List <string>
                {
                    "drive/special/approot:/PM/" + "Projects/" + name + id.Value
                },
                FolderName = "   "
            };

            if (refreshUserToken.IsSuccess)
            {
                var model = new OneDriveListViewModel()
                {
                    Paths      = dto.Paths,
                    FolderName = dto.FolderName,
                    MetaData   = new List <CloudMetaData>()
                };

                try
                {
                    foreach (var path in model.Paths)
                    {
                        model.MetaData.AddRange(await Mediator.Send(new GetChildrenQuery()
                        {
                            ExternalProvider = dto.ExternalProvider, FilePath = path
                        }));
                    }
                }
                catch (Exception e)
                {
                    throw new InvalidOperationException("Catch this: " + e.Message);
                }

                ViewBag.Name = "Projects/" + name;
                return(PartialView("_OneDriveTab", model));
            }

            throw new InvalidOperationException("Catch this: ");
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> GetFiles(string projectName, Guid?projectId, string activityName, Guid?activityId, Guid?changeRequestId, int projectNumber, int activityNumber)
        {
            if (!projectId.HasValue || projectId.Value == Guid.Empty || !activityId.HasValue ||
                activityId.Value == Guid.Empty)
            {
                return(BadRequest());
            }

            Result refreshUserToken = await _mediatorFactory.Execute(new RefreshCurrentUserTokenCommand()
            {
                ExternalProvider = ExternalProviders.OneDrive
            });

            var dto = new OneDriveTabDto()
            {
                ExternalProvider = ExternalProviders.OneDrive,
                Paths            = new List <string>
                {
                    "drive/special/approot:/PM/" + "Projects/" + projectName + projectId.Value + "/"
                    + "Activities/" + activityName + activityId.Value,
                    "drive/special/approot:/PM/" + "Projects/" + $"P{projectNumber.ToString().PadLeft(8, '0')}" + "/"
                    + "Activities/" + $"A{activityNumber.ToString().PadLeft(8, '0')}"
                },
                FolderName = "   "
            };

            if (refreshUserToken.IsSuccess)
            {
                var model = new OneDriveListViewModel()
                {
                    Paths      = dto.Paths,
                    FolderName = dto.FolderName,
                    MetaData   = new List <CloudMetaData>()
                };

                try
                {
                    model.MetaData = new List <CloudMetaData>();

                    if (changeRequestId.HasValue && changeRequestId != Guid.Empty)
                    {
                        var requestName = Mediator.Send(new GetRequestNameQuery {
                            Id = changeRequestId.Value
                        }).Result;
                        dto.Paths.Add("drive/special/approot:/PM/" + "Projects/" + projectName + projectId.Value + "/"
                                      + "Requests/" + requestName + changeRequestId.Value);

                        var changeRequest = await Mediator.Send(new GetChangeRequestDetailsQuery { Id = changeRequestId.Value });

                        dto.Paths.Add("drive/special/approot:/PM/" + "Projects/" + $"P{projectNumber.ToString().PadLeft(8, '0')}/" + "Requests/" + $"R{changeRequest.Number.ToString().PadLeft(8, '0')}");
                    }

                    foreach (var path in dto.Paths)
                    {
                        model.MetaData.AddRange(await Mediator.Send(new GetChildrenQuery()
                        {
                            ExternalProvider = dto.ExternalProvider, FilePath = path
                        }));
                    }
                }
                catch (Exception e)
                {
                    throw new InvalidOperationException("Catch this: " + e.Message);
                }

                ViewBag.Name = "Projects/" + projectName + "/Activities/" + activityName;
                return(PartialView("_OneDriveFilesForActivity", model));
            }

            throw new InvalidOperationException("Catch this: ");
        }