Exemplo n.º 1
0
        internal static AMessage Get(this List<AMessage> status, Person psn)
        {
            //## 模擬失敗可能性。
            if (ServiceSimulator.FAIL_RISE)
                throw ServiceSimulator.NewFailException("statusUpdates.GetMessage FAIL!");

            return status.Where(c => c.sender == psn).FirstOrDefault();
        }
Exemplo n.º 2
0
        internal static Person[] Get(this List<Person> friends, Person me)
        {
            ////## 模擬失敗可能性。
            //if (ServiceSimulator.FAIL_RISE)
            //    throw ServiceSimulator.NewFailException("friends.GetFriends FAIL!");

            Person thePerson = friends.Where(c => c.Name == me.Name).FirstOrDefault();
            if (thePerson == null)
                return null;
            // else
            return thePerson.GetFriends();
        }
Exemplo n.º 3
0
        private void InitTestData()
        {
            // had initialized.
            if (friends != null) return;

            #region init. friends

            // 定義所有人
            Person Alen   = new Person("Alan", "Taipei");
            Person Ben    = new Person("Ben", "Taipei");
            Person Colin = new Person("Colin", "Taipei");
            Person Daniel = new Person("Daniel", "New York");
            Person Edwin = new Person("Edwin", "New York");
            //
            Person Fiona = new Person("Fiona", "Taipei");
            Person Grace = new Person("Grace", "Taipei");
            Person Hebe  = new Person("Hebe", "Taipei");
            Person Ivy = new Person("Ivy", "New York");
            Person Jean = new Person("Jean", "New York");
            //
            Person Ken   = new Person("Ken", "Taipei");
            Person Lee   = new Person("Lee", "Taipei");
            Person Mark  = new Person("Mark", "Taipei");
            Person Neil = new Person("Neil", "New York");
            Person Oscar = new Person("Oscar", "New York");
            //
            Person Peggy    = new Person("Peggy", "Taipei");
            Person Quentian = new Person("Quentian", "Taipei");
            Person Rose     = new Person("Rose", "Taipei");
            Person Sandy = new Person("Sandy", "New York");
            Person Tina = new Person("Tina", "New York");
            //
            Person Upton   = new Person("Upton", "Taipei");
            Person Van     = new Person("Van", "Taipei");
            Person William = new Person("William", "Taipei");
            Person Xavier  = new Person("Xavier", "Taipei");
            Person York = new Person("York", "New York");
            Person Ziv = new Person("Ziv", "New York");

            // 互加好友
            Alen.AddFriend(Ben, Colin, Daniel, Edwin);
            Fiona.AddFriend(Grace, Hebe, Ivy, Jean);
            Ken.AddFriend(Lee, Mark, Neil, Oscar);
            Peggy.AddFriend(Quentian, Rose, Sandy, Tina);
            Upton.AddFriend(Van, William, Xavier, York, Ziv);

            // 存入數據庫
            friends = new List<Person>();
            friends.AddRange(new Person[] {
                Alen, Ben, Colin, Daniel, Edwin,
                Fiona, Grace, Hebe, Ivy, Jean,
                Ken, Lee, Mark, Neil, Oscar,
                Peggy, Quentian, Rose, Sandy, Tina,
                Upton, Van, William, Xavier, York, Ziv
            });

            #endregion of init. friends

            #region 留下一些訊息
            statusUpdates = new List<AMessage>();
            statusUpdates.Add(new AMessage(Alen, "Hi, I am Alen."));
            statusUpdates.Add(new AMessage(Alen, "Today is my day."));
            statusUpdates.Add(new AMessage(Ben, "Hi, I am Ben."));
            statusUpdates.Add(new AMessage(Ben, "Today is my day."));
            statusUpdates.Add(new AMessage(Colin, "Hi, I am Colin."));
            statusUpdates.Add(new AMessage(Colin, "Today is my day."));
            statusUpdates.Add(new AMessage(Daniel, "Hi, I am Daniel."));
            statusUpdates.Add(new AMessage(Daniel, "Today is my day."));
            statusUpdates.Add(new AMessage(Edwin, "Hi, I am Edwin."));
            statusUpdates.Add(new AMessage(Edwin, "Today is my day."));
            statusUpdates.Add(new AMessage(Fiona, "Hi, I am Fiona."));
            statusUpdates.Add(new AMessage(Fiona, "Today is my day."));
            statusUpdates.Add(new AMessage(Grace, "Hi, I am Grace."));
            statusUpdates.Add(new AMessage(Grace, "Today is my day."));
            statusUpdates.Add(new AMessage(Hebe, "Hi, I am Hebe."));
            statusUpdates.Add(new AMessage(Hebe, "Today is my day."));
            statusUpdates.Add(new AMessage(Ivy, "Hi, I am Ivy."));
            statusUpdates.Add(new AMessage(Ivy, "Today is my day."));
            statusUpdates.Add(new AMessage(Jean, "Hi, I am Jean."));
            statusUpdates.Add(new AMessage(Jean, "Today is my day."));
            #endregion
        }
Exemplo n.º 4
0
 public void SendMessage(Person target, string message, string protocol)
 {
     SendMessage(target.Name, message, protocol);
 }
Exemplo n.º 5
0
 public void SendEventInvite(Person me, Func<string, bool> isValid, string message)
 {
     foreach(Person friend in friends.Get(me))
     {
         AspectW.Define
             .OnLeave(() => _logger.WriteLine("Done"))
             .Retry<DataException>(3000, 5,
                 (ex)=> RefreshAddress(friend), // recovery action
                 (ex)=> _logger.WriteLine("5 retries failed")) // fail action
             .TraceException((ex) => _logger.WriteLine("CATCH@L1<{0}> : {1}", ex.GetType().Name, ex.Message))
             .Do(()=>
             {
                 string address = friend.GetAddress();
                 string protocol = "HTTPS";
                 AspectW.Define
                     .WhenTrue(isValid(address))
                     .RetryParam<ApplicationException>(3000, ()=> protocol="HTTP" )
                     .TraceException((ex) => _logger.WriteLine("CATCH@L2<{0}> : {1}", ex.GetType().Name, ex.Message))
                     .Do(()=>
                         SendMessage(friend, message, protocol)
                     );
             });
     }
 }
Exemplo n.º 6
0
        public void RefreshAddress(Person psn)
        {
            // 先假設一定成功

            // success
            _logger.Write(string.Format("[{0:HH:mm:ss}] ", DateTime.Now));
            _logger.WriteLine(string.Format("RefreshAddress({0})", psn.Name));
        }
Exemplo n.º 7
0
 public AMessage(Person _person, string _message)
 {
     sender = _person;
     message = _message;
     timeStamp = DateTime.Now;
 }