Пример #1
0
        public bool Import(string submission, string user, string project)
        {
            var  projectFilename = string.Format(@"{0}_{1}", submission, project);
            bool success         = XmlUserData.Import(projectFilename, user, "OgdTool");

            if (!success)
            {
                return(false);
            }

            // Copy output folder
            var userNameDest = Users.GetCurrentUserName();

            user = Users.LongUserToShort(user);

            var sourcePath = string.Format(@"\\{0}\Output Files\OgdTool\{1}\{2}\{3}",
                                           iPortalApp.AppServerName, user, submission, project);
            var destPath = string.Format(@"\\{0}\Output Files\OgdTool\{1}\{2}\{3}",
                                         iPortalApp.AppServerName, userNameDest, submission, project);

            if (Directory.Exists(sourcePath))
            {
                DirectoryTools.DirectoryCopy(sourcePath, destPath, true, true);
            }

            // Copy ouptut package if it exists
            FileInfo pkgFile = new FileInfo(sourcePath + ".zip");

            if (pkgFile.Exists)
            {
                pkgFile.CopyTo(destPath + ".zip", true);
            }

            return(true);
        }
Пример #2
0
        public void Save([FromBody] Project project)
        {
            var projectFilename = string.Format(@"{0}{1}_{2}",
                                                project.SubmissionType, project.SubmissionNumber, project.ProjectName);

            XmlUserData.Save <Project>(project, projectFilename, "OgdTool");
        }
        /// <summary>
        /// Create a project in the repository
        /// </summary>
        /// <param name="project">project to add to the repository</param>
        /// <param name="userName">project owner, defaults to current user</param>
        public bool CreateOrUpdate(Project project, string userName = null)
        {
            string xmlFilename = String.Format("{0}_{1}", project.SubmissionId, project.ProjectName ?? "");

            XmlUserData.Save <Project>(project, xmlFilename, "PkView", userName);
            return(true);
        }
        /// <summary>
        /// Retrieve list of projects for a given user
        /// </summary>
        /// <param name="submission">Name of the selected submission</param>
        /// <param name="userName">Name of the user excluding the domain</param>
        /// <returns>A list of analysis profiles</returns>
        private IEnumerable <string> getUserProjects(string submission, string userName)
        {
            var configFiles = XmlUserData.FindFiles(submission + "_*", "PkView", userName)
                              .OrderBy(f => f.LastWriteTime).Reverse()
                              .Select(f => f.Name.Substring(f.Name.IndexOf("_") + 1,
                                                            f.Name.LastIndexOf('.') - f.Name.IndexOf("_") - 1));

            return(configFiles);
        }
        /// <summary>
        /// Return a list of projects for the specified user and submission
        /// </summary>
        /// <param name="submissionId">Submission id</param>
        /// <param name="userName">optional, project owner</param>
        /// <returns></returns>
        public IEnumerable <string> List(string submissionId, string userName = null)
        {
            var projects = XmlUserData.FindFiles(submissionId + "_*", "PkView", userName)
                           .OrderBy(f => f.LastWriteTime).Reverse()
                           .Select(f => f.Name.Substring(f.Name.IndexOf("_") + 1,
                                                         f.Name.LastIndexOf('.') - f.Name.IndexOf("_") - 1));

            return(projects);
        }
Пример #6
0
 // Retrieve the user/role data from the XML file.
 private void ReadXmlDataStore()
 {
     // Lock the provider while the data is retrieved.
     lock (this)
     {
         try
         {
             // Test if the dictionary already has data.
             if (_XmlUserData.Count == 0)
             {
                 // Create an XML document object and load the data XML file
                 XPathDocument xmlDocument = new XPathDocument(_xmlFileName);
                 // Create a navigator object to navigate through the XML file.
                 XPathNavigator xmlNavigator = xmlDocument.CreateNavigator();
                 // Loop through the users in the XML file.
                 foreach (XPathNavigator node in xmlNavigator.Select("/Users/User"))
                 {
                     // Retrieve a user name.
                     string userName = GetInnerText(node, "UserName");
                     // Retrieve the user's password.
                     string password = GetInnerText(node, "Password");
                     // Test if the data is empty.
                     if ((String.IsNullOrEmpty(userName) == false) && (String.IsNullOrEmpty(password) == false))
                     {
                         // Retrieve the user's roles.
                         string xmlRoles = GetInnerText(node, "Roles");
                         // Create a string array for the user roles.
                         string[] userRoles = new string[0];
                         // Test if the user has any roles defined.
                         if (String.IsNullOrEmpty(xmlRoles) == false)
                         {
                             // Split the roles by comma.
                             userRoles = xmlRoles.Split(',');
                         }
                         // Create a user data class.
                         XmlUserData userData = new XmlUserData(password, userRoles);
                         // Store the user data in the dictionary.
                         _XmlUserData.Add(userName, userData);
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             // Raise an exception if an error occurs.
             throw new ProviderException(ex.Message);
         }
     }
 }
Пример #7
0
        public IEnumerator LoadWebSettings()
        {
            var www = new WWW(Application.dataPath + @"/settings.xml");

            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                Debug.LogError(www.error);
            }
            else
            {
                CoreContext.Settings = XmlSettings.Create(www.text);
                CoreContext.UserData = XmlUserData.Create();
            }
        }
Пример #8
0
        public List <User> Get()
        {
            using (var context = new PrincipalContext(ContextType.Domain, "localhost"))
            {
                var users = XmlUserData.GetUsers(context);

                if (users != null)
                {
                    return(users.Select(u => new User
                    {
                        UserName = u.Name,
                        DisplayName = String.Format("{0}, {1}{2}", u.Surname, u.GivenName,
                                                    u.Name.StartsWith("AD_APP_") ? " (admin)" : "")
                    }).ToList());
                }
            }
            return(null);
        }
Пример #9
0
        private void Initialize()
        {
#if UNITY_WEBPLAYER && !UNITY_EDITOR
            StartCoroutine(LoadWebSettings());
#else
            CoreContext.Settings = XmlSettings.Create();

            CoreContext.UserData = XmlUserData.Create();

            XmlUserData.UpdateSubGameBaseInfoList(CoreContext.Settings.SubGameBaseInfoList);
#endif
            CoreContext.AudioController = new Core.Model.Audio.AudioController();
            if (!CoreContext.AudioController.LoadSnapshot(CoreContext.UserData.Common.AudioControllerSnapshot))
            {
                CoreContext.AudioController.LoadSnapshot(CoreContext.Settings.DefaultAudioControllerSnapshot);
            }

            Application.LoadLevelAdditive(CoreContext.Settings.GameSceneArray.StartSceneName);
        }
        public List <SubmissionProjectsListItem> List(string submission)
        {
            var userName = Users.GetCurrentUserName();

            using (var context = new PrincipalContext(ContextType.Domain, "localhost"))
            {
                var users = XmlUserData.GetUsers(context);
                if (users == null)
                {
                    return(null);
                }

                return(users.SelectMany(u =>
                {
                    // Do not return profiles for the current user
                    if (userName.Equals(u.Name, StringComparison.InvariantCultureIgnoreCase))
                    {
                        return new SubmissionProjectsListItem[] { }
                    }
                    ;

                    // Do not return a user without profiles
                    var projects = this.getUserProjects(submission, u.Name);
                    if (projects == null || !projects.Any())
                    {
                        return new SubmissionProjectsListItem[] { }
                    }
                    ;

                    // return the list of profiles for the user
                    return new[] { new SubmissionProjectsListItem
                                   {
                                       User = u.Name,
                                       DisplayUser = String.Format("{0}, {1}{2}", u.Surname, u.GivenName,
                                                                   u.Name.StartsWith("AD_APP_") ? " (admin)" : ""),
                                       Projects = projects
                                   } };
                }).ToList());
            }
        }
        public List <UserProjectsListItem> List()
        {
            string outputPath = new DownloadController().GetRepositoryPath("PkView");
            IEnumerable <string> userProjects = XmlUserData.Find("*", "PkView");
            var splitProjects = userProjects.Select(p => {
                var i           = p.IndexOf('_');
                var submission  = p.Substring(0, i);
                var projectName = p.Substring(i + 1);
                return(new { submission, projectName });
            });

            return(splitProjects.GroupBy(p => p.submission, (s, l) =>
                                         new UserProjectsListItem
            {
                Submission = s,
                Projects = l.Select(pro => new ProjectMetadata {
                    Name = pro.projectName,
                    HasPackage = File.Exists(
                        Path.Combine(outputPath, pro.projectName, pro.submission + ".zip"))
                }).ToList()
            }).ToList());
        }
Пример #12
0
        public bool Delete(string submission, string project)
        {
            var projectFilename = string.Format(@"{0}_{1}", submission, project);
            var userName        = Users.GetCurrentUserName();

            // Delete output files
            var outputPath = string.Format(@"\\{0}\Output Files\OgdTool\{1}\{2}\{3}",
                                           iPortalApp.AppServerName, userName, submission, project);

            if (Directory.Exists(outputPath))
            {
                Directory.Delete(outputPath, true);
            }

            // Delete output package if present
            if (File.Exists(outputPath + ".zip"))
            {
                File.Delete(outputPath + ".zip");
            }

            // Delete config file
            return(XmlUserData.Delete(projectFilename, "OgdTool"));
        }
        /// <summary>
        /// Remove a project from the repository
        /// </summary>
        /// <param name="submissionId">Parent submission for the project</param>
        /// <param name="projectName">Project name</param>
        /// <param name="userName">user the project belongs to, defaults to current user</param>
        /// <returns></returns>
        public bool Remove(string submissionId, string projectName, string userName = null)
        {
            // Use current user if not specified
            userName = userName ?? Users.GetCurrentUserName();

            // Delete output files
            var outputPath = string.Format(@"\\{0}\Output Files\PkView\{1}\{2}\{3}",
                                           iPortalApp.AppServerName, userName, projectName, submissionId);

            if (Directory.Exists(outputPath))
            {
                Directory.Delete(outputPath, true);
            }

            // Delete output package if present
            if (File.Exists(outputPath + ".zip"))
            {
                File.Delete(outputPath + ".zip");
            }

            string xmlFilename = String.Format("{0}_{1}", submissionId, projectName ?? "");

            return(XmlUserData.Delete(xmlFilename, "PkView", userName));
        }
Пример #14
0
        public Project Load(string submission, string project)
        {
            var projectFilename = string.Format(@"{0}_{1}", submission, project);

            return(XmlUserData.Load <Project>(projectFilename, "OgdTool"));
        }
        /// <summary>
        /// Copy the project to the target user and set it as shared by the source user
        /// </summary>
        /// <param name="project"></param>
        /// <param name="sourceUserName"></param>
        /// <param name="targetUserName"></param>
        /// <returns></returns>
        private bool copyProject(Project project, string sourceUserName, string targetUserName)
        {
            string sourceProjectName = project.ProjectName;
            string submissionId      = project.SubmissionId;

            // Create share revision
            var revision = new ProjectRevision
            {
                RevisionId = project.RevisionHistory.Last().RevisionId + 1,
                Name       = sourceProjectName,
                Date       = DateTime.Now,
                Owner      = sourceUserName,
                Action     = ActionTypes.Share
            };

            project.RevisionHistory.Add(revision);

            // Fix name collisions
            var    targetProjectName = sourceProjectName;
            string xmlFilename       = String.Format("{0}_{1}", submissionId, sourceProjectName ?? "");

            if (XmlUserData.Exists(xmlFilename, "PkView", targetUserName))
            {
                // Add a project rename entry by the destination user
                var renameRevision = new ProjectRevision
                {
                    RevisionId = project.RevisionHistory.Last().RevisionId + 1,
                    Date       = DateTime.Now,
                    Owner      = targetUserName,
                    Action     = ActionTypes.Rename
                };
                project.RevisionHistory.Add(renameRevision);

                // Add an incremental numeric suffix while a collision is found
                int i = 1;
                do
                {
                    renameRevision.Name = string.Format("{0} ({1})", sourceProjectName, i++);
                    xmlFilename         = String.Format("{0}_{1}", submissionId, renameRevision.Name ?? "");
                } while (XmlUserData.Exists(xmlFilename, "PkView", targetUserName));
                targetProjectName   = renameRevision.Name;
                project.ProjectName = targetProjectName;

                // also change the project name of individual studies
                project.Studies.ForEach(s => { s.ProfileName = targetProjectName; });
            }

            // Save the project for the target user
            this.CreateOrUpdate(project, targetUserName);

            // Output paths
            var sourcePath = string.Format(@"\\{0}\Output Files\PkView\{1}\{2}\{3}",
                                           iPortalApp.AppServerName, sourceUserName, sourceProjectName, submissionId);
            var targetPath = string.Format(@"\\{0}\Output Files\PkView\{1}\{2}\{3}",
                                           iPortalApp.AppServerName, targetUserName, targetProjectName, submissionId);

            // Copy each study
            foreach (var study in project.Studies)
            {
                var sourceStudyPath = Path.Combine(sourcePath, study.SupplementNumber, study.StudyCode);
                var targetStudyPath = Path.Combine(targetPath, study.SupplementNumber, study.StudyCode);

                if (Directory.Exists(sourceStudyPath))
                {
                    DirectoryTools.DirectoryCopy(sourceStudyPath, targetStudyPath, true, true);
                }
            }

            return(true);
        }
        /// <summary>
        /// Find a project in the repository
        /// </summary>
        /// <param name="submissionId">Parent submission for the project</param>
        /// <param name="projectName">Project name</param>
        /// <param name="userName">user the project belongs to, defaults to current user</param>
        /// <returns></returns>
        public Project Find(string submissionId, string projectName, string userName = null, ProjectRetrievalFlags flags = 0)
        {
            string xmlFilename = String.Format("{0}_{1}", submissionId, projectName ?? "");

            if (XmlUserData.Exists(xmlFilename, "PkView", userName))
            {
                Project project;
                try
                {
                    project = XmlUserData.Load <Project>(xmlFilename, "PkView", userName);
                }
                catch
                { // Load legacy format
                    project         = new Project();
                    project.Studies = XmlUserData.Load <List <StudySettings> >(xmlFilename, "PkView", userName);
                    if (project.Studies == null || project.Studies.Count == 0)
                    {
                        return(null);
                    }
                    project.SubmissionId = submissionId;
                    project.ProjectName  = projectName;
                    userName             = userName ?? Users.GetCurrentUserName();

                    // Initialize revision history
                    project.RevisionHistory = new List <ProjectRevision>();
                    var revision = new ProjectRevision
                    {
                        RevisionId = 1,
                        Name       = projectName,
                        Owner      = userName,
                        Date       = DateTime.Now,
                        Action     = ActionTypes.Create
                    };
                    project.RevisionHistory.Add(revision);
                    project.Studies.ForEach(s => s.RevisionId = 1);
                    XmlUserData.Save <Project>(project, xmlFilename, "PkView", userName);
                }

                // Return if project is empty or null
                if (project == null || project.Studies == null || !project.Studies.Any())
                {
                    return(project);
                }

                // Trim data based on project retrieval flags
                switch (flags)
                {
                // Clear mean data
                case ProjectRetrievalFlags.MeanDataOnly:
                    foreach (var study in project.Studies)
                    {
                        if (study.Concentration != null && study.Concentration.Sections != null)
                        {
                            study.Concentration.Sections.ForEach(s => s.SubSections = null);
                        }
                        if (study.Pharmacokinetics != null && study.Pharmacokinetics.Sections != null)
                        {
                            study.Pharmacokinetics.Sections.ForEach(s => s.SubSections = null);
                        }
                    }
                    break;

                // Clear everything but metadata
                case ProjectRetrievalFlags.MetaDataOnly:
                    foreach (var study in project.Studies)
                    {
                        study.StudyMappings    = null;
                        study.ArmMappings      = null;
                        study.Concentration    = null;
                        study.Pharmacokinetics = null;
                        study.Analytes         = null;
                        study.Parameters       = null;
                        study.Reports          = null;
                    }
                    break;
                }

                return(project);
            }
            return(null);
        }
        /// <summary>
        /// Import a project from the source user
        /// </summary>
        /// <param name="submissionId">Parent submission for the project</param>
        /// <param name="projectName">Project name</param>
        /// <param name="sourceUserName">user the project belongs to</param>
        /// <returns></returns>
        public bool Import(string submissionId, string projectName, string sourceUserName)
        {
            // Find the source project
            var project = this.Find(submissionId, projectName, sourceUserName);

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

            // destination username
            var targetUserName = Users.GetCurrentUserName();

            // Create share revision
            var revision = new ProjectRevision
            {
                RevisionId = project.RevisionHistory.Last().RevisionId + 1,
                Name       = projectName,
                Date       = DateTime.Now,
                Owner      = sourceUserName,
                Action     = ActionTypes.Import
            };

            project.RevisionHistory.Add(revision);

            // Fix name collisions
            var    targetProjectName = projectName;
            string xmlFilename       = String.Format("{0}_{1}", submissionId, projectName ?? "");

            if (XmlUserData.Exists(xmlFilename, "PkView", targetUserName))
            {
                // Add a project rename entry by the destination user
                var renameRevision = new ProjectRevision
                {
                    RevisionId = project.RevisionHistory.Last().RevisionId + 1,
                    Date       = DateTime.Now,
                    Owner      = targetUserName,
                    Action     = ActionTypes.Rename
                };
                project.RevisionHistory.Add(renameRevision);

                // Add an incremental numeric suffix while a collision is found
                int i = 1;
                do
                {
                    renameRevision.Name = string.Format("{0} ({1})", projectName, i++);
                    xmlFilename         = String.Format("{0}_{1}", submissionId, renameRevision.Name ?? "");
                } while (XmlUserData.Exists(xmlFilename, "PkView", targetUserName));
                targetProjectName   = renameRevision.Name;
                project.ProjectName = targetProjectName;

                // also change the project name of individual studies
                project.Studies.ForEach(s => { s.ProfileName = targetProjectName; });
            }

            // Save the project for the target user
            this.CreateOrUpdate(project, targetUserName);

            // Copy output folder
            var sourcePath = string.Format(@"\\{0}\Output Files\PkView\{1}\{2}\{3}",
                                           iPortalApp.AppServerName, sourceUserName, projectName, submissionId);
            var destPath = string.Format(@"\\{0}\Output Files\PkView\{1}\{2}\{3}",
                                         iPortalApp.AppServerName, targetUserName, targetProjectName, submissionId);

            if (Directory.Exists(sourcePath))
            {
                DirectoryTools.DirectoryCopy(sourcePath, destPath, true, true);
            }

            // Copy ouptut package if it exists
            FileInfo pkgFile = new FileInfo(sourcePath + ".zip");

            if (pkgFile.Exists)
            {
                pkgFile.CopyTo(destPath + ".zip", true);
            }

            return(true);
        }
Пример #18
0
    // Retrieve the user/role data from the XML file.
    private void ReadXmlDataStore()
    {
        // Lock the provider while the data is retrieved.
        lock (this)
        {
            try
            {
                // Test if the dictionary already has data.
                if (_XmlUserData.Count == 0)
                {
                    // Create an XML document object and load the data XML file
                    XPathDocument xmlDocument = new XPathDocument(_xmlFileName);
                    // Create a navigator object to navigate through the XML file.
                    XPathNavigator xmlNavigator = xmlDocument.CreateNavigator();
                    // Loop through the users in the XML file.
                    foreach (XPathNavigator node in xmlNavigator.Select("/Users/User"))
                    {
                        // Retrieve a user name.
                        string userName = GetInnerText(node, "UserName");
                        // Retrieve the user's password.
                        string password = GetInnerText(node, "Password");
                        // Test if the data is empty.
                        if ((String.IsNullOrEmpty(userName) == false) && (String.IsNullOrEmpty(password) == false))
                        {
                            // Retrieve the user's roles.
                            string xmlRoles = GetInnerText(node, "Roles");
                            // Create a string array for the user roles.
                            string[] userRoles = new string[0];
                            // Test if the user has any roles defined.
                            if (String.IsNullOrEmpty(xmlRoles) == false)
                            {
                                // Split the roles by comma.
                                userRoles = xmlRoles.Split(',');
                            }
                            // Create a dictionary to hold the user's authorization rules.
                            Dictionary <string, FtpAccess> userRules =
                                new Dictionary <string, FtpAccess>(
                                    StringComparer.InvariantCultureIgnoreCase);
                            // Loop through the set of authorization rules for the user.
                            foreach (XPathNavigator rule in node.Select("Rules/Rule"))
                            {
                                // Retrieve the URL path for the authorization rule.
                                string xmlPath = rule.GetAttribute("path", string.Empty);
                                // Strip trailing slashes from paths.
                                if (xmlPath.EndsWith("/") && xmlPath.Length > 1)
                                {
                                    xmlPath = xmlPath.Substring(0, xmlPath.Length - 1);
                                }
                                // Retrieve the user's permissionsfor the authorization rule.
                                string xmlPermissions = rule.GetAttribute("permissions", string.Empty);
                                // Parse the FTP access permissions for the authorization rule.
                                FtpAccess userPermissions = FtpAccess.None;
                                switch (xmlPermissions.Replace(" ", "").ToLower())
                                {
                                case "read":
                                    userPermissions = FtpAccess.Read;
                                    break;

                                case "write":
                                    userPermissions = FtpAccess.Write;
                                    break;

                                case "read,write":
                                case "write,read":
                                    userPermissions = FtpAccess.ReadWrite;
                                    break;

                                default:
                                    userPermissions = FtpAccess.None;
                                    break;
                                }
                                // Add the authorization rule to the dictionary.
                                userRules.Add(xmlPath, userPermissions);
                            }
                            // Create a user data class.
                            XmlUserData userData = new XmlUserData(password, userRoles, userRules);
                            // Store the user data in the dictionary.
                            _XmlUserData.Add(userName, userData);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Raise an exception if an error occurs.
                throw new ProviderException(ex.Message);
            }
        }
    }