Esempio n. 1
0
        public GeneratedProxies(
            CommandProxies commandProxies,
            CommandSecurityProxies commandSecurityProxies,
            QueryProxies queryProxies,
            ReadModelProxies readModelProxies,
            ServiceProxies serviceProxies,
            NamespaceConfigurationProxies namespaceConfigurationProxies,
#if (NET461)
            HubProxies hubProxies,
#endif
            ITypeFinder typeFinder,
            IContainer container)
        {
            var builder = new StringBuilder();

            builder.Append(commandProxies.Generate());
            builder.Append(commandSecurityProxies.Generate());
            builder.Append(readModelProxies.Generate());
            builder.Append(queryProxies.Generate());
            builder.Append(serviceProxies.Generate());
            builder.Append(namespaceConfigurationProxies.Generate());
#if (NET461)
            builder.Append(hubProxies.Generate());
#endif

            var generatorTypes = typeFinder.FindMultiple <IProxyGenerator>().Where(t => !t.Namespace.StartsWith("Dolittle"));
            foreach (var generatorType in generatorTypes)
            {
                var generator = container.Get(generatorType) as IProxyGenerator;
                builder.Append(generator.Generate());
            }

            All = builder.ToString();
        }
        public static string CheckTweets(TraceWriter log)
        {
            string result = "Tweets updated.";

            try
            {
                List <Company> companies = Utils.DataRepository.GetCompaniesFromDb(log);

                foreach (Company company in companies)
                {
                    List <Tweet> tweets = ServiceProxies.SearchTweets(company.Name);
                    log.Info($"Found {tweets.Count.ToString()} tweets for company {company.Name}, adding...");
                    foreach (Tweet tweet in tweets)
                    {
                        DateTime publishDateTime = DateTime.ParseExact(tweet.DatePublished, "ddd MMM dd HH:mm:ss zzz yyyy", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AssumeLocal);
                        string   Price           = ServiceProxies.GetStockPrice(company.Symbol, publishDateTime.ToString("yyyy-MM-dd"), log);
                        DataRepository.AddUpdate(company.Name + "_TWEET_" + tweet.DatePublished, company.Name, company.Symbol, "TWEET", tweet.Text, Convert.ToInt32(tweet.FavoriteCount), Convert.ToInt32(tweet.RetweetCount), tweet.Sentiment.ToString(), Price, publishDateTime, log);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
                result = $"Check tweets error: {ex.ToString()}";
            }

            return(result);
        }
Esempio n. 3
0
        public GeneratedProxies(
            CommandProxies commandProxies,
            CommandSecurityProxies commandSecurityProxies,
            QueryProxies queryProxies,
            ReadModelProxies readModelProxies,
            ServiceProxies serviceProxies,
            NamespaceConfigurationProxies namespaceConfigurationProxies,
            ITypeDiscoverer typeDiscoverer,
            IContainer container)
        {
            var builder = new StringBuilder();
            builder.Append(commandProxies.Generate());
            builder.Append(commandSecurityProxies.Generate());
            builder.Append(readModelProxies.Generate());
            builder.Append(queryProxies.Generate());
            builder.Append(serviceProxies.Generate());
            builder.Append(namespaceConfigurationProxies.Generate());

            var generatorTypes = typeDiscoverer.FindMultiple<IProxyGenerator>().Where(t => !t.Namespace.StartsWith("Bifrost"));
            foreach (var generatorType in generatorTypes)
            {
                var generator = container.Get(generatorType) as IProxyGenerator;
                builder.Append(generator.Generate());
            }

            All = builder.ToString();
        }
Esempio n. 4
0
        protected virtual async Task AfterBirthdayEntry(IDialogContext context, IAwaitable <IMessageActivity> result)
        {
            var message = await result;

            context.ConversationData.SetValue <string>("INSURANCE-BIRTHDAY", message.Text);

            LuisResponse luisInfo = await ServiceProxies.GetEntityFromLUIS(message.Text);

            if (luisInfo.intents != null && luisInfo.intents.Length > 0 && luisInfo.intents[0].score > 0.6 && luisInfo.intents[0].intent == "Abort")
            {
                await context.PostAsync("Ok, sorry, wir hören jetzt auf. Vielleicht ein anderes mal!");

                context.Done <string>(null);
            }
            else
            {
                string birthday        = message.Text;
                string insuranceNumber = context.ConversationData.GetValue <string>("INSURANCE-NUMBER");
                string insuranceName   = context.ConversationData.GetValue <string>("INSURANCE-NAME");
                System.Diagnostics.Trace.TraceInformation($"KREDITABL {insuranceNumber} - {insuranceName} - {birthday}");
                await context.PostAsync($"Vielen Dank, Ihre Kreditablöseinformation ist unterwegs!");

                context.Done <string>(null);
            }
        }
        public static string Update(TraceWriter log)
        {
            string result = "Daily update complete, nothing unusual to report..";

            try
            {
                List <Company> companies = Utils.DataRepository.GetCompaniesFromDb(log);

                foreach (Company company in companies)
                {
                    if (!String.IsNullOrEmpty(company.Symbol))
                    {
                        DailyUpdate update = new DailyUpdate()
                        {
                            Name = company.Name, Symbol = company.Symbol, Date = DateTime.Now
                        };
                        //update.Id = company.Name + "_" + update.Date.ToString("yyyyMMdd");
                        //update.Id = update.Id.Replace(" ", "_");

                        TweetSummary tweets = TwitterUtils.GetTweetSummary(company.Name, log);
                        update.TweetCount    = tweets.TweetCount;
                        update.TweetLikes    = tweets.TweetLikes;
                        update.TweetRetweets = tweets.TweetRetweets;
                        update.StockPrice    = ServiceProxies.GetStockPrice(company.Symbol, "", log);
                        GitHub ghub = ServiceProxies.GetGitHubStars(company.Name);
                        if (ghub != null)
                        {
                            update.GitHubStars    = ghub.Stars;
                            update.GitHubWatchers = ghub.Watches;
                        }

                        List <News> news = ServiceProxies.SearchNews(company.Name, log);
                        update.NewsStories = news.Count;

                        DataRepository.AddDailyUpdate(update);

                        // Sleep to not overload free APIs
                        System.Threading.Thread.Sleep(12000);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
                result = "DailyUpdater Error: " + ex.ToString();
            }

            return(result);
        }
Esempio n. 6
0
        protected virtual async Task StartKreditAblöseDialog(IDialogContext context, IAwaitable <IMessageActivity> result)
        {
            var input = await result;

            LuisResponse luisInfo = await ServiceProxies.GetEntityFromLUIS(input.Text);

            if (luisInfo.intents.Length > 0 && luisInfo.intents[0].intent == "Ja")
            {
                // Yes start kreditablösedialog
                IDialog <string> kreditDialog = (IDialog <string>) new KreditAblöseDialog();
                context.Call(kreditDialog, AfterKreditDialog);
            }
            else
            {
                context.Wait(MessageReceivedAsync);
            }
        }
Esempio n. 7
0
        protected virtual async Task AfterInsuranceNumberEntry(IDialogContext context, IAwaitable <IMessageActivity> result)
        {
            var          message  = await result;
            LuisResponse luisInfo = await ServiceProxies.GetEntityFromLUIS(message.Text);

            if (luisInfo.intents != null && luisInfo.intents.Length > 0 && luisInfo.intents[0].score > 0.6 && luisInfo.intents[0].intent == "Abort")
            {
                await context.PostAsync("Ok, sorry, wir hören jetzt auf. Vielleicht ein anderes mal!");

                context.Done <string>(null);
            }
            else
            {
                string insuranceNumber = message.Text;
                context.ConversationData.SetValue <string>("INSURANCE-NUMBER", insuranceNumber);
                await context.PostAsync($"Ihre Versicherungsnummer lautet {String.Join(" ", insuranceNumber.ToCharArray())}. Ist das richtig?");

                context.Wait(this.ConfirmInsuranceNumberEntry);
            }
        }
Esempio n. 8
0
        protected virtual async Task AfterNameEntry(IDialogContext context, IAwaitable <IMessageActivity> result)
        {
            var message = await result;

            context.ConversationData.SetValue <string>("INSURANCE-NAME", message.Text);
            LuisResponse luisInfo = await ServiceProxies.GetEntityFromLUIS(message.Text);

            if (luisInfo.intents != null && luisInfo.intents.Length > 0 && luisInfo.intents[0].score > 0.6 && luisInfo.intents[0].intent == "Abort")
            {
                await context.PostAsync("Ok, sorry, wir hören jetzt auf. Vielleicht ein anderes mal!");

                context.Done <string>(null);
            }
            else
            {
                string name = message.Text;
                await context.PostAsync($"Bitte sagen Sie jetzt Ihr Geburtsdatum laut vor");

                context.Wait(this.AfterBirthdayEntry);
            }
        }
Esempio n. 9
0
        protected virtual async Task ConfirmInsuranceNumberEntry(IDialogContext context, IAwaitable <IMessageActivity> result)
        {
            var          message  = await result;
            LuisResponse luisInfo = await ServiceProxies.GetEntityFromLUIS(message.Text);

            if (luisInfo.intents != null && luisInfo.intents.Length > 0 && luisInfo.intents[0].score > 0.8 && luisInfo.intents[0].intent == "Ja")
            {
                await context.PostAsync($"Bitte sagen Sie jetzt Ihren Vor und Nach Namen laut vor");

                context.Wait(this.AfterNameEntry);
            }
            else if (luisInfo.intents != null && luisInfo.intents.Length > 0 && luisInfo.intents[0].score > 0.6 && luisInfo.intents[0].intent == "Abort")
            {
                await context.PostAsync("Ok, sorry, wir hören jetzt auf. Vielleicht ein anderes mal!");

                context.Done <string>(null);
            }
            else
            {
                await MessageReceivedAsync(context, result);
            }
        }
Esempio n. 10
0
        private static void SetWorkflowDescription(
            ServiceProxies.SchedulerService.EstimatedWorkflow wf,
            IEnumerable<Task> tasks, IEnumerable<Resource> resources,
            IEnumerable<TaskDependency> dependencies,
            IDictionary<ulong, Dictionary<NodeConfig, Estimation>> estimationsForTask,
            string schedulingWfId = null)
        {
            var now = DateTime.Now;

            var permittedResourceNames = new Func<IEnumerable<string>, IEnumerable<string>>((perms) =>
                perms.Select(p => p.Substring(0, p.IndexOf('.'))).Distinct()
            );

            var permittedNodeNames = new Func<string, IEnumerable<string>, IEnumerable<string>>((resName, perms) =>
                perms.Where(p => p.StartsWith(resName)).Select(st => st.Substring(resName.Length + 1))
            );

            var taskStateConvert = new Func<Task, ServiceProxies.SchedulerService.TaskSchedulerTaskState>(task =>
            {
                switch (task.State)
                {
                    case TaskState.Started:
                        return ServiceProxies.SchedulerService.TaskSchedulerTaskState.LAUNCHED;

                    case TaskState.Scheduled:
                        return ServiceProxies.SchedulerService.TaskSchedulerTaskState.SCHEDULED;

                    case TaskState.ReadyToExecute:
                        return ServiceProxies.SchedulerService.TaskSchedulerTaskState.SCHEDULED;

                    default:
                        throw new Exception(String.Format(
                            "Could not map task's {0} state {1} to scheduler's task state",
                            task.TaskId, task.State.ToString()
                        ));
                }
            });

            wf.Dependencies = dependencies.Select(d => new ServiceProxies.SchedulerService.TasksDepenendency()
            {
                ProviderId = d.ParentTaskId,
                ConsumerId = d.ChildTaskId,
            }).ToList();

            //Optimize = true,
            wf.Name = String.Join(", ", tasks.Select(t => t.TaskId.ToString()));

            wf.ActiveTasks = tasks
                .Where(t =>
                    (t.State != TaskState.ReadyToExecute && t.State != TaskState.Scheduled && t.State != TaskState.Defined) ||

                    // or another known urgent in parallel
                    (t.WfId != schedulingWfId && t.Priority == TaskPriority.Urgent && t.State == TaskState.ReadyToExecute &&
                    t.CurrentSchedule != null && !String.IsNullOrEmpty(t.CurrentSchedule.ResourceName)) // todo : -> Task.isScheduled()
                )
                .Select(t => new ServiceProxies.SchedulerService.ActiveEstimatedTask()
                {
                    ApplicationName = t.Package,

                    WFid = t.WfId,

                    Id = t.TaskId,
                    IsUrgent = (t.Priority == TaskPriority.Urgent),
                    Parameters = new Dictionary<string, string>(t.Params),
                    State = taskStateConvert(t),

                    Estimation = new ServiceProxies.SchedulerService.ActiveEstimation()
                    {
                        //Destination = new Common.LaunchDestination()
                        Destination = new ServiceProxies.SchedulerService.LaunchDestination()
                        {
                            ResourceName = t.CurrentSchedule.ResourceName,
                            NodeNames = t.CurrentSchedule.Nodes.Select(n => n.NodeName).ToList()
                        },

                        //Resource = new Common.Resource()
                        Resource = new ServiceProxies.SchedulerService.Resource()
                        {
                            Name = t.CurrentSchedule.ResourceName,

                            Nodes = resources
                                .Single(r => r.ResourceName == t.CurrentSchedule.ResourceName)
                                .Nodes.Where(n => t.CurrentSchedule.Nodes.Any(sn => sn.NodeName == n.NodeName))
                                //.Select(n => new Common.Node()
                                .Select(n => new ServiceProxies.SchedulerService.Node()
                                {
                                    ResourceName = n.ResourceName,
                                    DNSName = n.NodeName,
                                    Parameters = new Dictionary<string, string>(n.StaticHardwareParams),
                                    CoresAvailable = n.CoresAvailable,
                                    CoresTotal = (int)n.CoresCount,
                                }).ToList(),

                            Parameters = new Dictionary<string, string>(
                                resources.Single(r => r.ResourceName == t.CurrentSchedule.ResourceName).HardwareParams
                            ),
                        },

                        LaunchTime = t.Time.Duration[TaskTimeMetric.Calculation].TotalSeconds,
                        //Math.Max(0.0, ((t.CurrentSchedule.EstimatedStartTime ?? now) - now).TotalSeconds),

                        Result = new ServiceProxies.SchedulerService.EstimationResult()
                        //Result = new TimeMeter.EstimationResult(null)
                        {
                            //Time = t.CurrentSchedule.Estimation.TimeLeft(t.Time.WhenStarted[TaskTimeMetric.Calculation]).TotalSeconds, //t.Time.Left.Value.TotalSeconds,
                            CalculationTime = t.CurrentSchedule.Estimation.TimeLeft(t.Time.WhenStarted[TaskTimeMetric.Calculation]).TotalSeconds, //t.Time.Left.Value.TotalSeconds,
                            Overheads = 0, // todo : overheads estimation for scheduler

                            //Math.Max(0.0, ((t.CurrentSchedule.EstimatedFinishTime ?? now) - (t.CurrentSchedule.EstimatedStartTime ?? now)).TotalSeconds),
                            //Parameters = new[] { new ServiceProxies.SchedulerService.EstimationResult.ParameterValue()
                            Parameters = t.Params.Select(pair => new ServiceProxies.SchedulerService.EstimationResult.ParameterValue()
                            //Parameters = t.Params.Select(pair => new TimeMeter.EstimationResult.ParameterValue()
                            {
                                Name = pair.Key,
                                InitialValue = pair.Value,
                                NewValue = pair.Value
                            }).ToList(),
                            //}).ToList(),
                        },
                    },
                }).ToList();

            bool sendAllTasks = (Config.AppSettings[SCHEDULE_ALL_TASKS_PARAM_NAME] ?? "false").ToLowerInvariant().Trim() == "true";

            wf.Tasks = tasks
                .Where(t =>
                    (schedulingWfId == null && (t.State == TaskState.ReadyToExecute || t.State == TaskState.Scheduled || (t.State == TaskState.Defined && sendAllTasks))) ||

                    // to plan ahead all tasks in urgent WF, including future ones
                    (t.WfId == schedulingWfId && (t.State == TaskState.ReadyToExecute || t.State == TaskState.Scheduled || t.State == TaskState.Defined))
                )
                .Select(t => new ServiceProxies.SchedulerService.EstimatedTask()
                {
                    WFid = t.WfId,

                    Id = t.TaskId,
                    ApplicationName = (t.Package + (String.IsNullOrWhiteSpace(t.Method) ? "" : "_" + t.Method)).ToUpperInvariant(),

                    Parameters = new Dictionary<string, string>(t.Params),

                    Estimations = estimationsForTask[t.TaskId].Select(pair =>
                        new ServiceProxies.SchedulerService.ResourceEstimation()
                        {
                            Resource = new ServiceProxies.SchedulerService.Resource()
                            //Resource = new Common.Resource()
                            {
                                Name = pair.Key.ResourceName,

                                Nodes = resources.Single(r => r.ResourceName == pair.Key.ResourceName)
                                    .Nodes.Where(n => n.NodeName == pair.Key.NodeName) // note: single node now
                                    .Select(n => new ServiceProxies.SchedulerService.Node()
                                    //.Select(n => new Common.Node()
                                    {
                                        ResourceName = n.ResourceName,
                                        DNSName = n.NodeName,
                                        Parameters = new Dictionary<string, string>(n.StaticHardwareParams),
                                        CoresAvailable = n.CoresAvailable,
                                        CoresTotal = (int)n.CoresCount,
                                    }
                                ).ToList(),

                                Parameters = new Dictionary<string, string>(
                                    resources.Single(r => r.ResourceName == pair.Key.ResourceName).HardwareParams
                                ),
                            },

                            Result = new ServiceProxies.SchedulerService.EstimationResult()
                            //Result = new TimeMeter.EstimationResult(null)
                            {
                                //Time = pair.Value.CalcDuration.TotalSeconds,
                                CalculationTime = pair.Value.CalcDuration.TotalSeconds,
                                Overheads = 0, // todo : overheads estimation for scheduler

                                Parameters = new ServiceProxies.SchedulerService.EstimationResult.ParameterValue[]
                                //Parameters = new List<TimeMeter.EstimationResult.ParameterValue>()
                                {
                                    new ServiceProxies.SchedulerService.EstimationResult.ParameterValue()
                                    //new TimeMeter.EstimationResult.ParameterValue()
                                    {
                                        Name = "P", NewValue = pair.Key.Cores.ToString()
                                    },

                                    new ServiceProxies.SchedulerService.EstimationResult.ParameterValue()
                                    //new TimeMeter.EstimationResult.ParameterValue()
                                    {
                                        Name = "NODES", NewValue = "1" // todo: pair.Key.NodeNames.Count
                                    }
                                }.ToList()
                            }
                        }
                    ).ToList(),

                    /*
                    SuitableDestinations =
                        permittedResourceNames(permissionsForTask[t.TaskId])
                            .Select(resName => new ServiceProxies.SchedulerService.LaunchDestination()
                            {
                                ResourceName = resName,
                                NodeNames    = permittedNodeNames(resName, permissionsForTask[t.TaskId]).ToArray(),
                            })
                            .ToArray(),
                    */
                }).ToList();

            /*
            Resources = resources
                .Select(r => new ServiceProxies.SchedulerService.Resource()
                {
                    Name = r.ResourceName,
                    Nodes = r.Nodes.Select(n => new ServiceProxies.SchedulerService.Node()
                    {
                        DNSName = n.NodeName,
                        ResourceName = n.ResourceName,
                        CoresAvailable = n.CoresAvailable,
                        CoresTotal = n.CoresCount,
                        Parameters = new Dictionary<string, string>(n.StaticHardwareParams), //n.DynamicHardwareParams
                    }).ToArray(),

                    Parameters = new Dictionary<string, string>(r.HardwareParams),
                })
                .ToArray(),
            */

            if (wf.Tasks.Count + wf.ActiveTasks.Count != tasks.Count())
            {
                Log.Warn(String.Format(
                    "Probably error occurred while dividing tasks to active and non-active for Scheduler. " +
                    "{0} tasks ({1}) -> {2} active tasks ({3}) and {4} scheduling tasks ({5})",
                    tasks.Count(), String.Join(", ", tasks.Select(t => t.TaskId.ToString())),
                    wf.ActiveTasks.Count, String.Join(", ", wf.ActiveTasks.Select(t => t.Id.ToString())),
                    wf.Tasks.Count, String.Join(", ", wf.Tasks.Select(t => t.Id.ToString()))
                ));
            }
        }
Esempio n. 11
0
        public async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> argument)
        {
            var message = await argument;
            // First send typing
            var typingActivity = ((Activity)message).CreateReply();

            typingActivity.Type = ActivityTypes.Typing;
            await context.PostAsync(typingActivity);

            LuisResponse luisInfo = await ServiceProxies.GetEntityFromLUIS(message.Text);

            if (luisInfo.intents != null && luisInfo.intents.Length > 0 && luisInfo.intents[0].score > 0.8 && luisInfo.intents[0].intent == "Kreditablösen")
            {
                // Kredit
                await context.PostAsync("Wollen Sie die Kreditablösesumme jetzt anfordern?");

                context.Wait(this.StartKreditAblöseDialog);
            }
            //else if (luisInfo.intents != null && luisInfo.intents.Length > 0 && luisInfo.intents[0].score > 0.8 && luisInfo.intents[0].intent == "Wikipedia")
            //{
            //    // Wikipedia
            //    string answer = "Das weiß ich nicht, ich lerne noch..";
            //    string wikiResult = await ServiceProxies.SearchWikipedia(luisInfo.entities[0].entity);

            //    Newtonsoft.Json.Linq.JArray jsonResult = JArray.Parse(wikiResult);
            //    JArray titleArray = (JArray)jsonResult[1];
            //    JArray descriptionArray = (JArray)jsonResult[2];
            //    JArray linkArray = (JArray)jsonResult[3];

            //    if (titleArray.Count > 0)
            //    {
            //        answer = "Ich kenne mich nicht so aus, aber hier sind Infos von Wikipedia: " + titleArray[0].ToString() + ". " + descriptionArray[0].ToString();
            //    }

            //    await context.PostAsync(answer);
            //    context.Wait(MessageReceivedAsync);
            //}
            else
            {
                // Fall back on QnAMaker
                QnAResponse response = await ServiceProxies.GetQnAResponse(message.Text);

                string answer = "Das weiß ich nicht, ich lerne noch..";

                if (response.answers.Length > 0 && response.answers[0].score > 0.7)
                {
                    if (smalltalkData[response.answers[0].answer] != null)
                    {
                        // Get random answer from array
                        int index = randomGen.Next(0, ((JArray)smalltalkData[response.answers[0].answer]).Count - 1);
                        answer = smalltalkData[response.answers[0].answer][index].ToString();
                    }
                    else if (!response.answers[0].answer.Contains(".agent."))
                    {
                        answer = response.answers[0].answer;
                    }
                    else
                    {
                        System.Diagnostics.Trace.TraceError("MISSING-ANSWER: " + message.Text);
                    }
                }
                else
                {
                    System.Diagnostics.Trace.TraceError("MISSING-ANSWER: " + message.Text);
                }

                await context.PostAsync(answer);

                context.Wait(MessageReceivedAsync);
            }
        }