Exemple #1
0
        public bool Match(ThreadNodeViewModel thread)
        {
            if ( EnvironmentNames != null && EnvironmentNames.Length > 0 && !EnvironmentNames.Contains(thread.Environment, StringComparer.OrdinalIgnoreCase) )
            {
                return false;
            }

            if ( NodeNames != null && NodeNames.Length > 0 && !NodeNames.Contains(thread.Node, StringComparer.OrdinalIgnoreCase) )
            {
                return false;
            }

            if ( ThreadTypes != null && ThreadTypes.Length > 0 && !ThreadTypes.Contains(thread.ThreadType) )
            {
                return false;
            }

            if ( LogLevels != null && LogLevels.Length > 0 && !LogLevels.Contains(thread.Level) )
            {
                return false;
            }

            return true;
        }
        //-----------------------------------------------------------------------------------------------------------------------------------------------------
        public bool TryGetLogById(Guid id, out ThreadNodeViewModel log)
        {
            var filePath = Path.Combine(_folderPath, id.ToString("N") + ".threadlog");

            if ( File.Exists(filePath) )
            {
                log = LoadFileContents(filePath, captureId: -1);
                return true;
            }
            else
            {
                log = null;
                return false;
            }
        }
        //-----------------------------------------------------------------------------------------------------------------------------------------------------
        private static ThreadNodeViewModel LoadFileContents(string filePath, long captureId)
        {
            var retryCountDown = 5;

            while ( true )
            {
                try
                {
                    using ( var file = File.OpenRead(filePath) )
                    {
                        var serializer = new DataContractSerializer(typeof(ThreadLogSnapshot));
                        var snapshot = (ThreadLogSnapshot)serializer.ReadObject(file);
                        var contents = new ThreadNodeViewModel();
                        contents.PopulateFrom(snapshot);
                        contents.CaptureId = captureId;
                        return contents;
                    }
                }
                catch ( IOException )
                {
                    if ( --retryCountDown > 0 )
                    {
                        Thread.Sleep(250);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }