Пример #1
0
        /// <summary>
        /// 创建脚本文件信息对象
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        private ScriptFileInfo CreateScriptFile(string fileName)
        {
            ScriptFileInfo scriptFileInfo = null;

            if (!File.Exists(fileName))
            {
                return(scriptFileInfo);
            }

            FileInfo fi = new FileInfo(fileName);

            if (fi.Extension == ".cs")
            {
                string fileCode = GetScriptCode(fileName);
                scriptFileInfo = new CSharpFileInfo(fileCode, fileName);
                using (var sr = fi.OpenText())
                {
                    scriptFileInfo.Source = Decode(sr.ReadToEnd(), fi.Extension);
                }
                scriptFileInfo.HashCode = CryptoHelper.ToMd5Hash(scriptFileInfo.Source);
            }
            else
            {
                TraceLog.WriteError("Not supported \"{0}\" file type.", fileName);
            }
            return(scriptFileInfo);
        }
Пример #2
0
        private void LoadScriptInfo(string scriptPath)
        {
            Interlocked.Increment(ref ScriptVerionId);
            string title      = string.Format("Script.{0}", Path.GetFileName(scriptPath));
            string guid       = Guid.NewGuid().ToString();
            string path       = Path.Combine(scriptPath, "Properties");
            string fileName   = Path.Combine(path, "AssemblyInfo.cs");
            string scriptCode = GetScriptCode(fileName);
            string source     = string.Format(ScriptAssembllyInfo, title, guid, ScriptVerionId);

            try
            {
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }
                File.AppendAllText(fileName, source);
                ScriptFileInfo scriptFile = new CSharpFileInfo(scriptCode, fileName)
                {
                    HashCode = CryptoHelper.ToMd5Hash(source),
                    Source   = source
                };

                if (scriptPath == _modelScriptPath)
                {
                    _modelCodeCache[scriptCode] = scriptFile;
                }
                else
                {
                    _csharpCodeCache[scriptCode] = scriptFile;
                }
            }
            catch (Exception ex)
            {
                TraceLog.WriteWarn("Script AssemblyInfo error:{0}", ex);
            }
        }
        /// <summary>
        /// 创建脚本文件信息对象
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        private ScriptFileInfo CreateScriptFile(string fileName)
        {
            ScriptFileInfo scriptFileInfo = null;

            if (!File.Exists(fileName))
            {
                return(scriptFileInfo);
            }
            string ext = Path.GetExtension(fileName);

            if (string.Compare(ext, ".cs", StringComparison.OrdinalIgnoreCase) == 0)
            {
                string fileCode = GetScriptCode(fileName);
                scriptFileInfo          = new CSharpFileInfo(fileCode, fileName);
                scriptFileInfo.Source   = Decode(File.ReadAllText(fileName), ext);
                scriptFileInfo.HashCode = CryptoHelper.ToMd5Hash(scriptFileInfo.Source);
            }
            else
            {
                TraceLog.WriteError("Not supported \"{0}\" file type.", fileName);
            }
            return(scriptFileInfo);
        }
Пример #4
0
        /// <summary>
        /// 创建脚本文件信息对象
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        private static ScriptFileInfo CreateScriptFile(string fileName)
        {
            ScriptFileInfo scriptFileInfo = null;

            if (!File.Exists(fileName))
            {
                return(scriptFileInfo);
            }

            var watchDir = _watcherDict.Where(pair => fileName.StartsWith(pair.Value.Path)).FirstOrDefault();

            FileInfo fi       = new FileInfo(fileName);
            string   fileCode = GetScriptCode(fileName);
            string   fileHash = GetFileHashCode(fileName);

            if (fi.Extension == ".py")
            {
                CompiledCode compiledCode = CompilePython(fileName);
                if (compiledCode != null)
                {
                    scriptFileInfo           = new PythonFileInfo(fileCode, fileName, compiledCode);
                    scriptFileInfo.HashCode  = fileHash;
                    scriptFileInfo.GroupName = watchDir.Key;
                }
            }
            else if (fi.Extension == ".cs")
            {
                scriptFileInfo           = new CSharpFileInfo(fileCode, fileName);
                scriptFileInfo.HashCode  = fileHash;
                scriptFileInfo.GroupName = watchDir.Key;
            }
            else
            {
                TraceLog.WriteError("Not supported \"{0}\" file type.", fileName);
            }
            return(scriptFileInfo);
        }
Пример #5
0
        /// <summary>
        /// �����ű��ļ���Ϣ����
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        private static ScriptFileInfo CreateScriptFile(string fileName)
        {
            ScriptFileInfo scriptFileInfo = null;
            if (!File.Exists(fileName))
            {
                return scriptFileInfo;
            }

            var watchDir = _watcherDict.Where(pair => fileName.StartsWith(pair.Value.Path)).FirstOrDefault();

            FileInfo fi = new FileInfo(fileName);
            string fileCode = GetScriptCode(fileName);
            string fileHash = GetFileHashCode(fileName);
            if (fi.Extension == ".py")
            {
                CompiledCode compiledCode = CompilePython(fileName);
                if (compiledCode != null)
                {
                    scriptFileInfo = new PythonFileInfo(fileCode, fileName, compiledCode);
                    scriptFileInfo.HashCode = fileHash;
                    scriptFileInfo.GroupName = watchDir.Key;
                }
            }
            else if (fi.Extension == ".cs")
            {
                scriptFileInfo = new CSharpFileInfo(fileCode, fileName);
                scriptFileInfo.HashCode = fileHash;
                scriptFileInfo.GroupName = watchDir.Key;
            }
            else
            {
                TraceLog.WriteError("Not supported \"{0}\" file type.", fileName);
            }
            return scriptFileInfo;
        }
Пример #6
0
        /// <summary>
        /// 创建脚本文件信息对象
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        private ScriptFileInfo CreateScriptFile(string fileName)
        {
            ScriptFileInfo scriptFileInfo = null;
            if (!File.Exists(fileName))
            {
                return scriptFileInfo;
            }

            FileInfo fi = new FileInfo(fileName);
            if (fi.Extension == ".cs")
            {
                string fileCode = GetScriptCode(fileName);
                scriptFileInfo = new CSharpFileInfo(fileCode, fileName);
                using (var sr = fi.OpenText())
                {
                    scriptFileInfo.Source = Decode(sr.ReadToEnd(), fi.Extension);
                }
                scriptFileInfo.HashCode = CryptoHelper.ToMd5Hash(scriptFileInfo.Source);
            }
            else
            {
                TraceLog.WriteError("Not supported \"{0}\" file type.", fileName);
            }
            return scriptFileInfo;
        }
Пример #7
0
 /// <summary>
 /// �����ű��ļ���Ϣ����
 /// </summary>
 /// <param name="fileName"></param>
 /// <returns></returns>
 private static ScriptFileInfo CreateScriptFile(string fileName)
 {
     ScriptFileInfo scriptFileInfo = null;
     if (!File.Exists(fileName))
     {
         return scriptFileInfo;
     }
     FileInfo fi = new FileInfo(fileName);
     string fileCode = GetScriptCode(fileName);
     string fileHash = GetFileHashCode(fileName);
     if (fi.Extension == ".py")
     {
         CompiledCode compiledCode = CompilePython(fileName);
         if (compiledCode != null)
         {
             scriptFileInfo = new PythonFileInfo(fileCode, fileName, compiledCode);
             scriptFileInfo.HashCode = fileHash;
         }
     }
     else if (fi.Extension == ".cs")
     {
         scriptFileInfo = new CSharpFileInfo(fileCode, fileName);
         scriptFileInfo.HashCode = fileHash;
     }
     else
     {
         TraceLog.WriteError("Not supported \"{0}\" file type.", fileName);
     }
     return scriptFileInfo;
 }