Exemple #1
0
 public bool Update(Domain.Solution entity)
 {
     return(_solutionRepository.Update(entity));
 }
Exemple #2
0
        /// <summary>
        /// 导入解决方案
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public async Task <bool> ImportAsync(IFormFile file)
        {
            var dir      = _webHelper.MapPath("~/solution/import/" + DateTime.Now.ToString("yyMMddhhmmss"));
            var d        = Directory.CreateDirectory(dir);
            var filePath = dir + "/" + file.FileName;
            await file.SaveAs(filePath, _settingFinder, _webHelper).ConfigureAwait(false);

            IOHelper.UnZip(filePath);
            //解决方案信息
            var solution = new Domain.Solution();

            solution = solution.DeserializeFromXMLFile(dir + "/solution.xml");
            var existSolution = _solutionService.FindById(solution.SolutionId);

            if (existSolution != null)
            {
                existSolution.Name        = solution.Name;
                existSolution.Description = solution.Description;
                existSolution.Version     = solution.Version;
                existSolution.ModifiedBy  = _currentUser.SystemUserId;
                existSolution.ModifiedOn  = DateTime.Now;
                _solutionService.Update(existSolution);
            }
            else
            {
                solution.CreatedBy   = _currentUser.SystemUserId;
                solution.InstalledOn = DateTime.Now;
                solution.PublisherId = _currentUser.SystemUserId;
                _solutionService.Create(solution);
            }
            //自定义内容
            XDocument doc = XDocument.Load(dir + "/customizations.xml");
            IEnumerable <XElement> elements = from e in doc.Element("ImportExportXml").Elements()
                                              select e;

            foreach (var node in elements)
            {
                var importerTypeName = ImporterTypes[node.Name.ToString()];
                if (importerTypeName.IsNotEmpty())
                {
                    var importerType = ImporterNodeTypeMapper.Get(node.Name.ToString());//Type.GetType(importerTypeName);
                    if (importerType != null)
                    {
                        var componentArg    = importerType.GetInterface(typeof(ISolutionComponentImporter <>).Name).GenericTypeArguments[0];
                        var importerService = _serviceResolver.Get(typeof(ISolutionComponentImporter <>).MakeGenericType(componentArg));
                        var listType        = typeof(List <>).MakeGenericType(componentArg);
                        var listObj         = Activator.CreateInstance(listType);
                        foreach (var item in node.Elements())
                        {
                            var component = Activator.CreateInstance(componentArg);
                            component = Serializer.FromXml(componentArg, item.ToString());
                            listType.GetMethod("Add").Invoke(listObj, new[] { component });
                        }
                        //invoke import method
                        var importMethod = importerType.GetMethod("Import");
                        var importResult = importMethod.Invoke(importerService, new[] { solution.SolutionId, listObj });
                    }
                }
            }
            //delete files
            Directory.Delete(dir, true);

            return(true);
        }
Exemple #3
0
 public bool Create(Domain.Solution entity)
 {
     entity.OrganizationId = this._appContext.OrganizationId;
     return(_solutionRepository.Create(entity));
 }