public static void Create(TblMetaqueriesResult tblMetaqueryResult)
 {
     using (MetaqueriesContext context = new MetaqueriesContext())
     {
         context.TblMetaqueriesResults.Add(tblMetaqueryResult);
         context.MarkAsCreated(tblMetaqueryResult);
         context.SaveChanges();
     }
 }
        public static void SendAssignmentMail(TblMetaqueriesResult tblMetaqueriesResult, string strMetaquery)
        {
            string subject = string.Format("There is a result for Metaquery {0}", tblMetaqueriesResult.FkMetaqueryId);

            /*string strMsgBody =
             *                                                      @"Metaquery ID: {0}<br\>" +
             *                                                      @"Metaquery: {1}<br\>" +
             *                                                      @"Assignment: {2}<br\>" +
             *                                                      @"Support Value: {3}<br\>" +
             *                                                      @"Confidence Value: {4}<br\>";
             */
            string body = string.Format(GetStringHtmlMessage("MQAssignmentResult.html")
                                        , tblMetaqueriesResult.FkMetaqueryId, strMetaquery, tblMetaqueriesResult.Assignment, tblMetaqueriesResult.SupportValue, tblMetaqueriesResult.ConfidenceValue);

            MailHelper.SendHtmlMailAsync(subject, body);
        }
Esempio n. 3
0
        public static void OnGetMessageFromSolver(string strMessage)
        {
            MQMessage message = null;

            if (strMessage.Contains("Result"))            //strMessage is MQResultMessage
            {
                message = JsonConvert.DeserializeObject <MQResultMessage>(strMessage);
            }
            else             //strMessage is MQAssignmentResultMessage
            {
                message = JsonConvert.DeserializeObject <MQAssignmentResultMessage>(strMessage);
            }

            int          metaqueryID  = message.ID;
            TblMetaquery tblMetaquery = MetaqueryDS.GetByID(metaqueryID);

            try
            {
                if (tblMetaquery == null)
                {
                    throw new UnknownMetaqueryException(string.Format("There is an unknown metaquery id sent from solver. message id: {0}. MQ Solver message :", metaqueryID, message.ToString()));
                }

                if (message is MQResultMessage)
                {
                    MQResultMessage resultMessage = message as MQResultMessage;
                    tblMetaquery.FkResult = (int)resultMessage.Result;
                    StatusMQ statusMQ = (tblMetaquery.IsExpanded || tblMetaquery.Arity == tblMetaquery.TblDatabaseManagement.MaxArity ? StatusMQ.Done : StatusMQ.WaitingToExpand);
                    MetaqueryDS.UpdateStatus(tblMetaquery, statusMQ);
                    bool execSendMail = bool.Parse(ConfigurationManager.AppSettings["ExecSendMail"]);
                    if (execSendMail)
                    {
                        MQGeneratorMail.SendResultMail(tblMetaquery);
                    }

                    if (MQGenerator.IsAutoRunJobs)
                    {
                        if (statusMQ == StatusMQ.WaitingToExpand)
                        {
                            MQGenerator.StartExpandMQProcess();
                        }
                        else if (statusMQ == StatusMQ.Done)
                        {
                            MQGenerator.StartIncreaseDBArity();
                        }
                    }
                }
                else if (message is MQAssignmentResultMessage)
                {
                    MQAssignmentResultMessage assignmentResultMessage = message as MQAssignmentResultMessage;
                    TblMetaqueriesResult      tblMetaqueriesResult    = new TblMetaqueriesResult()
                    {
                        FkMetaqueryId   = metaqueryID,
                        Assignment      = assignmentResultMessage.Assignment,
                        ConfidenceValue = assignmentResultMessage.ConfidenceValue,
                        SupportValue    = assignmentResultMessage.SupportValue
                    };
                    MetaqueryResultDS.Create(tblMetaqueriesResult);

                    bool execSendMail = bool.Parse(ConfigurationManager.AppSettings["ExecSendMail"]);
                    if (execSendMail)
                    {
                        MQGeneratorMail.SendAssignmentMail(tblMetaqueriesResult, tblMetaquery.Metaquery);
                    }
                    if (MQGenerator.IsAutoRunJobs && !tblMetaquery.IsExpanded)
                    {
                        MQGenerator.StartExpandMQProcess();
                    }
                }
                else
                {
                    throw new UnknownMetaqueryException("There is an unknown metaquery sent from solver. MQ Solver message :" + message.ToString());
                }
            }
            catch (Exception ex)
            {
                MQGeneratorMail.SendExceptionMail(ex);
            }
        }