public void NLogAccessLayerTest()
        {
            string logFile = Path.GetTempFileName();

            LoggingConfiguration cfg  = new LoggingConfiguration();
            FileTarget           file = new FileTarget()
            {
                FileName = logFile, Layout = "${message}", AutoFlush = true
            };

            cfg.AddTarget("FILE", file);
            cfg.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, file));
            LogManager.Configuration = cfg;

            Logger logger = LogManager.GetLogger("TEST");
            IMyLog log    = NLogAccessLayer.Create <IMyLog>(logger);

            log.SomeError("Donald Duck", new Exception("Out of money."));

            string txt = File.ReadAllText(logFile);

            Assert.IsFalse(string.IsNullOrEmpty(txt));

            log.SomeOtherError("42");
            Assert.AreEqual(2, File.ReadAllLines(logFile).Length);
        }
Exemplo n.º 2
0
    protected void allFieldsValidation(object sender, ServerValidateEventArgs e)
    {
        bool bOk = true;

        errorSummary.Text    = "";
        errorSummary.Visible = false;

        // basic checks
        checkUserName_ServerValidate(ref bOk);
        checkTelx_ServerValidate(ref bOk, 1);
        checkTelx_ServerValidate(ref bOk, 2);
        checkTelx_ServerValidate(ref bOk, 3);
        checkTelx_ServerValidate(ref bOk, 4);
        checkTelx_ServerValidate(ref bOk, 5);
        checkEmail_ServerValidate(ref bOk);
        checkPasswordWithConfirm_ServerValidate(ref bOk);

        if (bOk)
        {
            IMyLog log = MyLog.GetLogger("Register");

            // basic test ok, see if the numbers are already used
            TelListController currentList = DSSwitch.appUser().GetCurrentTelList(log);
            using (var _lock = currentList.GetLock())
            {
                checkTelx_AlreadyRegistred(ref bOk, 1, _lock.Locked);
                checkTelx_AlreadyRegistred(ref bOk, 2, _lock.Locked);
                checkTelx_AlreadyRegistred(ref bOk, 3, _lock.Locked);
                checkTelx_AlreadyRegistred(ref bOk, 4, _lock.Locked);
                checkTelx_AlreadyRegistred(ref bOk, 5, _lock.Locked);
            }
        }

        e.IsValid = bOk;
    }
Exemplo n.º 3
0
 public MessageProcessing_TrayFrom(NiceSystemInfo niceSystem, d_OnScreenShot onScreenshot, IMyLog trayLog, LogForEmailSend log4Email)
 {
     this.onScreenshot = onScreenshot;
     this.trayLog      = trayLog;
     this.log4Email    = log4Email;
     this.niceSystem   = niceSystem;
 }
Exemplo n.º 4
0
        private void loadUserFileAndCheckGUID(Action action, IMyLog log)
        {
            string email = Data_AppUserFile.API_IdToEmail(m_RequId);

            if (email == null)
            {
                throw new ArgumentException("X-APIId unknown");
            }
            DSSwitch.appUser().Update_General(email, delegate(Data_AppUserFile user, Object args)
            {
                m_User = user;
                if (m_User == null)
                {
                    throw new ArgumentException("X-APIId unknown");
                }
                if (!m_User.IsAccountActive(m_Message))
                {
                    throw new ArgumentException("Account not active (1). " + m_User.AccountStatusExplained());
                }
                if (m_User.ApiGuId != m_RequId)
                {
                    throw new ArgumentException("X-APIId unknown");
                }
                action();
            }, null, null, log);
        }
Exemplo n.º 5
0
        public static Stream ForWrite(string path, IMyLog log)
        {
            Stopwatch watch = new Stopwatch();

            watch.Start();
            Stream r = null;

            while (r == null)
            {
                try
                {
                    r = File.Create(path);
                }
                catch (IOException)
                {
                    if (watch.ElapsedMilliseconds > 5000)
                    {
                        log.Error(String.Format("ForWrite failed on {0}", path));
                        break;
                    }
                    Thread.Sleep(50);
                }
            }
            return(r);
        }
Exemplo n.º 6
0
        public static void MultySystemDebugs(IMyLog log, QuestionOption it)
        {
            var x1 = DSSwitch.appUser().GetType();
            var x2 = DSSwitch.full().GetNiceSystemType();

            DSSwitch.appUser().RetrieveAll(Data_AppUserFile.SortType.State, null, log);
        }
Exemplo n.º 7
0
        private void lAny(IMyLog log, QuestionOption it)
        {
            Console.Clear();
            string select = "SELECT [Date], [Level], [Logger], [Message] FROM [dbo].[Log] ";

            string where = String.Format("WHERE [Logger] like '{0}'", it.OptionText);
            if (!String.IsNullOrEmpty(limitQueryForDate))
            {
                where += limitQueryForDate;
            }

            string order = "ORDER BY [Date] ";

            string cmd = select + where + order;

//            String.Format(@"
//SELECT [Date], [Level], [Logger], [Message] FROM [dbo].[Log]
//WHERE [Logger] like '{0}'
//ORDER BY [Date]
//", it.OptionText);

            using (SqlDisposable s = new SqlDisposable(SQLDBConfig.DBToUse.LogDB, cmd))
            {
                while (s.Reader.Read())
                {
                    DateTime Date = (DateTime)s.Reader["Date"];
                    Date = Date.AddHours(4);//mg to get date in brasil
                    String Level   = (String)s.Reader["Level"];
                    String Logger  = (String)s.Reader["Logger"];
                    String Message = (String)s.Reader["Message"];
                    Console.WriteLine(String.Format("{0:dd/MM HH:mm} {1} {2} {3}",
                                                    Date, Level, Logger, Message));
                }
            }
        }
Exemplo n.º 8
0
        public static Stream ForRead(string path, bool doRetry, bool readAndWrite, IMyLog log)
        {
            Stopwatch watch = new Stopwatch();

            watch.Start();
            Stream r = null;

            while (r == null)
            {
                try
                {
                    if (readAndWrite)
                    {
                        r = File.Open(path, FileMode.Open, FileAccess.ReadWrite);
                    }
                    else
                    {
                        r = File.OpenRead(path);
                    }
                }
                catch (FileNotFoundException)
                {
                    if (doRetry)
                    {
                        if (watch.ElapsedMilliseconds > 5000)
                        {
                            log.Error(String.Format("ForRead FileNotFoundException looped for 5sec {0}", path));
                            break;
                        }
                        Thread.Sleep(500);
                    }
                    else
                    {
                        if (!path.Contains("admin_at_niceapi_dot_net"))
                        {
                            log.Error(String.Format("ForRead FileNotFoundException no retry {0}", path));
                        }
                        break;
                    }
                }
                catch (IOException ioe)
                {
                    if (doRetry)
                    {
                        if (watch.ElapsedMilliseconds > 5000)
                        {
                            log.Error(String.Format("ForRead {1} looped for 5sec {0}", path, ioe.ToString()));
                            break;
                        }
                        Thread.Sleep(500);
                    }
                    else
                    {
                        log.Error(String.Format("ForRead {1} no retry {0}", path, ioe.ToString()));
                        break;
                    }
                }
            }
            return(r);
        }
Exemplo n.º 9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // This comes from the AdminTool

        try
        {
            string XAPIId          = Request.Headers["X-APIId"];
            string XAPIInstruction = Request.Headers["X-APIInstruction"];
            string Message         = "";
            IMyLog log             = MyLog.GetLogger("API");

            using (StreamReader sr = new StreamReader(Request.InputStream))
            {
                Message = sr.ReadToEnd();
            }

            MessageProcessing_API api = new MessageProcessing_API(XAPIId);
            string result             = api.Process_TelNumAPI(XAPIId.GetSystemInfoFromAPIId(), XAPIInstruction, Message, log);
            Response.ContentType = "text/plain";
            Response.Write(result);
        }
        catch (DataUnavailableException due)
        {
            Response.ContentType = "text/plain";
            Response.Write(due.Message);
        }
    }
Exemplo n.º 10
0
        public static void AddToFree(IMyLog log, QuestionOption it)
        {
            try
            {
                string email   = Question.Ask("Email");
                string telList = Question.Ask("TelList");

                string         url     = WhatsappMessages.GetHost("APIPrivAddTel");
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Method      = "POST";
                request.ContentType = "application/x-www-form-urlencoded";
                request.Headers.Add("X-EmailB64", Convert.ToBase64String(Encoding.ASCII.GetBytes(email)));
                request.Headers.Add("X-TelList", telList);
                LowLevelHttpDumper.Dump(request);
                using (StreamWriter streamOut = new StreamWriter(request.GetRequestStream()))
                {
                    streamOut.Write(" ");
                }
                using (StreamReader streamIn = new StreamReader(request.GetResponse().GetResponseStream()))
                {
                    Console.WriteLine(streamIn.ReadToEnd());
                }
            }
            catch (SystemException se)
            {
                Console.WriteLine(se.Message);
            }
            Console.ReadLine();
        }
Exemplo n.º 11
0
        public static void Go(IMyLog log, QuestionOption it)
        {
            List <One> d         = Fill();
            string     startWith = "";
            int        depth     = 1;

            while (true)
            {
                Question   q       = new Question();
                List <One> subList = d.Where(x => x.depth == depth && x.Id.StartsWith(startWith)).ToList();
                foreach (var c in subList)
                {
                    q.Add(new QuestionOption(c.Title, null));
                }
                QuestionOption u = q.AskAndReturnOption("Select");

                One selected = d.FirstOrDefault(x => x.Title == u.OptionText);
                if (selected.Text != null)
                {
                    // end
                    Console.Clear();
                    System.Windows.Forms.Clipboard.SetText(selected.Text);
                    Console.WriteLine(selected.Text);
                    Console.WriteLine();
                    Console.WriteLine("now in Clipboard");
                    Console.ReadKey();
                    return;
                }
                depth++;
                startWith = selected.Id + "_";
            }
        }
Exemplo n.º 12
0
 public KomBankTnCViewModel(KomBankE komBankE, IniFile iniFile, IMyLog logFile, IWindowManager windowManager, ChangesViewModel changesViewModel)
 {
     _komBankE         = komBankE;
     _iniFile          = iniFile;
     _logFile          = logFile;
     _windowManager    = windowManager;
     _changesViewModel = changesViewModel;
 }
Exemplo n.º 13
0
        public static void GetNewAPIId(IMyLog log, QuestionOption it)
        {
            string email = Question.Ask("Enter email");
            string apiid = Data_AppUserFile.API_ToId(email, Guid.NewGuid());

            Console.WriteLine("New APIId produced for " + email);
            Console.WriteLine(apiid);
        }
Exemplo n.º 14
0
 public static void NiceApiLibrary_StartUp(IMyLog log, bool waitUntilStartupIsDone)
 {
     if (!startupCalled)
     {
         startupCalled = true;
         DSSwitch.StartUp(log, waitUntilStartupIsDone);
     }
 }
Exemplo n.º 15
0
 private static IMyLog[] WrapLoggers(ILogger[] loggers)
 {
     IMyLog[] results = new IMyLog[loggers.Length];
     for (int i = 0; i < loggers.Length; i++)
     {
         results[i] = MyLogManager.WrapLogger(loggers[i]);
     }
     return(results);
 }
Exemplo n.º 16
0
        public void DeleteOne(string email, IMyLog log)
        {
            string filePath = getWalletFullPath(email);

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
        }
Exemplo n.º 17
0
 public static void DebugLoopback(IMyLog log, QuestionOption it)
 {
     using (DataFile_Loopback ld = new DataFile_Loopback(DataFile_Base.OpenType.ForUpdate_CreateIfNotThere))
     {
         ld.LastError = "e13";
         ld.GetEntry_CreateIfNotThere(NiceSystemInfo.DEFAULT_STR).debugStr = "Zero is nice at " + DateTime.UtcNow.Ticks.ToUkTime(false);
         ld.GetEntry_CreateIfNotThere("123").debugStr = "only testing";
     }
 }
Exemplo n.º 18
0
 public KomBankViewModel(IniFile iniFile, KomBankE komBank, IMyLog logFile, IWindowManager windowManager, ChangesViewModel changesViewModel)
 {
     _iniFile          = iniFile;
     KomBank           = komBank;
     _logFile          = logFile;
     _windowManager    = windowManager;
     _changesViewModel = changesViewModel;
     _baliApiUrl       = iniFile.Read(IniSection.General, IniKey.BaliApiUrl, "localhost:11082");
 }
Exemplo n.º 19
0
    private void doQueue_old(IMyLog log)
    {
        // show queued files
        responseWriteHomeLink();

        int queue = DSSwitch.msgFile00().GetNoOfQueuedItems(NiceASP.SessionData.SessionsSystem_Get(Session), log);

        Response.Write(String.Format("Length : {0}<br />", queue));
    }
Exemplo n.º 20
0
 public static void DebugAndroidSyncInLowLib(IMyLog log, QuestionOption it)
 {
     //AndroidSynchroniserThread.OnLog = ToDebug;
     //AndroidSynchroniserThread.DoWeRellyWantToRun = true;
     //var x = AndroidSynchroniserThread.I;
     //while (true)
     //{
     //    Thread.Sleep(500);
     //}
 }
Exemplo n.º 21
0
        public static void EmailFromAPpiKey(IMyLog log, QuestionOption it)
        {
            var    key   = Question.Ask("Enter API Key");
            string email = Data_AppUserFile.API_IdToEmail(key);

            email = Data_AppUserFile.EmailToRealEmail(email);
            Console.WriteLine(key);
            Console.WriteLine(email);
            Console.WriteLine("");
        }
Exemplo n.º 22
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);
        }
    }
Exemplo n.º 23
0
        public bool HasAccount(string email, IMyLog log)
        {
            string folder = FolderNames.GetFolder(NiceSystemInfo.DEFAULT, MyFolders.ASP_UserAccountFolder_);
            string file   = folder + Path.DirectorySeparatorChar + Data_AppUserFile.EmailSaveChars(email) + ".txt";

            if (File.Exists(file))
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 24
0
 public static ASPTrayBase ReadOne(string filePath, IMyLog log)
 {
     if (!s_MsgFile_IsOld(filePath))
     {
         using (BinaryReader br = new BinaryReader(OpenFile.ForRead(filePath, true, false, log)))
         {
             return(ASPTrayBase.ReadOne(br));
         }
     }
     return(null);
 }
Exemplo n.º 25
0
        public bool HasAccount(string email, IMyLog log)
        {
            String cmd = String.Format("SELECT * FROM {0} WHERE {1} like '{2}'",
                                       TABLE_NAME,
                                       "[Email]",
                                       email);

            using (SqlDisposable s = new SqlDisposable(Db, cmd))
            {
                return(s.Reader.HasRows);
            }
        }
Exemplo n.º 26
0
 public void RetrieveAll(d1_Data_AppUserWallet d, IMyLog log)
 {
     foreach (string f1 in Directory.GetFiles(FolderNames.GetFolder(NiceSystemInfo.DEFAULT, MyFolders.ASP_UserWalletFolder_)))
     {
         string             email = Data_AppUserWalletHandling_File.GetEmailFromFileName(Path.GetFileName(f1));
         Data_AppUserWallet w1    = RetrieveOne(email, log);
         if (w1 != null)
         {
             d(w1);
         }
     }
 }
Exemplo n.º 27
0
        public async void Start(IniFile iniFile, IMyLog logFile, IWindowManager windowManager, ChangesViewModel changesViewModel)
        {
            _logFile = logFile;
            _logFile.AppendLine("Kom banks listening started");

            foreach (var komBank in _firstPageList)
            {
                var viewModel = await new KomBankViewModel(iniFile, komBank, _logFile, windowManager, changesViewModel).GetSomeLast();
                Application.Current.Dispatcher.Invoke(() => Banks.Add(viewModel));
                var unused = await Task.Factory.StartNew(viewModel.StartPolling);
            }
        }
Exemplo n.º 28
0
        public ShellViewModel(IniFile iniFile, IMyLog logFile, IWindowManager windowManager, ShellVm shellVm, ChangesViewModel changesViewModel)
        {
            _windowManager    = windowManager;
            _changesViewModel = changesViewModel;
            Model             = shellVm;

            StartNbRbPoller();
            Task.Delay(3000).Wait();
            StartBelStockPoller();
            StartTradingViewPollers();

            StartKomBankPollers(iniFile, logFile);
        }
Exemplo n.º 29
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);
        }
    }
Exemplo n.º 30
0
        public Data_AppUserFile RetrieveOne(string email, IMyLog log)
        {
            Data_AppUserFile ret = null;
            var strCmd           = String.Format("SELECT * FROM {0} WHERE [Email] like '{1}'", TABLE_NAME, email);

            using (SqlDisposable s = new SqlDisposable(Db, strCmd))
            {
                if (s.Reader.Read())
                {
                    ret = readOneRecord(s.Reader);
                }
            }
            return(ret);
        }
Exemplo n.º 31
0
 /// <summary>
 /// Lookup the wrapper objects for the loggers specified
 /// </summary>
 /// <param name="loggers">the loggers to get the wrappers for</param>
 /// <returns>Lookup the wrapper objects for the loggers specified</returns>
 private static IMyLog[] WrapLoggers(ILogger[] loggers)
 {
     IMyLog[] results = new IMyLog[loggers.Length];
     for (int i = 0; i < loggers.Length; i++)
     {
         results[i] = WrapLogger(loggers[i]);
     }
     return results;
 }