コード例 #1
0
        /*
         * public SqLiteDAO GetOrCreateSqLiteDAO()
         * {
         *  return GetOrCreateSqLiteDAO(_DefaultDbFilenameWithoutPath);
         * }
         *
         * public SqLiteDAO GetOrCreateSqLiteDAO(string dbLogFilenameWithoutPath)
         * {
         *  SqLiteDAO result = null;
         *  // We're supposed to recieve a filename without path information. But we'll go ahead and fixup if necessary
         *  if ((dbLogFilenameWithoutPath.Contains("\\")) || (dbLogFilenameWithoutPath.Contains("/")))
         *  {
         *      dbLogFilenameWithoutPath = Path.GetFileName(dbLogFilenameWithoutPath);
         *  }
         *  string fullDBLogPathAndFilename = Path.Combine(FolderForDatabase, dbLogFilenameWithoutPath);
         *
         *  // We need to be thread-safe in this operation
         *  lock (_SQLiteFilesMgr_Lock)
         *  {
         *      foreach (SqLiteDAO nextDBLayer in _SQLiteFiles)
         *      {
         *          // If we found an item with the same underlying filename, return it
         *          if (string.Compare(nextDBLayer.SqLiteDbPathAndFilename, fullDBLogPathAndFilename, true) == 0)
         *          {
         *              result = nextDBLayer;
         *              break;
         *          }
         *      }
         *
         *      // If the desired layer doesn't exist in our list yet, create a new one and add it to the list
         *      if (result == null)
         *      {
         *          string dbConnectStr = string.Format("data source={0}", fullDBLogPathAndFilename);
         *          result = new SqLiteDAO(dbConnectStr, fullDBLogPathAndFilename);
         *          _SQLiteFiles.Add(result);
         *      }
         *  }
         *
         *  // Regardless of if we found an existing DB layer or created a new one, we will perform the DB Metadata check.
         *  // (This check will be very quick if it has already been validated, and will block until schema validation is finalized by any thread)
         *  // Note that this should be done outside of the "Lock" becasue we only want to lock out other threads when finding/modifying the
         *  // list of DB layers -- not when using them.
         *  // Before using the database, we need to be sure it has the correct Metadata/Schema information.
         *  // We will try to get exclusive access to a variable to see if whether or not the Metadata has been checked.
         *  // If we get exclusing access and DB Metadata hasn't been validated yet, we will do so now.
         *  if (!Monitor.TryEnter(result.MetadataHasBeenChecked_Lock))
         *  {
         *      // Somebody else already has this object locked. Let's immediately record this fact
         *      Logging.AddTextToGenericLog(Logging.LogLevel.Debug, "SqLite Metadata check is already locked by another thread. (" + _DefaultDbFilenameWithoutPath + ")",
         *          System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, System.Threading.Thread.CurrentThread.ManagedThreadId);
         *
         *      // Now we will do a normal Lock so we are blocked until the Metadata check is finished
         *      lock (result.MetadataHasBeenChecked_Lock)
         *      {
         *          Logging.AddTextToGenericLog(Logging.LogLevel.Debug, "Finished waiting for SqLite Metadata check to complete on different thread. (" + _DefaultDbFilenameWithoutPath + ")",
         *              System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, System.Threading.Thread.CurrentThread.ManagedThreadId);
         *      }
         *  }
         *  else
         *  {
         *      // The Monitor.TryEnter was successful, so we have a lock on the object. We will need to do Monitor.Exit when done
         *      try
         *      {
         *          if (result.MetadataHasBeenChecked == false)
         *          {
         *              Logging.AddTextToGenericLog(Logging.LogLevel.Debug, "Acquired exclusive access to verify SqLite Metadata. (" + _DefaultDbFilenameWithoutPath + ")",
         *                  System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, System.Threading.Thread.CurrentThread.ManagedThreadId);
         *
         *              SqLiteMetadataManager _DBMetadata = new SqLiteMetadataManager(false, LogMessage, result, _Metadata_OverstayVios.Tables);
         *              _DBMetadata.CheckAllTables(true);
         *              // Set flag so other threads know the Metadata check has already been performed
         *              result.MetadataHasBeenChecked = true;
         *
         *              // Update Metadata progress log in a thread-safe manner
         *              Logging.AddTextToGenericLog(Logging.LogLevel.Debug, "Finished SqLite Metadata verification. (" + _DefaultDbFilenameWithoutPath + ")",
         *                  System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, System.Threading.Thread.CurrentThread.ManagedThreadId);
         *          }
         *          else
         *          {
         *              Logging.AddTextToGenericLog(Logging.LogLevel.Debug, "No SqLite Metadata check needed -- it's already been performed. (" + _DefaultDbFilenameWithoutPath + ")",
         *                  System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, System.Threading.Thread.CurrentThread.ManagedThreadId);
         *          }
         *      }
         *      finally
         *      {
         *          // Set flag so other threads know the Metadata check has already been performed
         *          result.MetadataHasBeenChecked = true;
         *
         *          // Finally we will do the Monitor.Exit which does the unlocking
         *          Monitor.Exit(result.MetadataHasBeenChecked_Lock);
         *      }
         *  }
         *
         *  // Now we need to request DB transaction in the current DB access layer (This should never be done prior to the DB metadata being checked!)
         *  // Do a thread-safe increment of the counter to indicate transactions should stay active
         *  if (result != null)
         *  {
         *      lock (result.ClientCountWantingTransactionToStayOpen_Lock)
         *      {
         *          if (result.ClientCountWantingTransactionToStayOpen == 0)
         *          {
         *              result.ClientCountWantingTransactionToStayOpen++;
         *
         *              // Start a DB session so things are a bit faster in this bulk operation...
         *              // (The actual StartTransaction process will depend on how many "listeners" are wanting the transaction to stay active, and current state, etc.)
         *              result.StartTransactionSession();
         *          }
         *      }
         *  }
         *
         *  // Return our final result
         *  return result;
         * }
         */
        #endregion

        public void LogMessage(System.Diagnostics.TraceLevel logLevel, string textToLog, string classAndMethod, int threadID)
        {
            Logging.LogLevel convertedLogLevel = Logging.LogLevel.Debug;
            switch (logLevel)
            {
            case System.Diagnostics.TraceLevel.Error:
                convertedLogLevel = Logging.LogLevel.Error;
                break;

            case System.Diagnostics.TraceLevel.Info:
                convertedLogLevel = Logging.LogLevel.Info;
                break;

            case System.Diagnostics.TraceLevel.Verbose:
                convertedLogLevel = Logging.LogLevel.Debug;
                break;

            case System.Diagnostics.TraceLevel.Warning:
                convertedLogLevel = Logging.LogLevel.Warning;
                break;

            case System.Diagnostics.TraceLevel.Off:
                convertedLogLevel = Logging.LogLevel.DebugTraceOutput;
                break;

            default:
                convertedLogLevel = Logging.LogLevel.Debug;
                break;
            }

            Logging.AddTextToGenericLog(convertedLogLevel, textToLog, classAndMethod, threadID);
        }
コード例 #2
0
 static TraceLevel()
 {
     TraceLevel.Off     = System.Diagnostics.TraceLevel.Off;
     TraceLevel.Error   = System.Diagnostics.TraceLevel.Error;
     TraceLevel.Warning = System.Diagnostics.TraceLevel.Warning;
     TraceLevel.Info    = System.Diagnostics.TraceLevel.Info;
     TraceLevel.Verbose = System.Diagnostics.TraceLevel.Verbose;
 }
コード例 #3
0
ファイル: TraceLevel.cs プロジェクト: heber/FreeOQ
		static TraceLevel()
		{
			TraceLevel.Off = System.Diagnostics.TraceLevel.Off;
			TraceLevel.Error = System.Diagnostics.TraceLevel.Error;
			TraceLevel.Warning = System.Diagnostics.TraceLevel.Warning;
			TraceLevel.Info = System.Diagnostics.TraceLevel.Info;
			TraceLevel.Verbose = System.Diagnostics.TraceLevel.Verbose;
		}
コード例 #4
0
        public void Trace(TraceLevel level, string message, Exception ex)
        {
            var schemaValidationException = ex as SchemaValidationException;

            if (schemaValidationException != null)
            {
                SchemaValidationExceptions.Add(schemaValidationException);
            }
        }
コード例 #5
0
 public void OnMessage(long threadId,
                       TraceLevel level,
                       Datetime dateTime,
                       String
                       loggerName,
                       String message)
 {
     System.Console.WriteLine(dateTime + "  " + loggerName
                              + " [" + level.ToString() + "] Thread ID = "
                              + threadId + " " + message);
 }
コード例 #6
0
        public void Trace(System.Diagnostics.TraceLevel level, string message, Exception ex)
        {
            if (System.Diagnostics.TraceLevel.Off == level || null != pattern)
            {
                if (!message.Contains(pattern))   // Skip if not pattern
                {
                    return;
                }
            }

            UnityEngine.Debug.unityLogger.Log(logTypeFromTraceLevel[(int)level], message);
            if (null != ex)
            {
                UnityEngine.Debug.LogException(ex);
            }
        }
コード例 #7
0
        /// <summary>
        /// Appends a message with the right formatting to the feedbacka area.
        /// </summary>
        /// <param name="message">Message to emit.</param>
        /// <param name="style">Style for the message.</param>
        private void AppendMessageToFeedbackArea(string message, System.Diagnostics.TraceLevel style)
        {
            // Format the text we just added depending on the reporting level
            switch (style)
            {
            case System.Diagnostics.TraceLevel.Error:
                statusRichTextBox.SelectionColor = System.Drawing.Color.Red;
                break;

            default:
                break;
            }

            // Emit the text
            statusRichTextBox.SelectedText = message + "\n";
        }
コード例 #8
0
        public static void SendSetLivingTraceLevel(LivingObject living, System.Diagnostics.TraceLevel traceLevel)
        {
            var args = new Dictionary <string, object>()
            {
                { "livingID", living.ObjectID },
                { "traceLevel", traceLevel.ToString() },
            };

            var script =
                @"l = world.GetObject(livingID)
t = l.Trace
tl = t.TraceLevel.Parse(t.TraceLevel.GetType(), traceLevel)
t.TraceLevel = tl
";

            var msg = new Dwarrowdelf.Messages.IPScriptMessage(script, args);

            GameData.Data.User.Send(msg);
        }
コード例 #9
0
        internal static LogLevel ToLogLevel(System.Diagnostics.TraceLevel traceLevel)
        {
            switch (traceLevel)
            {
            case System.Diagnostics.TraceLevel.Verbose:
                return(LogLevel.Trace);

            case System.Diagnostics.TraceLevel.Info:
                return(LogLevel.Information);

            case System.Diagnostics.TraceLevel.Warning:
                return(LogLevel.Warning);

            case System.Diagnostics.TraceLevel.Error:
                return(LogLevel.Error);

            default:
                return(LogLevel.None);
            }
        }
コード例 #10
0
        private Logging.EventSeverity MapEventSeverity(System.Diagnostics.TraceLevel level)
        {
            switch (level)
            {
            case System.Diagnostics.TraceLevel.Error:
                return(Logging.EventSeverity.Error);

            case System.Diagnostics.TraceLevel.Verbose:
            case System.Diagnostics.TraceLevel.Info:
                return(Logging.EventSeverity.Status);

            case System.Diagnostics.TraceLevel.Off:
                return(Logging.EventSeverity.None);

            case System.Diagnostics.TraceLevel.Warning:
                return(Logging.EventSeverity.Warning);

            default:
                throw new NotImplementedException();
            }
        }
コード例 #11
0
        /// <summary>
        /// Appends the specified string and relevant new line characters to the log file
        /// </summary>
        /// <param name="strText">The text to append</param>
        /// <param name="traceLevel">if its info, prevents it coming out on the console for automation</param>
        public static void AppendToLogFile(string strText, System.Diagnostics.TraceLevel traceLevel = System.Diagnostics.TraceLevel.Info)
        {
            try
            {
                if (_outputToConsole)
                {
                    if (traceLevel <= System.Diagnostics.TraceLevel.Info)
                    {
                        lock (logLock)
                        {
                            Console.WriteLine(strText);
                        }
                    }
                }

                if (System.IO.File.Exists(System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("TEMP"), _verboseRequired)) == true)
                {
                    string strlogfile = System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("TEMP"), _verboseLog);
                    using (System.IO.StreamWriter sw = System.IO.File.AppendText(strlogfile))
                    {
                        lock (logLock)
                        {
                            sw.WriteLine(System.DateTime.Now.ToString() + ": " + strText);
                        }
                        sw.Close();
                    }
                }
            }
            catch (System.Exception)
            {
                /* If we couldn't write to the log file then don't fret - it's not the end of the world...*/

                /* But we should be able to log it to the system event log so we dont lose reference of it*/
                Logger.Warning("{0}", new object[] { strText });
            }
        }
コード例 #12
0
        private void registerCallback(int verbosityCount)
        {
            TraceLevel level = TraceLevel.Off;

            switch (verbosityCount)
            {
            case 1:
            {
                level = TraceLevel.Warning;
            } break;

            case 2:
            {
                level = TraceLevel.Info;
            } break;

            default:
            {
                level = TraceLevel.Verbose;
            } break;
            }
            ;
            Logging.RegisterCallback(new LoggingCallback(), level);
        }
コード例 #13
0
 public MapLog(string Message, System.Diagnostics.TraceLevel Severity) : this(Message, Severity, DateTime.Now)
 {
 }
コード例 #14
0
 /// <summary>
 /// Initialize data collector. Null is returned if collector is already registered.
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public GXAmiDataCollector Init(string name)
 {            
     GXAmiDataCollector dc = null;
     if (DC.DataCollectorGuid == Guid.Empty)
     {
         dc = DC.RegisterDataCollector();
         dc.Name = name;
         dc.Medias = Gurux.Communication.GXClient.GetAvailableMedias();
         if (m_AvailableSerialPorts != null)
         {
             GXSerialPortInfo e = new GXSerialPortInfo();
             m_AvailableSerialPorts(this, e);
             dc.SerialPorts = e.SerialPorts;
         }
         TraceLevel = dc.TraceLevel;
         DC.Update(dc);
     }
     else
     {                
         dc = DC.GetDataCollectorByGuid(DC.DataCollectorGuid);
         string[] old = dc.Medias;
         dc.Medias = Gurux.Communication.GXClient.GetAvailableMedias();
         bool changed = old != dc.Medias;
         if (m_AvailableSerialPorts != null)
         {
             GXSerialPortInfo e = new GXSerialPortInfo();
             m_AvailableSerialPorts(this, e);
             old = dc.SerialPorts;
             dc.SerialPorts = e.SerialPorts;
             changed |= old != dc.SerialPorts;                    
         }
         TraceLevel = DC.GetTraceLevel(DC);
         //If medias or serial ports are changed.
         if (changed)
         {
             DC.Update(dc);
         }
     }
     DC.OnTasksClaimed += new TasksClaimedEventHandler(DC_OnTasksClaimed);
     DC.OnTasksAdded += new TasksAddedEventHandler(DC_OnTasksAdded);
     DC.OnTasksRemoved += new TasksRemovedEventHandler(DC_OnTasksRemoved);
     DC.OnDevicesUpdated += new DevicesUpdatedEventHandler(DC_OnDevicesUpdated);
     DC.OnDevicesRemoved += new DevicesRemovedEventHandler(DC_OnDevicesRemoved);
     DC.OnDataCollectorsUpdated += new DataCollectorsUpdatedEventHandler(DC_OnDataCollectorsUpdated);
     DC.StartListenEvents();
     //Start Data Collector thread.
     Thread = new Thread(new ThreadStart(Run));
     Thread.IsBackground = true;
     Thread.Start();
     return dc;
 }
コード例 #15
0
 /// <summary>
 /// Initializes a new instance of the ImportDlg class.
 /// </summary>
 /// <param name="gxAddIn">The currently used protocol addin.</param>
 /// <param name="gxDevice">The target device.</param>
 public GXImportDlg(System.Diagnostics.TraceLevel traceLevel, GXProtocolAddIn addIn, GXDevice device, bool fromDataCollector)
 {
     try
     {
         InitializeComponent();
         Bitmap bm = Gurux.DeviceSuite.Properties.Resources.leaf;
         bm.MakeTransparent();
         panel1.BackgroundImage = bm;
         TraceLevel = traceLevel;
         GXCommon.Owner = this;
         Start = new GXImportStartForm(addIn);
         Trace = new GXImportSearchForm();
         Import = new GXImportPropertiesForm();
         MediaSettings = new GXImportMediaForm(fromDataCollector);
         m_GXAddIn = addIn;
         m_GXDevice = device;
         UpdateResources();
         //default settings								
         m_ProtocolCustomPages.Add(Start);
         m_ProtocolCustomPages.Add(MediaSettings);
         m_ProtocolCustomPages.Add(Trace);
         m_ProtocolCustomPages.Add(Import);
         addIn.ModifyWizardPages(device, GXPropertyPageType.Import, m_ProtocolCustomPages);
         m_GXAddIn.OnProgress += new Gurux.Device.Editor.GXProtocolAddIn.ProgressEventHandler(OnProgress);
         m_GXAddIn.OnTrace += new Gurux.Device.Editor.GXProtocolAddIn.TraceEventHandler(OnTraceEvent);
         ChangePage(0);               
     }
     catch (Exception Ex)
     {
         GXCommon.ShowError(this, Ex);
         this.DialogResult = DialogResult.None;
     }
 }
コード例 #16
0
 public MapLog(string Message, System.Diagnostics.TraceLevel Severity, DateTime When)
 {
     this.Message  = Message;
     this.Severity = Severity;
     this.When     = When;
 }
コード例 #17
0
ファイル: CliParserUnitTest.cs プロジェクト: nemec/clipr
 private TraceLevelOption(System.Diagnostics.TraceLevel value)
 {
     this.value = value;
 }
コード例 #18
0
 void DC_OnDataCollectorsUpdated(object sender, GXAmiDataCollector[] collectors)
 {
     foreach (GXAmiDataCollector it in collectors)
     {
         if (it.Guid == this.DC.DataCollectorGuid)
         {
             TraceLevel = it.TraceLevel;
             break;
         }
     }
 }
コード例 #19
0
 public void SetLog(TextWriter output, System.Diagnostics.TraceLevel consoleLevel)
 {
     Log.Open(output);
     Log.ConsoleLevel = consoleLevel;
 }
コード例 #20
0
 internal void Trace(System.Net.Http.HttpRequestMessage Request, string p1, System.Diagnostics.TraceLevel traceLevel, string p2, string p3)
 {
     throw new NotImplementedException();
 }
コード例 #21
0
ファイル: CliParserUnitTest.cs プロジェクト: mikecrews/clipr
 private TraceLevelOption(System.Diagnostics.TraceLevel value)
 {
     this.value = value;
 }