Example #1
0
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="ts"></param>
        /// <returns></returns>
        internal bool Insert <T>(List <T> ts) where T : SqliteDataTableBase
        {
            Open();
            bool   hasIdIncre = HasAutoIncrementID <T>();
            string cmdStr     = SqliteTabelCmdStrTool.GetInsertStr(ts, hasIdIncre);

            Debug.Log(cmdStr);

            SqliteTransaction st = connection.BeginTransaction();

            try
            {
                int res = 0;
                lock (_dbLocker)
                {
                    res = OperateRecords(cmdStr);
                    if (res > 0)
                    {
                        st.Commit();
                    }
                }
                return(res > 0);
            }
            catch (SqliteException e)
            {
                st.Rollback();
                LogOperator.AddWarnningRecord("插入数据时异常", e.Message);
                return(false);
            }
            finally
            {
                Close();
            }
        }
Example #2
0
 /// <summary>
 /// 下载Texttasset
 /// </summary>
 /// <returns></returns>
 private IEnumerator IEnumGetTextasset()
 {
     if (string.IsNullOrEmpty(this.url))
     {
         yield break;
     }
     using (UnityWebRequest request = new UnityWebRequest(url))
     {
         DownloadHandlerBuffer dht = new DownloadHandlerBuffer();
         request.timeout         = timeout;
         request.downloadHandler = dht;
         UnityWebRequestAsyncOperation ao = request.SendWebRequest();
         while (true)
         {
             progress?.Invoke(ao.progress);
             if (request.isDone)
             {
                 if (request.isHttpError || request.isNetworkError)
                 {
                     callbackTextasset?.Invoke(url, request.responseCode, null, args);
                     LogOperator.AddNetErrorRecord("获取Textasset时网络错误", url, request.responseCode);
                 }
                 else
                 {
                     callbackTextasset?.Invoke(url, request.responseCode, new TextAsset(dht.text), args);
                 }
                 break;
             }
             yield return(new WaitForEndOfFrame());
         }
     }
 }
Example #3
0
 private void CreateLogOperator()
 {
     mLogOperator         = new LogOperator();
     mLogOperator.LogPath =
         Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "UMP\\Wcf11102\\Logs");
     mLogOperator.Start();
 }
Example #4
0
        /// <summary>
        /// 上传WWWForm表单的POST,会有 urlencoded 加密支持
        /// </summary>
        /// <returns></returns>
        public IEnumerator IEnumPostWWWForm()
        {
            UnityWebRequest request = UnityWebRequest.Post(url, postDataForm);

            request.downloadHandler = new DownloadHandlerBuffer();
            UnityWebRequestAsyncOperation ao = request.SendWebRequest();

            while (true)
            {
                progress?.Invoke(ao.progress);
                if (request.isDone)
                {
                    if (request.isHttpError || request.isNetworkError)
                    {
                        callback?.Invoke(url, request.responseCode, args);
                        callbackByteArr?.Invoke(url, request.responseCode, null, args);
                        callbackStr?.Invoke(url, request.responseCode, null, args);
                        LogOperator.AddNetErrorRecord("POST请求失败", request.responseCode, request.error, url, request.isHttpError.ToString(), request.isNetworkError.ToString());
                    }
                    else
                    {
                        callback?.Invoke(url, request.responseCode, args);
                        callbackByteArr?.Invoke(url, request.responseCode, request.downloadHandler.data, args);
                        callbackStr?.Invoke(url, request.responseCode, request.downloadHandler.text, args);
                    }
                    break;
                }
                yield return(new WaitForEndOfFrame());
            }
            request.Dispose();
        }
Example #5
0
 /// <summary>
 /// 下载Texture2D
 /// </summary>
 /// <returns></returns>
 private IEnumerator IEnumGetTexture2D()
 {
     if (string.IsNullOrEmpty(this.url))
     {
         yield break;
     }
     using (UnityWebRequest request = UnityWebRequestTexture.GetTexture(url, false))
     {
         request.timeout = timeout;
         UnityWebRequestAsyncOperation ao = request.SendWebRequest();
         while (true)
         {
             progress?.Invoke(ao.progress);
             if (request.isDone)
             {
                 if (request.isHttpError || request.isNetworkError)
                 {
                     callbackTexture2D?.Invoke(url, request.responseCode, null, args);
                     LogOperator.AddNetErrorRecord("获取Texture2D时网络错误", url, request.responseCode);
                 }
                 else
                 {
                     Texture2D t2d = DownloadHandlerTexture.GetContent(request);
                     t2d.name = Path.GetFileName(url);
                     callbackTexture2D?.Invoke(url, request.responseCode, t2d, args);
                 }
                 break;
             }
             yield return(new WaitForEndOfFrame());
         }
     }
 }
Example #6
0
 /// <summary>
 /// 下载精灵图
 /// </summary>
 /// <returns></returns>
 private IEnumerator IEnumGetSprite()
 {
     if (string.IsNullOrEmpty(this.url))
     {
         yield break;
     }
     using (UnityWebRequest request = new UnityWebRequest(url))
     {
         DownloadHandlerTexture dht = new DownloadHandlerTexture();
         request.timeout         = timeout;
         request.downloadHandler = dht;
         UnityWebRequestAsyncOperation ao = request.SendWebRequest();
         while (true)
         {
             progress?.Invoke(ao.progress);
             if (request.isDone)
             {
                 if (request.isHttpError || request.isNetworkError)
                 {
                     callbackSprite?.Invoke(url, request.responseCode, null, args);
                     LogOperator.AddNetErrorRecord("获取Sprite时网络错误", url, request.responseCode);
                 }
                 else
                 {
                     Sprite sprite = Sprite.Create(dht.texture, new Rect(0, 0, dht.texture.width, dht.texture.height), Vector2.one / 2);
                     sprite.name = Path.GetFileName(url);
                     callbackSprite?.Invoke(url, request.responseCode, sprite, args);
                 }
                 break;
             }
             yield return(new WaitForEndOfFrame());
         }
     }
 }
Example #7
0
        private static int mWorkeTimeout = 60;             //LoggingUpdater工作的超时时间,超过超时时间将主动关闭LoggingUpdater程序

        static void Main(string[] args)
        {
            CreateLogOperator();
            WriteLog(LogMode.Info, "Welcome LoggingUpdater, You need do nothing just wait...");
            IsWorking      = true;
            mEngine        = new UpdateEngine();
            mEngine.Debug += WriteLog;
            mEngine.Start(args);
            while (IsWorking)
            {
                DateTime dt  = mEngine.LastActiveTime;
                DateTime now = DateTime.Now;
                if ((now - dt).TotalSeconds > mWorkeTimeout)
                {
                    WriteLog(LogMode.Info, "Timeout, will be shutdown now.");
                    mEngine.Stop();
                    mEngine = null;
                    break;
                }
                Thread.Sleep(100);
            }
            if (mEngine != null)
            {
                mEngine.Stop();
                mEngine = null;
            }
            if (mLogOperator != null)
            {
                mLogOperator.Stop();
            }
            mLogOperator = null;
        }
Example #8
0
 private void CreateFileLog()
 {
     try
     {
         string path = GetLogPath();
         mLogOperator         = new LogOperator();
         mLogOperator.LogPath = path;
         if (Program.IsDebug)
         {
             //调试模式下记录所有日志信息
             mLogOperator.LogMode = LogMode.All;
         }
         mLogOperator.Start();
         string strInfo = string.Empty;
         strInfo += string.Format("LogPath:{0}\r\n", path);
         strInfo += string.Format("\tExePath:{0}\r\n", AppDomain.CurrentDomain.BaseDirectory);
         strInfo += string.Format("\tName:{0}\r\n", AppDomain.CurrentDomain.FriendlyName);
         strInfo += string.Format("\tVersion:{0}\r\n",
                                  System.Reflection.Assembly.GetExecutingAssembly().GetName().Version);
         strInfo += string.Format("\tHost:{0}\r\n", Environment.MachineName);
         strInfo += string.Format("\tAccount:{0}", Environment.UserName);
         WriteLog(LogMode.Info, string.Format("{0}", strInfo));
     }
     catch (Exception ex)
     {
         WriteLog(LogMode.Error, string.Format("CreateFileLog fail.\t{0}", ex.Message));
     }
 }
Example #9
0
 /// <summary>
 /// 初始化所有的表并创建没有的表
 /// </summary>
 /// <returns></returns>
 internal bool InitAllTables()
 {
     Open();
     try
     {
         Type[]      ts    = this.GetType().Assembly.GetTypes();
         List <Type> types = ts.Where(t => t.BaseType != null && t.BaseType.Namespace.Equals(assembly) && t.BaseType.Name.Equals(typeof(SqliteDataTableBase).Name) && t.IsClass)
                             .Select(tt => tt).ToList();
         foreach (var t in types)
         {
             string tablename = SqliteTabelCmdStrTool.GetTableName(t);
             if (!CheckTable(tablename))
             {
                 string cmdStr = SqliteTabelCmdStrTool.GetCreateTableCmdStr(t, true, true);
                 OperateRecords(cmdStr);
             }
         }
         return(true);
     }
     catch (SqliteException e)
     {
         LogOperator.AddWarnningRecord("检查所有的表并创建没有的表时异常", e.Message);
         return(false);
     }
 }
Example #10
0
        /// <summary>
        /// 数据库操作
        /// </summary>
        /// <param name="dbFullName"></param>
        public TableOperator(string dbFullName)
        {
            try
            {
                dbFullName = dbFullName.ToLower().EndsWith(".db") ? dbFullName : string.Format("{0}.db", dbFullName);
                string[] sp = dbFullName.Split(',');
                this.assembly   = sp.Length >= 2 ? sp[0] : this.GetType().Namespace;
                dbFullName      = string.Format("{0}/{1}", Application.persistentDataPath, dbFullName);
                scsb            = new SqliteConnectionStringBuilder();
                scsb.DataSource = dbFullName;

                if (!File.Exists(dbFullName))
                {
                    CreateDB(dbFullName);
                    Debug.LogFormat("创建数据库:{0}", dbFullName);
                }
                else
                {
                    // 初始化所有的表,并创建没有的表
                    InitAllTables();
                }
            }
            catch (SqliteException e)
            {
                connection = null;
                LogOperator.AddWarnningRecord("创建数据库时有异常", e.Message);
            }
        }
Example #11
0
        /// <summary>
        /// 更新记录
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="ts"></param>
        /// <param name="args">存的是一个实例中的字段名与值,key为字段名字,value的List是实例的字段名字、类型和值</param>
        /// <returns></returns>
        internal bool Update <T>(List <T> ts, Dictionary <string, List <object> > args = null) where T : SqliteDataTableBase
        {
            Open();
            bool hasIdPk = HasIdPK <T>();
            Dictionary <string, string> argsStr = args != null?args.Select(arg => new { key = arg.Key, value = SqliteTabelCmdStrTool.GetFieldValue(arg.Value[0].ToString(), arg.Value[1] as Type, arg.Value[2]) }).ToDictionary(p => p.key, p => p.value) : null;

            string            cmdStr = SqliteTabelCmdStrTool.GetUpdateStr(ts, hasIdPk, argsStr);
            SqliteTransaction st     = connection.BeginTransaction();

            try
            {
                int res = 0;
                lock (_dbLocker)
                {
                    res = OperateRecords(cmdStr);
                    if (res > 0)
                    {
                        st.Commit();
                    }
                }
                return(res > 0);
            }
            catch (SqliteException e)
            {
                st.Rollback();
                LogOperator.AddWarnningRecord("更新记录时异常", e.Message);
                return(false);
            }
            finally
            {
                Close();
            }
        }
Example #12
0
        /// <summary>
        /// 删除记录
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="ts"></param>
        /// <returns></returns>
        internal bool Delete <T>(List <T> ts) where T : SqliteDataTableBase
        {
            Open();
            bool              hasIdPk = HasIdPK <T>();
            string            cmdStr  = SqliteTabelCmdStrTool.GetDeleteStr(ts, hasIdPk);
            SqliteTransaction st      = connection.BeginTransaction();

            try
            {
                int res = 0;
                lock (_dbLocker)
                {
                    res = OperateRecords(cmdStr);
                    if (res > 0)
                    {
                        st.Commit();
                    }
                }
                return(res > 0);
            }
            catch (SqliteException e)
            {
                st.Rollback();
                LogOperator.AddWarnningRecord("删除记录时异常", e.Message);
                return(false);
            }
            finally
            {
                Close();
            }
        }
Example #13
0
 private void CreateLogOperator()
 {
     try
     {
         string path = Path.Combine(TempPath, "Logs");
         if (!Directory.Exists(path))
         {
             Directory.CreateDirectory(path);
         }
         mLogOperator         = new LogOperator();
         mLogOperator.LogPath = path;
         mLogOperator.Start();
         string strInfo = string.Empty;
         strInfo += string.Format("AppInfo\r\n");
         strInfo += string.Format("\tLogPath:{0}\r\n", path);
         strInfo += string.Format("\tExePath:{0}\r\n", AppDomain.CurrentDomain.BaseDirectory);
         strInfo += string.Format("\tName:{0}\r\n", AppDomain.CurrentDomain.FriendlyName);
         strInfo += string.Format("\tVersion:{0}\r\n",
                                  System.Reflection.Assembly.GetExecutingAssembly().GetName().Version);
         strInfo += string.Format("\tHost:{0}\r\n", Environment.MachineName);
         strInfo += string.Format("\tAccount:{0}", Environment.UserName);
         WriteLog("AppLoad", strInfo);
     }
     catch { }
 }
Example #14
0
 private static void CreateLogOperator()
 {
     try
     {
         string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
                                    string.Format("{0}\\{1}\\Logs", "UMP", AppName));
         if (!Directory.Exists(path))
         {
             Directory.CreateDirectory(path);
         }
         mLogOperator         = new LogOperator();
         mLogOperator.LogPath = path;
         mLogOperator.Start();
         string strInfo = string.Empty;
         strInfo += string.Format("AppInfo\r\n");
         strInfo += string.Format("\tLogPath:{0}\r\n", path);
         strInfo += string.Format("\tExePath:{0}\r\n", AppDomain.CurrentDomain.BaseDirectory);
         strInfo += string.Format("\tName:{0}\r\n", AppDomain.CurrentDomain.FriendlyName);
         strInfo += string.Format("\tVersion:{0}\r\n",
                                  System.Reflection.Assembly.GetExecutingAssembly().GetName().Version);
         strInfo += string.Format("\tHost:{0}\r\n", Environment.MachineName);
         strInfo += string.Format("\tAccount:{0}", Environment.UserName);
         WriteLog(LogMode.Info, strInfo);
     }
     catch { }
 }
Example #15
0
 protected override void OnExit(ExitEventArgs e)
 {
     if (mLogOperator != null)
     {
         mLogOperator.Stop();
         mLogOperator = null;
     }
     base.OnExit(e);
 }
Example #16
0
        public Assembly GetAssembly()
        {
            if (Compiler.AssemblyName == default)
            {
                Compiler.AssemblyName = Guid.NewGuid().ToString("N");
            }


            //如果是文件编译,则初始化路径
            if (Compiler.AssemblyOutputKind == Framework.AssemblyBuildKind.File)
            {
                if (OutputFolder == GlobalOutputFolder)
                {
                    OutputFolder = Path.Combine(GlobalOutputFolder, Compiler.Domain.Name);
                }
                if (!Directory.Exists(OutputFolder))
                {
                    Directory.CreateDirectory(OutputFolder);
                }
                if (Compiler.DllPath == default)
                {
                    Compiler.DllPath = Path.Combine(OutputFolder, Compiler.AssemblyName + ".dll");
                    Compiler.PdbPath = Path.Combine(OutputFolder, Compiler.AssemblyName + ".pdb");
                }
            }


            //进入编译流程
            Compile();


            //如果编译出错
            if (Compiler.Assembly == null && Exceptions != null && Exceptions.Count > 0)
            {
                switch (Compiler.ErrorBehavior)
                {
                case ExceptionBehavior.Log | ExceptionBehavior.Throw:
                    LogOperator.ErrorRecoder(Compiler.Compilation, Exceptions);
                    throw Exceptions[0];

                case ExceptionBehavior.Log:
                    LogOperator.ErrorRecoder(Compiler.Compilation, Exceptions);
                    break;

                case ExceptionBehavior.Throw:
                    throw Exceptions[0];

                default:
                    break;
                }
            }
            else
            {
                LogOperator.SucceedRecoder(Compiler.Compilation);
            }
            return(Compiler.Assembly);
        }
Example #17
0
 protected override void OnExit(ExitEventArgs e)
 {
     WriteLog("AppExit", "Application exit.");
     if (mLogOperator != null)
     {
         mLogOperator.Stop();
         mLogOperator = null;
     }
     base.OnExit(e);
 }
Example #18
0
        public LogSearchModel FindById(int logId)
        {
            var result = _context.Logs.Where(v => v.LogId == logId);

            result = (IQueryable <Log>)ExpandOperator.ExpandRelatedEntities <Log>(result);

            var log       = result.FirstOrDefault();
            var logSearch = LogOperator.SetLogSearchModelCascade(log);

            return(logSearch);
        }
        public async Task <IEnumerable <LogSubSearchModel> > GetLogsByLogDescriptionIdAsync(int logDescriptionId)
        {
            var queryData = _context.Logs.Where(l => l.LogDescriptionId == logDescriptionId);
            var result    = QueryOperate <Log> .Execute(queryData);

            var logs = await result.ToListAsync();

            var logsSearch = LogOperator.SetLogSubSearchModel(logs);

            return(logsSearch);
        }
Example #20
0
 void MainWindow_Closing(object sender, CancelEventArgs e)
 {
     if (mDecConnector != null)
     {
         mDecConnector.Close();
     }
     if (mLogOperator != null)
     {
         mLogOperator.Stop();
         mLogOperator = null;
     }
 }
Example #21
0
 /// <summary>
 /// 结构是否存在自增长字段id
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 internal bool HasAutoIncrementID(Type t)
 {
     try
     {
         string    cmdStr = SqliteTabelCmdStrTool.GetAutoIncrement(t);
         DataTable dt     = OperateQuery(cmdStr);
         return(dt.Rows[0][0].ToString().Contains("INTEGER PRIMARY KEY AUTOINCREMENT"));
     }
     catch (SqliteException e)
     {
         LogOperator.AddWarnningRecord("执行查询结构是否存在自增长字段id时异常", e.Message);
         return(false);
     }
 }
Example #22
0
 protected override void OnStop()
 {
     // TODO:  在此处添加代码以执行停止服务所需的关闭操作。
     if (mMonitorServer != null)
     {
         mMonitorServer.Stop();
     }
     WriteLog(LogMode.Info, string.Format("Service stopped"));
     if (mLogOperator != null)
     {
         mLogOperator.Stop();
         mLogOperator = null;
     }
 }
Example #23
0
        public IEnumerable <LogSearchModel> GetAll()
        {
            var queryData = from L in _context.Logs
                            select L;

            var result = QueryOperate <Log> .Execute(queryData);

            result = (IQueryable <Log>)ExpandOperator.ExpandRelatedEntities <Log>(result);

            //以下执行完后才会去数据库中查询
            var logs       = result.ToList();
            var logsSearch = LogOperator.SetLogSearchModelCascade(logs);

            return(logsSearch);
        }
Example #24
0
 public virtual void Exit()
 {
     RemoveView();
     if (NetPipeHelper != null)
     {
         NetPipeHelper.Stop();
         NetPipeHelper = null;
     }
     WriteLog("AppExit", string.Format("App ended."));
     if (mLogOperator != null)
     {
         mLogOperator.Stop();
         mLogOperator = null;
     }
 }
 /// <summary>
 /// 错误处理
 /// </summary>
 /// <param name="exception"></param>
 private void HandlerErrors(NatashaException exception)
 {
     if (SyntaxErrorBehavior == ExceptionBehavior.Throw)
     {
         throw exception;
     }
     else if (SyntaxErrorBehavior == ExceptionBehavior.Log)
     {
         LogOperator.ErrorRecoder(exception);
     }
     else if (SyntaxErrorBehavior == (ExceptionBehavior.Log | ExceptionBehavior.Throw))
     {
         LogOperator.ErrorRecoder(exception);
         throw exception;
     }
 }
 private void HandlerErrors(CompilationException exception)
 {
     if (ErrorBehavior == ExceptionBehavior.Throw)
     {
         throw exception;
     }
     else if (ErrorBehavior == ExceptionBehavior.Log)
     {
         LogOperator.ErrorRecoder(exception);
     }
     else if (ErrorBehavior == (ExceptionBehavior.Log | ExceptionBehavior.Throw))
     {
         LogOperator.ErrorRecoder(exception);
         throw exception;
     }
 }
Example #27
0
 private void CreateLogOperator()
 {
     try
     {
         string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
                                    string.Format("UMP/{0}/Logs", AppName));
         if (!Directory.Exists(path))
         {
             Directory.CreateDirectory(path);
         }
         mLogOperator         = new LogOperator();
         mLogOperator.LogPath = path;
         mLogOperator.Start();
     }
     catch { }
 }
Example #28
0
 /// <summary>
 /// 关闭数据库链接
 /// </summary>
 /// <returns></returns>
 internal bool Close()
 {
     try
     {
         if (connection != null && connection.State != ConnectionState.Closed)
         {
             connection.Close();
         }
         return(true);
     }
     catch (SqliteException e)
     {
         LogOperator.AddWarnningRecord("关闭数据库时有异常", e.Message);
         return(false);
     }
 }
Example #29
0
 /// <summary>
 /// 转化为实例,忽略空字段
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="json"></param>
 /// <returns></returns>
 public static T JsonToTObject <T>(this string json) where T : class, new ()
 {
     try
     {
         JsonSerializerSettings setting = new JsonSerializerSettings()
         {
             NullValueHandling = NullValueHandling.Ignore
         };
         T t = JsonConvert.DeserializeObject <T>(json, setting);
         return(t);
     }
     catch (JsonSerializationException e)
     {
         LogOperator.AddFinalRecord(string.Format("转换json字符串 {0} 到类型 {1} 异常,异常原因:", json, typeof(T).Name, e.Message));
         return(null);
     }
 }
Example #30
0
 /// <summary>
 /// 转化为json字符串,忽略空字段
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="t"></param>
 /// <returns></returns>
 public static string TObjectToJson <T>(this T t) where T : class, new()
 {
     try
     {
         JsonSerializerSettings setting = new JsonSerializerSettings()
         {
             NullValueHandling = NullValueHandling.Ignore
         };
         string json = JsonConvert.SerializeObject(t, setting);
         return(json);
     }
     catch (JsonSerializationException e)
     {
         LogOperator.AddFinalRecord(string.Format("转换 {0} 类型 为json字符串异常,异常原因:", typeof(T).Name, e.Message));
         return(null);
     }
 }