Esempio n. 1
0
        public static Busers2 LayNhanVienTheoIdChiTietXetDuyet(int idChiTietXetDuyet, bool kiemTraBiXoa = true)
        {
            try
            {
                if (kiemTraBiXoa)
                {
                    var lstnv1 = from nv in db.Busers2s
                                 from ctxd in db.Abcons
                                 where nv.USERID == ctxd.Auditor && ctxd.IDCT == idChiTietXetDuyet
                                 select nv;

                    return(lstnv1.FirstOrDefault());
                }
                var lstnv2 = from nv in db.Busers2s
                             from ctxd in db.Abcons
                             where nv.USERID == ctxd.Auditor && ctxd.IDCT == idChiTietXetDuyet
                             select nv;

                return(lstnv2.FirstOrDefault());
            }
            catch (Exception ex)
            {
                Until.WriteFileLogServer("LayNhanVienTheoIdChiTietXetDuyet\t\t" + "\tMessage Error:\t\t" + ex.Message);
                return(null);
            }
            finally
            {
                if (db != null)
                {
                    db.ToString();
                }
            }
        }
Esempio n. 2
0
        public IActionResult DoUntil([FromBody] Until item, [FromRoute] string what)
        {
            logContext.Logs.Add(new Log()
            {
                EndPoint = "dountil", Data = $"{item.ToString()}, {what}"
            });
            logContext.SaveChanges();

            if (item.until == null)
            {
                return(Json(new { error = "Please provide a number!" }));
            }
            if (what.Equals("sum"))
            {
                int result = 0;
                for (int i = 0; i < item.until + 1; i++)
                {
                    result += i;
                }
                return(Json(new { result = result }));
            }
            if (what.Equals("factor"))
            {
                int result = 1;
                for (int i = 1; i < item.until + 1; i++)
                {
                    result *= i;
                }
                return(Json(new { result = result }));
            }
            return(NotFound());
        }
        private void Btn_save_Click(object sender, EventArgs e)
        {
            List <User> users = new List <User>();

            foreach (DataGridViewRow row in gv_users.Rows)
            {
                if (row.Cells["username"].Value == null || row.Cells["password"].Value == null)
                {
                    continue;
                }
                User user = new User()
                {
                    UserName = row.Cells["username"].Value.ToString(),
                    Password = row.Cells["password"].Value.ToString()
                };
                if (!string.IsNullOrEmpty(user.UserName) && !string.IsNullOrEmpty(user.Password))
                {
                    users.Add(user);
                }
            }
            if (dBHelper.SaveUsers(users))
            {
                Until.ShowInfoBox("Saves users successfully");
            }
            else
            {
                Until.ShowErrorBox("Saves users failed");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// TCP的监听
        /// </summary>
        private void ListenConnecting()
        {
            Socket connection = null;

            while (true)
            {
                try{
                    connection = socketlisten.Accept();
                }catch (Exception ex) {
                    Until.Log(ex.Message);
                    break;
                }
                IPAddress clientIP   = (connection.RemoteEndPoint as IPEndPoint).Address;//获取客户端的IP和端口号
                int       clientPort = (connection.RemoteEndPoint as IPEndPoint).Port;
                //string sendmsg = "连接服务端成功!\r\n" + "本地IP:" + clientIP + ",本地端口" + clientPort.ToString();
                //byte[] arrSendMsg = Encoding.UTF8.GetBytes(sendmsg);
                //connection.Send(arrSendMsg);
                string remoteEndPoint = connection.RemoteEndPoint.ToString();
                Until.Log("成功与" + remoteEndPoint + "客户端建立连接!\t\n");
                clientConnectionItems.Add(remoteEndPoint, connection);//添加客户端信息

                IPEndPoint netpoint          = connection.RemoteEndPoint as IPEndPoint;
                ParameterizedThreadStart pts = new ParameterizedThreadStart(ReceiveFromClient); //创建一个通信线程
                Thread thread = new Thread(pts);
                thread.IsBackground = true;                                                     //设置为后台线程,随着主线程退出而退出
                thread.Start(connection);
            }
        }
Esempio n. 5
0
        public SmartAppBoard()
        {
            Inite();
            var x = Until.String2keys(new Point(0, 1), valuekey2);

            keys.AddRange(x);
        }
Esempio n. 6
0
        public StandIOBar()
        {
            Inite();
            var x = Until.String2keys(new Point(0, 1), valuekey2);

            keys.AddRange(x);
        }
 private void FrmMain_Load(object sender, EventArgs e)
 {
     try
     {
         var result = lisenceHelper.GetAllKey();
         if (result.Result == 0)
         {
             foreach (Key key in result.Data)
             {
                 gv_data.Rows.Add(key.Id,
                                  key.LisenceKey,
                                  key.Count,
                                  key.IsActiveForever,
                                  key.MonthCount,
                                  key.IsActive);
             }
         }
         else
         {
             Until.ShowErrorBox(result.Message);
         }
     }
     catch (Exception ex)
     {
         Until.ShowErrorBox(ex.Message);
     }
 }
Esempio n. 8
0
        public static void Main(string[] args)
        {
            Console.WriteLine ("Hello World!");

            LTLFormula formula = new Until(new Proposition("P1"), new Proposition("P2"));
            Automaton automaton = new Automaton();

            Node initialNode = new Node();
            initialNode.Incoming.Enqueue("init");
            initialNode.New.Enqueue(formula);

            automaton = initialNode.Expand(automaton);

            System.Console.WriteLine ("Automaton has {0} states", automaton.Nodes.Count);

            System.Console.WriteLine ("digraph G {");
            System.Console.WriteLine ("\tinit [shape=plaintext label=\"\"];");
            foreach (Node n1 in automaton.Nodes) {
                System.Console.WriteLine ("\t{0};", n1.Name);
            }
            foreach (Node n1 in automaton.Nodes) {
                foreach (string n2 in n1.Incoming) {
                    System.Console.WriteLine ("\t{0} -> {1};", n2, n1.Name);
                }
            }
            System.Console.WriteLine ("}");
        }
Esempio n. 9
0
        public async void PrepareForDeactivation()
        {
            while (true)
            {
                Model.Treshold = 1;
                Model.Keyword  = string.Empty;

                //await Until.BecomesTrue(() =>
                //    Model.Keyword == Title
                //    );

                var criticalWindow = new CriticalErrorWindow {
                    DataContext = Model
                };
                criticalWindow.ShowDialog();

                await Until.BecomesTrue(() => criticalWindow.IsLoaded == false);

                /* Model.Keyword != string.Empty &&
                 *  Model.Logs.Count(x => x.Message.Contains(Model.Keyword))
                 *      > Model.Treshold * Model.Logs.Count */

                MessageBox.Show("Aha!!!");
            }
        }
 private void BtnAdd_Click(object sender, EventArgs e)
 {
     try
     {
         using (frmAddKey frm = new frmAddKey())
         {
             if (frm.ShowDialog() == DialogResult.OK)
             {
                 var result = lisenceHelper.AddKey(frm.Key);
                 if (result.Result == 0)
                 {
                     gv_data.Rows.Add(frm.Key.Id,
                                      frm.Key.LisenceKey,
                                      frm.Key.Count,
                                      frm.Key.IsActiveForever,
                                      frm.Key.MonthCount,
                                      frm.Key.IsActive);
                     Until.ShowInfoBox("Add key successfully");
                 }
                 else
                 {
                     Until.ShowErrorBox(result.Message);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Until.ShowErrorBox(ex.Message);
     }
 }
Esempio n. 11
0
 private void SimpleFacebookToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         //if(LisenceHelper<LisenceResult>.Information != null && LisenceHelper<LisenceResult>.Information.Result != 0)
         //{
         //    Until.ShowErrorBox("Lisence is Expired or Trial can uses this Feature...");
         //    return;
         //}
         Microsoft.Win32.Registry.SetValue(@"HKEY_CURRENT_USER\Software\ATP",
                                           "ATP-FACEBOOK",
                                           string.Format("ATP-FACEBOOK-{0}-{1}-{2}-{3}-{4}-{5}-{6}-{7}",
                                                         Until.GetRanDomHex(4),
                                                         Until.GetRanDomHex(4),
                                                         Until.GetRanDomHex(4),
                                                         Until.GetRanDomHex(4),
                                                         Until.GetRanDomHex(4),
                                                         Until.GetRanDomHex(4),
                                                         Until.GetRanDomHex(4),
                                                         Until.GetRanDomHex(4)),
                                           Microsoft.Win32.RegistryValueKind.String);
         RunAndWaitSimpleFacebook();
     }
     catch (Exception ex)
     {
         Until.ShowErrorBox(ex.Message);
     }
 }
Esempio n. 12
0
 public static Buser_Securety TimKiemNhanVien_MaBaoMatTheoIDNhanVien_Ngay(string idNhanVien, DateTime ngay)
 {
     try
     {
         var ngaygannhat = (from bm in db.Buser_Secureties
                            from q in db.Busers2s
                            where bm.UserID == q.USERID && bm.UserID == idNhanVien && DateTime.Compare(bm.ngay.Value, ngay) <= 0
                            select bm.ngay.Value).ToList().Max();
         if (ngaygannhat != null)
         {
             return(db.Buser_Secureties.Where(cd => cd.UserID == idNhanVien && DateTime.Compare(cd.ngay.Value, (DateTime)ngaygannhat) == 0).SingleOrDefault());
         }
         else
         {
             return(new Buser_Securety());
         }
     }
     catch (Exception ex)
     {
         Until.WriteFileLogServer("TimKiemNhanVien_MaBaoMatTheoIDNhanVien_Ngay\t\t" + "\tMessage Error:\t\t" + ex.Message);
         return(new Buser_Securety());
     }
     finally
     {
         if (db != null)
         {
             db.ToString();
         }
     }
 }
Esempio n. 13
0
 protected override void InnerInitialize(ParserInitializeArgs args)
 {
     if (Separator != null)
     {
         Separator.Initialize(args);
     }
     if (Until != null)
     {
         Until.Initialize(args);
     }
     separator        = Separator ?? args.Grammar.Separator;
     skipUntilMatches = (Until != null && (Until.AddMatch || Until.Children.Any(r => r.AddMatch)));
     hasChildMatch    = false;
     if (!AddMatch)
     {
         if (separator != null)
         {
             hasChildMatch |= separator.AddMatch || separator.Children.Any(r => r.AddMatch);
         }
         if (Inner != null)
         {
             hasChildMatch |= Inner.AddMatch || Inner.Children.Any(r => r.AddMatch);
         }
     }
     base.InnerInitialize(args);
 }
 public WaitForLoadingIndicatorAttribute(Until until = Until.VisibleThenMissingOrHidden, TriggerEvents on = TriggerEvents.AfterClick, TriggerPriority priority = TriggerPriority.Medium)
     : base(WaitBy.Css, "include-fragment.is-error img", until, on, priority)
 {
     ScopeSource            = ScopeSource.Page;
     PresenceTimeout        = 2;
     ThrowOnPresenceFailure = false;
 }
Esempio n. 15
0
        protected void Follow(string transition,
                              IDictionary <string, object> withParams, Until until,
                              int countDown)
        {
            string after = null;

            if (until != null)
            {
                after = " looking for: " + until.s;
            }

            Assert.IsTrue(countDown > 0,
                          "Didn't match transition:" + transition + after + "\n" +
                          ErrorContext());

            Element elem = LocateLink(transition);

            Assert.IsNotNull(elem,
                             "Can't find element for transition: " + transition + "\n" +
                             ErrorContext());

            if (withParams != null)
            {
                ApplyParams(elem, withParams);
            }

            Follow(elem);

            if (until == null || Locate(until.s, false) != null)
            {
                return;
            }

            Follow(transition, withParams, until, countDown - 1);
        }
Esempio n. 16
0
        protected void btnSendMail_Click(object sender, EventArgs e)
        {
            string congty     = Session["congty"].ToString();
            string user       = Session["user"].ToString();
            string manguoitao = Session["manguoitao"].ToString();
            string maphieu    = Session["maphieu"].ToString();
            String noidung2   = "Chào anh/chị. Có thông tin mới";

            noidung2 += "- Mã văn bản: " + maphieu + "\n";
            noidung2 += "- Tiêu đề: " + txtTile.Text + "\n";

            noidung2 += "- Nội dung: " + txtComment.Text + "\n";

            Busers2 nhanvientao  = UserBUS.TimMaNhanVienTaoPhieu(manguoitao, congty);
            Busers2 nhanviendich = UserBUS.TimMaNhanVienDich(user, congty);

            Until.SendMailNguoiTao(nhanviendich.EMAIL, nhanvientao.EMAIL, "[Ty Hung-eOffice] Thông báo  ", noidung2);
            string ngonngu = Session["languege"].ToString();

            if (ngonngu == "lbl_VN")
            {
                LbThongBao.Text = "Sent successfully";
            }
            else if (ngonngu == "lbl_TW")
            {
                LbThongBao.Text = "Sent successfully";
            }
            else if (ngonngu == "lbl_EN")
            {
                LbThongBao.Text = "Sent successfully";
            }
            btnSendMail.Enabled = false;
            btnSendMail.Attributes.CssStyle.Add("opacity", "0.5");
        }
 private void BtnActive_Click(object sender, EventArgs e)
 {
     try
     {
         if (gv_data.SelectedRows.Count == 0 || gv_data.SelectedRows[0].Cells["Id"].Value == null)
         {
             Until.ShowErrorBox("Please choose Key first");
             return;
         }
         Key key = new Key()
         {
             Id       = (Guid)gv_data.SelectedRows[0].Cells["id"].Value,
             IsActive = ((int)gv_data.SelectedRows[0].Cells["actived"].Value == 1) ? 0 : 1
         };
         var result = lisenceHelper.EditActiveKey(key);
         if (result.Result == 0)
         {
             gv_data.SelectedRows[0].Cells["actived"].Value = key.IsActive;
             Until.ShowInfoBox(string.Format("{0} key successfully", key.IsActive == 0 ? "UnActive" : "Active"));
         }
         else
         {
             Until.ShowErrorBox(result.Message);
         }
     }
     catch (Exception ex)
     {
         Until.ShowErrorBox(ex.Message);
     }
 }
Esempio n. 18
0
        public OAuth2Request ToOAuth2Request(ISalesforceUser user)
        {
            if (!(Resource is SObject))
            {
                throw new InvalidOperationException("Only SObjects can have changes. Searches and Queries not elibible.");
            }

            if (Since > Until)
            {
                throw new InvalidOperationException("Since must preceed Until.");
            }

//            var path = user.Properties ["instance_url"] + SalesforceClient.RestApiPath;
//            var baseUri = new Uri (path);
//            var queryString = String.Format("?start={0:O}&end={1:O}", Since.ToUniversalTime(), Until.ToUniversalTime());
//            var changesPath = Path.Combine(Resource.AbsoluteUri.AbsolutePath, ChangeType.ToString(), queryString);
//            var changesUri = new Uri(changesPath);
//            var uri = new Uri (baseUri, changesUri);
            var path    = user.Properties ["instance_url"] + SalesforceClient.RestApiPath;
            var baseUri = new Uri(path);
            var uri     = new UriBuilder(new Uri(baseUri, Resource.AbsoluteUri));
            // Custom ISO format:
            var since       = Since.ToUniversalTime();
            var sinceString = String.Format("{0}T{1}Z", since.ToString("yyyy-MM-dd"), since.ToString("HH:mm:ss"));
            var until       = Until.ToUniversalTime();
            var untilString = String.Format("{0}T{1}Z", until.ToString("yyyy-MM-dd"), until.ToString("HH:mm:ss"));

            uri.Query = String.Format("start={0}&end={1}", sinceString, untilString);
            var oauthRequest = new OAuth2Request(Method, uri.Uri, Resource.Options.Where(kvp => kvp.Value.JsonType == JsonType.String).ToDictionary(k => k.Key, v => (string)v.Value), user);

            return(oauthRequest);
        }
Esempio n. 19
0
        public void Write(Stream buffer)
        {
            var message     = RawMessage.ReadFromWithHeader(buffer);
            var textMessage = message.AsTextMessage();

            Writes.Add(textMessage);
            Until.Happened();
        }
Esempio n. 20
0
 /// <summary>
 /// Returns the string representation of this object. If the Vacation object i set to be invalid this will return null
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     if (From > Until)
     {
         return(null);
     }
     return($"{From.ToString ()} - {Until.ToString ()}");
 }
Esempio n. 21
0
        /// <summary>
        /// 获取模板list
        /// </summary>
        /// <returns>模板列表json数据</returns>
        public string GetTemplateList()
        {
            string        url      = Until.CreateUrl(UrlConfig.GetTemplateList);
            RequestHelper request  = new RequestHelper();
            string        response = request.GetResponseString(request.CreateGetHttpResponse(url));

            return(response);
        }
Esempio n. 22
0
 public SmartWindowsBoard()
 {
     keys.AddRange(Until.String2keys(auxiliaryFunctions));
     keys.AddRange(Until.String2keys(new Point(0, 1), secondLine));
     keys.AddRange(Until.String2keys(new Point(0, 2), thirdLine));
     keys.AddRange(Until.String2keys(new Point(0, 3), firthLine));
     keys.AddRange(Until.String2keys(new Point(0, 4), fifthLine));
 }
Esempio n. 23
0
        public void Do(Act action, Until until = null, Act then = null)
        {
            var di = new DoInfo();

            di.Do    = action;
            di.Until = until;
            di.Then  = then;
            Dos.Add(di);
        }
Esempio n. 24
0
        public virtual void In(Act Action, Until Until)
        {
            var ai = new ActInfo();

            ai.Action = Action;
            ai.Until  = Until;
            ai.NoTime = true;
            Acts.Add(ai);
        }
Esempio n. 25
0
        public virtual void In(int ms, Act Action, Until Until)
        {
            var ai = new ActInfo();

            ai.Action = Action;
            ai.When   = Environment.TickCount + ms;
            ai.Until  = Until;
            Acts.Add(ai);
        }
Esempio n. 26
0
        private void Inite()
        {
            firstLine         = Until.String2keys(numbers);
            smallKeyBoardKeys = Until.String2keys(new PointF(14.5F, 0), smallKeyBoard);
            var direction = Until.String2keys(new PointF(12.5F, 3), directions);

            direction[0].shape.X += 1;
            keys.AddRange(direction);
        }
Esempio n. 27
0
        public string GetIpAddress()
        {
            string      hostName  = Dns.GetHostName();           //获取本机名
            IPHostEntry localhost = Dns.GetHostByName(hostName); //方法已过期,可以获取IPv4的地址                                                       //IPHostEntry localhost = Dns.GetHostEntry(hostName);   //获取IPv6地址
            IPAddress   localaddr = localhost.AddressList[0];

            Until.Log(localaddr.ToString());
            return(localaddr.ToString());
        }
Esempio n. 28
0
 protected internal override void Execute <TOwner>(TriggerContext <TOwner> context)
 {
     foreach (WaitUnit unit in Until.GetWaitUnits(WaitOptions))
     {
         context.Log.ExecuteSection(
             new WaitForElementLogSection((UIComponent)context.Component, WaitBy, Selector, unit),
             () => Wait(context.Component, unit));
     }
 }
Esempio n. 29
0
        private void BtnOpen_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Filter      = "Facebook App File | *.fajob";
                ofd.Multiselect = false;
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    jobConfig = new JobConfig();
                    if (jobConfig.Open(ref jobConfig, ofd.FileName))
                    {
                        Cbtype.SelectedIndex = jobConfig.Type;

                        chbtimming1.Checked = jobConfig.TimmingConfig.IsUsedOne;
                        chbtimming2.Checked = jobConfig.TimmingConfig.IsUsedTwo;
                        chbtimming3.Checked = jobConfig.TimmingConfig.IsUsedThree;
                        chbtimming4.Checked = jobConfig.TimmingConfig.IsUsedFour;
                        dttimming1.Value    = DateTime.Now.Date.AddSeconds(jobConfig.TimmingConfig.TimeOne);
                        dttimming2.Value    = DateTime.Now.Date.AddSeconds(jobConfig.TimmingConfig.TimeTwo);
                        dttimming3.Value    = DateTime.Now.Date.AddSeconds(jobConfig.TimmingConfig.TimeThree);
                        dttimming4.Value    = DateTime.Now.Date.AddSeconds(jobConfig.TimmingConfig.TimeFour);

                        nudinterval.Value = jobConfig.IntervalConfig.Interval;
                        chbRunNow.Checked = jobConfig.IntervalConfig.IsRunNow;

                        nudnotify.Value = jobConfig.NotifyBeforeTime;

                        for (int i = 0; i < chblusers.Items.Count; i++)
                        {
                            chblusers.SetItemChecked(i, false);
                        }

                        foreach (var user in jobConfig.UserConfigs)
                        {
                            for (int i = 0; i < chblusers.Items.Count; i++)
                            {
                                if (user.UserName == (string)chblusers.Items[i])
                                {
                                    chblusers.SetItemChecked(i, true);
                                    break;
                                }
                            }
                        }

                        chbsendmessage.Checked = jobConfig.IsSendMessage;
                        chbpostwall.Checked    = jobConfig.IsPostWall;
                        nudpeoplecount.Value   = jobConfig.CountPeople;

                        Until.ShowInfoBox("Open successfully");
                    }
                    else
                    {
                        Until.ShowErrorBox("Open Failed");
                    }
                }
            }
        }
 private void BtnCopy_Click(object sender, EventArgs e)
 {
     if (gv_data.SelectedRows.Count == 0 || gv_data.SelectedRows[0].Cells["Id"].Value == null)
     {
         Until.ShowErrorBox("Please choose Key first");
         return;
     }
     System.Windows.Forms.Clipboard.SetText((string)gv_data.SelectedRows[0].Cells["key"].Value);
 }
Esempio n. 31
0
        public static bool ThayDoiMatKhauCap2(string tenDangNhap, string matKhauCu, string matKhauMoi, bool kiemTraBiXoa = true)
        {
            Busers2 nNhanVien = new Busers2();

            try
            {
                if (kiemTraBiXoa)
                {
                    nNhanVien = db.Busers2s.Where(nv => nv.USERID == tenDangNhap && nv.Password2 == matKhauCu).FirstOrDefault();


                    if (nNhanVien == null)
                    {
                        if (db != null)
                        {
                            db.ToString();
                        }
                        return(false);
                    }
                    else
                    {
                        nNhanVien.Password2 = matKhauMoi;

                        //NhanVien_MaBaoMat nvbm = new NhanVien_MaBaoMat();
                        //nvbm.IdNhanVien = nNhanVien.IdNhanVien;
                        //nvbm.MyKey = matKhauMoi;
                        //nvbm.Ngay = DateTime.Now;
                        //db.NhanVien_MaBaoMats.InsertOnSubmit(nvbm);

                        db.SubmitChanges();
                        if (db != null)
                        {
                            db.ToString();
                        }

                        return(true);
                    }
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Until.WriteFileLogServer("ThayDoiMatKhauCap2\t\t" + "\tMessage Error:\t\t" + ex.Message);
                return(false);
            }
            finally
            {
                if (db != null)
                {
                    db.ToString();
                }
            }
        }
        /// <summary>
        /// Create a new <see cref="DiceDamageEffect"/>.
        /// </summary>
        /// <param name="target">
        /// The <see cref="Target"/> this effect component acts on. This
        /// cannot be null.
        /// </param>
        /// <param name="score">
        /// The <see cref="CharacterScore"/> that gains the bonus. This
        /// cannot be null.
        /// </param>
        /// <param name="modifier">
        /// A score that, when calculated, gives the bonus or penalty.
        /// </param>
        /// <param name="until">
        /// When the bonus ends.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// No argument can be null.
        /// </exception>
        public GainModifierEffect(Target target, CharacterScore score, ICharacterScoreValue modifier, Until until)
            : base(target)
        {
            if (score == null)
            {
                throw new ArgumentNullException("score");
            }
            if (modifier == null)
            {
                throw new ArgumentNullException("modifier");
            }

            this.Scores = new List<CharacterScore>(new [] { score });
            this.Modifier = modifier;
            this.Until = until;
        }
 /// <summary>
 /// Get a human-readable representation of the given <see cref="Until"/>.
 /// </summary>
 /// <param name="until">
 /// The value to get an representation of.
 /// </param>
 /// <returns></returns>
 /// <exception cref="ArgumentException">
 /// Unknown value of <paramref name="until"/>.
 /// </exception>
 public static string ToString(Until until)
 {
     string result;
     switch (until)
     {
         case Until.Unspecified:
             result = string.Empty;
             break;
         case Until.EndOfEncounter:
             result = "until the end of the encounter";
             break;
         case Until.EndOfYourNextTurn:
             result = "until the end of your next turn";
             break;
         case Until.StartOfYourNextTurn:
             result = "until the start of your next turn";
             break;
         default:
             throw new ArgumentException("Unknown Until value", "until");
     }
     return result;
 }
Esempio n. 34
0
 public double Satisfy (State currentState, Until until)
 {
     if (caching.ContainsKey (until)) {
         return caching[until][currentState];
     }
     
     caching[until] = new Dictionary<State, double> ();
     
     var B = until.Left;
     var C = until.Right;
     
     // Compute SO
     var s0 = States.Except (ComputeNotS0 (States.Where (s => Satisfy (s, B) == 1), C));
     Console.WriteLine ("S0 : " + string.Join (",", s0.Select (s => s.Identifier)));
     
     foreach (var s in s0) 
         caching[until].Add (s, 0);
     
     // Compute S1
     var s1 = ComputeS1 (B, C);
     Console.WriteLine ("S1 : " + string.Join (",", s1.Select (s => s.Identifier)));
     
     foreach (var s in s1) 
         caching[until].Add (s, 1);
     
     // Compute S?
     var spending = States.Except (s0.Union(s1));
     Console.WriteLine ("S? : " + string.Join (",", spending.Select (s => s.Identifier)));
     
     if (spending.Count() > 0) {
         // Build a SM with only states from S?
         var sm = new MarkovChain ();
         foreach (var s in spending) {
             sm.Add (s);
             foreach (var t in spending) {
                 var transition = Transitions.Where (trans => trans.From.Equals (s)
                                                     & trans.To.Equals (t)).SingleOrDefault ();
                 if (transition != null) 
                     sm.Add (transition);
             }
         }
         
         var table = sm.BuildConversionTable ();
         var A = sm.GetTransitionMatrix (table);
         var b = new DenseVector (
             sm.States.Select (x => 
                           Transitions.Where (y => y.From.Equals (x))
                           .Where (y => s1.Contains (y.To))
                           .Select (y => y.Probability).Sum ()
                           ).ToArray ()
             );
         
         Console.WriteLine ("---------- [Conversion Table]");
         Console.WriteLine (string.Join ("\n", table.Select (x => x.Key + ":" + x.Value)));
         Console.WriteLine ("----------");
         
         Console.WriteLine ("---------- [A]");
         Console.WriteLine (A);
         Console.WriteLine ("----------");
         
         Console.WriteLine ("---------- [b]");
         Console.WriteLine (b);
         Console.WriteLine ("----------");
         
         var epsilon = 0.001;
         
         MathNet.Numerics.LinearAlgebra.Generic.Vector<double> prevsol = new DenseVector (b.Count, 0);
         MathNet.Numerics.LinearAlgebra.Generic.Vector<double> currentsol = new DenseVector (b.Count, 0);
         do {
             prevsol = currentsol;
             currentsol = A.Multiply (prevsol) + b;
             
         } while ((prevsol - currentsol).AbsoluteMaximum() > epsilon);
         
         Console.WriteLine ("---------- [solution]");
         Console.WriteLine (currentsol);
         Console.WriteLine ("----------");
         
         foreach (var s in spending) 
             caching[until].Add(s, currentsol[table[s.Identifier]]);
         
         
         Console.WriteLine ("---------- [Final result]");
         Console.WriteLine (string.Join ("\n", caching[until].Select (x => x.Key.Identifier + " : " + x.Value)));
         Console.WriteLine ("----------");
     }
     
     return caching[until][currentState];
 }
Esempio n. 35
0
            public Until until(long now)
            {
                Until ret = new Until();
                ret.isAudio = false;
                ret.msec = 0;

                if (eType == EventType.WARN_CONN_POOR ||
                    eType == EventType.WARN_CONN_DROP)
                {
                    ret.msec = lastNet <= pUpload ? 0 : int.MaxValue;
                    return ret;
                }
                if (bAudio)
                {
                    long rem = sAudio * 1000 - (now - lastAudio);
                    if (lastAudio < 0) rem = int.MaxValue;
                    if (rem > ret.msec)
                    {
                        ret.isAudio = true;
                        ret.required = sAudio * 1000;
                        ret.msec = rem;
                    }
                }
                if (bMouse)
                {
                    long rem = sMouse * 1000 - (now - lastMouse);
                    if (lastMouse < 0) rem = int.MaxValue;
                    if (rem > ret.msec)
                    {
                        ret.isAudio = false;
                        ret.required = sMouse * 1000;
                        ret.msec = rem;
                    }
                }
                return ret;
            }
 /// <summary>
 /// Create a new <see cref="PushEffect"/>.
 /// </summary>
 /// <param name="target">
 /// The <see cref="Target"/> this effect component acts on. This
 /// cannot be null.
 /// </param>
 /// <param name="to">
 /// Who combat advantage is granted to.
 /// </param>
 /// <param name="until">
 /// When the effect will end.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// No argument can be null.
 /// </exception>        
 public GrantCombatAdvantageEffect(Target target, To to, Until until)
     : base(target)
 {
     this.To = to;
     this.Until = until;
 }
 /// <summary>
 /// Create a new <see cref="ConditionEffect"/>.
 /// </summary>
 /// <param name="target">
 /// The <see cref="Target"/> that is immobilized.
 /// </param>
 /// <param name="condition">
 /// The <see cref="Condition"/> imposed on the target.
 /// </param>
 /// <param name="until">
 /// Then the immoblization ceases.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="target"/> cannot be null.
 /// </exception>
 public ConditionEffect(Target target, Condition condition, Until until)
     : base(target)
 {
     this.Condition = condition;
     this.Until = until;
 }
        /// <summary>
        /// Create a new <see cref="DiceDamageEffect"/>.
        /// </summary>
        /// <param name="target">
        /// The <see cref="Target"/> this effect component acts on. This
        /// cannot be null.
        /// </param>
        /// <param name="scores">
        /// The <see cref="CharacterScore"/>s that gain the bonus. This 
        /// cannot be null or contain null.
        /// </param>
        /// <param name="modifier">
        /// A score that, when calculated, gives the bonus or penalty.
        /// </param>
        /// <param name="until">
        /// When the bonus ends.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// No argument can be null.
        /// </exception>
        public GainModifierEffect(Target target, IEnumerable<CharacterScore> scores, ICharacterScoreValue modifier, Until until)
            : base(target)
        {
            if (scores == null)
            {
                throw new ArgumentNullException("scores");
            }
            if (scores.Any(x => x == null))
            {
                throw new ArgumentNullException("scores");
            }
            if (modifier == null)
            {
                throw new ArgumentNullException("modifier");
            }

            this.Scores = new List<CharacterScore>(scores);
            this.Modifier = modifier;
            this.Until = until;
        }
 /// <summary>
 /// Create a new <see cref="DiceDamageEffect"/>.
 /// </summary>
 /// <param name="target">
 /// The <see cref="Target"/> this effect component acts on. This
 /// cannot be null.
 /// </param>
 /// <param name="score">
 /// The <see cref="CharacterScore"/> that gains the bonus. This
 /// cannot be null.
 /// </param>
 /// <param name="bonus">
 /// The amount of the bonus.
 /// </param>
 /// <param name="until">
 /// Then the bonus ends.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// No argument can be null.
 /// </exception>
 public GainModifierEffect(Target target, CharacterScore score, int bonus, Until until)
     : this(target, score, new ConstantValue(bonus), until)
 {
     // Do nothing
 }