Exemplo n.º 1
0
 public override Wisdom EnlightMe(Question question)
 {
     using (var guruClient = new GuruClient())
     {
         var result = guruClient.EnlightMe(question);
         return result;
     }
 }
Exemplo n.º 2
0
 public override Wisdom EnlightMe(Question question)
 {
     DateTime startOfEnlightning = DateTime.Now;
     Think();
     var result = new Wisdom { By = PresentYourSelf(), Question = question, Answer = new Answer { Content = getAnswerContent() } };
     DateTime endOfEnlightning = DateTime.Now;
     result.ThinkTime = endOfEnlightning - startOfEnlightning;
     return result;
 }
Exemplo n.º 3
0
 public override Wisdom EnlightMe(Question question)
 {
     var result = WisdomDataAccessFind.Find(question);
     if (result == null)
     {
         m_log.Debug("WisdomDataAccessFind didn't find an answer. Asking the RealGuru");
         result = RealGuru.EnlightMe(question);
         WisdomDataAccessSave.Save(result);
     }
     return result;
 }
Exemplo n.º 4
0
        public virtual Wisdom GetWisdom(Question question)
        {
            Wisdom result = null;
            Locked.DoLocked(
                () =>
                {
                    if (MinAddLockMillis > 0)
                    {
                        int sleepMillis = Random.Next(MinGetLockMillis, MaxGetLockMillis);
                        m_log.Debug(string.Format("GetWisdom --> sleeping for {0} millis", sleepMillis));
                        Thread.Sleep(sleepMillis);
                    }
                    question = new Question { Content = question.Content.ToLower() };
                    if (m_store.ContainsKey(question))
                    {
                        result = m_store[question];
                    }

                });
            return result;
        }
Exemplo n.º 5
0
 public WisdomViewModel EnlightMe(Question question)
 {
     BeginWork();
     bool failed = false;
     try
     {
         var startedAt = DateTime.Now;
         var wisdomViewModel = new WisdomViewModel(this, Guru.EnlightMe(question), startedAt);
         return wisdomViewModel;
     }
     catch (Exception)
     {
         failed = true;
         throw;
     }
     finally
     {
         EndWork(failed);
     }
 }
Exemplo n.º 6
0
 public abstract Wisdom EnlightMe(Question question);
 public Wisdom Find(Question question)
 {
     var result = Store.GetWisdom(question);
     return result;
 }
Exemplo n.º 8
0
 private void AskAllGurusAQuestion(Question question, int numberOfTimes, bool askInParallel)
 {
     m_log.Debug(string.Format("AskAllGurusAQuestion, {0}times, in parallel {1}", numberOfTimes, askInParallel));
     for (var i = 0; i < numberOfTimes; i++)
     {
         foreach (var guruViewModel in GuruViewModels)
         {
             if (askInParallel)
             {
                 var localGuruViewModel = guruViewModel;
                 Task.Factory.StartNew(() => AskAGuruAQuestion(localGuruViewModel, question));
             }
             else
             {
                 AskAGuruAQuestion(guruViewModel, question);
             }
         }
     }
 }
Exemplo n.º 9
0
 private void AskAllGurusAQuestion(Question question, int numberOfTimes, bool askInParallel, bool waitForAnswer)
 {
     if (waitForAnswer)
     {
         m_log.Debug("AskAllGurusAQuestion, waitForAnswer");
         AskAllGurusAQuestion(question, numberOfTimes, askInParallel);
     }
     else
     {
         m_log.Debug("AskAllGurusAQuestion, don't waitForAnswer");
         Task.Factory.StartNew(() => AskAllGurusAQuestion(question, numberOfTimes, askInParallel));
     }
 }
Exemplo n.º 10
0
 private void AskAGuruAQuestion(GuruViewModel guruViewModel, Question question)
 {
     try
     {
         var wisdomViewModel = guruViewModel.EnlightMe(question);
         if (CollectWisdom)
         {
             Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => WisdomViewModels.Insert(0, wisdomViewModel)));
         }
     }
     catch (Exception e)
     {
         m_log.Error(string.Format("AskAGuruAQuestion got an exception when asking # {0}: {1} the question {2}", guruViewModel.Nr, guruViewModel.Nick, question), e);
     }
 }
Exemplo n.º 11
0
 public override Wisdom EnlightMe(Question question)
 {
     var result = m_realGuru.EnlightMe(question);
     return result;
 }