예제 #1
0
        public WebClient(IAppLogger logger, string url, IContentBuilder builder)
        {
            _logger  = logger;
            _url     = url;
            _builder = builder.CheckNull(nameof(builder));

#if NETCOREAPP2_1 || NETCOREAPP2_2 || NETCOREAPP3_1
            _handler = new SocketsHttpHandler();
            _client  = new HttpClient(_handler);
#else
            _client = new HttpClient();

            if (!string.IsNullOrWhiteSpace(url))
            {
                var uri = new Uri(_url);
                _servicePoint = ServicePointManager.FindServicePoint(uri);
            }
#endif

            ConnectionsLimit       = 1024;
            MaxIdleTime            = 300000; // 5 мин
            ConnectionLeaseTimeout = 0;      // закрываем соединение сразу после выполнения запроса

            Culture = CultureInfo.CurrentCulture;
        }
예제 #2
0
        public WebClient(HttpClient client, IContentBuilder builder)
        {
            _builder = builder.CheckNull(nameof(builder));
            _client  = client;

            Culture = CultureInfo.CurrentCulture;
        }
        public static IContentBuilder AddUpdater(this IContentBuilder builder, Action <ContentUpdaterOptions> options)
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (options is null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var o = new ContentUpdaterOptions();

            options(o);

            var ourBuilder = (LocalizerConfiguration)builder;

            ourBuilder.UpdaterFactory = new Lazy <ContentUpdater>(() => new ContentUpdater(
                                                                      ourBuilder.Sources[0],
                                                                      o.StartupDelay,
                                                                      o.Frequency,
                                                                      ourBuilder.ContentLogger,
                                                                      ourBuilder.ClassGenerator
                                                                      ));

            return(builder);
        }
        public static IContentLocalizer BuildLocalizer(this IContentBuilder builder)
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var            ourBuilder = (LocalizerConfiguration)builder;
            var            list       = ourBuilder.Sources;
            IContentSource last       = null;

            foreach (var source in list)
            {
                if (last != null)
                {
                    last.NextSource = source;
                }

                last = source;
            }


            var updater = ourBuilder.UpdaterFactory?.Value;

            _ = updater?.StartAsync();

            return(new LocalizerContainer(
                       contentLocalizer: new ContentLocalizer(list[0], "en-US"),
                       updater: updater
                       ));
        }
 public void LogRequestPayload(IContentBuilder contentBuilder)
 {
     _logger.Debug(() =>
     {
         return($">>> Request Payload: {Environment.NewLine}{contentBuilder.GetPayloadForLogging()}{Environment.NewLine}");
     });
 }
예제 #6
0
 public ReflectionContentManager([ImportMany] IEnumerable <Lazy <IContentManager, IPrioritisedMefMetaData> > contentManagers,
                                 IReflectionModuleBuilder moduleBuilder, IContentBuilder contentBuilder,
                                 [ImportMany] IEnumerable <Lazy <ICultureManager, IPrioritisedMefMetaData> > cultureInfoManagers /*,
                                                                                                                                  * IContentPublicationStateManager contentPublicationStateManager, IContentPublicationDateTimeManager contentPublicationDateTimeManager*/)
     : this(contentManagers.OrderByDescending(x => x.Metadata.Priority).First().Value, moduleBuilder, contentBuilder,
            cultureInfoManagers.OrderByDescending(x => x.Metadata.Priority).First().Value /*, contentPublicationStateManager, contentPublicationDateTimeManager*/)
 {
 }
        public static IContentBuilder Name(this IContentBuilder @this, string name)
        {
            var last = @this.Last();

            last.Headers.ContentDisposition.Name = name;

            return(@this);
        }
        public static IContentBuilder AddManager <TEntry, TModel>(this IContentBuilder builder)
            where TEntry : class, IContentEntry
            where TModel : class
        {
            AddManager <ContentManager <TEntry, TModel>, TEntry, TModel>(builder);

            return(builder);
        }
        public static IContentBuilder AddStore <TEntry, TStore>(this IContentBuilder builder, ServiceLifetime serviceLifetime)
            where TEntry : class, IContentEntry
            where TStore : class, IContentStore <TEntry>
        {
            builder.Services.Add(new ServiceDescriptor(typeof(IContentStore <TEntry>), typeof(TStore), serviceLifetime));

            return(builder);
        }
예제 #10
0
        public static IServiceCollection GetServices(this IContentBuilder builder)
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(((NetCoreLocalizationBuilder)builder).Services);
        }
예제 #11
0
        public static IContentBuilder AddSerilog(this IContentBuilder builder)
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.AddSerilog(Log.Logger));
        }
        public static void Register(string key, IContentBuilder builder)
        {
            if (_RegisteredFactories.ContainsKey(key))
            {
                throw new ArgumentException(String.Format("{0} has already been registered", key));
            }

            _RegisteredFactories.Add(key, builder);
        }
예제 #13
0
 public EmailService(ISmtpClientProvider smtpClient,
                     ITemplateProvider templateProvider,
                     IContentBuilder contentBuilder,
                     ICredentialsProvider credentialsProvider)
 {
     this.smtpClient          = smtpClient;
     this.templateProvider    = templateProvider;
     this.contentBuilder      = contentBuilder;
     this.credentialsProvider = credentialsProvider;
 }
        public static IContentBuilder AddMemorySource(this IContentBuilder builder)
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.AddContentSource(() => new MemoryContentSource());
            return(builder);
        }
        public static IContentBuilder ContentDisposition(this IContentBuilder @this, string type, string name, string fileName = null)
        {
            var h = new ContentDispositionHeaderValue(type)
            {
                Name         = name,
                FileName     = fileName,
                FileNameStar = fileName
            };

            return(@this.ContentDisposition(h));
        }
        public static IContentBuilder File(this IContentBuilder @this, string fileName)
        {
            var last = @this.Last();

            fileName = Path.GetFileName(fileName);

            last.Headers.ContentDisposition.FileName     = fileName;
            last.Headers.ContentDisposition.FileNameStar = fileName;

            return(@this);
        }
예제 #17
0
        //private readonly IContentPublicationStateManager _contentPublicationStateManager;
        //private readonly IContentPublicationDateTimeManager _contentPublicationDateTimeManager;

        public ReflectionContentManager(IContentManager contentManager, IReflectionModuleBuilder moduleBuilder,
                                        IContentBuilder contentBuilder, ICultureManager cultureInfoManager /*,
                                                                                                            * IContentPublicationStateManager contentPublicationStateManager, IContentPublicationDateTimeManager contentPublicationDateTimeManager*/)
        {
            _contentManager     = contentManager;
            _moduleBuilder      = moduleBuilder;
            _contentBuilder     = contentBuilder;
            _cultureInfoManager = cultureInfoManager;
            //_contentPublicationStateManager = contentPublicationStateManager;
            //_contentPublicationDateTimeManager = contentPublicationDateTimeManager;
        }
        public static IContentBuilder AddManager <TManager, TEntry, TModel>(this IContentBuilder builder)
            where TManager : class, IContentManager <TEntry, TModel>
            where TEntry : class, IContentEntry
            where TModel : class
        {
            builder.Services.AddScoped <IContentManager <TEntry, TModel>, TManager>();
            builder.Services.AddScoped(s => (TManager)s.GetRequiredService <IContentManager <TEntry, TModel> >());
            builder.Services.AddSingleton <IContentStore <TEntry>, MemoryContentStore <TEntry> >();

            return(builder);
        }
예제 #19
0
        public static IContentBuilder AddSerilog(this IContentBuilder builder, ILogger logger)
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.AddLogger(() => new SerilogContentLogger(logger));

            return(builder);
        }
        /// <summary>
        /// Wordpress Recipe Builder. Takes a wordpress export and creates an Orchard Core recipe.
        /// </summary>
        /// <param name="fileToImport">Path to wordpress export file</param>
        /// <param name="recipeTemplateFile">Path to template Orchard Core recipe containing required content definitions</param>
        /// <param name="workingFolder">Output folder where recipe zip will end up</param>
        public WPRecipeBuilder(string fileToImport, string recipeTemplateFile, string workingFolder, RecipeSettings recipeSettings)
        {
            creationDateTime        = DateTime.UtcNow.ToString("o");
            this.fileToImport       = fileToImport;
            this.recipeTemplateFile = recipeTemplateFile;

            // Setup folder for saving files to
            this.workingFolder = workingFolder;
            recipeFolder       = Path.Combine(workingFolder, "recipe");
            Directory.CreateDirectory(recipeFolder);

            this.recipeSettings = recipeSettings;

            wordpressItems      = new List <WordpressItem>();
            wordpressCategories = new List <WordpressCategory>();
            wordpressTags       = new List <WordpressTag>();
            urlCleaner          = new UrlCleaner();
            failedMediaUrls     = new List <string>();

            // initialise content builders to reflect the desired recipe
            switch (recipeSettings.Theme)
            {
            case RecipeSettings.Themes.TheBlog:
                postBuilder = new TheBlogPostBuilder
                {
                    ParentId            = "4m2pj0mpy25450jcz817odyhbg",
                    WordpressItems      = wordpressItems,
                    WordpressCategories = wordpressCategories,
                    WordpressTags       = wordpressTags
                };
                pageBuilder = new TheBlogPageBuilder
                {
                    WordpressItems = wordpressItems
                };
                break;

            case RecipeSettings.Themes.EtchPlayBoilerplate:
                postBuilder = new EtchPlayBoilerplatePostBuilder
                {
                    ParentId            = "4dzdnpafscnp33y8xdz4ch45xt",
                    WordpressItems      = wordpressItems,
                    WordpressCategories = wordpressCategories,
                    WordpressTags       = wordpressTags
                };
                pageBuilder = new EtchPlayBoilerplatePageBuilder
                {
                    WordpressItems = wordpressItems
                };
                break;
            }
        }
예제 #21
0
 public AppController(
     IContentBuilder <TreeList, PremissionAgency> agencyTreeListBuilder,
     IContentBuilder <SelectedList, PremissionAgency> agencySelectedListBuilder,
     IContentBuilder <SelectedList, PremissionRegion> regionSelectedListBuilder)
 {
     _agencyTreeListBuilder     = agencyTreeListBuilder;
     _agencySelectedListBuilder = agencySelectedListBuilder;
     _regionSelectedListBuilder = regionSelectedListBuilder;
     int dictAgencyId     = 123;
     var treeListAgency   = _agencyTreeListBuilder.BuildContent(dictAgencyId, new List <PremissionAgency>());
     var selectListAgency = _agencySelectedListBuilder.BuildContent(dictAgencyId, new List <PremissionAgency>());
     int dictRegionId     = 321;
     var selectListRegion = _regionSelectedListBuilder.BuildContent(dictRegionId, new List <PremissionRegion>());
 }
예제 #22
0
        public static IContentBuilder AddJsonFileSource(this IContentBuilder builder, Action <JsonFileContentSourceOptions> options)
        {
            if (options is null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var o = new JsonFileContentSourceOptions();

            options(o);

            builder.AddContentSource(() => new JsonFileContentSource(o.Location));
            return(builder);
        }
예제 #23
0
        public static IContentBuilder AddProtoFileSource(this IContentBuilder builder, string location)
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (location is null)
            {
                throw new ArgumentNullException(nameof(location));
            }

            builder.AddContentSource(() => new ProtoFileContentSource(location, builder.ContentLogger));
            return(builder);
        }
예제 #24
0
            public IApiRequest AddFormParameter(string key, string value)
            {
                StringContentBuilder stringContentBuilder;

                if (_contentBuilder == null || !(_contentBuilder is StringContentBuilder))
                {
                    _contentBuilder = stringContentBuilder = new StringContentBuilder();
                }
                else
                {
                    stringContentBuilder = _contentBuilder as StringContentBuilder;
                }

                stringContentBuilder.AddParameter(key, value);
                return(this);
            }
        public static IContentBuilder AddClassGenerator(this IContentBuilder builder, Action <ClassGeneratorOptions> options)
        {
            if (options is null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var ourBuilder = (LocalizerConfiguration)builder;

            var o = new ClassGeneratorOptions();

            options(o);

            ourBuilder.ClassGenerator = new  StaticContentClassGenerator(o);

            return(builder);
        }
예제 #26
0
        public static IApiBuilder AddContentApi(this IContentBuilder contentBuilder,
                                                Action <ApiBuilderDependency> configureDependency = null,
                                                Func <IExtensionBuilder, ApiBuilderDependency, IApiBuilder> builderFactory = null)
        {
            var builder = contentBuilder.AddApi(configureDependency, builderFactory);

            var parameterMapper = contentBuilder.AccessorTypeParameterMapper;

            var apiMutationType = typeof(ContentGraphApiMutation <, , , , , , , , , , , ,>).MakeGenericType(
                parameterMapper.Category.ArgumentType,
                parameterMapper.Source.ArgumentType,
                parameterMapper.Claim.ArgumentType,
                parameterMapper.Tag.ArgumentType,
                parameterMapper.Unit.ArgumentType,
                parameterMapper.UnitClaim.ArgumentType,
                parameterMapper.UnitTag.ArgumentType,
                parameterMapper.UnitVisitCount.ArgumentType,
                parameterMapper.Pane.ArgumentType,
                parameterMapper.PaneClaim.ArgumentType,
                parameterMapper.BaseMapper.GenId.ArgumentType,
                parameterMapper.BaseMapper.IncremId.ArgumentType,
                parameterMapper.BaseMapper.CreatedBy.ArgumentType);

            var apiQueryType = typeof(ContentGraphApiQuery <, , , , , , , , , , , ,>).MakeGenericType(
                parameterMapper.Category.ArgumentType,
                parameterMapper.Source.ArgumentType,
                parameterMapper.Claim.ArgumentType,
                parameterMapper.Tag.ArgumentType,
                parameterMapper.Unit.ArgumentType,
                parameterMapper.UnitClaim.ArgumentType,
                parameterMapper.UnitTag.ArgumentType,
                parameterMapper.UnitVisitCount.ArgumentType,
                parameterMapper.Pane.ArgumentType,
                parameterMapper.PaneClaim.ArgumentType,
                parameterMapper.BaseMapper.GenId.ArgumentType,
                parameterMapper.BaseMapper.IncremId.ArgumentType,
                parameterMapper.BaseMapper.CreatedBy.ArgumentType);

            contentBuilder.Services.TryReplaceAll(typeof(IGraphApiMutation), apiMutationType);
            contentBuilder.Services.TryReplaceAll(typeof(IGraphApiQuery), apiQueryType);

            return(builder);
        }
예제 #27
0
 public TreeListContentBuilder(IContentBuilder <RDSElement, TPremission> contentBuilder)
 {
     _contentBuilder = contentBuilder;
 }
예제 #28
0
 public IApiRequest AddJsonContent <T>(T obj)
 {
     _contentBuilder = new ObjectContentBuilder <T>(obj);
     return(this);
 }
예제 #29
0
 public void AppendTo(IContentBuilder builder)
 {
     throw new NotSupportedException();
 }
예제 #30
0
 public IApiRequest AddFile(string filePath, string contentType = null)
 {
     _contentBuilder = new FileContentBuilder(filePath, contentType);
     return(this);
 }