Ejemplo n.º 1
0
        public void ArchiveServiceModel <T>(T dataToSerialize, int instanceId, Type type, string org, string service, string edition, int partyId)
        {
            string archiveDirectory = _settings.GetEditionPath(org, service, edition, 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);
            }
        }
Ejemplo n.º 2
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="edition">The edition 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, string edition, int partyId)
        {
            string formDataFilePath = _settings.GetEditionPath(org, service, edition, 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));
            }
        }
Ejemplo n.º 3
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>
        /// <param name="edition">The edition code for the current service</param>
        /// <returns>The service instance list</returns>
        public List <ServiceInstance> GetFormInstances(int partyId, string org, string service, string edition)
        {
            List <ServiceInstance> formInstances = new List <ServiceInstance>();
            string formDataFilePath  = _settings.GetEditionPath(org, service, edition, 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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Read all source documents for a given service and put it in a syntax tree array.
        /// </summary>
        /// <param name="org">The Organization code for the service owner</param>
        /// <param name="service">The service code for the current service</param>
        /// <param name="edition">The edition code for the current service</param>
        /// <returns>The syntax tree</returns>
        private SyntaxTree[] GetSyntaxTrees(string org, string service, string edition)
        {
            List <SyntaxTree> syntaxTrees = new List <SyntaxTree>();
            string            dir         = _settings.GetEditionPath(org, service, edition, 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());
        }