Exemplo n.º 1
0
        /// <summary>
        /// Creates the specified service running all life cycles for it.
        /// </summary>
        /// <param name="type">The service type.</param>
        /// <returns></returns>
        protected override object CreateService(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            object instance;

            try
            {
                instance = Activator.CreateInstance(type);
            }
            catch (Exception ex)
            {
                throw new MonoRailException("Error trying to instantiate service " + type.FullName, ex);
            }

            try
            {
                ServiceInitializer.Initialize(instance, this);
            }
            catch (Exception ex)
            {
                throw new MonoRailException("Error running lifecycle steps for MonoRail service " + type.FullName, ex);
            }

            return(instance);
        }
        public static void Run([ServiceBusTrigger("hweb_poc_passage_published_topic2", "hweb_sbus_subscription_passage_processor", Connection = "SASListener")] Message sbusMsg, ILogger log)
        {
            try
            {
                ServiceInitializer.Initialize();

                ParaMessage message = null;

                if (sbusMsg != null && sbusMsg.Body != null)
                {
                    var messageBody = Encoding.UTF8.GetString(sbusMsg.Body);

                    message = JsonConvert.DeserializeObject <ParaMessage>(messageBody, new JsonSerializerSettings {
                        NullValueHandling = NullValueHandling.Ignore
                    });

                    log.LogInformation($"C# ServiceBus topic trigger function processed message: {message.Title}");
                }

                if (message != null)
                {
                    var analyser = GetAnalyser();

                    var result = analyser.Analyse(message.Sample);

                    if (result != null)
                    {
                        log.LogInformation($"Longest Sentence is: {result.LongestSentence} having {result.MaxWordCount} words!");
                    }
                }
            }
            catch (Exception ex)
            {
                log.LogCritical(ex, $"FAILED to process message! : {ex.Message} - {ex.StackTrace}");
            }
        }
Exemplo n.º 3
0
 protected void Application_Start(object sender, EventArgs e)
 {
     ServiceInitializer.Initialize(null);
 }