Commit f586ae8c by wangonghui

添加log日志和添加捕获异常

parent 472a3e7d
......@@ -5,5 +5,8 @@
<add key="vizIpMain" value=""/>
<add key="vizIpBack" value=""/>
<add key="leagueId" value="401"/>
<add key="AppID" value="100001"/>
<add key="AppKey" value="ffrw7ilc8i6r3pkzvl"/>
<add key="newUrl" value="http://180.184.78.246:18080/miku/api/open_api/proxy_api/beitai/api/schedule/getdayschedule"/>
</appSettings>
</configuration>
\ No newline at end of file
using DevExpress.ClipboardSource.SpreadsheetML;
using DevExpress.Mvvm;
using log4net;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
......@@ -11,24 +15,25 @@ namespace VIZ.TVP.CBA.Module.Common
{
public static class JsonHelper
{
/// <summary>
/// 日志
/// </summary>
private static readonly ILog Log = LogManager.GetLogger(typeof(JsonHelper));
/// <summary>
/// 根据POST方法请求获取
/// </summary>
/// <param name="url"></param>
/// <param name="dic"></param>
/// <returns></returns>
public static string Post(string url, Dictionary<string, string> dic)
public static string Post(string url, Dictionary<string, string> dic,string key)
{
string result = null;
//try
//{
string result = "";
try
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.Headers.Add("App-Authorization", key);
StringBuilder builder = new StringBuilder();
int i = 0;
foreach (var item in dic)
......@@ -51,15 +56,12 @@ namespace VIZ.TVP.CBA.Module.Common
{
result = reader.ReadToEnd();
}
// }
//catch (Exception ex)
//{
// log.Error(ex);
//}
//finally
//{
// LogRequest(url, result);
//}
}
catch(Exception ex)
{
Log.Error(ex.Message);
}
return result;
}
......@@ -73,15 +75,23 @@ namespace VIZ.TVP.CBA.Module.Common
public static string GetResult(string url)
{
string data = "";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Headers["Accept-Encoding"] = "gzip,deflate";
req.AutomaticDecompression = DecompressionMethods.GZip;
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream stream = resp.GetResponseStream();
//获取内容
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
try
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Headers["Accept-Encoding"] = "gzip,deflate";
req.AutomaticDecompression = DecompressionMethods.GZip;
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream stream = resp.GetResponseStream();
//获取内容
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
data = reader.ReadToEnd();
}
}
catch(Exception ex)
{
data = reader.ReadToEnd();
Log.Error(ex.Message);
}
return data;
......
......@@ -34,6 +34,34 @@ namespace VIZ.TVP.CBA.Module.Common
}
/// <summary>
/// 艾果的密钥加密
/// </summary>
/// <param name="appId"></param>
/// <param name="appKey"></param>
/// <returns></returns>
public static string GetKey(string appId,string appKey)
{
int random = new Random().Next(0, 100);
long timeStamp = DateToTicks(DateTime.Now);
string key = Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("{0},{1},{2},{3}",appId,appKey,timeStamp,random)));
return key;
}
/// <summary>
/// 获取时间戳
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
public static long DateToTicks(DateTime? time)
{
return ((time.HasValue ? time.Value.Ticks : DateTime.Parse("1990-01-01").Ticks) - 621355968000000000) / 10000;
}
/// <summary>
/// 设置主队和客队球员技术数据统计
/// </summary>
/// <param name="mainViewModel"></param>
......
using System;
using log4net;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
......@@ -11,6 +12,8 @@ namespace VIZ.TVP.CBA.Module
{
public static class ConfigManage
{
private static ILog Log = LogManager.GetLogger(typeof(ConfigManage));
#region 1.获取当前类库的文件配置
public static Configuration InitLogConfig()
......@@ -35,8 +38,9 @@ namespace VIZ.TVP.CBA.Module
}
catch (Exception ex)
{
throw new Exception(ex.Message);
//throw new Exception(ex.Message);
Log.Error(ex.Message);
return null;
}
#endregion
......
......@@ -9,15 +9,21 @@ using VIZ.TVP.CBA.Module.Common;
using VIZ.TVP.CBA.Module.DayMatch.Model;
using VIZ.TVP.CBA.Module.TempEnum;
using VIZ.TVP.CBA.Domain;
using log4net;
namespace VIZ.TVP.CBA.Module.DayMatch.ViewModel
{
public class DayMatchViewModel : ViewModelBase
{
/// <summary>
/// 日志
/// </summary>
private static ILog Log= LogManager.GetLogger(typeof(DayMatchViewModel));
public DayMatchViewModel()
{
BtnCmd = new VCommand(BtnCommand);
BtnMatchDayUp = new VCommand(BtnMatchDayUpData);
matchDate = DateTime.Today.ToShortDateString();
......@@ -55,7 +61,7 @@ namespace VIZ.TVP.CBA.Module.DayMatch.ViewModel
/// </summary>
private void BtnMatchDayUpData()
{
Log.Info("比赛日期上版和数据:"+ CombineMatchData());
ApplicationDomainEx.VizEngineModel.STAGE_START("Default/JRSCBEN", "Data", CombineMatchData());
}
......@@ -115,37 +121,48 @@ namespace VIZ.TVP.CBA.Module.DayMatch.ViewModel
/// </summary>
private void GetSchedule()
{
string date = Convert.ToDateTime(matchDate).ToString("yyyy-MM-dd");
try
{
var dayschedules = JsonModel.TomorrowMatch_Path(date);
// matchData.AddRange(dayschedules.dayschedule);
string date = Convert.ToDateTime(matchDate).ToString("yyyy-MM-dd");
MatchData = new ObservableCollection<Dayschedule>();
foreach (var dayschedule in dayschedules.dayschedule)
{
if (dayschedule.Status == "1")
{
dayschedule.Status = "未开赛";
}
else if (dayschedule.Status == "2")
{
dayschedule.Status = "进行中";
}
else if (dayschedule.Status == "3")
{
dayschedule.Status = "进行中";
}
else if (dayschedule.Status == "4")
{
dayschedule.Status = "已结束";
}
else if (dayschedule.Status == "5")
var dayschedules = JsonModel.TomorrowMatch_Path(date);
if (dayschedules == null) return;
// matchData.AddRange(dayschedules.dayschedule);
MatchData = new ObservableCollection<Dayschedule>();
foreach (var dayschedule in dayschedules.dayschedule)
{
dayschedule.Status = "延期";
if (dayschedule.Status == "1")
{
dayschedule.Status = "未开赛";
}
else if (dayschedule.Status == "2")
{
dayschedule.Status = "进行中";
}
else if (dayschedule.Status == "3")
{
dayschedule.Status = "进行中";
}
else if (dayschedule.Status == "4")
{
dayschedule.Status = "已结束";
}
else if (dayschedule.Status == "5")
{
dayschedule.Status = "延期";
}
MatchData.Add(dayschedule);
}
MatchData.Add(dayschedule);
}
catch(Exception ex)
{
Log.Error(ex.Message);
}
}
......
......@@ -10,12 +10,18 @@ using VIZ.TVP.CBA.Module.DayMatch.Model;
using VIZ.TVP.CBA.Module.RoundMatch.Model;
using VIZ.TVP.CBA.Module.TempEnum;
using VIZ.TVP.CBA.Domain;
using log4net;
namespace VIZ.TVP.CBA.Module.RoundMatch.ViewModel
{
public class RoundMatchViewModel: ViewModelBase
{
/// <summary>
/// 日志
/// </summary>
private static ILog Log=LogManager.GetLogger(typeof(RoundMatchViewModel));
public RoundMatchViewModel()
{
RoundMatchs = new ObservableCollection<int>();
......@@ -153,7 +159,7 @@ namespace VIZ.TVP.CBA.Module.RoundMatch.ViewModel
private void BtnCmdDataUp()
{
Log.Info("轮次比赛上版信息和数据:" + CombineMatchData());
ApplicationDomainEx.VizEngineModel.STAGE_START("Default/JRSCBEN", "Data", CombineMatchData());
}
......@@ -209,6 +215,8 @@ namespace VIZ.TVP.CBA.Module.RoundMatch.ViewModel
public void BtnCommand()
{
var roundSchedules = JsonModel.GetGameRound_Path(roundMatchItem.ToString());
if (roundSchedules == null) return;
RoundMatchData = new ObservableCollection<RoundSchedule>();
foreach(var rudData in roundSchedules.schedulelist)
......
......@@ -9,13 +9,20 @@ using VIZ.TVP.CBA.Module.Common;
using VIZ.TVP.CBA.Module.DayMatch.Model;
using VIZ.TVP.CBA.Module.TeamStandings.Model;
using VIZ.TVP.CBA.Domain;
using log4net;
namespace VIZ.TVP.CBA.Module.TeamStandings.ViewModel
{
public class TeamStandingViewModel: ViewModelBase
{
/// <summary>
/// 日志
/// </summary>
private static ILog Log= LogManager.GetLogger(typeof(TeamStandingViewModel));
/// <summary>
/// 球队排名初始化排名
/// </summary>
public TeamStandingViewModel()
{
//TeamRanksModel = new ObservableCollection<Model.Teamrank>()
......@@ -143,7 +150,7 @@ namespace VIZ.TVP.CBA.Module.TeamStandings.ViewModel
private void BtmCommand()
{
var teamStands = JsonModel.TeamScoreData_Path();
if (teamStands == null) return;
TeamRanksModel = new ObservableCollection<Teamrank>();
int i = 1;
foreach(var teamRank in teamStands.teamrank)
......@@ -174,6 +181,7 @@ namespace VIZ.TVP.CBA.Module.TeamStandings.ViewModel
{
if(TeamRanksModel!=null)
{
Log.Info("球队排名上版信息和数据:"+ CombineTeamStandingData());
ApplicationDomainEx.VizEngineModel.STAGE_START("Default/JFB", "Data", CombineTeamStandingData());
}
}
......
......@@ -10,15 +10,18 @@ using VIZ.TVP.CBA.Module.TempEnum;
namespace VIZ.TVP.CBA.Module.TeamStats.Model
{
/// <summary>
/// 技术统计类
/// </summary>
public class MatchStatsNumbers:ViewModelBase
{
// public string HomeName { get; set; }
/// <summary>
/// 主队得分
/// </summary>
private string homeScore;
public string HomeScore
......@@ -28,7 +31,9 @@ namespace VIZ.TVP.CBA.Module.TeamStats.Model
set { homeScore = value; this.RaisePropertiesChanged(nameof(HomeScore)); }
}
/// <summary>
/// 主队赛季得分
/// </summary>
private string hSeasonScore;
public string HSeasonScore
{
......@@ -40,7 +45,9 @@ namespace VIZ.TVP.CBA.Module.TeamStats.Model
//public string AwayName { get; set; }
/// <summary>
/// 客场得分
/// </summary>
private string awayScore;
public string AwayScore
{
......@@ -49,7 +56,9 @@ namespace VIZ.TVP.CBA.Module.TeamStats.Model
}
/// <summary>
/// 客场赛季得分
/// </summary>
private string aSeasonScore;
public string ASeasonScore
{
......@@ -68,7 +77,9 @@ namespace VIZ.TVP.CBA.Module.TeamStats.Model
set { light = value; this.RaisePropertiesChanged(nameof(Light)); }
}
/// <summary>
/// 技术统计
/// </summary>
private TechStats techStats = TechStats.Goal;
......@@ -78,7 +89,9 @@ namespace VIZ.TVP.CBA.Module.TeamStats.Model
set { techStats = value; this.RaisePropertiesChanged(nameof(TechStats)); }
}
/// <summary>
/// 选中行是否高亮
/// </summary>
private string selectLight = "不高亮";
public string SelectLight
{
......@@ -86,7 +99,9 @@ namespace VIZ.TVP.CBA.Module.TeamStats.Model
set { selectLight = value; this.RaisePropertyChanged(nameof(SelectLight)); }
}
/// <summary>
/// 技术统计名称
/// </summary>
private string techStatsName;
public string TechStatsName
{
......
......@@ -15,12 +15,15 @@ using VIZ.TVP.CBA.Domain;
using VIZ.TVP.CBA.Module.SeasonData;
using VIZ.TVP.CBA.Module.OnAirData;
using System.ComponentModel;
using log4net;
namespace VIZ.TVP.CBA.Module.TeamStats.ViewModel
{
public class TeamStatsViewModel : ViewModelBase
{
private static ILog Log=LogManager.GetLogger(typeof(TeamStatsViewModel));
private static TeamStatsViewModel _createInstance = null;
public static TeamStatsViewModel CreateInstance
......@@ -35,8 +38,6 @@ namespace VIZ.TVP.CBA.Module.TeamStats.ViewModel
}
}
public TeamStatsViewModel()
{
BtnCommand = new VCommand(BtnCmd);
......@@ -233,10 +234,14 @@ namespace VIZ.TVP.CBA.Module.TeamStats.ViewModel
/// </summary>
public TeamSeasonData TeamSeasonData = new TeamSeasonData();
/// <summary>
/// 实时直播数据
/// </summary>
public OnAirDataModel onAirDataModel = new OnAirDataModel();
/// <summary>
/// 技术统计项
/// </summary>
private string matchStatsId;
public string MatchStatsId
......@@ -446,6 +451,8 @@ namespace VIZ.TVP.CBA.Module.TeamStats.ViewModel
{
//CombineTeamComData();
Log.Info("球队对比数据:"+CombineTeamComData());
ApplicationDomainEx.VizEngineModel.STAGE_START("Default/SQD", "dqyData", CombineTeamComData());
}
......@@ -522,7 +529,7 @@ namespace VIZ.TVP.CBA.Module.TeamStats.ViewModel
private void BtnCmd()
{
onAirDataModel = JsonModel.OnAirData_Path(ScheduleID);
if (onAirDataModel == null) return;
Utils.SetHomeTeamDictionary(this);
Utils.SetVisitTeamDictionary(this);
Utils.SetHData(this);
......@@ -537,6 +544,7 @@ namespace VIZ.TVP.CBA.Module.TeamStats.ViewModel
ScheduleID = SetMatchDict[SelectMatchItems];
onAirDataModel = JsonModel.OnAirData_Path(ScheduleID);
if (onAirDataModel == null) return;
if (onAirDataModel != null)
{
......@@ -564,6 +572,7 @@ namespace VIZ.TVP.CBA.Module.TeamStats.ViewModel
AwayTeam = onAirDataModel.liveTeamInfo.VisitingTeamCNAlias;
TeamSeasonData = JsonModel.TeamSeasonData_Path(Matchtypeid);
SetTeamSeasonDictionary();
Utils.SetHomeTeamDictionary(this);
......@@ -574,12 +583,13 @@ namespace VIZ.TVP.CBA.Module.TeamStats.ViewModel
}
/// <summary>
/// 设置球队赛季数据字典集合
/// </summary>
private void SetTeamSeasonDictionary()
{
CNAliasVisitSportsDictionary.Clear();
if (TeamSeasonData == null) return;
foreach (var teamSeasonData in TeamSeasonData.teamstats)
{
......@@ -618,57 +628,66 @@ namespace VIZ.TVP.CBA.Module.TeamStats.ViewModel
private void GetSchedule()
{
MatchItems = new ObservableCollection<string>();
string date = Convert.ToDateTime(matchDate).ToString("yyyy-MM-dd");
var dayschedules = JsonModel.TomorrowMatch_Path(date);
// matchData.AddRange(dayschedules.dayschedule);
//MatchData = new ObservableCollection<Dayschedule>();
try
if (dayschedules != null)
{
dayschedules.dayschedule = dayschedules.dayschedule.OrderBy(a => Convert.ToDateTime(a.time)).ToList();
}
MatchItems = new ObservableCollection<string>();
string date = Convert.ToDateTime(matchDate).ToString("yyyy-MM-dd");
SetMatchDict.Clear();
MatchItems.Clear();
var dayschedules = JsonModel.TomorrowMatch_Path(date);
foreach (var dayschedule in dayschedules.dayschedule)
{
if (dayschedule.Status == "1")
{
dayschedule.Status = "未开赛";
}
else if (dayschedule.Status == "2")
{
dayschedule.Status = "进行中";
}
else if (dayschedule.Status == "3")
{
dayschedule.Status = "进行中";
}
else if (dayschedule.Status == "4")
{
dayschedule.Status = "已结束";
}
else if (dayschedule.Status == "5")
{
dayschedule.Status = "延期";
}
if (!SetMatchDict.ContainsKey(dayschedule.time + dayschedule.HomeTeamName
+ "VS" + dayschedule.VisitingTeamName))
{
SetMatchDict.Add(dayschedule.time + dayschedule.HomeTeamName
+ "VS" + dayschedule.VisitingTeamName, dayschedule.ScheduleID);
}
Matchtypeid = dayschedule.ScheduleTypeID;
if (dayschedules == null) return;
// matchData.AddRange(dayschedules.dayschedule);
//MatchData = new ObservableCollection<Dayschedule>();
MatchItems.Add(dayschedule.time + dayschedule.HomeTeamName
+ "VS" + dayschedule.VisitingTeamName);
//if (dayschedules != null)
//{
dayschedules.dayschedule = dayschedules.dayschedule.OrderBy(a => Convert.ToDateTime(a.time)).ToList();
// }
SetMatchDict.Clear();
MatchItems.Clear();
foreach (var dayschedule in dayschedules.dayschedule)
{
if (dayschedule.Status == "1")
{
dayschedule.Status = "未开赛";
}
else if (dayschedule.Status == "2")
{
dayschedule.Status = "进行中";
}
else if (dayschedule.Status == "3")
{
dayschedule.Status = "进行中";
}
else if (dayschedule.Status == "4")
{
dayschedule.Status = "已结束";
}
else if (dayschedule.Status == "5")
{
dayschedule.Status = "延期";
}
if (!SetMatchDict.ContainsKey(dayschedule.time + dayschedule.HomeTeamName
+ "VS" + dayschedule.VisitingTeamName))
{
SetMatchDict.Add(dayschedule.time + dayschedule.HomeTeamName
+ "VS" + dayschedule.VisitingTeamName, dayschedule.ScheduleID);
}
Matchtypeid = dayschedule.ScheduleTypeID;
MatchItems.Add(dayschedule.time + dayschedule.HomeTeamName
+ "VS" + dayschedule.VisitingTeamName);
}
}
catch(Exception ex)
{
Log.Error(ex.Message);
}
}
......
......@@ -95,6 +95,7 @@
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml" />
......
......@@ -12,5 +12,11 @@ namespace VIZ.MIGU.CBA
/// </summary>
public partial class App : Application
{
public App()
{
string configPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log.config");
log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(configPath));
}
}
}
......@@ -61,8 +61,13 @@
<Reference Include="DevExpress.Xpf.Core.v22.1" />
<Reference Include="DevExpress.Xpf.Themes.Office2019Colorful.v22.1" />
<Reference Include="DevExpress.Drawing.v22.1" />
<Reference Include="log4net, Version=2.0.14.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.14\lib\net45\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
......@@ -114,6 +119,10 @@
<None Include="App.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="log.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
......
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="errorAppender" type="log4net.Appender.RollingFileAppender">
<filter type="log4net.Filter.LevelMatchFilter">
<levelToMatch value="ERROR" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
<file value="Logs\err.log" />
<encoding value="utf-8"/>
<preserveLogFileNameExtension value="true" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>
<appender name="infoAppender" type="log4net.Appender.RollingFileAppender">
<filter type="log4net.Filter.LevelMatchFilter">
<levelToMatch value="INFO" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
<file value="Logs\info.log" />
<encoding value="utf-8"/>
<preserveLogFileNameExtension value="true" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>
<appender name="debugAppender" type="log4net.Appender.RollingFileAppender">
<filter type="log4net.Filter.LevelMatchFilter">
<levelToMatch value="DEBUG" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
<file value="Logs\debug.log" />
<encoding value="utf-8"/>
<preserveLogFileNameExtension value="true" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>
<appender name="perfAppender" type="log4net.Appender.RollingFileAppender">
<filter type="log4net.Filter.LevelMatchFilter">
<levelToMatch value="INFO" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
<file value="Logs\perf.log" />
<encoding value="utf-8"/>
<preserveLogFileNameExtension value="true" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %logger - %message%newline" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="errorAppender" />
<appender-ref ref="infoAppender" />
<appender-ref ref="debugAppender" />
</root>
<logger name="Performance" additivity="false">
<level value="ALL" />
<appender-ref ref="perfAppender" />
</logger>
</log4net>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.14" targetFramework="net48" />
</packages>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment