Exemple #1
0
        private void QueryExecute(object sender, CfrV8HandlerExecuteEventArgs e)
        {
            try
            {
                var qryString   = e.Arguments[0].StringValue;
                var paramObject = ParseParameter(e.Arguments[1]);
                var counter     = 0;

                using (var connect = GetConnection())
                {
                    var reader = connect.Query(qryString, paramObject);
                    var arrObj = CfrV8Value.CreateArray(reader.Count());

                    foreach (var obj in reader)
                    {
                        var exp_obj = ToExpandoObject(obj);
                        arrObj.SetValue(counter, ConvertValue(exp_obj));

                        counter++;
                    }

                    e.SetReturnValue(arrObj);
                }
            }
            catch (Exception ex)
            {
                e.Exception = ex.Message;
                e.SetReturnValue(CfrV8Value.CreateUndefined());
            }
        }
Exemple #2
0
        private void ResetPasswordExecute(object sender, CfrV8HandlerExecuteEventArgs e)
        {
            try
            {
                var userId      = e.Arguments[0].IntValue;
                var newPassword = e.Arguments[1].StringValue;

                using (var context = new HotelContext())
                {
                    var user = context.Users.Find(userId);

                    if (user != null)
                    {
                        user.UpdatePassword(newPassword);

                        context.Entry(user).State = EntityState.Modified;
                        context.SaveChanges();
                        e.SetReturnValue(true);
                    }
                    else
                    {
                        e.SetReturnValue(false);
                    }
                }
            }
            catch (Exception ex)
            {
                e.Exception = ex.Message;
            }
        }
Exemple #3
0
        private void CreateExecute(object sender, CfrV8HandlerExecuteEventArgs e)
        {
            try
            {
                var data      = e.Arguments[0];
                var username  = data.GetValue("Username").StringValue;
                var fullname  = data.GetValue("Fullname").StringValue;
                var password  = data.GetValue("Password").StringValue;
                var level     = data.GetValue("Level").IntValue;
                var is_active = data.GetValue("IsActive").BoolValue;
                var user      = new User
                {
                    Fullname = fullname,
                    Username = username,
                    IsActive = is_active,
                    Level    = Convert.ToByte(level)
                };

                user.UpdatePassword(password);

                using (var context = new HotelContext())
                {
                    context.Users.Add(user);
                    context.SaveChanges();

                    var convertVal = ConvertValue(user);
                    e.SetReturnValue(convertVal);
                }
            }
            catch (Exception ex)
            {
                e.Exception = ex.Message;
            }
        }
Exemple #4
0
        private static void Host_PostTestPort(object sender, CfrV8HandlerExecuteEventArgs e)
        {
            try
            {
                if (SerialPortManager.Device2.SerialPortDevice.BaudRate != WinApi.B38400)
                {
                    SerialPortManager.Device2.SerialPortDevice.SetBaudRate(WinApi.B38400);
                    Thread.Sleep(10);
                }

                byte[] by  = PortAgreement.TestPort(SerialPortManager.Device2Address);
                bool   ret = SerialPortManager.WriteSerialPortData(SerialPortManager.Device2, by);
                if (ret)
                {
                    ReceivedManager.SetReceivedFunction <TestPort>();
                }
                e.SetReturnValue(ret);
            }
            catch (Exception ex)
            {
                SerialPortManager.Device2.SerialPortDevice.SetBaudRate(WinApi.B19200);

                Log4Helper.ErrorInfo(ex.Message, ex);
                ViewCallFunction.ViewAlert(ex.Message);
            }
        }
Exemple #5
0
        private void UpdateExecute(object sender, CfrV8HandlerExecuteEventArgs e)
        {
            try
            {
                var userId    = e.Arguments[0].IntValue;
                var userData  = e.Arguments[1];
                var fullname  = userData.GetValue("Fullname").StringValue;
                var level     = userData.GetValue("Level").IntValue;
                var is_active = userData.GetValue("IsActive").BoolValue;

                using (var context = new HotelContext())
                {
                    var user = context.Users
                               .Where(x => x.Id == userId)
                               .Single();

                    user.Fullname = fullname;
                    user.Level    = Convert.ToByte(level);
                    user.IsActive = is_active;

                    context.Entry(user).State = EntityState.Modified;
                    context.SaveChanges();

                    var convertVal = ConvertValue(user);
                    e.SetReturnValue(convertVal);
                }
            }
            catch (Exception ex)
            {
                e.Exception = ex.Message;
            }
        }
Exemple #6
0
 private void ResetExecute(object sender, CfrV8HandlerExecuteEventArgs e)
 {
     Settings.Default.Reset();
     Settings.Default.Reload();
     SettingHelper.Load();
     e.SetReturnValue(true);
 }
Exemple #7
0
        private void GetBookingNumberExecute(object sender, CfrV8HandlerExecuteEventArgs e)
        {
            using (var context = new HotelContext())
            {
                var startnumber  = 1;
                var today        = DateTime.Today;
                var result       = "BOK" + today.ToString("yyyyMMdd");
                var bookingToday = context
                                   .Bookings
                                   .Where(b => b.BookingAt >= today)
                                   .Where(b => b.Id.Contains(result))
                                   .OrderByDescending(b => b.BookingAt)
                                   .FirstOrDefault();

                if (bookingToday != null)
                {
                    // Generate new
                    var subNumber = bookingToday.Id.Substring(11, 5);
                    startnumber = Convert.ToInt32(subNumber);
                    startnumber++;
                }

                result = string.Format("{0}{1:00000}", result, startnumber);
                e.SetReturnValue(result);
            }
        }
Exemple #8
0
        private void GetUploadUrl(object sender, CfrV8HandlerExecuteEventArgs e)
        {
            var filename = e.Arguments[0].StringValue;
            var retUrl   = baseUrl + filename;

            e.SetReturnValue(retUrl);
        }
Exemple #9
0
        private void ValidateExecute(object sender, CfrV8HandlerExecuteEventArgs e)
        {
            try
            {
                var username     = e.Arguments[0].StringValue;
                var password     = e.Arguments[1].StringValue;
                var hashPassword = AuthHelper.HashText(password, AppKey);

                using (var context = new HotelContext())
                {
                    var user = context.Users
                               .Where(x => x.Username == username)
                               .Where(x => x.Password == hashPassword)
                               .Where(x => x.IsActive)
                               .SingleOrDefault();
                    var convertuser = ConvertValue(user);

                    e.SetReturnValue(convertuser);
                }
            }
            catch (Exception ex)
            {
                e.Exception = ex.Message;
            }
        }
Exemple #10
0
        private void GetConfigFormCSFunc_Execute(object sender, CfrV8HandlerExecuteEventArgs e)
        {
            var config           = JsonConvert.SerializeObject(CommonUtils.ConfigInstance);
            var jsObjectAccessor = new CfrV8Accessor();
            var jsObject         = CfrV8Value.CreateObject(jsObjectAccessor);

            jsObject.SetValue("config", config, CfxV8PropertyAttribute.DontDelete);
            e.SetReturnValue(jsObject);
        }
Exemple #11
0
        public void GetFlowPicSize(object func, CfrV8HandlerExecuteEventArgs args)
        {
            var jsObjectAccessor = new CfrV8Accessor();
            var jsObject         = CfrV8Value.CreateObject(jsObjectAccessor);

            jsObject.SetValue("width", CfrV8Value.CreateInt(GlobDef.sz_image.width), CfxV8PropertyAttribute.ReadOnly);
            jsObject.SetValue("height", CfrV8Value.CreateInt(GlobDef.sz_image.height), CfxV8PropertyAttribute.ReadOnly);
            args.SetReturnValue(jsObject);
        }
Exemple #12
0
        private void ListExecute(object sender, CfrV8HandlerExecuteEventArgs e)
        {
            using (var context = new HotelContext())
            {
                var list       = context.Users.ToArray();
                var convertval = ConvertValue(list);

                e.SetReturnValue(convertval);
            }
        }
Exemple #13
0
        private void QueryScalarExecute(object sender, CfrV8HandlerExecuteEventArgs e)
        {
            try
            {
                var qryString   = e.Arguments[0].StringValue;
                var paramObject = ParseParameter(e.Arguments[1]);

                using (var connData = GetConnection())
                {
                    var result = connData.Execute(qryString, paramObject);
                    e.SetReturnValue(result);
                }
            }
            catch (Exception ex)
            {
                e.Exception = ex.Message;
                e.SetReturnValue(CfrV8Value.CreateUndefined());
            }
        }
Exemple #14
0
        void TestDoubleCallback_Execute(object sender, CfrV8HandlerExecuteEventArgs e)
        {
            var doubleCallback = e.Arguments[0];
            var args           = new CfrV8Value[] {
                "This is the first argument",
                123.4567
            };
            var retval = doubleCallback.ExecuteFunction(null, args);

            e.SetReturnValue(retval);
        }
Exemple #15
0
        static void HelloApp_Execute(object sender, CfrV8HandlerExecuteEventArgs e)
        {
            var numberOfArguments = e.Arguments.Length;

            if (numberOfArguments > 0)
            {
                var firstArg = e.Arguments[0].IntValue;
                MessageBox.Show("First argument supplied: " + firstArg);
            }
            e.SetReturnValue(100);
        }
Exemple #16
0
        public void JavascriptCallback(object sender, CfrV8HandlerExecuteEventArgs e)
        {
            if (!Functions.ContainsKey(e.Name))
            {
                return;
            }
            var func = Functions[e.Name];

            func.Arguments     = e.Arguments;
            func.LastEventArgs = e;
            e.SetReturnValue(func.Invoke(e, this, Wrapper));
        }
Exemple #17
0
        private void DeleteExecute(object sender, CfrV8HandlerExecuteEventArgs e)
        {
            try
            {
                var userId = e.Arguments[0].IntValue;

                using (var context = new HotelContext())
                {
                    var user = context.Users.Where(x => x.Id == userId).Single();

                    context.Entry(user).State = EntityState.Deleted;
                    context.SaveChanges();

                    e.SetReturnValue(true);
                }
            }
            catch
            {
                e.SetReturnValue(false);
            }
        }
Exemple #18
0
        void CfxHelloWorld_Execute(object sender, CfrV8HandlerExecuteEventArgs e)
        {
            if (e.Arguments.Length > 1)
            {
                var r1 = e.Arguments[0].IntValue;
                var r2 = e.Arguments[1].StringValue;
                LogWriteLine("CfxHelloWorld_Execute arguments: " + r1 + ", '" + r2 + "'");
            }
            LogCallback(sender, e);
            var context = CfrV8Context.GetEnteredContext();

            e.SetReturnValue("CfxHelloWorld returns this text.");
        }
Exemple #19
0
        private void ChangePasswordExecute(object sender, CfrV8HandlerExecuteEventArgs e)
        {
            try
            {
                var userId          = e.Arguments[0].IntValue;
                var oldPassword     = e.Arguments[1].StringValue;
                var newPassword     = e.Arguments[2].StringValue;
                var hashOldPassword = AuthHelper.HashText(oldPassword, AppKey);

                using (var context = new HotelContext())
                {
                    var user = context.Users
                               .Where(x => x.Id == userId)
                               .Where(x => x.Password == hashOldPassword)
                               .Where(x => x.IsActive)
                               .SingleOrDefault();

                    if (user != null)
                    {
                        user.UpdatePassword(newPassword);

                        context.Entry(user).State = EntityState.Modified;
                        context.SaveChanges();
                        e.SetReturnValue(true);
                    }
                    else
                    {
                        e.SetReturnValue(false);
                    }
                }
            }
            catch (Exception ex)
            {
                e.Exception = ex.Message;
            }
        }
Exemple #20
0
        private void GetHistoryContentFormCSFunc_Execute(object sender, CfrV8HandlerExecuteEventArgs e)
        {
            var htime = e.Arguments.FirstOrDefault(p => p.IsString).ToString();

            foreach (var item in noteContentHistoryList)
            {
                if (item != null && item.create_time.Equals(htime))
                {
                    var jsObjectAccessor = new CfrV8Accessor();
                    var jsObject         = CfrV8Value.CreateObject(jsObjectAccessor);
                    jsObject.SetValue("n_content", item.n_content, CfxV8PropertyAttribute.DontDelete);
                    e.SetReturnValue(jsObject);
                    break;
                }
            }
        }
Exemple #21
0
        void TestDoubleCallback_Execute(object sender, CfrV8HandlerExecuteEventArgs e)
        {
            var doubleCallback = e.Arguments[0];
            var args           = new CfrV8Value[] {
                "This is the first argument",
                123.4567
            };

            var self    = e.Object.GetValue("testDoubleCallback");
            var handler = self.FunctionHandler;

            LogWriteLine("testDoubleCallback is a CEF created function: {0}", handler != null);
            LogWriteLine("doubleCallback is a CEF created function: {0}", doubleCallback.FunctionHandler != null);

            var retval = doubleCallback.ExecuteFunction(null, args);

            e.SetReturnValue(retval);
        }
Exemple #22
0
        private void GetNoteContentHistoryFormCSFunc_Execute(object sender, CfrV8HandlerExecuteEventArgs e)
        {
            var noteID = e.Arguments.FirstOrDefault(p => p.IsString).ToString();

            noteContentHistoryList = noteUtils.GetHistoryNoteContent(Convert.ToInt32(noteID));
            if (noteContentHistoryList != null && noteContentHistoryList.Count > 0)
            {
                var jsObjectAccessor = new CfrV8Accessor();
                var jsObject         = CfrV8Value.CreateObject(jsObjectAccessor);
                var noteListArray    = CfrV8Value.CreateArray(noteContentHistoryList.Count);
                int i = 0;
                foreach (var note in noteContentHistoryList)
                {
                    noteListArray.SetValue(i, note.create_time);
                    i++;
                }
                jsObject.SetValue("historyArray", noteListArray, CfxV8PropertyAttribute.DontDelete);
                e.SetReturnValue(jsObject);
            }
        }
Exemple #23
0
        private void InvokeHandler(object sender, CfrV8HandlerExecuteEventArgs e)
        {
            MethodInfo method = HandlerMap.FirstOrDefault(element => element.Key == e.Name).Value;

            if (method == null)
            {
                e.Exception = $"There is no function named { e.Name }.";
            }

            ParameterInfo[] infos = method.GetParameters();

            if ((e.Arguments == null || e.Arguments.Length == 0) && infos.Length != 0)
            {
                //js传递参数数量为0,但是对应的Handler需要传参
                e.Exception = "ArgumentException";
                return;
            }

            object ret = null;

            if (infos.Length == 0)
            {
                ret = method.Invoke(this, null); //对应的Handler不需要传参
            }
            else if (infos[0].ParameterType == typeof(string))
            {
                ret = method.Invoke(this, new object[1] {
                    e.Arguments[0].StringValue
                });                                                                      //对应的Handler需要传参
            }
            else
            {
                throw new ArgumentException(); //对应的Handler参数类型错误
            }
            if (method.ReturnType != typeof(void))
            {
                //给js返回值
                using (CfrV8Value retvalue = CfrV8Value.CreateString((string)ret))
                    e.SetReturnValue(retvalue);
            }
        }
Exemple #24
0
        private void GetExecute(object sender, CfrV8HandlerExecuteEventArgs e)
        {
            try
            {
                var userId = e.Arguments[0].IntValue;

                using (var context = new HotelContext())
                {
                    var user = context.Users
                               .Where(x => x.Id == userId)
                               .SingleOrDefault();
                    var convertVal = ConvertValue(user);

                    e.SetReturnValue(convertVal);
                }
            }
            catch (Exception ex)
            {
                e.Exception = ex.Message;
            }
        }
Exemple #25
0
 private static void Host_PostPersonnelRecovery(object sender, CfrV8HandlerExecuteEventArgs e)
 {
     try
     {
         string          loseCardNumber = GetLoseNumber(e);
         List <CardInfo> list           = CardManager.GetCardInfos(loseCardNumber);
         CardManager.LossLists = list;
         byte[] by  = PortAgreement.ReadACard("797979", 1);
         bool   ret = SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
         if (ret)
         {
             ReceivedManager.SetReceivedFunction <PersonnelCardLoss>();
         }
         e.SetReturnValue(ret);
     }
     catch (Exception ex)
     {
         Log4Helper.ErrorInfo(ex.Message, ex);
         ViewCallFunction.ViewAlert(ex.Message);
     }
 }
Exemple #26
0
        private void JS_bigStringFunction(object sender, CfrV8HandlerExecuteEventArgs e)
        {
            if (e.Arguments.Length > 0)
            {
                var arg = e.Arguments[0].StringValue;
                LogWriteLine("Big string received: {0}(...) ({1} chars)", arg.Substring(0, 20), arg.Length);
                return;
            }

            var rnd        = new Random(DateTime.Now.Millisecond);
            var size       = rnd.Next(50 * 1024 * 1024, 51 * 1024 * 1024);
            var chars      = new char[size];
            var charSource = "abcdefghijklmnopqrstuvwzyz0123456789";

            for (int i = 0; i < chars.Length; ++i)
            {
                chars[i] = charSource[rnd.Next(0, charSource.Length)];
            }
            var str = new string(chars);

            LogWriteLine("Sending big string: {0}(...) ({1} chars)", str.Substring(0, 20), str.Length);
            e.SetReturnValue(str);
        }
Exemple #27
0
 public void GetLiveMaxWidth(object func, CfrV8HandlerExecuteEventArgs args)
 {
     args.SetReturnValue(CfrV8Value.CreateInt(GlobDef.sz_image.width));
 }