Esempio n. 1
0
        public string LogEvent(EventLogModel eventModel)
        {
            string success;

            try
            {
                using (var db = new OggleBoobleMySqlContext())
                {
                    db.EventLogs.Add(new EventLog()
                    {
                        FolderId    = eventModel.FolderId,
                        EventCode   = eventModel.EventCode,
                        EventDetail = eventModel.EventDetail,
                        CalledFrom  = eventModel.CalledFrom,
                        VisitorId   = eventModel.VisitorId,
                        Occured     = DateTime.Now
                    });
                    db.SaveChanges();
                }
                success = "ok";
            }
            catch (Exception ex)
            {
                success = Helpers.ErrorDetails(ex);
            }
            return(success);
        }
Esempio n. 2
0
 public LineApiController()
 {
     func                          = new Functional();
     richMenu                      = new LineMessageTemplate.RichMenuResponse();
     ChannelAccessToken            = "q281ubFyT1L3Z1gAyrcLdLY4mHv2hXJFqAb/MEUO2OncgbgXdSsR6BDCXsrTZh0I3haZwDDaz1lrKF694gC0fTnp/CnbLma8WkiHW3UXwSf6gHxU5lNJP/IYeb1+KQRFeun9E5jJT8qx9lpQpY1S9AdB04t89/1O/w1cDnyilFU=";
     AccessTokenForSupport         = "4bw1smnE8oLXGQg09XJRhq9H4xHh9w1207hwUxq5q1l";
     clsPushMultiCast              = new PushLineResponseMultiCastModel();
     clsdupBubbleMultiCast         = new dupBubbleMulticast();
     clsdupBubbleMultiCastNoFooter = new dupBubbleMulticastNoFooter();
     dataEvent                     = new EventLogModel();
 }
Esempio n. 3
0
        public async Task AddStudentEvent(int studentId, EventLogTypes eventType, string remoteIp)
        {
            EventLogModel log = new EventLogModel()
            {
                Date      = DateTime.Now,
                StudentId = studentId,
                Type      = (int)eventType,
                IPAddress = remoteIp
            };

            await AddStudentEvent(log);
        }
Esempio n. 4
0
 public LineApiController(string ChannelName)
 {
     func               = new Functional();
     richMenu           = new LineMessageTemplate.RichMenuResponse();
     ChannelAccessToken = "q281ubFyT1L3Z1gAyrcLdLY4mHv2hXJFqAb/MEUO2OncgbgXdSsR6BDCXsrTZh0I3haZwDDaz1lrKF694gC0fTnp/CnbLma8WkiHW3UXwSf6gHxU5lNJP/IYeb1+KQRFeun9E5jJT8qx9lpQpY1S9AdB04t89/1O/w1cDnyilFU=";
     // ChannelAccessToken = "Pq+kySWPUtbt1YvcDtMHXkbUIrN7CDqzx18DAPS4Ij153mb+1id7NNKp7m3c74Fg5h54zPR1kFraEGm8JC31540oCiUPSwgK3SiKsYd9+nftcztMkFRg2u0PXGReejmHfKccPvNmTSwEIB63yyOvFAdB04t89/1O/w1cDnyilFU=";
     AccessTokenForSupport         = "4bw1smnE8oLXGQg09XJRhq9H4xHh9w1207hwUxq5q1l";
     clsPushMultiCast              = new PushLineResponseMultiCastModel();
     clsdupBubbleMultiCast         = new dupBubbleMulticast();
     clsdupBubbleMultiCastNoFooter = new dupBubbleMulticastNoFooter();
     dataEvent = new EventLogModel();
 }
Esempio n. 5
0
        public EventLogModel GetFeulByObject(int ObjectId)
        {
            var    url    = "api/EventLog?ObjectId=" + ObjectId;
            string result = SC.Getcaller(url);

            if (result != null)
            {
                EventLogModel _event = JsonConvert.DeserializeObject <EventLogModel>(result);
                return(_event);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 6
0
        public async Task AddStudentEvent(EventLogModel log)
        {
            const string sql = @"
                INSERT INTO [dbo].[EventLog]
                ([Date], [ModifiedBy], [StudentId], [Type], [IPAddress])
                VALUES
                (@Date, @ModifiedBy, @StudentId, @Type, @IpAddress)";

            try
            {
                log.Date = log.Date.ToUniversalTime();
                await UnitOfWork.Context().ExecuteAsync(sql, log);
            }
            catch (Exception e)
            {
                e.Data["SQL"] = sql;
                ErrorStore.LogException(e, HttpContext.Current);
                throw e;
            }
        }
Esempio n. 7
0
        public async Task UpsertAsync(EventLogModel eventLog)
        {
            ItemResponse <EventLogModel> recordAdded = await _db.EventLog.UpsertItemAsync(eventLog);

            _logger.LogInformation($"{nameof(UpsertAsync)} RequestCharge:{recordAdded.RequestCharge}");
        }
Esempio n. 8
0
        public async Task <IActionResult> RunAsync(
            [HttpTrigger(AuthorizationLevel.Function, "put", Route = "v1/event_log")] HttpRequest req
            )
        {
            _logger.LogInformation($"{nameof(RunAsync)}");

            // Check Content-Length.
            if (!req.Headers.ContainsKey(HEADER_CONTENT_LENGTH))
            {
                return(new StatusCodeResult((int)HttpStatusCode.BadRequest));
            }

            string contentLengthHeader = req.Headers[HEADER_CONTENT_LENGTH].ToString();
            bool   isNumeric           = long.TryParse(contentLengthHeader, out long contentLength);

            if (!isNumeric)
            {
                return(new StatusCodeResult((int)HttpStatusCode.BadRequest));
            }
            else if (contentLength < 0)
            {
                return(new StatusCodeResult((int)HttpStatusCode.BadRequest));
            }
            else if (contentLength > Constants.MAX_SIZE_EVENT_LOG_PAYLOAD_BYTES)
            {
                return(new StatusCodeResult((int)HttpStatusCode.RequestEntityTooLarge));
            }

            var requestBody = await new StreamReader(req.Body).ReadToEndAsync();

            // Check RequestBody size.
            if (Encoding.ASCII.GetBytes(requestBody).LongLength > Constants.MAX_SIZE_EVENT_LOG_PAYLOAD_BYTES)
            {
                return(new StatusCodeResult((int)HttpStatusCode.RequestEntityTooLarge));
            }

            // Check Valid Route
            IValidationServerService.ValidateResult validateResult = _validationServerService.Validate(req);
            if (!validateResult.IsValid)
            {
                if (validateResult.ErrorActionResult is BadRequestResult)
                {
                    return(new StatusCodeResult((int)HttpStatusCode.BadRequest));
                }
                else
                {
                    return(validateResult.ErrorActionResult);
                }
            }

            V1EventLogSubmissionParameter submissionParameter;

            try
            {
                submissionParameter = JsonConvert.DeserializeObject <V1EventLogSubmissionParameter>(requestBody);
            }
            catch (JsonSerializationException e)
            {
                _logger.LogError("JsonSerializationException occurred.");
                return(new StatusCodeResult((int)HttpStatusCode.BadRequest));
            }

            var requestTime = DateTimeOffset.UtcNow;

            // validation device
            if (!await _deviceValidationService.Validation(submissionParameter.Platform, submissionParameter, requestTime))
            {
                _logger.LogInformation($"Invalid Device");
                return(new StatusCodeResult((int)HttpStatusCode.BadRequest));
            }

            var timestamp = (ulong)DateTimeOffset.UtcNow.ToUnixTimeSeconds();

            using (SHA256 sha256 = SHA256.Create())
            {
                foreach (var eventLog in submissionParameter.EventLogs)
                {
                    // For considering user-privacy safe.
                    if (!eventLog.HasConsent)
                    {
                        _logger.LogError("No consent log detected.");
                        continue;
                    }

                    string id = ByteArrayUtils.ToHexString(sha256.ComputeHash(Encoding.ASCII.GetBytes(eventLog.ClearText)));

                    var eventLogModel = new EventLogModel(
                        eventLog.HasConsent,
                        eventLog.Epoch,
                        eventLog.Type,
                        eventLog.Subtype,
                        eventLog.Content,
                        eventLog.Timestamp
                        )
                    {
                        id      = id,
                        Created = timestamp,
                    };
                    await _eventLogRepository.UpsertAsync(eventLogModel);
                }
            }

            return(new StatusCodeResult((int)HttpStatusCode.Created));
        }
Esempio n. 9
0
 public static void Add(EventLogModel eventLog)
 {
     eventLog.ID   = _logs.Count + 1;
     eventLog.Time = DateTime.Now;
     _logs.Add(eventLog);
 }
Esempio n. 10
0
 private async Task AddStudentEvent(EventLogModel log)
 {
     await EventLogRepository.AddStudentEvent(log);
 }