Exemplo n.º 1
0
        private async Task<bool> SaveJsonParameterAsync<T>(T parameter, string name, Type publisherType, params JsonConverter[] converters)
        {
            var publisher = exporter.Publishers.SingleOrDefault(p => p.GetType() == publisherType);

            if (!publisher?.CanPublish ?? true)
                return false;

            var serializedInfo = await exporter.GetPublisherParametersAsync(publisher, p => p.Name == name &&
                                                                                            p.Type == PublisherParameterType.Json);

            var savedParameters = serializedInfo.FirstOrDefault();
            var parametersJson = JsonConvert.SerializeObject(parameter, converters);

            if (savedParameters == null)
            {
                var publisherParameter = new PublisherParameter(publisher, name, parametersJson, PublisherParameterType.Json);
                exporter.AddPublisherParameters(publisherParameter);
            }
            else
                savedParameters.Value = parametersJson;

            await exporter.SavePublisherParametersChangesAsync();
            return true;
        }
Exemplo n.º 2
0
 public void AddParameter(PublisherParameter parameter)
 {
     context.PublisherParameters.Add(parameter);
 }