예제 #1
0
        public void Push(PushOptions options)
        {
            var config      = ReadConfig(options);
            var publishList = new List <Guid>(config.Count);

            foreach (var wrCfg in config)
            {
                _logger.Info($"Processing Web Resource {wrCfg.Name}...");

                var existingResource = _webResourceRepo.Get(wrCfg.Name);

                if (!options.Overwrite && existingResource != null)
                {
                    _logger.Info($"Web Resource {wrCfg.Name} already exists and overwriting is disabled. Skipping.");
                    continue;
                }

                if (existingResource == null)
                {
                    var type = wrCfg.Path.GetWebResourceType();
                    if (type == null)
                    {
                        _logger.Warn($"Web Resource {wrCfg.Path} contains no extension or has the unsupported one. Skipping.");
                        continue;
                    }

                    existingResource = new Entity(WebResource.LogicalName);
                    existingResource[WebResource.name]            = wrCfg.Name;
                    existingResource[WebResource.webresourcetype] = type.Value.ToOptionSetValue();
                }

                existingResource[WebResource.displayname] = string.IsNullOrEmpty(wrCfg.DisplayName) ? wrCfg.Name.GetDisplayName() : wrCfg.DisplayName;

                var file        = File.ReadAllBytes(wrCfg.Path);
                var filecontent = Convert.ToBase64String(file);
                existingResource[WebResource.content] = filecontent;

                _webResourceRepo.CreateOrUpdate(existingResource, wrCfg.Name);

                publishList.Add(existingResource.Id);
            }

            _webResourceRepo.Publish(publishList);
        }