Beispiel #1
0
 public void Next()
 {
     Count++;
     if (Count % 100 == 0)
     {
         Log.Info(Count.ToString());
     }
 }
Beispiel #2
0
        /// <summary>
        /// 创建系统日志
        /// </summary>
        /// <param name="level">级别</param>
        /// <param name="type">类名,可自定义</param>
        /// <param name="parasHashtable">自定义参数,目前固定三个{UserId;IP;FunName}</param>
        /// <param name="message">内容</param>
        public void Log(MsgLevel level, System.String type, Hashtable parasHashtable, object message)
        {
            switch (level)
            {
            case MsgLevel.DEBUG:
                MyLog.Debug(type, parasHashtable, message);
                break;

            case MsgLevel.INFO:
                MyLog.Info(type, parasHashtable, message);
                break;

            case MsgLevel.WARN:
                MyLog.Warn(type, parasHashtable, message);
                break;

            case MsgLevel.ERROR:
                MyLog.Error(type, parasHashtable, message);
                break;

            case MsgLevel.FATAL:
                MyLog.Fatal(type, parasHashtable, message);
                break;
            }
        }
Beispiel #3
0
        /// <summary>
        /// 创建系统日志
        /// </summary>
        /// <param name="level">级别</param>
        /// <param name="type">类名,可自定义</param>
        /// <param name="parasHashtable">自定义参数,目前固定三个{UserId;IP;FunName}</param>
        /// <param name="message">内容</param>
        public void Log(MsgLevel level, System.String type, Hashtable parasHashtable, object message)
        {
            switch (level)
            {
            case MsgLevel.Debug:
                MyLog.Debug(type, parasHashtable, message);
                break;

            case MsgLevel.Info:
                MyLog.Info(type, parasHashtable, message);
                break;

            case MsgLevel.Warn:
                MyLog.Warn(type, parasHashtable, message);
                break;

            case MsgLevel.Error:
                MyLog.Error(type, parasHashtable, message);
                break;

            case MsgLevel.Fatal:
                MyLog.Fatal(type, parasHashtable, message);
                break;
            }
        }
Beispiel #4
0
    protected void Click_LogIn(object sender, EventArgs e)
    {
        try
        {
            if (IsValid)
            {
                IMyLog log = MyLog.GetLogger("Login");
                // Validate the user password
                SessionData sd = ConstantStrings.GetSessionData(Session);
                CommonHelper.DoLogout(sd);

                Data_AppUserFile user = DSSwitch.appUser().RetrieveOne(Email.Text, log);

                if (isAdmin())
                {
                    sd.LoggedOnUserEmail           = ConfigurationManager.AppSettings["AdminEmail"];
                    sd.LoggedOnUserName            = "******";
                    sd.LoggonOnUserIsAdmin         = true;
                    sd.LoggedOnUsersNiceSystemInfo = NiceSystemInfo.DEFAULT;
                    Response.Redirect("~/");
                }
                else if (((user != null) && (user.Password == Password.Text)) ||
                         ((user != null) && (Password.Text == ConfigurationManager.AppSettings["AdminPassword"]))
                         )
                {
                    sd.LoggedOnUserEmail           = Email.Text;
                    sd.LoggedOnUserName            = user.UserName;
                    sd.LoggedOnUsersNiceSystemInfo = user.ApiGuId.GetSystemInfoFromAPIId();
                    log.Info(string.Format("NiceSystemInfo: {0} {1} {2}", user.ApiGuId, sd.LoggedOnUsersNiceSystemInfo.Name, sd.LoggedOnUsersNiceSystemInfo.APIId));
                    string url      = "~/Details";
                    string redirect = Request.QueryString[ConstantStrings.url_Redirect];
                    if (redirect != null)
                    {
                        try
                        {
                            url = System.Text.Encoding.ASCII.GetString(Convert.FromBase64String(redirect));
                        }
                        catch
                        {
                        }
                    }
                    Response.Redirect(url);
                }
                else
                {
                    FailureText.Text     = "Invalid username or password.";
                    ErrorMessage.Visible = true;
                }
            }
        }
        catch (DataUnavailableException)
        {
            DSSwitch.OnDataUnavailableException(this);
        }
    }
Beispiel #5
0
    protected void Commit_Click(object sender, EventArgs e)
    {
        IMyLog logUpgrade = MyLog.GetLogger("Upgrade");

        try
        {
            UpdateInfo priceInfo = getHardcodedPriceInfoOrGoBackToPricePage();

            int howManyNumbers = 0;
            int.TryParse(HowManyNumbers.SelectedItem.Value, out howManyNumbers);

            int howManyMessages = 0;
            int.TryParse(HowManyMessages.SelectedItem.Value, out howManyMessages);

            int howManyTopups = 0;
            int.TryParse(HowManyTopups.SelectedItem.Value, out howManyTopups);

            int fullpayment = 0;
            int.TryParse(FullPayment.SelectedItem.Value, out fullpayment);

            logUpgrade.Info("Commit");

            Data_AppUserWallet wal = Data_AppUserWallet.Create(
                sd.LoggedOnUserEmail,
                TitleId.Text,
                priceInfo.Info,
                priceInfo.Type,
                new AmountAndPrice(howManyNumbers, GetPrice(priceInfo.Number)),
                new AmountAndPrice(howManyMessages, GetPrice(priceInfo.Message)),
                new AmountAndPrice(howManyTopups, GetPrice(priceInfo.Month)),
                new AmountAndPrice(1, GetPrice(priceInfo.OneTimeSetup)),
                new AmountAndPrice(fullpayment, GetPrice(priceInfo.FullPayment)));

            string emailBody = wal.GetEmailBody(sd.LoggedOnUserName, sd.LoggedOnUserEmail);

            bool alreadyThere;
            DSSwitch.appWallet().StoreNew(wal, out alreadyThere, logUpgrade);

            EMail.SendGeneralEmail(sd.LoggedOnUserEmail, true, wal.Title, emailBody, new LogForEmailSend(MyLog.GetLogger("Email")));

            showStoredData(wal);
        }
        catch (DataUnavailableException)
        {
            DSSwitch.OnDataUnavailableException(this);
        }
        catch (Exception ex)
        {
            logUpgrade.Debug(ex.Message);
        }
    }
Beispiel #6
0
        public string Process_Registration(NiceSystemInfo niceSystem, out bool fileArleadyUsed, bool sendActivationEmail, string UserName, string MoblieAllNumbers, string Email, string Password, string CreationIp, string WhereHeardText, IMyLog log, LogForEmailSend log4Email)
        {
            StringBuilder sbInfo = new StringBuilder();

            fileArleadyUsed = true;
            try
            {
                timeNow = DateTime.UtcNow;
                Data_AppUserFile ud = Data_AppUserFile.Create(
                    UserName, true, MoblieAllNumbers, Email, Password, CreationIp);
                sbInfo.Append(ud.ApiGuId);
                DSSwitch.appUser().StoreNew(ud, out fileArleadyUsed, log);
                if (!fileArleadyUsed)
                {
                    if (sendActivationEmail)
                    {
                        EMail.SendRegisterActivation(ud, log4Email);
                    }
                    if (log != null)
                    {
                        log.Info(ud.Email + " account created");
                    }
                    if (log != null)
                    {
                        log.Info("WhereHeard " + WhereHeardText);
                    }
                }
            }
            catch (ArgumentException ae)
            {
                sbInfo.Append(ae.Message);
            }
            catch (Exception)
            {
                sbInfo.Append("ERROR");
            }
            return(sbInfo.ToString());
        }
Beispiel #7
0
    protected void CancelCommit_Click(object sender, EventArgs e)
    {
        IMyLog logUpgrade = MyLog.GetLogger("Upgrade");

        try
        {
            logUpgrade.Info("CancelCommit_Click");

            sd.QuickMessage     = "You have just cancelled your upgrade request";
            sd.QuickMessageGood = true;

            DSSwitch.appWallet().DeleteOne(sd.LoggedOnUserEmail, logUpgrade);

            Response.Redirect("~/Price");
        }
        catch (DataUnavailableException)
        {
            DSSwitch.OnDataUnavailableException(this);
        }
        catch (Exception ex)
        {
            logUpgrade.Debug(ex.Message);
        }
    }
Beispiel #8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // This comes from the Android direct

        IMyLog trayLog = MyLog.GetLogger("TrayApp");

        trayLog.Info("Incoming 17:00");
        string inBody = "notSet";

        try
        {
            LogForEmailSend log4Email = new LogForEmailSend(MyLog.GetLogger("Email"));
            Stream          inStream  = Request.InputStream;

            if (inStream.Length == 0)
            {
                Response.ContentType = "text/plain";
                Response.Write("DirectTel: Zero!");
                return;
            }

            DirectTel_InJson inJson = null;
            using (var sr = new StreamReader(inStream))
            {
                inBody = sr.ReadToEnd();
                inJson = JsonConvert.DeserializeObject <DirectTel_InJson>(inBody);
            }
            trayLog.Debug("In Json: ");
            trayLog.Debug(JsonConvert.SerializeObject(inJson));

            DirectTel_OutJson outJson = DirectTel_Processing.ProcessDirectTel(inJson, trayLog, log4Email,
                                                                              delegate(NiceSystemInfo subSystem)
            {
                //OnGet
                // Update loopback file (with the data from the incoming object)
                using (DataFile_Loopback ld = new DataFile_Loopback(DataFile_Base.OpenType.ForUpdate_CreateIfNotThere))
                {
                    DataFile_Loopback_Entry sub = ld.GetEntry_CreateIfNotThere(subSystem.Name);
                    sub.lastDirectTelGet        = DateTime.UtcNow;
                }
            },
                                                                              delegate(NiceSystemInfo subSystem)
            {
                //OnAck
                // Update loopback file (with the data from the incoming object)
                using (DataFile_Loopback ld = new DataFile_Loopback(DataFile_Base.OpenType.ForUpdate_CreateIfNotThere))
                {
                    DataFile_Loopback_Entry sub = ld.GetEntry_CreateIfNotThere(subSystem.Name);
                    sub.lastDirectTelAck        = DateTime.UtcNow;
                }
            });

            trayLog.Debug("Out Json: ");
            trayLog.Debug(JsonConvert.SerializeObject(outJson));
            Tx(outJson);
        }
        catch (ThreadAbortException)
        {
            trayLog.Debug("ThreadAbortException");
        }
        catch (Exception se)
        {
            trayLog.Error("DirectTel " + se.Message + " " + se.ToString());
            trayLog.Error("DirectTel " + inBody);
            Response.ContentType = "text/plain";
            Response.Write("Exception");
            Response.Write(se.Message);
            Response.Write(se.ToString());
        }
    }
Beispiel #9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // This comes from the Admin User (protected)

        NiceASP.SessionData.LoggedOnOrRedirectToRoot(Session, Response, true);

        if (!IsPostBack)
        {
            IMyLog          logInTest = MyLog.GetLogger("Test");
            LogForEmailSend log4Email = new LogForEmailSend(MyLog.GetLogger("Email"));

            string           user  = null;
            Data_AppUserFile userF = null;

            string sVal = Request.QueryString["Id"];
            switch (sVal)
            {
            case "ShowRecentMessages":
                Response.ContentType = "text/plain";
                Response.Write("ShowRecentMessages:\r\n");
                int Days = 5;
                if (Request.QueryString["Days"] != null)
                {
                    Days = Int32.Parse(Request.QueryString["Days"]);
                }
                DateTime pivTime = DateTime.UtcNow;
                pivTime = pivTime.AddDays(-1 * Days);
                DSSwitch.msgFile00().ForEach(
                    NiceASP.SessionData.SessionsSystem_Get(Session), pivTime, null, Data_Net__00NormalMessage.eLocation.Processed, logInTest,
                    delegate(Data_Net__00NormalMessage _00)
                {
                    if (!_00.NoCounterUpdate)
                    {
                        Response.Write(_00.DestMobile + "\r\n".PadLeft(40, '*'));
                        Response.Write(_00.UserId + "\r\n");
                        Response.Write(_00.MsgTicks.ToUkTime(true) + "\r\n");
                        if (_00.FailedCounter != 0)
                        {
                            Response.Write(String.Format("FailedCounter: {0} / {1}\r\n", _00.FailedCounter, _00.DisposeAfterNFailed));
                        }
                        Response.Write(_00.Msg + "\r\n\r\n");
                    }
                });
                break;

            case "ShowSentMessages":
                Response.ContentType = "text/plain";
                Response.Write("ShowSentMessages:\r\n");
                user = Request.QueryString["u"];
                Response.Write(user + ":\r\n");
                DSSwitch.msgFile00().ForEach(NiceASP.SessionData.SessionsSystem_Get(Session), DateTime.MinValue, user, Data_Net__00NormalMessage.eLocation.Processed, logInTest,
                                             delegate(Data_Net__00NormalMessage _00)
                {
                    Response.Write(_00.DestMobile + "\r\n");
                    Response.Write(_00.MsgTicks.ToUkTime(true) + "\r\n");
                    Response.Write(String.Format("FailedCounter: {0} / {1}\r\n", _00.FailedCounter, _00.DisposeAfterNFailed));
                    Response.Write("NoCounterUpdate: " + _00.NoCounterUpdate.ToString() + "\r\n");
                    Response.Write(_00.Msg + "\r\n\r\n");
                });
                break;

            case "ShowUsers":
                bool filterOut_email_sent_for_verification = false;
                bool filterOut_verified_welcome_No_sent    = false;
                bool filterOut_verified_welcome_queued     = false;
                bool filterOut_verified_checkingTelNumbers = false;
                bool filterOut_blocked                      = false;
                bool filterOut_free_account                 = false;
                bool filterOut_commercial_monthly           = false;
                bool filterOut_commercial_payassent         = false;
                bool filterOut_commercial_systemDuplication = false;
                switch (Request.QueryString["Filter"])
                {
                case "OnlyInteresting":
                    filterOut_email_sent_for_verification = true;
                    filterOut_blocked = true;
                    break;

                case "OnlyCommercial":
                    filterOut_verified_checkingTelNumbers = true;
                    filterOut_verified_welcome_No_sent    = true;
                    filterOut_verified_welcome_queued     = true;
                    filterOut_email_sent_for_verification = true;
                    filterOut_blocked      = true;
                    filterOut_free_account = true;
                    break;
                }

                Data_AppUserFile.SortType sortType = Data_AppUserFile.SortType.State;
                switch (Request.QueryString["Sort"])
                {
                case "Date":
                    sortType = Data_AppUserFile.SortType.Date;
                    break;

                case "State":
                    sortType = Data_AppUserFile.SortType.State;
                    break;

                case "Email":
                    sortType = Data_AppUserFile.SortType.Email;
                    break;

                case "Usage":
                    sortType = Data_AppUserFile.SortType.Usage;
                    break;
                }

                showUsers_tableHeader(DSSwitch.appUser().GetInfo());
                int count = 0;
                DSSwitch.appUser().RetrieveAll(sortType,
                                               delegate(Data_AppUserFile d)
                {
                    if (count++ > 1000)
                    {
                        // limit to 1000 results
                        return;
                    }

                    switch (d.AccountStatus)
                    {
                    case Data_AppUserFile.eUserStatus.email_sent_for_verification:
                        if (!filterOut_email_sent_for_verification)
                        {
                            showUsers_tableEntry(d, Data_AppUserFile.EmailSaveChars(d.Email));
                        }
                        break;

                    case Data_AppUserFile.eUserStatus.verified_welcome_No_sent:
                        if (!filterOut_verified_welcome_No_sent)
                        {
                            showUsers_tableEntry(d, Data_AppUserFile.EmailSaveChars(d.Email));
                        }
                        break;

                    case Data_AppUserFile.eUserStatus.verified_welcome_queued:
                        if (!filterOut_verified_welcome_queued)
                        {
                            showUsers_tableEntry(d, Data_AppUserFile.EmailSaveChars(d.Email));
                        }
                        break;

                    case Data_AppUserFile.eUserStatus.verified_checkingTelNumbers:
                        if (!filterOut_verified_checkingTelNumbers)
                        {
                            showUsers_tableEntry(d, Data_AppUserFile.EmailSaveChars(d.Email));
                        }
                        break;

                    case Data_AppUserFile.eUserStatus.blocked:
                        if (!filterOut_blocked)
                        {
                            showUsers_tableEntry(d, Data_AppUserFile.EmailSaveChars(d.Email));
                        }
                        break;

                    case Data_AppUserFile.eUserStatus.free_account:
                        if (!filterOut_free_account)
                        {
                            showUsers_tableEntry(d, Data_AppUserFile.EmailSaveChars(d.Email));
                        }
                        break;

                    case Data_AppUserFile.eUserStatus.commercial_monthly:
                    case Data_AppUserFile.eUserStatus.commercial_monthlyDifPrice:
                        if (!filterOut_commercial_monthly)
                        {
                            showUsers_tableEntry(d, Data_AppUserFile.EmailSaveChars(d.Email));
                        }
                        break;

                    case Data_AppUserFile.eUserStatus.commercial_payassent:
                        if (!filterOut_commercial_payassent)
                        {
                            showUsers_tableEntry(d, Data_AppUserFile.EmailSaveChars(d.Email));
                        }
                        break;

                    case Data_AppUserFile.eUserStatus.commercial_systemDuplication:
                        if (!filterOut_commercial_systemDuplication)
                        {
                            showUsers_tableEntry(d, Data_AppUserFile.EmailSaveChars(d.Email));
                        }
                        break;
                    }
                },
                                               logInTest);
                showUsers_tableFooter();
                break;

            //case "CopyAppUsersToDB":
            //    int count = 0;
            //    DSSwitch.appUser().RetrieveAll(
            //        Data_AppUserFile.SortType.State,
            //        delegate(Data_AppUserFile d)
            //        {
            //            bool fileArleadyUsed;
            //            DSSwitch.appUser_DB().StoreNew(d, out fileArleadyUsed, logInTest);
            //            count++;
            //        },
            //        logInTest);
            //    Response.ContentType = "text/plain";
            //    Response.Write("Done " + count.ToString());
            //    break;


            case "SendWelcomeSMS":
                Response.ContentType = "text/plain";
                user  = Request.QueryString["u"];
                userF = DSSwitch.appUser().RetrieveOne(user, logInTest);
                Response.ContentType = "text/plain";
                foreach (string tel1 in userF.MobileNumberArray())
                {
                    string additionalInfo;
                    Response.Write(tel1 + " " +
                                   (new APIActualSending(NiceASP.SessionData.SessionsSystem_Get(Session)).SendWhatsApp(
                                        userF.ApiGuId,
                                        tel1,
                                        "Welcome to NiceApi.net\r\n",
                                        true,
                                        logInTest,
                                        out additionalInfo)));
                    Response.Write(" " + additionalInfo);
                    System.Threading.Thread.Sleep(200);
                    Response.Write(" slept\r\n");
                }
                break;

            case "SendJustActivated":
                user  = Request.QueryString["u"];
                userF = DSSwitch.appUser().RetrieveOne(user, logInTest);
                Response.ContentType = "text/plain";
                Response.Write(sVal + (
                                   EMail.SendJustActivated(userF, log4Email) ?
                                   " ok" : " failed"));
                break;

            case "ResendVerifyMail":
                user  = Request.QueryString["u"];
                userF = DSSwitch.appUser().RetrieveOne(user, logInTest);
                Response.ContentType = "text/plain";
                Response.Write(sVal + (
                                   EMail.SendRegisterActivation(userF, log4Email) ?
                                   " ok" : " failed"));
                break;

            case "Queue":
                doQueue(logInTest);
                break;

            case "Log":
                logInTest.Info("A test msg from Test.Log");
                Response.ContentType = "text/plain";
                Response.Write("Log done");
                break;

            case "null":
                userF = null;
                user  = userF.UserName;    // simulate bad code
                break;

            default:
                throw new ArgumentNullException("only a test");
            }
        }
    }
Beispiel #10
0
        public string Process_Registration_JustVerified(NiceSystemInfo niceSystem, out bool ok, bool sendAdminNotification, bool sendAdminNotificationToWhatsapp, IMyLog log, LogForEmailSend log4Email)
        {
            StringBuilder sbInfo     = new StringBuilder();
            string        telToCheck = null;

            ok = false;
            string friendlyEmail = null;
            bool   okIntern      = false;

            try
            {
                timeNow = DateTime.UtcNow;
                // 1 extract (check) input data
                if (string.IsNullOrEmpty(APIId))
                {
                    throw new ArgumentException("X-APIId missing");
                }

                // 2 load user file and check guid
                string email = Data_AppUserFile.API_IdToEmail(APIId);
                if (email == null)
                {
                    throw new ArgumentException("X-APIId unknown");
                }
                DSSwitch.appUser().Update_General(email, delegate(Data_AppUserFile user, Object args)
                {
                    if (user == null)
                    {
                        throw new ArgumentException("X-APIId unknown");
                    }
                    if (user.ApiGuId != APIId)
                    {
                        throw new ArgumentException("X-APIId unknown");
                    }
                    if (user.AccountStatus != Data_AppUserFile.eUserStatus.email_sent_for_verification)
                    {
                        throw new ArgumentException("AccountStatus is wrong");
                    }

                    // 3 action, produce telCheck file and update AccountStatus
                    user.AccountStatus = Data_AppUserFile.eUserStatus.verified_checkingTelNumbers;
                    telToCheck         = user.MobileNumbers_AllConfirmed__.getVal + user.MobileNumbers_AllUnConfirmed__.getVal;
                    friendlyEmail      = user.Email;
                    okIntern           = true;
                }, null, delegate(Object args)
                {
                    // post process
                    if (log != null)
                    {
                        log.Info(friendlyEmail + " just verified his email");
                    }
                    if (sendAdminNotification)
                    {
                        EMail.SendAdminNotification(friendlyEmail + " just verified his email", log4Email);
                    }
                    if (sendAdminNotificationToWhatsapp)
                    {
                        NotificationInfo notificationInfo = DSSwitch.full().GetNotificationInfo();
                        NiceSystemInfo notifyToUse        = DSSwitch.full().GetSystems(false).FirstOrDefault(s => s.Name == notificationInfo.Name);
                        if (notifyToUse != null)
                        {
                            Data_Net__00NormalMessage msg = new Data_Net__00NormalMessage(
                                Data_AppUserFile.API_IdToEmail(notifyToUse.APIId),
                                "zapi_" + notificationInfo.RxTel,
                                DateTime.UtcNow.Ticks,
                                friendlyEmail + " just verified his email",
                                0, 10, true);
                            DSSwitch.msgFile00().Store(notifyToUse, msg, Data_Net__00NormalMessage.eLocation.Queued, log);
                        }
                    }
                    Data_Net__04CheckTelNumbers _04 = new Data_Net__04CheckTelNumbers(friendlyEmail, timeNow.Ticks, telToCheck, "");
                    DSSwitch.msgFile04().Store(niceSystem, _04, log);
                }, log);
            }
            catch (ArgumentException ae)
            {
                sbInfo.Append(ae.Message);
            }
            catch (Exception)
            {
                sbInfo.Append("ERROR");
            }
            ok = okIntern;
            return(sbInfo.ToString());
        }
Beispiel #11
0
 public static void JustALogMessage(IMyLog log, QuestionOption it)
 {
     log.Info("JustALogMessage");
 }