Example #1
0
        private async Task <string> request()
        {
            HttpClient client = new HttpClient();
            string     res    = string.Empty;

            try
            {
                res = await client.GetStringAsync(Request_Query);
            }
            catch (ArgumentNullException)
            {
                log.Error("Request Query is Empty");
            }
            catch (Exception e)
            {
                log.Error(e.Message + " Link: " + Request_Query);
            }

            if (res.Equals("{\"error\":{\"type\":\"Exception\",\"message\":\"Quota limit exceeded\",\"code\":4}}"))
            {
                log.Info("API Rate Limit waiting 2 sec.");
                Thread.Sleep(2000);
                res = await request();
            }

            if (string.IsNullOrWhiteSpace(res))
            {
                log.Info("Response is Empty");
            }
            return(res);
        }
Example #2
0
        /// <summary>
        /// Create Missing Playlists on Deezer
        /// </summary>
        /// <param name="MusicProvider">Music Provider Playlists</param>
        /// <param name="Deezer">Deezer Playlists</param>
        /// <returns></returns>
        internal async Task CreateMissingPlaylists(List <StandardPlaylist> MusicProvider, List <StandardPlaylist> Deezer)
        {
            // Initialize Objects
            List <string> dz = new List <string>();
            List <string> sc = new List <string>();

            DeezerAPI.Private api = new DeezerAPI.Private();

            // Write Playlist Names to Lists
            foreach (var d in Deezer)
            {
                dz.Add(d.title);
            }

            foreach (var s in MusicProvider)
            {
                sc.Add(s.title);
            }

            // Get differences from Lists
            IEnumerable <string> different = sc.Except(dz);

            // Create mising playlists
            foreach (var diff in different)
            {
                log.Info("Create Deezer Playlist: " + diff);
                await api.CreatePlaylistasync(diff);
            }
        }
Example #3
0
 void NLogFinish()
 {
     if (!DisableLogging)
     {
         NLogger.Info(TaskName, TaskType, "END", TaskHash, Logging.STAGE, Logging.CurrentLoadProcess?.Id);
     }
 }
Example #4
0
        public void FileSaveAs(Guid beforeGuid, Guid afterGuid)
        {
            if (!_isEnable)
            {
                return;
            }
            NLogger.Info("Try to saveas.beforeGuid:{0} afterGuid:{1}", beforeGuid, afterGuid);
            var existFile = RecoveryInfo.RecoveryFiles.FirstOrDefault(x => x.Guid == beforeGuid);

            if (existFile != null)
            {
                NLogger.Info("Recovery file with before guid {0} is exist.Try to remove it.", beforeGuid);
                RecoveryInfo.RecoveryFiles.Remove(existFile);
                try
                {
                    File.Delete(existFile.GetFullPath());
                    NLogger.Info("Remove recovery file with beforeguid successfully.");
                }
                catch (Exception ex)
                {
                    NLogger.Info("Remove recovery file with beforeguid failed.ex:{0}", ex.ToString());
                }
            }

            ManualSave();
        }
Example #5
0
        public void CloseWithoutSave()
        {
            if (!_isEnable)
            {
                return;
            }
            NLogger.Info("User closed a document without saving before.");
            this.LoadRecoveryFiles();
            IDocumentService doc = ServiceLocator.Current.GetInstance <IDocumentService>();

            if (!GlobalData.IsKeepLastAutoSaved && doc.Document != null)
            {
                NLogger.Info("IsKeepLastAutoSaved is false.Try to remove last recovery file.Guid is {0}", doc.Document.Guid);
                var existFile = RecoveryInfo.RecoveryFiles.FirstOrDefault(x => x.Guid == doc.Document.Guid);
                if (existFile != null)
                {
                    NLogger.Info("Last recovery file is exist, remove it from settings.");
                    RecoveryInfo.RecoveryFiles.Remove(existFile);
                    try
                    {
                        File.Delete(existFile.GetFullPath());
                        NLogger.Info("Remove last recovery file successfully.");
                    }
                    catch (Exception ex)
                    {
                        NLogger.Warn("Remove last recovery file failed.{0}", ex.ToString());
                    }

                    SaveRecoveryFiles();
                }
            }
        }
Example #6
0
        private void LoadRecoveryFiles()
        {
            NLogger.Info("Try to load RecoveryFilesInfo.");
            if (File.Exists(RecoveryFileXmlPath))
            {
                try
                {
                    SyncNamed.WaitOne();
                    using (var rdr = new StreamReader(RecoveryFileXmlPath))
                    {
                        var serializer = new XmlSerializer(typeof(RecoveryInfo));
                        RecoveryInfo = (RecoveryInfo)serializer.Deserialize(rdr);
                        NLogger.Info("Load RecoveryFilesInfo successfully.");
                    }

                    SyncNamed.ReleaseMutex();
                }
                catch
                {
                    RecoveryInfo = new RecoveryInfo();
                    NLogger.Info("Load RecoveryFilesInfo failed.Create new setting file.");
                }
            }
            else
            {
                RecoveryInfo = new RecoveryInfo();
                NLogger.Info("RecoveryFilesInfo not exist.Create new setting file.");
            }
        }
Example #7
0
        public void PerformSetting()
        {
            _isEnable = true;
            if (_isAutoSaveEnable != GlobalData.IsAutoSaveEnable ||
                _autoSaveTick != GlobalData.AutoSaveTick)
            {
                NLogger.Info("IsAutoSaveEnable [{0}] or AutoSaveTick [{1}] is changed.", GlobalData.IsAutoSaveEnable, GlobalData.AutoSaveTick);
                _isAutoSaveEnable = GlobalData.IsAutoSaveEnable;
                _autoSaveTick     = GlobalData.AutoSaveTick;

                if (_timer != null)
                {
                    _timer.Dispose();
                }

                if (_isAutoSaveEnable)
                {
                    _timer = new Timer(TimerTick, null, _autoSaveTick * 60 * 1000, _autoSaveTick * 60 * 1000);
                    //_timer = new Timer(TimerTick, null, 10000, 10000);
                    NLogger.Info("Set timer for tick {0}", _autoSaveTick);
                }
                else
                {
                    NLogger.Info("Disable auto save and remove timer.");
                }
            }
        }
Example #8
0
        public void CloseFile(IDocumentService doc)
        {
            if (!_isEnable)
            {
                return;
            }
            NLogger.Info("Closing file.");
            this.LoadRecoveryFiles();
            if (doc != null && doc.Document != null && !doc.Document.IsDirty)
            {
                NLogger.Info("The current document isn't dirty.It has been saved before.Try to remove relevant recovery file.");
                var existFile = RecoveryInfo.RecoveryFiles.FirstOrDefault(x => x.Guid == doc.Document.Guid);
                if (existFile != null)
                {
                    NLogger.Info("Relevant recovery file is exist.");
                    RecoveryInfo.RecoveryFiles.Remove(existFile);
                    try
                    {
                        File.Delete(existFile.GetFullPath());
                        NLogger.Info("Remove Relevant recovery file successfully.");
                    }
                    catch (Exception ex)
                    {
                        NLogger.Warn("Remove Relevant recovery file failed.ex:{0}", ex.ToString());
                    }

                    SaveRecoveryFiles();
                }
            }
        }
Example #9
0
        public void CloseFile()
        {
            if (!_isEnable)
            {
                return;
            }
            NLogger.Info("Close file by shuting down application.");
            this.LoadRecoveryFiles();
            if (RecoveryInfo.DocsClosedUnGracefully.Contains(_processId))
            {
                RecoveryInfo.DocsClosedUnGracefully.Remove(_processId);
                NLogger.Info("Remove current process Id {0} from DocsClosedUnGracefully.", _processId);
            }

            SaveRecoveryFiles();
            try
            {
                if (Directory.Exists(Tmp))
                {
                    NLogger.Info("Try to clear tmp folder.");
                    Directory.Delete(Tmp, true);
                    NLogger.Info("Try to clear tmp folder successfully.");
                }
            }
            catch
            {
            }

            CloseFile(ServiceLocator.Current.GetInstance <IDocumentService>());
        }
Example #10
0
        public void TestInfoPass()
        {
            var message = TestContext.TestName;

            logger.Info(new Exception(), $"{message}", null);
            Assert.AreEqual($"Info|{message}", target.LastMessage);
        }
Example #11
0
        public void SwitchToNewWindow()
        {
            try
            {
                string currentWindowHandle = driver.CurrentWindowHandle;
                var    windowHandles       = driver.WindowHandles;
                foreach (string windowHandle in windowHandles)
                {
                    if (windowHandle != currentWindowHandle)
                    {
                        driver.Close();
                        driver.SwitchTo().Window(windowHandle);
                    }
                }

                string info = string.Format(string.Format("Switch to new window"));
                NLogger.Info(info);
                HtmlReporter.Pass(info);
            }
            catch (WebDriverException ex)
            {
                string message    = string.Format("An error happens when trying to switch to new window");
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Example #12
0
 void NLogFinish()
 {
     if (!DisableLogging)
     {
         NLogger.Info(TaskName, TaskType, "END", TaskHash, ControlFlow.STAGE, ControlFlow.CurrentLoadProcess?.LoadProcessKey);
     }
 }
Example #13
0
        public void WaitForFullPageLoaded()
        {
            try
            {
                IJavaScriptExecutor js = (IJavaScriptExecutor)driver;

                for (int i = 0; i < 60; i++)
                {
                    Thread.Sleep(1000);
                    if (js.ExecuteScript("return document.readyState").ToString().Equals("complete"))
                    {
                        break;
                    }
                }

                string info = string.Format("Wait for page to be loaded completedly");
                NLogger.Info(info);
                HtmlReporter.Pass(info);
            }
            catch (Exception ex)
            {
                string message    = string.Format("WaitForFullPageLoaded: Error occurs");
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Example #14
0
        public void DatabaseLogger_LogsInfo_DatabaseLogs()
        {
            var message = "Some entry";
            var config  = new DatabaseLoggingConfiguration();

            config.Host         = "sql.emitknowledge.com";
            config.Database     = "app.db";
            config.Username     = "******";
            config.Password     = "******";
            config.DataProvider = DataProvider.SqlClient;
            config.TableName    = "Log2";

            Aspects.Logging.ILogger logger = new NLogger(config);

            logger.Info(message);

            string connectionString = $"Data Source={config.Host};Initial Catalog={config.Database}; User Id={config.Username}; Password={config.Password}";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlDataReader reader = new SqlCommand(@"SELECT * FROM LogEntry;", connection).ExecuteReader();
                while (reader.Read())
                {
                    Assert.Contains(message, reader["Payload"].ToString());
                }
                reader.Close();

                var command = new SqlCommand("DELETE FROM LogEntry", connection);
                command.ExecuteNonQuery();
            }
        }
Example #15
0
        public void SelectByValue(string elementName, By byObject, string value)
        {
            ReadOnlyCollection <IWebElement> listElements = null;

            try
            {
                listElements = WaitForVisibilityOfAllElementsLocatedBy(elementName, byObject);

                foreach (IWebElement e in listElements)
                {
                    string text = e.GetAttribute("value");
                    if (text.Equals(value))
                    {
                        e.Click();
                        break;
                    }
                }

                string info = string.Format("Get list of elements [{0}].", elementName);
                NLogger.Info(info);
                HtmlReporter.Pass(info);
            }
            catch (WebDriverException ex)
            {
                foreach (IWebElement element in listElements)
                {
                    ScreenShotCapturing.HighlightElement(driver, element);
                }
                string message    = string.Format("An error happens when trying to get list of elements [{0}].", elementName);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Example #16
0
        public void ClickAll(string elementName, By byObject)
        {
            IReadOnlyCollection <IWebElement> listElements = null;

            try
            {
                listElements = WaitForVisibilityOfAllElementsLocatedBy(elementName, byObject);

                foreach (IWebElement e in listElements)
                {
                    e.Click();
                }

                string info = string.Format("Click on all elements [{0}].", elementName);
                NLogger.Info(info);
                HtmlReporter.Pass(info);
            }
            catch (WebDriverException ex)
            {
                foreach (IWebElement element in listElements)
                {
                    ScreenShotCapturing.HighlightElement(driver, element);
                }
                string message    = string.Format("An error happens when trying to click all on list of elements [{0}].", elementName);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Example #17
0
        public List <string> GetTextFromElements(string elementName, By byObject)
        {
            ReadOnlyCollection <IWebElement> listElements = null;

            try
            {
                List <string> listElementText = new List <string>();
                listElements = WaitForVisibilityOfAllElementsLocatedBy(elementName, byObject);
                foreach (IWebElement element in listElements)
                {
                    string text = element.Text;
                    listElementText.Add(text);
                }

                string info = string.Format("Get text from list of elemets [{0}]", elementName);
                NLogger.Info(info);
                HtmlReporter.Pass(info);

                return(listElementText);
            }
            catch (WebDriverException ex)
            {
                foreach (IWebElement element in listElements)
                {
                    ScreenShotCapturing.HighlightElement(driver, element);
                }
                string message    = string.Format("An error happens when trying to get text for list of elements [{0}].", elementName);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
 public void Save()
 {
     try
     {
         using (SqlConnection conn = DbHelperSQL.GetOpenConnection())
         {
             using (SqlTransaction tran = conn.BeginTransaction(ImportTransId.ToString().Substring(0, 8)))
             {
                 try
                 {
                     SaveImport(conn, tran);
                     SaveAttributes(conn, tran);
                     tran.Commit();
                     NLogger.Info(MethodBase.GetCurrentMethod().DeclaringType.FullName, MethodBase.GetCurrentMethod().Name, "ZillowImport (" + ImportTransId.ToString() + ") completed.");
                 }
                 catch (Exception ex)
                 {
                     tran.Rollback(ImportTransId.ToString());
                     NLogger.Error(MethodBase.GetCurrentMethod().DeclaringType.FullName, MethodBase.GetCurrentMethod().Name, ex.Message, ex);
                     throw;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         NLogger.Error(MethodBase.GetCurrentMethod().DeclaringType.FullName, MethodBase.GetCurrentMethod().Name, ex.Message, ex);
         throw;
     }
 }
Example #19
0
 void NLogStart()
 {
     if (!DisableLogging)
     {
         NLogger.Info(TaskName, TaskType, "START", TaskHash, ControlFlow.ControlFlow.STAGE, ControlFlow.ControlFlow.CurrentLoadProcess?.LoadProcessKey);
     }
 }
Example #20
0
 private void NLogStart()
 {
     if (!DisableLogging)
     {
         NLogger.Info(TaskName, TaskType, "START", TaskHash, Logging.Logging.STAGE, Logging.Logging.CurrentLoadProcess?.Id);
     }
 }
 /// <inheritdoc/>
 public virtual void SetDefaultSettings(IEnumerable <string> settingFullCodes)
 {
     CallMethodLogging(settingFullCodes);
     GetFacade <SettingsFacade>().SetSettings(settingFullCodes.Select(code => new SetSettingsRequest {
         FullCode = code, NeedSetDefaultValue = true
     }).ToList());
     NLogger.Info(() => "Set default settings:\n" + string.Join("\n", settingFullCodes));
 }
        /// <inheritdoc/>
        public virtual void SetSettings(List <SetSettingsRequest> request)
        {
            CallMethodLogging(request);

            GetFacade <SettingsFacade>().SetSettings(request);

            NLogger.Info(() => "Set settings:\n" + string.Join("\n", request.ConvertAll(setting => $"Code <{setting.FullCode}>, Value <{setting.Value}>")));
        }
Example #23
0
 void LoggingEnd(LogType logType)
 {
     NLogger.Info(TaskName, TaskType, "END", TaskHash, ControlFlow.STAGE, ControlFlow.CurrentLoadProcess?.LoadProcessKey);
     if (logType == LogType.Rows)
     {
         NLogger.Debug($"Rows affected: {RowsAffected ?? 0}", TaskType, "RUN", TaskHash, ControlFlow.STAGE, ControlFlow.CurrentLoadProcess?.LoadProcessKey);
     }
 }
Example #24
0
 protected void LogProgress()
 {
     ProgressCount += 1;
     if (!DisableLogging && HasLoggingThresholdRows && (ProgressCount % LoggingThresholdRows == 0))
     {
         NLogger.Info(TaskName + $" processed {ProgressCount} records.", TaskType, "LOG", TaskHash, Logging.Logging.STAGE, Logging.Logging.CurrentLoadProcess?.Id);
     }
 }
Example #25
0
 void LoggingStart(LogType logType)
 {
     NLogger.Info(TaskName, TaskType, "START", TaskHash, ControlFlow.STAGE, ControlFlow.CurrentLoadProcess?.LoadProcessKey);
     if (logType == LogType.Bulk)
         NLogger.Debug($"SQL Bulk Insert", TaskType, "RUN", TaskHash, ControlFlow.STAGE, ControlFlow.CurrentLoadProcess?.LoadProcessKey);
     else
         NLogger.Debug($"{Command}", TaskType, "RUN", TaskHash, ControlFlow.STAGE, ControlFlow.CurrentLoadProcess?.LoadProcessKey);
 }
Example #26
0
 /// <summary>
 /// Get NClick info and send it.
 /// </summary>
 /// <param name="panel">object to send nClick when click</param>
 private void SendNClick(string lbrNclickCode)
 {
     if (!string.IsNullOrEmpty(lbrNclickCode))
     {
         ServiceLocator.Current.GetInstance <INClickService>().SendNClick(lbrNclickCode);
         NLogger.Info("Send nclick: {0}", lbrNclickCode);
     }
 }
Example #27
0
 void LogProgress(int rowsProcessed)
 {
     ProgressCount += rowsProcessed;
     if (!DisableLogging && HasLoggingThresholdRows && (ProgressCount % LoggingThresholdRows == 0))
     {
         NLogger.Info(TaskName + $" processed {ProgressCount} records.", TaskType, "LOG", TaskHash, ControlFlow.ControlFlow.STAGE, ControlFlow.ControlFlow.CurrentLoadProcess?.LoadProcessKey);
     }
 }
Example #28
0
        public async Task <IActionResult> Menu()
        {
            NLogger.Info("菜单:" + JsonHelper.SerializeObject(CurrentUser));
            List <Module> modules = await RoleAuthorizeApp.GetModuleList(CurrentUser.RoleId, CurrentUser.IsSys);

            NLogger.Info(JsonHelper.SerializeObject(modules));
            return(Json(ToMenu(modules, 0)));
        }
Example #29
0
 void LoggingEnd(LogType logType = LogType.None)
 {
     NLogger.Info(TaskName, TaskType, "END", TaskHash, Logging.Logging.STAGE, Logging.Logging.CurrentLoadProcess?.Id);
     if (logType == LogType.Rows)
     {
         NLogger.Debug($"Rows affected: {RowsAffected ?? 0}", TaskType, "RUN", TaskHash, Logging.Logging.STAGE, Logging.Logging.CurrentLoadProcess?.Id);
     }
 }
Example #30
0
        private async Task RunSession(FSSession session, ushort index, int count, bool needNetty)
        {
            var account    = "account" + index;
            var password   = "******";
            var playerName = "player" + index;

            try
            {
                session.SetDestroyedHandler((sender, e) =>
                {
                    NLogger.Info($"session:{session.GetId()} destroyed!");
                });

                //注册账号
                var playerprx = session.UncheckedCast(IPlayerCoPrxHelper.uncheckedCast, IPlayerCoPrxHelper.ice_staticId());
                var ret       = await playerprx.RegOrLoginReqAsync(account, password);

                NLogger.Debug("RegOrLoginReqAsync ok:" + account + ", result=" + ret);

                var zoneprx = session.UncheckedCast(IZoneCoPrxHelper.uncheckedCast, IZoneCoPrxHelper.ice_staticId());
                await zoneprx.TestApiReqAsync();

                NLogger.Debug("TestApiReqAsync ok:" + account);


                for (int i = 0; i < 20; ++i)
                {
                    var str = Console.In.ReadLine();
                    switch (str)
                    {
                    case "1":
                        await zoneprx.TestApiReq2Async();

                        break;

                    case "13":
                        await zoneprx.TestApiReq3Async();

                        break;
                    }
                }


                NLogger.Info($"{account} playerPrx end!");
            }
            catch (Ice.Exception ex)
            {
                NLogger.Error(account + ":" + ex.Message);
            }
            catch (System.Exception e)
            {
                NLogger.Error(account + ":" + e.ToString());
            }
            finally
            {
                //session.Destory();
            }
        }