public Build Create(string buildName, string description = null)
        {
            var build = new Build
            {
                BuildName = $"Билд {buildName} от {DateTime.Now:dd-MM-yyyy HH:mm:ss}", BuildDescription = description
            };

            Context.Builds.Add(build);

            Context.SaveChanges();

            return(build);
        }
Пример #2
0
        /// <summary>
        /// Автоматически сопоставить файлы и записать их в БД
        /// </summary>
        public void AutoMapFiles(Build build, bool isStartMapping = false)
        {
            var buildDirectory = Path.Combine(ScriptsPath, Configuration.GetSection("AppSettings")["BuildDirectory"]);

            if (!Directory.Exists(buildDirectory))
            {
                throw new DirectoryNotFoundException("Не найдена директория со скриптами!.");
            }

            var fileNames = Directory.GetFiles(buildDirectory, "*.js", SearchOption.AllDirectories);

            var savedWebResources = WebResourceContext.WebResourceMaps.Select(x => x).ToList();

            foreach (var fileName in fileNames)
            {
                var webResourceHash = CryptographyHelper.GetMd5Hash(fileName);

                var index       = fileName.IndexOf("new_", StringComparison.Ordinal);
                var crmFileName = fileName.Substring(index, fileName.Length - index).Replace("\\", "/")
                                  .Replace(".bundle", "");

                var savedWebResource = savedWebResources.FirstOrDefault(x => x.CrmFileName == crmFileName);

                if (savedWebResource?.LocalFileMd5Hash == webResourceHash)
                {
                    continue;
                }

                savedWebResource = savedWebResource ?? new WebResourceMap();
                savedWebResource.IsAutoUpdate     = crmFileName.Contains("/ribbon") || crmFileName.Contains("/form");
                savedWebResource.CrmFileName      = crmFileName;
                savedWebResource.CreatedOn        = DateTime.Now;
                savedWebResource.LocalFileMd5Hash = webResourceHash;
                savedWebResource.FileSystemPath   = fileName;

                var crmWebResource = WebResourceRepository.RetrieveWebresource(crmFileName);
                if (crmWebResource != null)
                {
                    savedWebResource.CrmWebResourceId = crmWebResource.Id;
                }

                if (savedWebResource.Id == Guid.Empty)
                {
                    WebResourceContext.WebResourceMaps.Add(savedWebResource);
                }
                else
                {
                    WebResourceContext.Entry(savedWebResource).State = EntityState.Modified;
                }

                if (!isStartMapping)
                {
                    WebResourceContext.ChangedWebResources.Add(new ChangedWebResource
                    {
                        Build          = build,
                        WebResourceMap = savedWebResource,
                        ChangedDate    = DateTime.Now
                    });
                }
            }

            WebResourceContext.SaveChanges();
        }