Example #1
0
        public string RegisterWatch([FromBody] RegisterRequest request, [FromServices] WatchDog watchDog)
        {
            var registerContext = WatchDagServerContext.RegisterContext.FirstOrDefault(temp => temp.Token == request.Token);

            if (registerContext == null)
            {
                // 恭喜你,是第一次注册,汪
                registerContext = new RegisterContext
                {
                    Token = request.Token,
                };
                WatchDagServerContext.RegisterContext.Add(registerContext);
            }
            // 更新一下数据
            registerContext.CurrentDelayCount = 0;
            registerContext.MaxDelayCount     = request.MaxDelayCount;
            registerContext.DelaySecond       = request.DelaySecond;
            registerContext.LastRegisterTime  = DateTimeOffset.Now;

            WatchDagServerContext.SaveChanges();

            watchDog.AddWatch(registerContext);

            return($"注册成功,汪");
        }
Example #2
0
        public void UnionTest1()
        {
            RegisterContext ctx = new RegisterContext();

            ctx.ui32 = 0x12345678;

            Assert.AreEqual(
                (uint)0x12345678,
                ctx.ui32,
                "ui32フィールドの値が正しくありません");

            Assert.AreEqual(
                (ushort)0x5678,
                ctx.ui16,
                "ui16フィールドの値が正しくありません");

            Assert.AreEqual(
                (byte)0x56,
                ctx.ui8h,
                "ui8hフィールドの値が正しくありません");

            Assert.AreEqual(
                (byte)0x78,
                ctx.ui8l,
                "ui8lフィールドの値が正しくありません");
        }
Example #3
0
 private void ProcessReportDeviceRegister(string message)
 {
     try
     {
         RegisterContext context = JsonConvert.DeserializeObject <RegisterContext>((string)message);
         DeviceItem      item    = new DeviceItem();
         foreach (DeviceData data in context.Data)
         {
             item.deviceId   = data.DeviceId;
             item.secret     = data.Secret;
             item.modelId    = data.ModelId;
             item.registered = true;
             item.online     = true;
             item.deleted    = false;
             if (this.AddDeviceItem(item))
             {
                 this.UpdateWithDeviceItem(item);
                 this.Notify(REFRESH_DEVICE_LIST_EVENT, DeviceOperateEvent.ListAdd.ToString(), item, "");
                 this.GetDeviceAllAttribute(item.deviceId);
             }
         }
     }
     catch (Newtonsoft.Json.JsonReaderException)
     {
     }
 }
Example #4
0
        private void Check(string token)
        {
            // 判定一下时间
            using (var serviceScope = _serviceProvider.CreateScope())
            {
                var watchDagServerContext = serviceScope.ServiceProvider.GetService <WatchDagServerContext>();

                var registerContext = watchDagServerContext !.RegisterContext.FirstOrDefault(temp => temp.Token == token);
                if (registerContext == null)
                {
                    return;
                }

                // 如果当前时间大于最后注册时间的 DelayTime 那么加一
                var delayTime = TimeSpan.FromSeconds(registerContext.DelaySecond);
                if (DateTimeOffset.Now - registerContext.LastRegisterTime > delayTime)
                {
                    registerContext.CurrentDelayCount++;
                    watchDagServerContext.SaveChanges();

                    if (registerContext.CurrentDelayCount > registerContext.MaxDelayCount)
                    {
                        // 咬人
                        _logger.LogError($"{registerContext.Token}已经很久没喂狗了");
                    }
                }

                // 再次注册回去
                AddWatch(registerContext);
            }
        }
Example #5
0
        public IActionResult RegisteredUserReport()
        {
            var records = new List <Registrations>();

            using (var dbContext = new RegisterContext())
            {
                records = dbContext.Registrations.OrderByDescending(x => x.Date).ToList();
            }
            return(View(records));
        }
 /// <summary>
 /// Saves the context and handles the excpetion.
 /// </summary>
 /// <param name="eax">Current status of eax</param>
 /// <param name="ebx">Current status of ebx</param>
 /// <param name="ecx">Current status of ecx</param>
 /// <param name="edx">Current status of edx</param>
 /// <param name="esi">Current status of esi</param>
 /// <param name="edi">Current status of edi</param>
 /// <param name="ebp">Current status of ebp</param>
 /// <param name="exception">The exception object</param>
 /// <param name="eip">Current status of eip</param>
 /// <param name="esp">Current status of esp</param>
 public static void ThrowException(uint eax, uint ebx, uint ecx, uint edx, uint esi, uint edi, uint ebp, Exception exception, uint eip, uint esp)
 {
     // Read callee's EIP from method header
     //eip = Native.GetEip();
     // Create context
     RegisterContext registerContext = new RegisterContext(eax, ebx, ecx, edx, esi, edi, ebp, eip, esp + 40);
     // Try to handle the exception
     HandleException(registerContext, exception, eip);
     // Return after exception has been handled
     RestoreContext(registerContext);
 }
        protected override BikeDisplayResult ExecuteCommand(BikeDisplayCommand command)
        {
            string s        = command.Action;
            Logger myLogger = new Logger();

            myLogger.LogIt("about to enter DL");
            RegisterContext    context  = new RegisterContext();
            BikeDAL            bikeDA   = new BikeDAL(context, myLogger);
            IEnumerable <Bike> result   = bikeDA.GetBikes();
            BikeDisplayResult  allbikes = new BikeDisplayResult(result);

            myLogger.LogIt("returning to BL");
            return(allbikes);
        }
Example #8
0
        public string UserExists(RegisterContext registerContext)
        {
            var user = new Register(_authenticationContext, registerContext);

            var confirmationResponse = new Confirmation();

            if (user.UserExists())
            {
                confirmationResponse.Status = StatusEnum.RecordExists;
            }
            else
            {
                confirmationResponse.Status = StatusEnum.RecordNotFound;
            }

            return(JsonConvert.SerializeObject(confirmationResponse, Formatting.Indented));
        }
Example #9
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            RegisterContext db = new RegisterContext();

            //Take the additional field property name and value
            PropertyInfo additionalPropertyName =
                validationContext.ObjectInstance.GetType().GetProperty(AdditionalFields);
            object additionalPropertyValue =
                additionalPropertyName.GetValue(validationContext.ObjectInstance, null);

            bool validateRegNumber = db.ParkedVehicles.Any(x => x.RegNumber == (string)value && x.Id != (int)additionalPropertyValue);

            if (validateRegNumber == true)
            {
                return(new ValidationResult
                           ("The vehicle registration already exist", new string[] { "RegNumber" }));
            }
            return(ValidationResult.Success);
        }
Example #10
0
        public RegisterContext register()
        {
            RegisterContext _localctx = new RegisterContext(Context, State);

            EnterRule(_localctx, 14, RULE_register);
            try {
                EnterOuterAlt(_localctx, 1);
                {
                    State = 64; Match(REGISTER);
                }
            }
            catch (RecognitionException re) {
                _localctx.exception = re;
                ErrorHandler.ReportError(this, re);
                ErrorHandler.Recover(this, re);
            }
            finally {
                ExitRule();
            }
            return(_localctx);
        }
Example #11
0
        public async void AddWatch(RegisterContext registerContext)
        {
            var token = registerContext.Token;

            if (WatchContextList.TryGetValue(token, out var context))
            {
                context.TaskCompletionSource.TrySetResult();
            }

            var delaySecond = registerContext.DelaySecond;

            var delayTask            = Task.Delay(TimeSpan.FromSeconds(delaySecond));
            var taskCompletionSource = new TaskCompletionSource();

            WatchContextList[token] = new WatchContext()
            {
                TaskCompletionSource = taskCompletionSource
            };

            await Task.WhenAny(delayTask, taskCompletionSource.Task);

            Check(token);
        }
Example #12
0
        public IActionResult Index(Registrations customer)
        {
            if (ModelState.IsValid)
            {
                using (var dbContext = new RegisterContext())
                {
                    dbContext.Registrations.Add(new Registrations()
                    {
                        LastName  = customer.LastName,
                        FirstName = customer.FirstName,
                        Address1  = customer.Address1,
                        Address2  = customer.Address2,
                        City      = customer.City,
                        State     = customer.State,
                        Country   = customer.Country,
                        Zip       = customer.Zip,
                        Date      = DateTime.Now
                    });

                    try
                    {
                        dbContext.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        //log this error
                        return(Redirect("Home/ValidationError"));
                    }
                }
                return(View("Confirmation"));
            }
            else
            {
                return(View());
            }
        }
Example #13
0
 public CategoriesController(RegisterContext context)
 {
     _context = context;
 }
 public StudentController(RegisterContext context)
 {
     _context = context;
 }
Example #15
0
	public RegisterContext register() {
		RegisterContext _localctx = new RegisterContext(Context, State);
		EnterRule(_localctx, 20, RULE_register);
		int _la;
		try {
			EnterOuterAlt(_localctx, 1);
			{
			State = 113;
			_la = TokenStream.La(1);
			if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << A) | (1L << B) | (1L << C) | (1L << D) | (1L << E) | (1L << F) | (1L << H) | (1L << L) | (1L << AF) | (1L << BC) | (1L << DE) | (1L << HL) | (1L << SP) | (1L << HLPLUS) | (1L << HLMINUS))) != 0)) ) {
			ErrorHandler.RecoverInline(this);
			}
			else {
			    Consume();
			}
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			ErrorHandler.ReportError(this, re);
			ErrorHandler.Recover(this, re);
		}
		finally {
			ExitRule();
		}
		return _localctx;
	}
Example #16
0
 public AccountRepository(RegisterContext context) : base(context)
 {
 }
Example #17
0
 public void Register(RegisterContext context)
 {
 }
Example #18
0
 public EnrollmentRepository(RegisterContext context) : base(context)
 {
 }
Example #19
0
 /// <summary>
 /// Calls the given filter to handle the exception
 /// </summary>1
 /// <param name="registerContext">The register status right before the throw</param>
 /// <param name="exceptionInformation">The exception handler information</param>
 private static void CallFilter(RegisterContext registerContext, object exceptionInformation)
 {
     //Native.CallFilter();
 }
Example #20
0
 /// <summary>
 /// Call the appropriate handler or rethrow the exception
 /// </summary>
 /// <param name="registerContext">The register status right before the throw</param>
 /// <param name="exception">The thrown exception</param>
 /// <param name="eip">EIP to return to when handled</param>
 private static void HandlerInvocationPass(RegisterContext registerContext, Exception exception, uint eip)
 {
 }
Example #21
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="registerContext"></param>
 public void Update(RegisterContext registerContext)
 {
     Eax = registerContext.Eax;
     Ebx = registerContext.Ebx;
     Ecx = registerContext.Ecx;
     Edx = registerContext.Edx;
     Esi = registerContext.Esi;
     Edi = registerContext.Edi;
     Ebp = registerContext.Ebp;
     Eip = registerContext.Eip;
     Esp = registerContext.Esp;
 }
 public PatientRepository(RegisterContext context) : base(context)
 {
 }
Example #23
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="registerContext"></param>
 public RegisterContext(RegisterContext registerContext)
 {
     this.Update(registerContext);
 }
 public CategoryRepository(RegisterContext dbContext) : base(dbContext)
 {
 }
 public GetController(UserManager <Register> userManager, RegisterContext context)
 {
     _userManager = userManager;
     _context     = context;
 }
Example #26
0
 public ClassService(RegisterContext _context)
 {
     registerContext = _context;
 }
Example #27
0
 public StudentsService(RegisterContext _registerContext)
 {
     registerContext = _registerContext;
 }
Example #28
0
 /// <summary>
 /// Tries to handle the exception by searching the method header for a suitable exception handler/filter.
 /// </summary>
 /// <param name="registerContext">The register status right before the throw</param>
 /// <param name="exception">The thrown exception</param>
 /// <param name="eip">EIP to return to when handled</param>
 private static void HandleException(RegisterContext registerContext, Exception exception, uint eip)
 {
     HandlerIdentificationPass(registerContext, exception, eip);
     HandlerInvocationPass(registerContext, exception, eip);
 }
Example #29
0
 public DoctorRepository(RegisterContext context) : base(context)
 {
 }
Example #30
0
 /// <summary>
 /// Restores the context by loading the values from the given context.
 /// </summary>
 /// <param name="context">The register context to restore the state from</param>
 private static void RestoreContext(RegisterContext context)
 {
     //Native.RestoreContext();
 }
Example #31
0
 public ClientRepository(RegisterContext dbContext) : base(dbContext)
 {
 }
Example #32
0
 public DeptRepository(RegisterContext context) : base(context)
 {
 }
Example #33
0
 public ClassController(RegisterContext context)
 {
     _context = context;
 }
Example #34
0
 public ChecksController(RegisterContext context)
 {
     _context = context;
 }
 public ProductRepository(RegisterContext dbContext) : base(dbContext)
 {
 }
Example #36
0
 public HomeController(RegisterContext context)
 {
     _context = context;
 }
Example #37
0
 public ProductIngredientsController(RegisterContext context)
 {
     _context = context;
 }