Beispiel #1
0
        public ServiceResults DoService(string[] inputData)
        {
            var output = new ServiceResults();

            output.Result.Add("MESSAGE", string.Empty);

            if (inputData.Length == 3)
            {
                try
                {
                    Account registeredAccount = dbAccessor.AddAccount(inputData[0], inputData[1], inputData[2]);
                    Random  rnd    = new Random();
                    string  authNo = rnd.Next(10000).ToString("D4");
                    string  msg    = "\n認証番号:" + authNo;

                    bool MessageWasSent = lineMessenger.SendMessage(registeredAccount.access_token, msg);

                    if (MessageWasSent)
                    {
                        logger.Log("認証番号送信成功", inputData[0]);
                        output.Result["MESSAGE"] = Messages.PM03;
                        output.Result.Add("AUTHNO", authNo);
                        output.IsSuccessed = true;
                        return(output);
                    }
                    else
                    {
                        logger.Log("認証番号送信失敗", inputData[0]);
                        dbAccessor.DeleteAccount(inputData[0]);
                        output.Result["MESSAGE"] = Messages.EM04;
                        return(output);
                    }
                }
                catch (Exception e)
                {
                    if (!string.IsNullOrEmpty(e.InnerException.ToString()))
                    {
                        List <string> innerException = e.InnerException.ToString().Split("\'").ToList();
                        //IDが重複している場合
                        if (innerException.Any(x => x == @"PRIMARY"))
                        {
                            output.Result["MESSAGE"] = Messages.EM03a;
                            return(output);
                        }
                        //アクセストークンが重複している場合
                        if (innerException.Any(x => x == @"access_token"))
                        {
                            output.Result["MESSAGE"] = Messages.EM03b;
                            return(output);
                        }
                    }
                    logger.Log("データベース未接続", inputData[0]);
                    output.Result["MESSAGE"] = Messages.EM01;
                    return(output);
                }
            }
            logger.Log("登録サービスへの入力データが不正", inputData[0]);
            output.Result["MESSAGE"] = Messages.EM10;
            return(output);
        }
Beispiel #2
0
        public ServiceResults DoService(string[] inputData)
        {
            var output = new ServiceResults();

            output.Result.Add("MESSAGE", string.Empty);
            string    alertMessage;
            EventInfo convertedEventInfo = eventInfoConverter.ConvertEventInfo();

            if (DateTime.TryParseExact(convertedEventInfo.date, "yyyy.MM.dd", null, DateTimeStyles.AssumeLocal, out DateTime eventDateTime))
            {
                //ローカル時刻とローカルのタイムゾーンから東京(UTC+9:00)の現在時刻を取得
                TimeZoneInfo tokyoTimeInfo    = TZConvert.GetTimeZoneInfo("Tokyo Standard Time");
                DateTime     localTimeInTokyo = TimeZoneInfo.ConvertTime(DateTime.Now, tokyoTimeInfo);

                //東京の日付とイベントの日付を比較
                if (eventDateTime == localTimeInTokyo.Date)
                {
                    //本日のイベントがある場合
                    alertMessage = Messages.AM01(convertedEventInfo.title, convertedEventInfo.artist);
                }
                else
                {
                    //直近のイベントが本日でない場合
                    alertMessage = Messages.AM02;
                }
            }
            else
            {
                //イベント情報を取得できなかった場合
                alertMessage = Messages.AM03;
            }

            logger.Log(alertMessage, "アラートメッセージ");
            alertMessage += Messages.URL;

            try
            {
                //有効な通知先情報を取得
                var tokens = dbAccessor.GetActiveAccounts();
                foreach (var x in tokens)
                {
                    string logMessage = lineMessenger.SendMessage(x.access_token, alertMessage) ? "アラート送信成功" : "アラート送信失敗";
                    logger.Log(logMessage, x.id);
                }
                return(output);
            }
            catch
            {
                logger.Log(message: "データベース未接続");
                return(output);
            }
        }
Beispiel #3
0
        public ServiceResults DoService(string[] inputData)
        {
            var output = new ServiceResults();

            output.Result.Add("MESSAGE", string.Empty);

            if (inputData.Length == 3)
            {
                if (!Equals(inputData[1], inputData[2]))
                {
                    logger.Log("認証番号照合失敗", inputData[0]);
                    output.Result["MESSAGE"] = Messages.EM05;
                    return(output);
                }
                else
                {
                    try
                    {
                        logger.Log("認証番号照合成功", inputData[0]);
                        dbAccessor.ActivateAccount(inputData[0]);
                        logger.Log("新規通知先登録完了", inputData[0]);
                        output.Result["MESSAGE"] = Messages.PM01;
                        output.IsSuccessed       = true;
                        return(output);
                    }
                    catch
                    {
                        logger.Log("データベース未接続", inputData[0]);
                        output.Result["MESSAGE"] = Messages.EM01;
                        return(output);
                    }
                }
            }
            logger.Log("認証サービスへの入力データが不正", inputData[0]);
            output.Result["MESSAGE"] = Messages.EM10;
            return(output);
        }
Beispiel #4
0
        public ServiceResults DoService(string[] inputData)
        {
            var output = new ServiceResults();

            output.Result.Add("MESSAGE", string.Empty);

            if (inputData.Length == 2)
            {
                try
                {
                    if (dbAccessor.IsVerified(inputData[0], inputData[1]))
                    {
                        logger.Log("パスワード照合成功", inputData[0]);
                        dbAccessor.DeleteAccount(inputData[0]);
                        logger.Log("通知先登録解除完了", inputData[0]);
                        output.Result["MESSAGE"] = Messages.PM02;
                        output.IsSuccessed       = true;
                    }
                    else
                    {
                        logger.Log("パスワード照合失敗", inputData[0]);
                        output.Result["MESSAGE"] = Messages.EM06;
                    }
                    return(output);
                }
                catch
                {
                    logger.Log("データベース未接続", inputData[0]);
                    output.Result["MESSAGE"] = Messages.EM01;
                    return(output);
                }
            }
            logger.Log("登録解除サービスへの入力データが不正", inputData[0]);
            output.Result["MESSAGE"] = Messages.EM10;
            return(output);
        }