Example #1
0
        public async Task <ActionResult> GetMessageBoxInstance(int instanceOwnerPartyId, Guid instanceGuid, [FromQuery] string language)
        {
            string[] acceptedLanguages = { "en", "nb", "nn" };
            string   languageId        = "nb";

            if (language != null && acceptedLanguages.Contains(language.ToLower()))
            {
                languageId = language;
            }

            string instanceId = $"{instanceOwnerPartyId}/{instanceGuid}";

            Instance instance = await _instanceRepository.GetOne(instanceId, instanceOwnerPartyId);

            if (instance == null)
            {
                return(NotFound($"Could not find instance {instanceId}"));
            }

            //// TODO: Authorise

            Dictionary <string, Dictionary <string, string> > appTitle = await _applicationRepository.GetAppTitles(new List <string> {
                instance.AppId
            });

            MessageBoxInstance messageBoxInstance = InstanceHelper.ConvertToMessageBoxInstance(new List <Instance> {
                instance
            }, appTitle, languageId).First();

            return(Ok(messageBoxInstance));
        }
Example #2
0
        public async Task <ActionResult> GetMessageBoxInstance(int instanceOwnerId, Guid instanceGuid, [FromQuery] string language)
        {
            string[] acceptedLanguages = new string[] { "en", "nb", "nn-no" };

            string languageId = "nb";

            if (language != null && acceptedLanguages.Contains(language.ToLower()))
            {
                languageId = language;
            }

            string instanceId = instanceOwnerId.ToString() + "/" + instanceGuid.ToString();

            Instance instance = await _instanceRepository.GetOne(instanceId, instanceOwnerId);

            if (instance == null)
            {
                return(NotFound($"Could not find instance {instanceId}"));
            }

            // TODO: authorize

            // Get title from app metadata
            Dictionary <string, Dictionary <string, string> > appTitle = await _applicationRepository.GetAppTitles(new List <string> {
                instance.AppId
            });

            // Simplify instances and return
            MessageBoxInstance messageBoxInstance = InstanceHelper.ConvertToMessageBoxInstance(new List <Instance>()
            {
                instance
            }, appTitle, languageId).First();

            return(Ok(messageBoxInstance));
        }
Example #3
0
            public async void GetMessageBoxInstance_RequestsExistingInstance_InstanceIsSuccessfullyMappedAndReturned()
            {
                // Arrange
                string instanceId             = "1337/6323a337-26e7-4d40-89e8-f5bb3d80be3a";
                string expectedTitle          = "Name change";
                string expectedSubstatusLabel = "Application approved";

                HttpClient client = GetTestClient();

                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetToken(3, 1337, 3));

                // Act
                HttpResponseMessage responseMessage = await client.GetAsync($"{BasePath}/sbl/instances/{instanceId}?language=en");

                // Assert
                Assert.Equal(HttpStatusCode.OK, responseMessage.StatusCode);

                string responseContent = await responseMessage.Content.ReadAsStringAsync();

                MessageBoxInstance actual = JsonConvert.DeserializeObject <MessageBoxInstance>(responseContent);

                Assert.Equal(expectedTitle, actual.Title);
                Assert.True(actual.AllowDelete);
                Assert.True(actual.AuthorizedForWrite);
                Assert.Equal(expectedSubstatusLabel, actual.Substatus.Label);
            }
Example #4
0
        public void OnEventAcquired(object sender, ParserEventArgs args)
        {
            try
            {
                //Update property window anyway
                PropertyGridViewModel.Clear();
                DataViewModel?.Clear();

                if (args == null)
                {
                    throw new NullReferenceException("Invalid arguments passed");
                }

                PropertyGridViewModel.AddData(args.TreeNode?.Properties);

                var argsType = args.ArgsType;

                if ((argsType & MessageType.ProcessAll) != 0)
                {
                    DataViewModel = MarkupManager.Resolve(args.TreeNode?.Markup) ?? new DataGridViewModel();
                    DataViewModel.ProcessNodeData(args.TreeNode);
                }

                DataViewModel?.Refresh();
                PropertyGridViewModel.Refresh();
            }
            catch (Exception ex)
            {
                MessageBoxInstance.Raise(ex.Message);
            }
        }
Example #5
0
        public async Task <ActionResult> GetMessageBoxInstance(int instanceOwnerPartyId, Guid instanceGuid, [FromQuery] string language)
        {
            string[] acceptedLanguages = { "en", "nb", "nn" };
            string   languageId        = "nb";

            if (language != null && acceptedLanguages.Contains(language.ToLower()))
            {
                languageId = language;
            }

            string instanceId = $"{instanceOwnerPartyId}/{instanceGuid}";

            Instance instance = await _instanceRepository.GetOne(instanceId, instanceOwnerPartyId);

            if (instance == null)
            {
                return(NotFound($"Could not find instance {instanceId}"));
            }

            MessageBoxInstance messageBoxInstance = InstanceHelper.ConvertToMessageBoxInstance(instance);

            // Setting these two properties could be handled by custom PEP.
            messageBoxInstance.AllowDelete        = true;
            messageBoxInstance.AuthorizedForWrite = true;

            Dictionary <string, Dictionary <string, string> > appTitle = await _applicationRepository.GetAppTitles(new List <string> {
                instance.AppId
            });

            InstanceHelper.AddTitleToInstances(new List <MessageBoxInstance> {
                messageBoxInstance
            }, appTitle, languageId);

            return(Ok(messageBoxInstance));
        }
Example #6
0
        private void StartExportCommandHandler()
        {
            try
            {
                if (string.IsNullOrEmpty(ExportPath) || CurrentExporter == null || !ExportNodes.Any())
                {
                    throw new NullReferenceException("Bad Export path // no export nodes // no exporter chosen");
                }

                exportTask = Task.Run(() =>
                {
                    var dataList = new List <DataTuple>();
                    foreach (var node in ExportNodes)
                    {
                        dataList.AddRange(GatherExportList(node));
                    }

                    ExportProcess(dataList);
                });
            }
            catch (Exception ex)
            {
                MessageBoxInstance.Raise(ex.Message);
                PLogger.Log(ex.Message);
            }
        }
Example #7
0
        public void ConvertToMessageBoxInstance_TC02()
        {
            // Arrange
            string   lastChangedBy = "20000000";
            Instance instance      = TestData.Instance_1_1;

            // Act
            MessageBoxInstance actual = InstanceHelper.ConvertToMessageBoxInstance(instance);

            // Assert
            Assert.Equal(lastChangedBy, actual.LastChangedBy);
        }
Example #8
0
        private void ExportCommandHandler()
        {
            var exportNodes = TreeViewModel.GatherExportNodes().ToList();

            if (exportNodes.Count == 0)
            {
                MessageBoxInstance?.Raise("There are no export nodes!");
                return;
            }

            ExportViewModel.ExportNodes = exportNodes;
            ExportViewModel.ToggleModalWindow();
        }
        public void ConvertToMessageBoxInstance_TC01()
        {
            // Arrange
            string instanceOwner = "instanceOwner";
            string instanceGuid = "instanceGuid";
            Instance instance = TestData.Instance_1_1;
            instance.Id = $"{instanceOwner}/{instanceGuid}";

            // Act
            MessageBoxInstance actual = InstanceHelper.ConvertToMessageBoxInstance(instance);

            // Assert
            Assert.Equal(instanceGuid, actual.Id);
        }
Example #10
0
        public async Task <ActionResult> GetMessageBoxInstance(
            int instanceOwnerPartyId,
            Guid instanceGuid,
            [FromQuery] string language)
        {
            string[] acceptedLanguages = { "en", "nb", "nn" };
            string   languageId        = "nb";

            if (language != null && acceptedLanguages.Contains(language.ToLower()))
            {
                languageId = language;
            }

            string instanceId = $"{instanceOwnerPartyId}/{instanceGuid}";

            Instance instance = await _instanceRepository.GetOne(instanceId, instanceOwnerPartyId);

            if (instance == null)
            {
                return(NotFound($"Could not find instance {instanceId}"));
            }

            List <MessageBoxInstance> authorizedInstanceList =
                await _authorizationHelper.AuthorizeMesseageBoxInstances(
                    HttpContext.User, new List <Instance> {
                instance
            });

            if (authorizedInstanceList.Count <= 0)
            {
                return(Forbid());
            }

            MessageBoxInstance authorizedInstance = authorizedInstanceList.First();

            // get app texts and exchange all text keys.
            List <TextResource> texts = await _textRepository.Get(new List <string> {
                instance.AppId
            }, languageId);

            InstanceHelper.ReplaceTextKeys(new List <MessageBoxInstance> {
                authorizedInstance
            }, texts, languageId);

            return(Ok(authorizedInstance));
        }
Example #11
0
        private void OpenCommandHandler()
        {
            try
            {
                var path        = FileDialogInstance.Raise();
                var rootStorage = PluginManager?.FetchPlugins(path);

                if (rootStorage == null)
                {
                    PLogger.Log("Storage Ptr is Zero...");
                    return;
                }

                Utilities.RunDispatcherTask(() => { TreeViewModel.AddElementBack(Utilities.FormNodeFromStorage(rootStorage)); });
            }
            catch (Exception ex)
            {
                MessageBoxInstance.Raise(ex.Message);
            }
        }
Example #12
0
        private void ExportProcess(List <DataTuple> data)
        {
            try
            {
                ProgressBarMaximum         = data.Count;
                CurrentExporter.ExportPath = ExportPath;
                CurrentExporter.Init("OutData");

                IsStartButtonEnabled = false;
                IsStopButtonEnabled  = true;
                IsPauseButtonEnabled = true;

                for (var index = 0; index < data.Count; ++index)
                {
                    //check if we need to pause
                    WaitHandle.WaitAny(new WaitHandle[] { pauseEvent, cancelEvent });

                    if (cancelationRequested)
                    {
                        PLogger.Log("Export cancellation requested");
                        cancelationRequested = false;
                        ProgressBarValue     = 0;
                        return;
                    }

                    CurrentExporter.Export(data[index]);
                    ProgressBarValue = index;
                }

                IsStartButtonEnabled = true;
                IsStopButtonEnabled  = false;
                IsPauseButtonEnabled = false;

                ProgressBarValue = 0;
            }
            catch (Exception ex)
            {
                MessageBoxInstance.Raise(ex.Message);
                PLogger.Log(ex.Message);
            }
        }
        public void ConvertToMessageBoxSingleInstance_TC03()
        {
            // Arrange
            string lastChangedBy = TestData.UserId_1;
            Instance instance = TestData.Instance_1_1;
            instance.Data = new List<DataElement>()
            {
                new DataElement()
                {
                    LastChanged = Convert.ToDateTime("2019-08-21T19:19:22.2135489Z"),
                    LastChangedBy = lastChangedBy
                }
            };

            // Act
            MessageBoxInstance actual = InstanceHelper.ConvertToMessageBoxInstance(instance);
            string actualLastChangedBy = actual.LastChangedBy;

            // Assert
            Assert.Equal(lastChangedBy, actualLastChangedBy);            
        }