Beispiel #1
0
        public static bool Write(Exception ex)
        {
            //    return Write(ex, ChoStackTrace.GetStackFrame(typeof(ChoTrace)));
            //}

            //internal static bool Write(Exception ex, StackFrame callerStackFrame)
            //{
            if (ex == null)
            {
                return(false);
            }

            if (!ChoApplicationException.IsProcessed(ex))
            {
                //if (ChoTraceSwitch.Switch.TraceError)
                //    ChoLogger.Log(callerStackFrame, String.Format("[{0}]: {1}{2}", ChoStackTrace.GetCallerName(), ex.Message, Environment.NewLine));

                try
                {
                    Trace.WriteLineIf(ChoTraceSwitch.Switch.TraceError, String.Format("[{0}]: {1}", ChoStackTrace.GetCallerName(), ChoApplicationException.ToString(ex)));
                    return(true);
                }
                catch (Exception exception)
                {
                    ChoApplication.WriteToEventLog(ChoApplicationException.ToString(exception), EventLogEntryType.Error);
                }
                finally
                {
                    ChoApplicationException.SetProcessed(ex);
                }
            }
            return(false);
        }
Beispiel #2
0
 public void AppendIf(bool condition, Exception ex)
 {
     if (condition)
     {
         AppendLine(ChoApplicationException.ToString(ex));
     }
 }
Beispiel #3
0
        public override object DoObjectInitialize(object target)
        {
            if (target == null)
            {
                return(null);
            }

            base.DoObjectInitialize(target);

            Type            objType = target.GetType();
            Action <object> _objectInitializers;

            foreach (MethodInfo methodInfo in ChoType.GetMethods(objType, typeof(ChoSingletonInstanceInitializerAttribute)))
            {
                try
                {
                    _objectInitializers = methodInfo.CreateDelegate <Action <object> >(target);
                    _objectInitializers(target);
                }
                catch (Exception ex)
                {
                    ChoApplication.WriteToEventLog(ChoApplicationException.ToString(ex));
                }
            }

            return(target);
        }
Beispiel #4
0
 void eSquare.Core.Diagnostics.IChoProfile.Append(Exception ex)
 {
     if (ex == null)
     {
         return;
     }
     Append(ChoApplicationException.ToString(ex));
 }
Beispiel #5
0
 public static void Backup()
 {
     try
     {
         Trace.Write(BACKUP);
     }
     catch (Exception ex)
     {
         ChoApplication.WriteToEventLog(ChoApplicationException.ToString(ex), EventLogEntryType.Error);
     }
 }
Beispiel #6
0
 internal static void WriteNewLineIf(bool condition, StackFrame callerStackFrame)
 {
     //ChoLogger.Log(callerStackFrame, Environment.NewLine);
     try
     {
         Trace.WriteLineIf(condition, Environment.NewLine);
     }
     catch (Exception ex)
     {
         ChoApplication.WriteToEventLog(ChoApplicationException.ToString(ex), EventLogEntryType.Error);
     }
 }
Beispiel #7
0
 public virtual void Log(bool condition, string msg)
 {
     if (condition)
     {
         try
         {
             ChoFile.WriteLine(Path.Combine(LogDirectory, LogFileName), String.Format("{1}{0}{2}", Environment.NewLine,
                                                                                      DateTime.Now.ToString(LogTimeStampFormat), msg.ToString()));
         }
         catch (Exception ex)
         {
             ChoApplication.WriteToEventLog(ChoApplicationException.ToString(ex), EventLogEntryType.Error);
         }
     }
 }
Beispiel #8
0
        internal static void WriteIf(bool condition, StackFrame callerStackFrame, string msg)
        {
            if (msg == null)
            {
                return;
            }
            //if (condition) ChoLogger.Log(callerStackFrame, msg);

            try
            {
                Trace.WriteIf(condition, msg);
            }
            catch (Exception ex)
            {
                ChoApplication.WriteToEventLog(ChoApplicationException.ToString(ex), EventLogEntryType.Error);
            }
        }
Beispiel #9
0
        public static void Backup()
        {
            if (!ChoFileProfileSettings.TurnOn)
            {
                return;
            }

            string logDirectory = ChoFileProfileSettings.LogDirectory;

            try
            {
                //Has any files
                if (!HasAnyFiles(logDirectory))
                {
                    return;
                }

                //Backup the directory
                string newLogDirectory = logDirectory + "_" + DateTime.Now.ToString("yyyyMMdd");

                int index = 0;
                while (Directory.Exists(newLogDirectory))
                {
                    newLogDirectory = logDirectory + "_" + DateTime.Now.ToString("yyyyMMdd") + "." + index.ToString("D3");
                    index++;
                }

                Directory.CreateDirectory(newLogDirectory);

                //Move files
                foreach (string file in Directory.GetFiles(logDirectory))
                {
                    File.Move(file, newLogDirectory + "\\" + Path.GetFileName(file));
                }

                //Move Directories
                foreach (string directory in Directory.GetDirectories(logDirectory))
                {
                    Directory.Move(directory, newLogDirectory + "\\" + Path.GetFileName(directory));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ChoApplicationException.ToString(ex));
            }
        }
Beispiel #10
0
        private static void ExecuteShellExtensionMethod(string command, string[] args)
        {
            ChoEnvironment.CommandLineArgs = args;
            foreach (MethodInfo methodInfo in GetShellExtensionMethods())
            {
                ChoShellExtensionContextMenuAttribute attr = methodInfo.GetCustomAttribute <ChoShellExtensionContextMenuAttribute>();
                if (attr == null)
                {
                    continue;
                }
                if (methodInfo.Name == command)
                {
                    try
                    {
                        methodInfo.Invoke(null, new object[] { args });
                    }
                    catch (Exception ex)
                    {
                        ChoTrace.WriteLine("Error while executing '{0}' shell extension command. \n {1}".FormatString(command, ChoApplicationException.ToString(ex)));
                        ChoApplication.WriteToEventLog("Error while executing '{0}' shell extension command. \n {1}".FormatString(command, ChoApplicationException.ToString(ex)));
                    }

                    return;
                }
            }

            ChoApplication.WriteToEventLog("'{0}' shell extension command not found.".FormatString(command));
        }
        private bool SetNThrowException(Exception ex, ref bool isModified)
        {
            bool handled = false;

            if (ex == null)
            {
                return(handled);
            }

            if (ConfigObject != null && ConfigObject is ChoConfigurableObject)
            {
                handled = ((ChoConfigurableObject)ConfigObject).RaiseConfigurationObjectLoadError(ex, ref isModified);
            }

            if (!handled)
            {
                if (ConfigObject != null && ConfigObject is IChoExceptionHandledObject)
                {
                    handled = ((IChoExceptionHandledObject)ConfigObject).HandleException(ex, ref isModified);
                }
            }

            //ChoConfigurationErrorsProfiler.Me.AppendLine(ChoApplicationException.ToString(ex));

            if (!Silent)
            {
                throw new ChoConfigurationConstructionException("Failed to build configuration element.", ex);
            }
            else
            {
                //if (_configSection is IChoCustomConfigSection)
                //    ChoConfigurationObjectErrorManagerService.SetObjectError(_configSection.ConfigData, ChoApplicationException.ToString(ex));
                //else
                ChoConfigurationObjectErrorManagerService.SetObjectError(ConfigObject, ChoApplicationException.ToString(ex));
            }
            return(handled);
        }
Beispiel #12
0
        private void SyncFileWriter()
        {
            while (true)
            {
                try
                {
                    object queueObject = null;
                    if (_messageQ.Count > 0)
                    {
                        queueObject = _messageQ.Dequeue();
                    }
                    else
                    {
                        _newMsgArrived.WaitOne();
                        continue;
                    }

                    TextTraceMsg item = (TextTraceMsg)queueObject;
                    if (item.IsFlushMsg)
                    {
                        break;
                    }

                    switch (item.Operation)
                    {
                    case FileOperation.WriteLine:
                        if (base.Writer == null)
                        {
                            base.Writer = new StreamWriter(new ChoFileStreamWithBackup(FileName,
                                                                                       _maxFileSize, _maxFileCount, FileMode.Append, _cyclic, _autoBackup, _allowSplitMsg));
                        }
                        base.Writer.WriteLine(item.Msg);
                        base.Writer.Flush();
                        break;

                    case FileOperation.Write:
                        if (base.Writer == null)
                        {
                            base.Writer = new StreamWriter(new ChoFileStreamWithBackup(FileName,
                                                                                       _maxFileSize, _maxFileCount, FileMode.Append, _cyclic, _autoBackup, _allowSplitMsg));
                        }
                        base.Writer.Write(item.Msg);
                        base.Writer.Flush();
                        break;

                    case FileOperation.CreateNew:
                        base.Writer.Flush();
                        base.Writer.Close();
                        base.Writer = new StreamWriter(new ChoFileStreamWithBackup(FileName,
                                                                                   _maxFileSize, _maxFileCount, FileMode.Append, _cyclic, _autoBackup, _allowSplitMsg));
                        break;

                    case FileOperation.Rename:
                        base.Writer.Flush();
                        base.Writer.Close();
                        base.Writer = new StreamWriter(new ChoFileStreamWithBackup(Path.Combine(_directoryName, Path.ChangeExtension(_baseFileName, _fileExt)), _maxFileSize, _maxFileCount, FileMode.Append, _cyclic, _autoBackup, _allowSplitMsg));
                        if (File.Exists(Path.Combine(_directoryName, Path.ChangeExtension(item.PrevLogFileName, _fileExt))))
                        {
                            using (StreamReader reader = File.OpenText(Path.Combine(_directoryName, Path.ChangeExtension(item.PrevLogFileName, _fileExt))))
                                base.Writer.WriteLine(reader.ReadToEnd());

                            File.Delete(Path.Combine(_directoryName, Path.ChangeExtension(item.PrevLogFileName, _fileExt)));
                        }
                        break;
                    }
                }
                catch (Exception ex)
                {
                    ChoApplication.WriteToEventLog(ChoApplicationException.ToString(ex), EventLogEntryType.Error);
                }
            }
        }
Beispiel #13
0
        public void StartFileCopy(string sourceDirectory = null, string destDirectory = null)
        {
            try
            {
                ChoAppSettings appSettings = new ChoAppSettings();
                if (!SettingsFilePath.IsNullOrWhiteSpace())
                {
                    if (!File.Exists(SettingsFilePath))
                    {
                        throw new ArgumentException("Can't find '{0}' settings file.".FormatString(SettingsFilePath));
                    }

                    appSettings.LoadXml(File.ReadAllText(SettingsFilePath));
                }

                ChoConsole.WriteLine();

                ChoRoboCopyManager _roboCopyManager = new ChoRoboCopyManager(SettingsFilePath);
                _roboCopyManager.Status += (sender, e) =>
                {
                    ChoTrace.Write(e.Message);
                    ChoConsole.Write(e.Message, ConsoleColor.Yellow);
                };
                _roboCopyManager.AppStatus += (sender, e) =>
                {
                    ChoTrace.Write(e.Message);
                    ChoConsole.Write(e.Message, ConsoleColor.Yellow);
                };

                _roboCopyManager.Process(appSettings.RoboCopyFilePath, appSettings.GetCmdLineParams(sourceDirectory, destDirectory));
            }
            catch (ThreadAbortException)
            {
                Console.WriteLine("RoboCopy operation cancelled by user.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("RoboCopy operation failed." + Environment.NewLine + ChoApplicationException.ToString(ex));
            }
        }