Beispiel #1
0
        public IActionResult Publish([FromBody] PublishInput input)
        {
            Logger.LogDebug($"PublishMessageController - Publish method called with this input: {input}");
            if (input == null)
            {
                return(BadRequest(new ApiValidationError(nameof(input), ErrorKeys.ParameterNull)));
            }

            if (input.Payload == null)
            {
                return(BadRequest(new ApiValidationError(nameof(PublishInput.Payload), ErrorKeys.ParameterNull)));
            }

            if (string.IsNullOrWhiteSpace(input.Category))
            {
                return(BadRequest(new ApiValidationError(nameof(PublishInput.Category), ErrorKeys.ParameterNull)));
            }

            if (!input.ValidateTags())
            {
                return(BadRequest(new ApiValidationError(nameof(PublishInput.Tags), ErrorKeys.ParameterNull)));
            }

            var result = _publishMessageLogic.ProduceMessage(input);

            if (!string.IsNullOrEmpty(result.Error))
            {
                return(BadRequest(new { Message = result.Error }));
            }

            return(Ok(ApiValidationResult.Ok()));
        }
Beispiel #2
0
 // Start is called before the first frame update
 void Start()
 {
     text_ui = GetComponent <TextMeshProUGUI>();
     emitter = GetComponent <PublishInput>();
     if (cursor_blink_time > 0)
     {
         InvokeRepeating("BlinkCursor", 0.1f, cursor_blink_time);
     }
 }
 protected override void beforeEach()
 {
     theSpec  = new NugetSpec("Nug", "Nug.nuspec");
     theInput = new PublishInput
     {
         Version       = "1.0.0",
         ArtifactsFlag = "arts",
         ApiKey        = "pw"
     };
 }
Beispiel #4
0
        public void Given_Sane_Tags_ValidateTags_Should_Return_True()
        {
            var input = new PublishInput
            {
                Tenant   = "sample-tenant",
                Category = "sample-category",
                Payload  = "sample-payload",
                Tags     = new[] { "t1", " ", "t2" }
            };

            Assert.True(input.ValidateTags());
        }
Beispiel #5
0
        public void Given_List_With_Empty_Strings_As_Tags_ValidateTags_Should_Return_False()
        {
            var input = new PublishInput
            {
                Tenant   = "sample-tenant",
                Category = "sample-category",
                Payload  = "sample-payload",
                Tags     = new[] { "", " ", "\t" }
            };

            Assert.False(input.ValidateTags());
        }
Beispiel #6
0
        public void Given_Empty_List_ValidateTags_Should_Return_False()
        {
            var input = new PublishInput
            {
                Tenant   = "sample-tenant",
                Category = "sample-category",
                Payload  = "sample-payload",
                Tags     = new List <string>()
            };

            Assert.False(input.ValidateTags());
        }
Beispiel #7
0
        public ProduceMessageOutput ProduceMessage(PublishInput input)
        {
            try
            {
                _producer.Produce(input.Tenant, input);

                return(new ProduceMessageOutput
                {
                    Success = true
                });
            }
            catch (Exception ex)
            {
                Logger.LogError($"PublishMessageLogic - ProduceMessage: {ex.Message}",
                                ex);

                return(new ProduceMessageOutput
                {
                    Success = false,
                    Error = ErrorKeys.UnableProduceMessage
                });
            }
        }
Beispiel #8
0
        public override Hash Publish(PublishInput input)
        {
            // TODO: Maybe need to check permission.

            var novelId = Context.GenerateId(Context.Self,
                                             HashHelper.ConcatAndCompute(HashHelper.ComputeFrom(Context.Sender),
                                                                         HashHelper.ComputeFrom(input.NovelTextHash)));

            Assert(State.NovelInfos[novelId] == null, "Novel already exists.");

            var setInfo = State.NovelSetInfos[input.SetId];

            if (setInfo == null)
            {
                throw new AssertionException($"Set with Id {input.SetId} not found.");
            }

            var rank = setInfo.NovelCount.Add(1);

            setInfo.NovelCount = rank;
            State.NovelHashes[input.SetId][rank] = novelId;
            State.NovelSetInfos[input.SetId]     = setInfo;

            State.NovelInfos[novelId] = new NovelInfo
            {
                SetId            = input.SetId,
                Length           = input.Length,
                NovelId          = novelId,
                NovelName        = input.NovelName,
                NovelTextHash    = input.NovelTextHash,
                PublisherAddress = Context.Sender,
                PublishTime      = Context.CurrentBlockTime,
                LatestEditTime   = Context.CurrentBlockTime,
                Text             = input.Text
            };

            var profile = State.Profiles[Context.Sender];

            if (profile == null)
            {
                profile = new Profile
                {
                    Address          = Context.Sender,
                    FirstPublishTime = Context.CurrentBlockTime,
                };
            }
            else
            {
                if (profile.FirstPublishTime == null)
                {
                    profile.FirstPublishTime = Context.CurrentBlockTime;
                }
            }

            State.Profiles[Context.Sender] = profile;

            Context.Fire(new NovelPublished
            {
                SetId            = input.SetId,
                Length           = input.Length,
                NovelId          = novelId,
                NovelName        = input.NovelName,
                NovelTextHash    = input.NovelTextHash,
                PublisherAddress = Context.Sender,
                PublishTime      = Context.CurrentBlockTime,
            });

            return(novelId);
        }
Beispiel #9
0
 void Start()
 {
     emitter = GetComponent <PublishInput>();
     StartDictationEngine();
 }