Exemplo n.º 1
0
        public ServiceConfiguration GetServiceConfig(string org, string service)
        {
            string serviceConfigPath = _settings.GetServicePath(org, service, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext)) + _settings.ServiceConfigFileName;
            ServiceConfiguration serviceConfigurationObject = null;

            if (System.IO.File.Exists(serviceConfigPath))
            {
                string serviceConfiguration = System.IO.File.ReadAllText(serviceConfigPath, Encoding.UTF8);
                serviceConfigurationObject = JsonConvert.DeserializeObject <ServiceConfiguration>(serviceConfiguration);
            }

            return(serviceConfigurationObject);
        }
Exemplo n.º 2
0
        public ServiceConfiguration GetServiceConfig(string org, string app)
        {
            string serviceConfigPath = _settings.GetServicePath(org, app, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext)) + _settings.ServiceConfigFileName;
            ServiceConfiguration serviceConfigurationObject = null;
            var watch = System.Diagnostics.Stopwatch.StartNew();

            if (System.IO.File.Exists(serviceConfigPath))
            {
                string serviceConfiguration = System.IO.File.ReadAllText(serviceConfigPath, Encoding.UTF8);
                serviceConfigurationObject = JsonConvert.DeserializeObject <ServiceConfiguration>(serviceConfiguration);
            }

            watch.Stop();
            _logger.Log(LogLevel.Information, "Getserviceconfig - {0} ", watch.ElapsedMilliseconds);
            return(serviceConfigurationObject);
        }
Exemplo n.º 3
0
        public void ArchiveServiceModel <T>(T dataToSerialize, int instanceId, Type type, string org, string service, int partyId)
        {
            string archiveDirectory = _settings.GetServicePath(org, service, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext)) + "Testdataforparty/" + partyId + "/Archive/";

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

            string formDataFilePath = archiveDirectory + instanceId + ".xml";

            using (Stream stream = File.Open(formDataFilePath, FileMode.Create, FileAccess.ReadWrite))
            {
                XmlSerializer serializer = new XmlSerializer(type);
                serializer.Serialize(stream, dataToSerialize);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Method that creates the form model object based on serialized data on disk.
        /// </summary>
        /// <param name="formID">The formId</param>
        /// <param name="type">The type that form data will be serialized to</param>
        /// <param name="org">The Organization code for the service owner</param>
        /// <param name="service">The service code for the current service</param>
        /// <param name="partyId">The partyId used to find the party on disc</param>
        /// <returns>The deserialized form model</returns>
        public object GetFormModel(int formID, Type type, string org, string service, int partyId)
        {
            string formDataFilePath = _settings.GetServicePath(org, service, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext)) + "Testdataforparty/" + partyId + "/" + formID + ".xml";

            XmlSerializer serializer = new XmlSerializer(type);

            try
            {
                using (Stream stream = File.Open(formDataFilePath, FileMode.Open, FileAccess.Read))
                {
                    return(serializer.Deserialize(stream));
                }
            }
            catch
            {
                return(Activator.CreateInstance(type));
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Verifies if developer has a local repo
        /// </summary>
        /// <param name="org"></param>
        /// <param name="service"></param>
        /// <returns></returns>
        public bool IsLocalRepo(string org, string service)
        {
            string localServiceRepoFolder = _settings.GetServicePath(org, service, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext));

            if (Directory.Exists(localServiceRepoFolder))
            {
                try
                {
                    using (Repository repo = new Repository(localServiceRepoFolder))
                    {
                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    return(false);
                }
            }

            return(false);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Method that fetches the users repo, zips it and returns the zip file.
        /// </summary>
        /// <param name="org">The organization for the service.</param>
        /// <param name="service">The name of the service.</param>
        /// <param name="developer">The current developer.</param>
        /// <returns>The zipped file.</returns>
        public FileStream ZipAndReturnFile(string org, string service, string developer)
        {
            CheckAndUpdateWorkflowFile(org, service, developer);
            string startPath = _settings.GetServicePath(org, service, developer);
            string zipPath   = $"{_settings.GetOrgPath(org, developer)}{service}.zip";

            if (File.Exists(zipPath))
            {
                File.Delete(zipPath);
            }

            ZipFile.CreateFromDirectory(startPath, zipPath);
            return(File.Open(zipPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a list of form instances stored on disk for a given partyId and serviceId
        /// </summary>
        /// <param name="partyId">The partyId</param>
        /// <param name="org">The Organization code for the service owner</param>
        /// <param name="service">The service code for the current service</param>
        /// <returns>The service instance list</returns>
        public List <ServiceInstance> GetFormInstances(int partyId, string org, string service)
        {
            List <ServiceInstance> formInstances = new List <ServiceInstance>();
            string formDataFilePath  = _settings.GetServicePath(org, service, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext)) + "Testdataforparty/" + partyId;
            string archiveFolderPath = formDataFilePath + "/Archive/";

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

            string[] files = Directory.GetFiles(formDataFilePath);

            foreach (string file in files)
            {
                if (int.TryParse(Path.GetFileNameWithoutExtension(file), out int instanceId))
                {
                    ServiceInstance serviceInstance = new ServiceInstance()
                    {
                        ServiceInstanceID = instanceId,
                        LastChanged       = File.GetLastWriteTime(file)
                    };

                    string archiveFilePath = archiveFolderPath + "/" + serviceInstance.ServiceInstanceID + ".xml";

                    if (File.Exists(archiveFilePath))
                    {
                        serviceInstance.LastChanged = File.GetLastWriteTime(archiveFilePath);
                        serviceInstance.IsArchived  = true;
                    }

                    formInstances.Add(serviceInstance);
                }
            }

            return(formInstances);
        }
Exemplo n.º 8
0
        private bool IsLocalRepo(string org, string app)
        {
            string localAppRepoFolder = _settings.GetServicePath(org, app, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext));

            if (Directory.Exists(localAppRepoFolder))
            {
                try
                {
                    using (LibGit2Sharp.Repository repo = new LibGit2Sharp.Repository(localAppRepoFolder))
                    {
                        return(true);
                    }
                }
                catch (Exception)
                {
                    return(false);
                }
            }

            return(false);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Read all source code for a given app and put it in a syntax tree array.
        /// </summary>
        /// <param name="org">Unique identifier of the organisation responsible for the app.</param>
        /// <param name="app">Application identifier which is unique within an organisation.</param>
        /// <returns>The syntax tree.</returns>
        private SyntaxTree[] GetSyntaxTrees(string org, string app)
        {
            List <SyntaxTree> syntaxTrees = new List <SyntaxTree>();
            string            dir         = _settings.GetServicePath(org, app, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext));
            var ext = new List <string> {
                ".cs"
            };
            var codeFiles = Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories)
                            .Where(s => ext.Any(e => s.EndsWith(e)));

            foreach (string filePath in codeFiles)
            {
                using (var stream = File.OpenRead(filePath))
                {
                    SourceText text = SourceText.From(stream, Encoding.UTF8);
                    SyntaxTree tree = CSharpSyntaxTree.ParseText(text, null, filePath);
                    syntaxTrees.Add(tree);
                }
            }

            return(syntaxTrees.ToArray());
        }
        public async Task <IActionResult> Index(string org, string service, int reporteeId)
        {
            var    developer = AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext);
            string apiUrl    = _settings.GetRuntimeAPIPath("ZipAndSendRepo", org, service, developer);

            using (HttpClient client = AuthenticationHelper.GetDesignerHttpClient(_httpContextAccessor.HttpContext, _testdataRepositorySettings.GetDesignerHost()))
            {
                client.BaseAddress = new Uri(apiUrl);
                HttpResponseMessage response = await client.GetAsync(apiUrl);

                string zipPath     = $"{_settings.GetServicePath(org, service, developer)}{service}.zip";
                string extractPath = _settings.GetServicePath(org, service, developer);
                if (!Directory.Exists(extractPath))
                {
                    Directory.CreateDirectory(extractPath);
                }
                else
                {
                    Directory.Delete(extractPath, true);
                    Directory.CreateDirectory(extractPath);
                }

                using (Stream s = response.Content.ReadAsStreamAsync().Result)
                {
                    using (var w = System.IO.File.OpenWrite(zipPath))
                    {
                        s.CopyTo(w);
                    }
                }

                ZipFile.ExtractToDirectory(zipPath, extractPath);
            }

            RequestContext requestContext = RequestHelper.GetRequestContext(Request.Query, 0);

            requestContext.UserContext = _userHelper.GetUserContext(HttpContext);
            requestContext.Reportee    = requestContext.UserContext.Reportee;

            var startServiceModel = new StartServiceModel
            {
                ServiceID    = org + "_" + service,
                ReporteeList = _authorization.GetReporteeList(requestContext.UserContext.UserId)
                               .Select(x => new SelectListItem {
                    Text = x.ReporteeNumber + " " + x.ReporteeName, Value = x.PartyID.ToString()
                })
                               .ToList(),
                PrefillList = _testdata.GetServicePrefill(requestContext.Reportee.PartyId, org, service)
                              .Select(x => new SelectListItem {
                    Text = x.PrefillKey + " " + x.LastChanged, Value = x.PrefillKey
                })
                              .ToList(),
                ReporteeID = requestContext.Reportee.PartyId,
                Org        = org,
                Service    = service,
            };

            if (reporteeId != 0 && reporteeId != startServiceModel.ReporteeID && startServiceModel.ReporteeList.Any(r => r.Value.Equals(reporteeId.ToString())))
            {
                startServiceModel.ReporteeID          = reporteeId;
                requestContext.Reportee               = _register.GetParty(startServiceModel.ReporteeID);
                requestContext.UserContext.ReporteeId = reporteeId;
                requestContext.UserContext.Reportee   = requestContext.Reportee;
                HttpContext.Response.Cookies.Append("altinncorereportee", startServiceModel.ReporteeID.ToString());
            }

            List <ServiceInstance> formInstances = _testdata.GetFormInstances(requestContext.Reportee.PartyId, org, service, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext));

            ViewBag.InstanceList = formInstances.OrderBy(r => r.LastChanged).ToList();

            return(View(startServiceModel));
        }