Ejemplo n.º 1
0
        public void ProjectArtifact_Unittest() {
            var storage = new Storage(ArtifactDir + "/test_project");
            var tempDir = storage.GetItem("/temp",StorageTypes.Directory,true) as IStorageDirectory;
            var projLocation = storage.GetItem("/web", StorageTypes.Directory, true) as IStorageDirectory;
            var modelDir = projLocation.GetItem("models",StorageTypes.Directory,true) as IStorageDirectory;
            var modelCode = @"
public class AuthModel{
    public string Username{get;set;}
    public string Password{get;set;}
}
";
            modelDir.PutText("AuthModel.cs",modelCode);

            var controllerDir = projLocation.GetItem("controllers",StorageTypes.Directory,true) as IStorageDirectory;
            var controllerCode = @"
public class AuthController{
    public object Signin(string username,string password){
        return new AuthModel(){Username = username , Password = password};
    }
}
";
            controllerDir.PutText("AuthController.cs",controllerCode);

            var jsDir = projLocation.GetDirectory("js",true);
            var jsCode = @"
alert('11');
";
            jsDir.PutText("alert.js",jsCode);

            var artifact = new ProjectArtifact(null,projLocation, tempDir, null);
            var assembly = artifact.Assembly;
            var types = assembly.DefinedTypes;
            Assert.Equal(2, types.Count());
            var rs = artifact.GetResourceText("/js/alert.js");
            Assert.Equal(jsCode,rs);

            //测试源代码改变后是否重新编译
            var addictionCode = @"public class AuthModel{
    public string Username{get;set;}
    public string Password{get;set;}
    public int Gender{get;set;}
}";
            modelDir.PutText("AuthModel.cs",addictionCode);
            Task.Run(async ()=> {
                await Task.Delay(1000);
                var newAssembly = artifact.Assembly;
                types = newAssembly.DefinedTypes;
                Assert.Equal(2, types.Count());
                var modelType = types.First(p => p.Name.Contains("Model"));
                var genderMember  = modelType.GetMembers().FirstOrDefault(p=>p.Name=="Gender");
                Assert.NotNull(genderMember);
            }).Wait();
            
        }
        /// <summary>
        /// Function to save project artifact details.
        /// </summary>
        /// <param name="projectArtifact">Project Artifact information</param>
        public void InsertOrUpdate(ProjectArtifact projectArtifact)
        {
            if (projectArtifact == null)
            {
                throw new ArgumentNullException(ProjectArtifactConstant);
            }

            if (projectArtifact.ProjectArtifactID == default(int))
            {
                this.unitOfWork.Context.ProjectArtifacts.Add(projectArtifact);
            }
            else
            {
                projectArtifact.ApplicationEntityState = ApplicationEntityState.Modified;
                this.unitOfWork.Context.ProjectArtifacts.Attach(projectArtifact);
                this.unitOfWork.Context.ApplyStateChanges();
            }
        }
        public IVisualStudioProject Render <T>(CodeGenSettings settings, object template, IEnumerable <T> collection, IVisualStudioProject projectFile)
        {
            IStaticAsset         asset           = (IStaticAsset)template;
            List <StaticContent> renderedAssests = asset.Render();


            IClassMetadata classmeta = asset;

            string projectNamespace = string.Format("{0}.{1}", settings.SolutionNamespace, classmeta.ProjectNamespace);
            string projectDirectory = string.Format(@"{0}\{1}", settings.CodeGenerationDirectory, projectNamespace);

            projectFile = ClassesLogic.SetProjectProperties(settings, classmeta, projectFile, projectDirectory);

            //create Directory if it doesn't exists
            if (!File.Exists(projectDirectory))
            {
                Directory.CreateDirectory(projectDirectory);
            }

            //Set File properties... optional Namespace, and the full file path.
            string fullProjectNamespace = projectNamespace + ClassesLogic.AddFolderNamespaces(classmeta);


            foreach (StaticContent content in renderedAssests)
            {
                string filePath         = string.Format(@"{0}\{1}{2}", projectDirectory, classmeta.ClassFilePath, content.FileName);
                string projectClassPath = (string.IsNullOrEmpty(classmeta.ClassFilePath)
                               ? content.FileName
                               : classmeta.ClassFilePath + content.FileName);

                ProjectArtifact artifact = new ProjectArtifact(projectClassPath, content.CreateGeneratedCounterpart);
                projectFile.Classes.Add(artifact);

                StaticContent _content = content;
                if (content.SetNamespace)
                {
                    _content.Content = SetNamespaceAndClass(content.Content.ToString(), fullProjectNamespace);
                }

                SaveContent(classmeta, projectDirectory, content, _content, fullProjectNamespace, filePath);
            }

            return(projectFile);
        }
        /// <summary>
        /// Function to save project artifact details.
        /// </summary>
        /// <param name="processComplianceListItem">Process compliance information</param>
        /// <param name="modifyByDeveloperId">Modified by developer id</param>
        public void InsertOrUpdate(ProcessComplianceListItem processComplianceListItem, int modifyByDeveloperId)
        {
            if (processComplianceListItem == null)
            {
                throw new ArgumentNullException(ProcessComplianceListItemConst);
            }

            var projectArtifact = new ProjectArtifact()
            {
                ArtifactID = processComplianceListItem.ArtifactID.Value,
                Comment = processComplianceListItem.Comment,
                DueDate = processComplianceListItem.DueDate,
                ModifiedByDeveloperID = modifyByDeveloperId,
                ProjectArtifactID = processComplianceListItem.ProjectArtifactID.Value,
                ProjectID = processComplianceListItem.ProjectID,
                ReleaseCalendarID = processComplianceListItem.ReleaseCalendarID,
                Status = processComplianceListItem.Status.Value,
                URL = processComplianceListItem.URL
            };

            this.projectArtifactRepository.InsertOrUpdate(projectArtifact);
            this.unitOfWork.Save();
        }