public DefaultEnvironment() { NPath localAppData; NPath commonAppData; if (IsWindows) { localAppData = GetSpecialFolder(Environment.SpecialFolder.LocalApplicationData).ToNPath(); commonAppData = GetSpecialFolder(Environment.SpecialFolder.CommonApplicationData).ToNPath(); } else if (IsMac) { localAppData = NPath.HomeDirectory.Combine("Library", "Application Support"); // there is no such thing on the mac that is guaranteed to be user accessible (/usr/local might not be) commonAppData = GetSpecialFolder(Environment.SpecialFolder.ApplicationData).ToNPath(); } else { localAppData = GetSpecialFolder(Environment.SpecialFolder.LocalApplicationData).ToNPath(); commonAppData = "/usr/local/share/".ToNPath(); } UserCachePath = localAppData.Combine(ApplicationInfo.ApplicationName); SystemCachePath = commonAppData.Combine(ApplicationInfo.ApplicationName); if (IsMac) { LogPath = NPath.HomeDirectory.Combine("Library/Logs").Combine(ApplicationInfo.ApplicationName).Combine(logFile); } else { LogPath = UserCachePath.Combine(logFile); } LogPath.EnsureParentDirectoryExists(); }
/// <summary>加载完成后</summary> protected override void OnLoaded() { if (LogPath.IsNullOrEmpty()) { LogPath = "Log"; } if (DataPath.IsNullOrEmpty()) { DataPath = "Data"; } if (BackupPath.IsNullOrEmpty()) { BackupPath = "Backup"; } if (LogFileFormat.IsNullOrEmpty()) { LogFileFormat = "{0:yyyy_MM_dd}.log"; } if (PluginServer.IsNullOrWhiteSpace()) { PluginServer = "http://x.newlifex.com/"; } base.OnLoaded(); }
/// <summary> /// Determines whether [is log file ready]. /// </summary> /// <returns> /// <c>true</c> if [is log file ready]; otherwise, <c>false</c>. /// </returns> private bool isLogFileReady() { if (!String.IsNullOrWhiteSpace(LogPath)) { if (!File.Exists(LogPath)) { try { int seperator = LogPath.LastIndexOf('\\'); string dirPath = LogPath.Substring(0, Math.Max(seperator, 0)); string filename = LogPath.Substring(seperator + 1); if (!String.IsNullOrWhiteSpace(dirPath)) { Directory.CreateDirectory(dirPath); } if (!String.IsNullOrWhiteSpace(filename)) { File.Create(LogPath); } } catch {} } if (File.Exists(LogPath)) { return(true); } } return(false); }
private void OpenProcessByName(string name, bool uac = false, Action action = null) { string fileName = LogPath.GetExeFilePath(name); try { ProcessStartInfo processInfo = new ProcessStartInfo(); if (uac && Environment.OSVersion.Version.Major >= 6) { processInfo.Verb = "runas"; } processInfo.FileName = fileName; var process = Process.Start(processInfo); if (action != null) { process.EnableRaisingEvents = true; process.Exited += (object sender, EventArgs e) => { action(); }; } } catch (Exception) { // MessageBox.Show(string.Format("文件'{0}'不存在,或者需要管理员权限才能运行。", name)); } }
private bool SaveLogOutputOptions() { if (IsLogOutputEnabled.IsChecked == true) { if (!Directory.Exists(LogPath.Text)) { LogOutputTab.Focus(); MessageBox.Show( "The specified path does not exist. Please enter a valid path.", "vmPing Error", MessageBoxButton.OK, MessageBoxImage.Error); LogPath.Focus(); return(false); } ApplicationOptions.IsLogOutputEnabled = true; ApplicationOptions.LogPath = LogPath.Text; } else { ApplicationOptions.IsLogOutputEnabled = false; } return(true); }
internal string GetNewHpGeFile(string sid = null) { string path = LogPath.GetDeviceLogFilePath("scada.hpge"); if (string.IsNullOrEmpty(sid)) { sid = GetCurrentSid(); } string currentFilePath = Path.Combine(path, sid); if (Directory.Exists(currentFilePath)) { string[] files = Directory.GetFiles(currentFilePath); foreach (var file in files) { string fileName = Path.GetFileName(file); if (!fileName.StartsWith("!")) { return(file); } } return(string.Empty); } else { return(string.Empty); } }
public override int GetHashCode() { int hash = 1; if (Name.Length != 0) { hash ^= Name.GetHashCode(); } if (CommunicationVersion.Length != 0) { hash ^= CommunicationVersion.GetHashCode(); } if (LogPath.Length != 0) { hash ^= LogPath.GetHashCode(); } hash ^= brainParameters_.GetHashCode(); if (PackageVersion.Length != 0) { hash ^= PackageVersion.GetHashCode(); } if (capabilities_ != null) { hash ^= Capabilities.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
private Device Load(DeviceEntry entry) { if (entry == null) { return(null); } //实例化设备 StringValue className = (StringValue)entry[DeviceEntry.ClassName]; if (typeof(StandardDevice).ToString() == className) { return(new StandardDevice(entry)); } else if (typeof(WebFileDevice).ToString() == className) { return(new WebFileDevice(entry)); } else if (typeof(FormProxyDevice).ToString() == className) { return(new FormProxyDevice(entry)); } else if (typeof(CinderlDataDevice).ToString() == className) { return(new CinderlDataDevice(entry)); } else if (typeof(CinderlStatusDevice).ToString() == className) { return(new CinderlStatusDevice(entry)); } else if (typeof(ShelterDevice).ToString() == className) { return(new ShelterDevice(entry)); } else if (typeof(HPGEFileDevice).ToString() == className) { return(new HPGEFileDevice(entry)); } else if (typeof(WeatherDevice).ToString() == className) { return(new WeatherDevice(entry)); } // Other Device defined in some Assemblies. if (entry[DeviceEntry.Assembly] != null) { string assemblyName = (StringValue)entry[DeviceEntry.Assembly]; string assemblyFile = LogPath.GetExeFilePath(assemblyName); Assembly assembly = Assembly.LoadFile(assemblyFile); Type deviceClass = assembly.GetType((StringValue)entry[DeviceEntry.ClassName]); if (deviceClass != null) { object device = Activator.CreateInstance(deviceClass, new object[] { entry }); return(device as Device); } } MessageBox.Show("Create Device Failed"); return((Device)null); }
public DefaultEnvironment() { if (IsWindows) { LocalAppData = GetSpecialFolder(Environment.SpecialFolder.LocalApplicationData).ToNPath(); CommonAppData = GetSpecialFolder(Environment.SpecialFolder.CommonApplicationData).ToNPath(); } else if (IsMac) { LocalAppData = NPath.HomeDirectory.Combine("Library", "Application Support"); // there is no such thing on the mac that is guaranteed to be user accessible (/usr/local might not be) CommonAppData = GetSpecialFolder(Environment.SpecialFolder.ApplicationData).ToNPath(); } else { LocalAppData = GetSpecialFolder(Environment.SpecialFolder.LocalApplicationData).ToNPath(); CommonAppData = GetSpecialFolder(Environment.SpecialFolder.ApplicationData).ToNPath(); } UserCachePath = LocalAppData.Combine(ApplicationInfo.ApplicationName); SystemCachePath = CommonAppData.Combine(ApplicationInfo.ApplicationName); if (IsMac) { LogPath = NPath.HomeDirectory.Combine("Library/Logs").Combine(ApplicationInfo.ApplicationName).Combine(logFile); } else { LogPath = UserCachePath.Combine(logFile); } LogPath.EnsureParentDirectoryExists(); GitDefaultInstallation = new GitInstaller.GitInstallDetails(UserCachePath, this); }
public override int GetHashCode() { int hash = 1; if (Name.Length != 0) { hash ^= Name.GetHashCode(); } if (Version.Length != 0) { hash ^= Version.GetHashCode(); } if (LogPath.Length != 0) { hash ^= LogPath.GetHashCode(); } hash ^= brainParameters_.GetHashCode(); if (environmentParameters_ != null) { hash ^= EnvironmentParameters.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
/// <summary>加载完成后</summary> protected override void OnLoaded() { var web = Runtime.IsWeb; if (LogPath.IsNullOrEmpty()) { LogPath = web ? "..\\Log" : "Log"; } if (DataPath.IsNullOrEmpty()) { DataPath = web ? "..\\Data" : "Data"; } if (BackupPath.IsNullOrEmpty()) { BackupPath = web ? "..\\Backup" : "Backup"; } //if (TempPath.IsNullOrEmpty()) TempPath = web ? "..\\Temp" : "Temp"; if (LogFileFormat.IsNullOrEmpty()) { LogFileFormat = "{0:yyyy_MM_dd}.log"; } if (PluginServer.IsNullOrWhiteSpace()) { PluginServer = "http://x.newlifex.com/"; } base.OnLoaded(); }
public string GetNaIDeviceData(DateTime time) { string fileName = this.GetFileName(time); string datePath = this.GetDatePath(time); string filePath = LogPath.GetDeviceLogFilePath("scada.naidevice", time) + "\\" + time.Day.ToString() + "\\" + fileName; string content = string.Empty; try { if (File.Exists(filePath)) { using (StreamReader fs = new StreamReader(filePath)) { content = fs.ReadToEnd(); return(content); } } else { Log.GetLogFile("scada.naidevice").Log(string.Format("{0} Not_Found", filePath)); } } catch (Exception) { return(""); } return(content); }
public virtual IEnvironment Initialize( string projectPath, string extensionInstallPath, string unityVersion = null, string EditorApplication_applicationPath = default, string EditorApplication_applicationContentsPath = default ) { UserCachePath.EnsureDirectoryExists(); SystemCachePath.EnsureDirectoryExists(); LogPath.EnsureDirectoryExists(); UnityProjectPath = projectPath.ToSPath(); ExtensionInstallPath = extensionInstallPath.ToSPath(); UnityVersion = unityVersion; if (!string.IsNullOrEmpty(EditorApplication_applicationPath)) { UnityApplication = EditorApplication_applicationPath.ToSPath(); } if (!string.IsNullOrEmpty(EditorApplication_applicationContentsPath)) { UnityApplicationContents = EditorApplication_applicationContentsPath.ToSPath(); } UserSettings = new UserSettings(this); LocalSettings = new LocalSettings(this); SystemSettings = new SystemSettings(this); return(this); }
private static void CreateErrorLogFile() { CreateLogFile(); if (!File.Exists(ErrorLogPath)) { ErrorLogPath = Path.Combine(LogDir, $"{LogPath.Split('\\').Last().Replace("log", "log_error")}"); StreamWriter sw = new StreamWriter(File.Open(ErrorLogPath, FileMode.OpenOrCreate, FileAccess.Write), Encoding.UTF8); sw.Close(); SafeWriteLine(string.Format(GlobalMessages.ERROR_LOG_CREATED, ErrorLogPath)); } }
/// <summary>关闭文件</summary> private void DoWriteAndClose(Object state) { // 同步写日志 if (Interlocked.CompareExchange(ref _writing, 1, 0) == 0) { WriteAndClose(_NextClose); } // 检查文件是否超过上限 if (!_isFile && Backups > 0) { // 判断日志目录是否已存在 var di = LogPath.GetBasePath().AsDirectory(); if (di.Exists) { // 删除*.del try { var dels = di.GetFiles("*.del"); if (dels != null && dels.Length > 0) { foreach (var item in dels) { item.Delete(); } } } catch { } var ext = Path.GetExtension(FileFormat); var fis = di.GetFiles("*" + ext); if (fis != null && fis.Length > Backups) { // 删除最旧的文件 var retain = fis.Length - Backups; fis = fis.OrderBy(e => e.CreationTime).Take(retain).ToArray(); foreach (var item in fis) { OnWrite(LogLevel.Info, "日志文件达到上限 {0},删除 {1},大小 {2:n0}Byte", Backups, item.Name, item.Length); try { item.Delete(); } catch { item.MoveTo(item.FullName + ".del"); } } } } } }
public string GetLabrDeviceFile(DateTime time) { string fileName = this.GetLabrFileName(time); string datePath = GetDatePath(time); string filePath = LogPath.GetDeviceLogFilePath(Devices.Labr, time) + "\\" + time.Day.ToString() + "\\" + fileName; string content = string.Empty; if (File.Exists(filePath)) { return(filePath); } return(null); }
private void UpdateSidFile(string sid) { string path = LogPath.GetDeviceLogFilePath("scada.hpge"); string sidFile = Path.Combine(path, "SID"); using (FileStream fs = File.OpenWrite(sidFile)) { var bs = Encoding.ASCII.GetBytes(sid); fs.Write(bs, 0, bs.Length); string sidFolder = Path.Combine(path, sid); Directory.CreateDirectory(sidFolder); } }
public static void Write(object o) { if (LogPath == null || !File.Exists(LogPath) || !LogPath.EndsWith(".txt")) { LogPath = Path.Combine(Directory.GetCurrentDirectory(), "BOILOG.txt"); } FileInfo lf = new FileInfo(LogPath); try { string result = o?.ToString() ?? "null"; File.AppendAllText(LogPath, result); } catch (IOException) { } }
public static void WriteException(string msg, string trace, string innermsg) { if (Directory.Exists(LogPath.Replace(LogFile, "")) == false) { Directory.CreateDirectory(LogPath.Replace(LogFile, "")); } using (FileStream fs = new FileStream(LogPath, FileMode.Append, FileAccess.Write, FileShare.None)) { using (StreamWriter sw = new StreamWriter(fs)) { string message = string.Format("{0} : {1} \n ##-##-#### Trace : {2} \n ##-##-#### Inner : {3}", DateTime.Now, msg, trace, innermsg); sw.WriteLine(message); } } }
private static string GetDeviceLogPath(Device device, DateTime now) { string deviceLogPath = LogPath.GetDeviceLogFilePath(device.Id, now); if (!existPaths.ContainsKey(deviceLogPath.ToLower())) { if (!Directory.Exists(deviceLogPath)) { Directory.CreateDirectory(deviceLogPath); } existPaths.Add(deviceLogPath.ToLower(), true); } string fileName = string.Format("{0}-{1}-{2}.daq.log", now.Year, now.Month, now.Day); string path = string.Format("{0}\\{1}", deviceLogPath, fileName); return(path); }
private void OpenProcessByName(string name, bool uac = false) { string fileName = LogPath.GetExeFilePath(name); try { ProcessStartInfo processInfo = new ProcessStartInfo(); if (uac && Environment.OSVersion.Version.Major >= 6) { processInfo.Verb = "runas"; } processInfo.FileName = fileName; Process.Start(processInfo); } catch (Exception) { MessageBox.Show(string.Format("文件'{0}'不存在,或者需要管理员权限才能运行。", name)); } }
internal static string GetCurrentSid() { string path = LogPath.GetDeviceLogFilePath("scada.hpge"); string sidFile = Path.Combine(path, "SID"); string sid = string.Empty; if (!File.Exists(sidFile)) { return(string.Empty); } using (FileStream fs = File.OpenRead(sidFile)) { long len = fs.Length; byte[] bs = new byte[len]; fs.Read(bs, 0, (int)len); sid = Encoding.ASCII.GetString(bs); } return(sid); }
// NO USE for NaI device. public string GetNaIDeviceData(DateTime time) { string fileName = this.GetLabrFileName(time); string datePath = GetDatePath(time); string filePath = LogPath.GetDeviceLogFilePath("scada.naidevice", time) + "\\" + fileName; string content = string.Empty; if (File.Exists(filePath)) { StreamReader fs = new StreamReader(filePath); content = fs.ReadToEnd(); } else { Log.GetLogFile("scada.naidevice").Log(string.Format("{0} Not_Found", filePath)); } return(content); }
public void WriteLog(string msg) { if (string.IsNullOrEmpty(msg)) { return; } if (Directory.Exists(LogPath.Replace(LogFile, "")) == false) { Directory.CreateDirectory(LogPath.Replace(LogFile, "")); } using (FileStream fs = new FileStream(LogPath, FileMode.Append, FileAccess.Write, FileShare.None)) { using (StreamWriter sw = new StreamWriter(fs)) { string message = string.Format("{0} : {1}", DateTime.Now, msg); sw.WriteLine(message); } } }
/// <summary>获取日志文件路径</summary> /// <returns></returns> private String GetLogFile() { // 单日志文件 if (_isFile) { return(LogPath.GetBasePath()); } // 目录多日志文件 var logfile = LogPath.CombinePath(FileFormat.F(TimerX.Now)).GetBasePath(); // 是否限制文件大小 if (MaxBytes == 0) { return(logfile); } // 找到今天第一个未达到最大上限的文件 var max = MaxBytes * 1024L * 1024L; var ext = Path.GetExtension(logfile); var name = logfile.TrimEnd(ext); for (var i = 1; i < 1024; i++) { if (i > 1) { logfile = $"{name}_{i}{ext}"; } var fi = logfile.AsFile(); if (!fi.Exists || fi.Length < max) { return(logfile); } } return(null); }
///<summary>This method takes a string that should be some kind of an identifier (usually method name) for the method that is being logged. ///The optional string is for any additional information the implementer finds useful to be in the log string. ///LogPath determines the directory to log to and LogPhase determines whether the logger is a "Start" line or a "Stop" line.</summary> public static void LogToPath(string log, LogPath path, LogPhase logPhase, string optionalDesc = "") { string logWrite = GetCallingMethod() + " " + log; switch (logPhase) { case LogPhase.Unspecified: break; case LogPhase.Start: logWrite += " start"; break; case LogPhase.End: logWrite += " end"; break; } if (optionalDesc != "") { logWrite += " ... " + optionalDesc; } LogVerbose(logWrite, path.ToString() + "\\" + Process.GetCurrentProcess().Id.ToString()); }
/// <summary>加载完成后</summary> protected override void OnLoaded() { var web = Runtime.IsWeb; if (LogPath.IsNullOrEmpty()) { LogPath = web ? "..\\Log" : "Log"; } if (TempPath.IsNullOrEmpty()) { TempPath = web ? "..\\XTemp" : "XTemp"; } if (LogFileFormat.IsNullOrEmpty()) { LogFileFormat = "{0:yyyy_MM_dd}.log"; } #if !__MOBILE__ if (PluginCache.IsNullOrWhiteSpace()) { // 兼容Linux Mono var sys = Environment.SystemDirectory; if (sys.IsNullOrEmpty()) { sys = "/"; } PluginCache = Path.GetPathRoot(sys).CombinePath("X", "Cache"); } #endif if (PluginServer.IsNullOrWhiteSpace() || PluginServer.StartsWithIgnoreCase("ftp://")) { PluginServer = "http://x.newlifex.com/"; } base.OnLoaded(); }
/// <summary>加载完成后</summary> protected override void OnLoaded() { var web = Runtime.IsWeb; if (LogPath.IsNullOrEmpty()) { LogPath = web ? "..\\Log" : "Log"; } if (TempPath.IsNullOrEmpty()) { TempPath = web ? "..\\XTemp" : "XTemp"; } if (LogFileFormat.IsNullOrEmpty()) { LogFileFormat = "{0:yyyy_MM_dd}.log"; } if (PluginServer.IsNullOrWhiteSpace()) { PluginServer = "http://x.haocoding.com/"; } base.OnLoaded(); }
public LogDetailViewModel(string logPath) { LogPath = Path.Combine(FolderFactory.LogFolder, logPath); CanExecuteClose = true; CanExecuteExport = true; ShowScoreItems = Visibility.Collapsed; ShowActivityItems = Visibility.Collapsed; if (File.Exists(LogPath) && LogPath.EndsWith(".xml")) { if (LogPath.Contains("Score")) { LogType = LogTypes.Score; ScoreItems = GetScoreItems(); ShowScoreItems = Visibility.Visible; } else if (LogPath.Contains("Activity")) { LogType = LogTypes.Activity; ActivityItems = GetActivityItems(); ShowActivityItems = Visibility.Visible; } } }
/// <summary> /// /// </summary> /// <param name="o"></param> private void TimerCallback(object o) { // The temp file name is fixed. DateTime now = DateTime.Now; string tempFile = this.DeviceConfigPath + "\\temp_download_file.xml"; string filePath = string.Empty; if (this.IsVirtual) { filePath = this.DeviceConfigPath + "/sara0231_2012-09-01T03_50_00Z-5min.n42"; File.Copy(filePath, tempFile, true); } else { // Start download ... string fileName1 = GetFileNameOnDevice(now); // 判断NaI谱文件是否已经成功下载 if (fileName1 == LastDownLoadFileName) { return; } string fileName2 = GetFileName(now); string datePath = LogPath.GetDeviceLogFilePath(this.Id, now) + "\\" + now.Day.ToString(); this.DoFolderPolicy(datePath); if (!Directory.Exists(datePath)) { Directory.CreateDirectory(datePath); } filePath = datePath + "\\" + fileName2; if (File.Exists(filePath)) { return; } // Download the file. string address = this.addr + fileName1; using (WebClient client = new WebClient()) { try { client.Credentials = new NetworkCredential("root", "root"); // DO NOT USE the FOLLOWING LINE // client.UseDefaultCredentials = true; if (File.Exists(tempFile)) { File.Delete(tempFile); } client.DownloadFile(address, tempFile); } catch (Exception e) { RecordManager.DoSystemEventRecord(this, string.Format("{0} Try to download {1}: Failed.", now, address)); RecordManager.DoSystemEventRecord(this, e.Message); return; } } // 下载成功之后记录,防止多次下载 LastDownLoadFileName = fileName1; } Thread.Sleep(1000); if (File.Exists(tempFile)) { try { XmlDocument doc = new XmlDocument(); doc.Load(tempFile); // XmlElement root = doc.DocumentElement; var nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("a", "http://physics.nist.gov/Divisions/Div846/Gp4/ANSIN4242/2005/ANSIN4242"); nsmgr.AddNamespace("s", "http://www.technidata.com/ENVINET/SARA"); nsmgr.AddNamespace("e", "http://www.technidata.com/ENVINET"); NuclideDataSet set = this.ParseData(doc, nsmgr); this.Record(set, now); File.Move(tempFile, filePath); } catch (IOException e) { RecordManager.DoSystemEventRecord(this, e.Message); } catch (Exception e) { RecordManager.DoSystemEventRecord(this, e.Message); } finally { // TODO: Gzip the file, put it into the Date-folder, then delete this xml file. } } }