/// <inheritdoc />
 public override void RunPipelineTasks(IQueryConfig config, IList <PipelineStepInfo> processors, int timeoutInMilliseconds)
 {
     foreach (var processor in processors)
     {
         this.RunSync(
             () => (IPipelineStep)this.container.Resolve(
                 processor.Type,
                 new ParameterOverride("cancellationToken", this.cancellationTokenSource.Token)));
     }
 }
Example #2
0
 private Dictionary <object, object> GetData(IQueryConfig qConfig)
 {
     return(new Dictionary <object, object>( )
     {
         { "type", this.GetRecordText(qConfig.RECORD_TYPE) },
         { "name", qConfig.RECORD_NAME },
         { "content", qConfig.RECORD_CONTENT },
         { "ttl", 120 }
     });
 }
Example #3
0
        public async Task <ICFAPIResponse> RemoveRecord(IQueryConfig qConfig)
        {
            try {
                ICFAPIResponse aPI = await this.ExistsRecord(qConfig);

                if (aPI.success != true)
                {
                    return(new CFAPIResponse {
                        success = true, messages = new object[] { "Not Exists this record!!!" }
                    });
                }
                throw new NotImplementedException("!TODO");
            } catch (Exception e) {
                _logger.Write("Error occured Remove DNS TXT Record for {0} . Error=> {1}", qConfig.DOMAIN_NAME, e.Message);
                _logger.Write(e.StackTrace);
                return(new CFAPIResponse {
                    success = true, messages = new object[] { e.Message }
                });
            }
        }
Example #4
0
        public async Task <ICFAPIResponse> ExistsRecord(IQueryConfig qConfig)
        {
            string           requestUriString = string.Format("{0}zones/{1}/dns_records?type={2}&name={3}&content={4}", _config.CF_URI, _config.CF_DNS_ZONE, qConfig.RECORD_TYPE, qConfig.NAME, qConfig.RECORD_CONTENT);
            IWebHttpResponse resp             = await _webHttp.GetAsync(requestUriString, this.GetHeader( ));

            if (resp.status != WebHttpStatus.SUCCESS)
            {
                _logger.Write("Error occured while checking {0} record for {1} . Error=>", qConfig.RECORD_NAME, qConfig.DOMAIN_NAME, resp.errorDescription);
                return(new CFAPIResponse {
                    success = false, errors = new object[] { resp.errorDescription }
                });
            }
            if (string.IsNullOrEmpty(resp.responseText))
            {
                return(new CFAPIResponse {
                    success = false, errors = new object[] { "No Response found from API!!!" }
                });
            }
            ICFAPIResponse cFAPIResponse = JsonConvert.DeserializeObject <CFAPIResponse>(resp.responseText, jsonSettings);

            if (cFAPIResponse.result == null)
            {
                return(new CFAPIResponse {
                    success = false, errors = new object[] { "No Response found from API!!!" }
                });
            }
            if (cFAPIResponse.result is Newtonsoft.Json.Linq.JArray)
            {
                Newtonsoft.Json.Linq.JArray rs = (Newtonsoft.Json.Linq.JArray)cFAPIResponse.result;
                if (rs.Count <= 0)
                {
                    return(new CFAPIResponse {
                        success = false, errors = new object[] { "Not Exists!!!" }
                    });
                }
                _logger.Write("{0} record already exists in {1}", qConfig.RECORD_NAME, qConfig.DOMAIN_NAME);
            }
            return(cFAPIResponse);
        }
Example #5
0
        /// <summary>
        /// The init container.
        /// </summary>
        /// <param name="config">
        /// The config.
        /// </param>
        private void InitContainer(IQueryConfig config)
        {
            var documentDictionary = new DocumentDictionary(MaximumDocumentsInQueue);

            var queueManager = new QueueManager();

            this.container.RegisterInstance <IQueueManager>(queueManager);
            this.container.RegisterInstance <IDocumentDictionary>(documentDictionary);
            this.container.RegisterInstance <IJobConfig>(config);

            IElasticSearchUploaderFactory elasticSearchUploaderFactory =
                this.container.Resolve <IElasticSearchUploaderFactory>();

            var schemaLoader = new SchemaLoader(config.ConnectionString, config.TopLevelKeyColumn);

            this.container.RegisterInstance <ISchemaLoader>(schemaLoader);

            this.container.RegisterType <IEntityJsonWriter, EntityJsonWriter>();

            if (config.WriteDetailedTemporaryFilesToDisk)
            {
                this.container.RegisterType <IDetailedTemporaryFileWriter, FileWriter>();
            }
            else
            {
                this.container.RegisterType <IDetailedTemporaryFileWriter, NullFileWriter>();
            }

            if (config.WriteTemporaryFilesToDisk)
            {
                this.container.RegisterType <ITemporaryFileWriter, FileWriter>();
            }
            else
            {
                this.container.RegisterType <ITemporaryFileWriter, NullFileWriter>();
            }

            this.container.RegisterType <IFileWriter, FileWriter>();
        }
Example #6
0
        /// <inheritdoc />
        public override void RunPipelineTasks(
            IQueryConfig config,
            IList <PipelineStepInfo> processors,
            int timeoutInMilliseconds)
        {
            var tasks = processors
                        .Select(
                processor => this.RunAsync(
                    () => (IPipelineStep)this.container.Resolve(
                        processor.Type,
                        new ParameterOverride("cancellationToken", this.cancellationTokenSource.Token)),
                    processor.Count)).SelectMany(task => task)
                        .ToList();

            try
            {
                Task.WaitAll(tasks.ToArray(), timeoutInMilliseconds, this.cancellationTokenSource.Token);
            }
            catch (Exception)
            {
                var exceptions = tasks.Where(task => task.Exception != null).Select(task => task.Exception.Flatten()).ToList();
                throw new AggregateException(exceptions);
            }
        }
Example #7
0
        public async Task <ICFAPIResponse> AddRecord(IQueryConfig qConfig, bool checkExistence = true)
        {
            if (qConfig.RECORD_TYPE != CFRecordType.TXT)
            {
                throw new NotImplementedException("Not Implemented Yet!!!");
            }
            if (checkExistence)
            {
                ICFAPIResponse aPI = await this.ExistsRecord(qConfig);

                if (aPI.success == true)
                {
                    return(new CFAPIResponse {
                        success = true, messages = new object[] { "Exists this record!!!" }
                    });
                }
            }
            _logger.Write("Adding DNS Record for {0}, Record type {1}", qConfig.DOMAIN_NAME, this.GetRecordText(qConfig.RECORD_TYPE));
            IWebHttpResponse resp = await _webHttp.PostAsync(string.Format("{0}zones/{1}/dns_records", _config.CF_URI, _config.CF_DNS_ZONE), JsonConvert.SerializeObject(this.GetData(qConfig), jsonSettings), this.GetHeader());

            if (resp.status != WebHttpStatus.SUCCESS)
            {
                _logger.Write("Error occured while add {0} record for {1} . Error=> {2}", qConfig.RECORD_NAME, qConfig.DOMAIN_NAME, resp.errorDescription);
                return(new CFAPIResponse {
                    success = false, errors = new object[] { resp.errorDescription }
                });
            }
            if (string.IsNullOrEmpty(resp.responseText))
            {
                _logger.Write("Error occured while add {0} record for {1} . Error=> No Response found from API!!!", qConfig.RECORD_NAME, qConfig.DOMAIN_NAME);
                return(new CFAPIResponse {
                    success = false, errors = new object[] { "No Response found from API!!!" }
                });
            }
            return(JsonConvert.DeserializeObject <CFAPIResponse>(resp.responseText, jsonSettings));
        }
Example #8
0
 public QueryManager(IQueryConfig queryConfig)
 {
     Config = queryConfig;
 }
Example #9
0
 /// <inheritdoc />
 public abstract void RunPipelineTasks(IQueryConfig config, IList <PipelineStepInfo> processors, int timeoutInMilliseconds);