示例#1
0
                internal static DiagnosticState GetOrCreateDiagnosticState(DiagnosticState[,] diagnosticStateMaps, StateType stateType, int providerIndex, ProviderId providerId, DiagnosticAnalyzer provider, string language)
                {
                    Contract.ThrowIfFalse(providerIndex >= 0);
                    Contract.ThrowIfFalse(providerIndex < diagnosticStateMaps.GetLength(1));

                    if (diagnosticStateMaps[(int)stateType, providerIndex] == null)
                    {
                        var nameAndVersion = GetUniqueDiagnosticStateNameAndVersion(stateType, providerId, provider);

                        var name    = nameAndVersion.Item1;
                        var version = nameAndVersion.Item2;
                        diagnosticStateMaps[(int)stateType, providerIndex] = new DiagnosticState(name, version, language);

#if DEBUG
                        // Ensure diagnostic state name is indeed unique.
                        foreach (var type in DocumentScopeStateTypes)
                        {
                            for (var pId = 0; pId < diagnosticStateMaps.GetLength(1); pId++)
                            {
                                if (diagnosticStateMaps[(int)type, pId] != null)
                                {
                                    Contract.ThrowIfFalse(name != diagnosticStateMaps[(int)type, pId].Name ||
                                                          (stateType == type &&
                                                           (pId == providerIndex || language != diagnosticStateMaps[(int)type, pId].Language)));
                                }
                            }
                        }
#endif
                    }

                    return(diagnosticStateMaps[(int)stateType, providerIndex]);
                }
示例#2
0
 public static void ChangeGameToMakingPotions()
 {
     diagnosticState = DiagnosticState.MakingPotion;
     PrognosticPanelController.Show();
     DiagnosticPanelController.Hide();
     OptionsToolController.Hide();
 }
        public override void Dispose()
        {
            DataAccess.Dispose(true);
            Config.Dispose();
            DiagnosticState.Dispose();

            base.Dispose();
        }
示例#4
0
        private void ClearProjectState(Project project, DiagnosticAnalyzer analyzer, DiagnosticState state)
        {
            // remove saved cache
            state.Remove(project.Id);

            // raise diagnostic updated event
            var solutionArgs = new SolutionArgument(project);

            RaiseDiagnosticsUpdated(StateType.Project, project.Id, analyzer, solutionArgs, ImmutableArray <DiagnosticData> .Empty);
        }
            private async Task AppendProjectAndDocumentDiagnosticsAsync(DiagnosticState state, object documentOrProject, Func <DiagnosticData, bool> predicate, CancellationToken cancellationToken)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var existingData = await state.TryGetExistingDataAsync(documentOrProject, cancellationToken).ConfigureAwait(false);

                if (existingData == null || existingData.Items.Length == 0)
                {
                    return;
                }

                AppendDiagnostics(existingData.Items.Where(predicate));
            }
        /// <summary>
        /// Disposes the mock diagnostic system.
        /// </summary>
        public virtual void DisposeMockDiagnostics()
        {
            if (EnableTestLogging)
            {
                FixtureLogGroup.Dispose();
                FixtureLogGroup = null;

                DisposeLogging();
            }

            DiagnosticState.Dispose();


            ReportLogs();
        }
示例#7
0
 /// <summary>
 /// Initiate diagnostic operation
 /// </summary>
 /// <param name="SessionState">Operational state to enter</param>
 /// <returns></returns>
 public ServiceResult Mode10(DiagnosticState SessionState)
 {
     try
     {
         return(serviceTransaction((byte)J2190Mode.INITIATE_DIAG_OP, 1, new byte[] { (byte)SessionState }));
     }
     catch
     {
         if (SessionState == DiagnosticState.IVFER)
         {
             return(null);
         }
         throw;
     }
 }
            private static DiagnosticState[] CreateDiagnosticStates(string language, DiagnosticAnalyzer analyzer)
            {
                var states = new DiagnosticState[s_stateTypeCount];

                for (int stateType = 0; stateType < s_stateTypeCount; stateType++)
                {
                    var nameAndVersion = GetNameAndVersion(analyzer, (StateType)stateType);

                    var name = nameAndVersion.Item1;
                    var version = nameAndVersion.Item2;

                    states[stateType] = new DiagnosticState(name, version, language);
                }

                return states;
            }
            private static DiagnosticState[] CreateDiagnosticStates(string language, DiagnosticAnalyzer analyzer)
            {
                var states = new DiagnosticState[s_stateTypeCount];

                for (int stateType = 0; stateType < s_stateTypeCount; stateType++)
                {
                    var nameAndVersion = GetNameAndVersion(analyzer, (StateType)stateType);

                    var name    = nameAndVersion.Item1;
                    var version = nameAndVersion.Item2;

                    states[stateType] = new DiagnosticState(name, version, language);
                }

                return(states);
            }
示例#10
0
        private async Task RemoveCacheDataAsync(Project project, DiagnosticState state, ProviderId providerId, CancellationToken cancellationToken)
        {
            try
            {
                // remove memory cache
                state.Remove(project.Id);

                // remove persistent cache
                await state.PersistAsync(project, AnalysisData.Empty, cancellationToken).ConfigureAwait(false);

                // raise diagnostic updated event
                var solutionArgs = new SolutionArgument(project);
                RaiseDiagnosticsUpdated(StateType.Project, project.Id, providerId, solutionArgs, ImmutableArray <DiagnosticData> .Empty);
            }
            catch (Exception e) when(FatalError.ReportUnlessCanceled(e))
            {
                throw ExceptionUtilities.Unreachable;
            }
        }
示例#11
0
        private static async Task PersistProjectData(Project project, DiagnosticState state, AnalysisData data)
        {
            // TODO: Cancellation is not allowed here to prevent data inconsistency. But there is still a possibility of data inconsistency due to
            //       things like exception. For now, I am letting it go and let v2 engine take care of it properly. If v2 doesnt come online soon enough
            //       more refactoring is required on project state.

            // clear all existing data
            state.Remove(project.Id);
            foreach (var document in project.Documents)
            {
                state.Remove(document.Id);
            }

            // quick bail out
            if (data.Items.Length == 0)
            {
                return;
            }

            // save new data
            var group = data.Items.GroupBy(d => d.DocumentId);

            foreach (var kv in group)
            {
                if (kv.Key == null)
                {
                    // save project scope diagnostics
                    await state.PersistAsync(project, new AnalysisData(data.TextVersion, data.DataVersion, kv.ToImmutableArrayOrEmpty()), CancellationToken.None).ConfigureAwait(false);

                    continue;
                }

                // save document scope diagnostics
                var document = project.GetDocument(kv.Key);
                if (document == null)
                {
                    continue;
                }

                await state.PersistAsync(document, new AnalysisData(data.TextVersion, data.DataVersion, kv.ToImmutableArrayOrEmpty()), CancellationToken.None).ConfigureAwait(false);
            }
        }
示例#12
0
        private async Task RemoveCacheDataAsync(Document document, DiagnosticState state, ProviderId providerId, StateType type, CancellationToken cancellationToken)
        {
            try
            {
                // remove memory cache
                state.Remove(document.Id);

                // remove persistent cache
                await state.PersistAsync(document, AnalysisData.Empty, cancellationToken).ConfigureAwait(false);

                // raise diagnostic updated event
                var documentId   = type == StateType.Project ? null : document.Id;
                var projectId    = document.Project.Id;
                var key          = documentId ?? (object)projectId;
                var solutionArgs = new SolutionArgument(document.Project.Solution, projectId, documentId);

                RaiseDiagnosticsUpdated(type, key, providerId, solutionArgs, ImmutableArray <DiagnosticData> .Empty);
            }
            catch (Exception e) when(FatalError.ReportUnlessCanceled(e))
            {
                throw ExceptionUtilities.Unreachable;
            }
        }
                internal static DiagnosticState GetOrCreateDiagnosticState(DiagnosticState[,] diagnosticStateMaps, StateType stateType, int providerIndex, ProviderId providerId, DiagnosticAnalyzer provider, string language)
                {
                    Contract.ThrowIfFalse(providerIndex >= 0);
                    Contract.ThrowIfFalse(providerIndex < diagnosticStateMaps.GetLength(1));

                    if (diagnosticStateMaps[(int)stateType, providerIndex] == null)
                    {
                        var nameAndVersion = GetUniqueDiagnosticStateNameAndVersion(stateType, providerId, provider);

                        var name = nameAndVersion.Item1;
                        var version = nameAndVersion.Item2;
                        diagnosticStateMaps[(int)stateType, providerIndex] = new DiagnosticState(name, version, language);

#if DEBUG
                        // Ensure diagnostic state name is indeed unique.
                        foreach (var type in s_documentScopeStateTypes)
                        {
                            for (var pId = 0; pId < diagnosticStateMaps.GetLength(1); pId++)
                            {
                                if (diagnosticStateMaps[(int)type, pId] != null)
                                {
                                    Contract.ThrowIfFalse(name != diagnosticStateMaps[(int)type, pId].Name ||
                                        (stateType == type &&
                                         (pId == providerIndex || language != diagnosticStateMaps[(int)type, pId].Language)));
                                }
                            }
                        }
#endif
                    }

                    return diagnosticStateMaps[(int)stateType, providerIndex];
                }
示例#14
0
        private void ClearDocumentState(Document document, DiagnosticAnalyzer analyzer, StateType type, DiagnosticState state, bool raiseEvent)
        {
            // remove saved info
            state.Remove(document.Id);

            if (raiseEvent)
            {
                // raise diagnostic updated event
                var documentId   = document.Id;
                var solutionArgs = new SolutionArgument(document);

                RaiseDiagnosticsUpdated(type, document.Id, analyzer, solutionArgs, ImmutableArray <DiagnosticData> .Empty);
            }
        }
示例#15
0
 public void Test_PopGroup_Empty()
 {
     DiagnosticState.PopGroup();
     // If no error occurred then it succeeded
 }
        private static async Task PersistProjectData(Project project, DiagnosticState state, AnalysisData data)
        {
            // TODO: Cancellation is not allowed here to prevent data inconsistency. But there is still a possibility of data inconsistency due to
            //       things like exception. For now, I am letting it go and let v2 engine take care of it properly. If v2 doesnt come online soon enough
            //       more refactoring is required on project state.

            // clear all existing data
            state.Remove(project.Id);
            foreach (var document in project.Documents)
            {
                state.Remove(document.Id);
            }

            // quick bail out
            if (data.Items.Length == 0)
            {
                return;
            }

            // save new data
            var group = data.Items.GroupBy(d => d.DocumentId);
            foreach (var kv in group)
            {
                if (kv.Key == null)
                {
                    // save project scope diagnostics
                    await state.PersistAsync(project, new AnalysisData(data.TextVersion, data.DataVersion, kv.ToImmutableArrayOrEmpty()), CancellationToken.None).ConfigureAwait(false);
                    continue;
                }

                // save document scope diagnostics
                var document = project.GetDocument(kv.Key);
                if (document == null)
                {
                    continue;
                }

                await state.PersistAsync(document, new AnalysisData(data.TextVersion, data.DataVersion, kv.ToImmutableArrayOrEmpty()), CancellationToken.None).ConfigureAwait(false);
            }
        }
            private async Task RemoveCacheDataAsync(Project project, DiagnosticState state, ProviderId providerId, CancellationToken cancellationToken)
            {
                try
                {
                    // remove memory cache
                    state.Remove(project.Id);

                    // remove persistent cache
                    await state.PersistAsync(project, AnalysisData.Empty, cancellationToken).ConfigureAwait(false);

                    // raise diagnostic updated event
                    var solutionArgs = new SolutionArgument(project);
                    RaiseDiagnosticsUpdated(StateType.Project, project.Id, providerId, solutionArgs, ImmutableArray<DiagnosticData>.Empty);
                }
                catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
                {
                    throw ExceptionUtilities.Unreachable;
                }
            }
            private async Task RemoveCacheDataAsync(Document document, DiagnosticState state, ProviderId providerId, StateType type, CancellationToken cancellationToken)
            {
                try
                {
                    // remove memory cache
                    state.Remove(document.Id);

                    // remove persistent cache
                    await state.PersistAsync(document, AnalysisData.Empty, cancellationToken).ConfigureAwait(false);

                    // raise diagnostic updated event
                    var documentId = type == StateType.Project ? null : document.Id;
                    var projectId = document.Project.Id;
                    var key = documentId ?? (object)projectId;
                    var solutionArgs = new SolutionArgument(document.Project.Solution, projectId, documentId);

                    RaiseDiagnosticsUpdated(type, key, providerId, solutionArgs, ImmutableArray<DiagnosticData>.Empty);
                }
                catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
                {
                    throw ExceptionUtilities.Unreachable;
                }
            }
示例#19
0
 private static void SetStatusToShowingDialog()
 {
     diagnosticState = DiagnosticState.MakingDiagnostic;
 }
            private async Task <AnalysisData> GetExistingProjectAnalysisDataAsync(Project project, DiagnosticState state, CancellationToken cancellationToken)
            {
                // quick bail out
                if (state.Count == 0)
                {
                    return(null);
                }

                var textVersion  = VersionStamp.Default;
                var dataVersion  = VersionStamp.Default;
                var existingData = await state.TryGetExistingDataAsync(project, cancellationToken).ConfigureAwait(false);

                var builder = ImmutableArray.CreateBuilder <DiagnosticData>();

                if (existingData != null)
                {
                    textVersion = existingData.TextVersion;
                    dataVersion = existingData.DataVersion;

                    builder.AddRange(existingData.Items);
                }

                foreach (var document in project.Documents)
                {
                    existingData = await state.TryGetExistingDataAsync(document, cancellationToken).ConfigureAwait(false);

                    if (existingData == null)
                    {
                        continue;
                    }

                    if (dataVersion != VersionStamp.Default && dataVersion != existingData.DataVersion)
                    {
                        continue;
                    }

                    textVersion = existingData.TextVersion;
                    dataVersion = existingData.DataVersion;

                    builder.AddRange(existingData.Items);
                }

                if (dataVersion == VersionStamp.Default)
                {
                    Contract.Requires(textVersion == VersionStamp.Default);
                    return(null);
                }

                return(new AnalysisData(textVersion, dataVersion, builder.ToImmutable()));
            }
示例#21
0
 private void SetStateToPlaying()
 {
     diagnosticState = DiagnosticState.MakingDiagnostic;
 }
            private async Task<AnalysisData> GetExistingProjectAnalysisDataAsync(Project project, DiagnosticState state, CancellationToken cancellationToken)
            {
                // quick bail out
                if (state.Count == 0)
                {
                    return null;
                }

                var textVersion = VersionStamp.Default;
                var dataVersion = VersionStamp.Default;
                var existingData = await state.TryGetExistingDataAsync(project, cancellationToken).ConfigureAwait(false);

                var builder = ImmutableArray.CreateBuilder<DiagnosticData>();
                if (existingData != null)
                {
                    textVersion = existingData.TextVersion;
                    dataVersion = existingData.DataVersion;

                    builder.AddRange(existingData.Items);
                }

                foreach (var document in project.Documents)
                {
                    existingData = await state.TryGetExistingDataAsync(document, cancellationToken).ConfigureAwait(false);
                    if (existingData == null)
                    {
                        continue;
                    }

                    if (dataVersion != VersionStamp.Default && dataVersion != existingData.DataVersion)
                    {
                        continue;
                    }

                    textVersion = existingData.TextVersion;
                    dataVersion = existingData.DataVersion;

                    builder.AddRange(existingData.Items);
                }

                if (dataVersion == VersionStamp.Default)
                {
                    Contract.Requires(textVersion == VersionStamp.Default);
                    return null;
                }

                return new AnalysisData(textVersion, dataVersion, builder.ToImmutable());
            }
示例#23
0
 public static void ChangeGameToDiagnostic()
 {
     diagnosticState = DiagnosticState.MakingDiagnostic;
     DiagnosticPanelController.Show();
     PrognosticPanelController.Hide();
 }
            private async Task AppendProjectAndDocumentDiagnosticsAsync(DiagnosticState state, object documentOrProject, Func<DiagnosticData, bool> predicate, CancellationToken cancellationToken)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var existingData = await state.TryGetExistingDataAsync(documentOrProject, cancellationToken).ConfigureAwait(false);
                if (existingData == null || existingData.Items.Length == 0)
                {
                    return;
                }

                AppendDiagnostics(existingData.Items.Where(predicate));
            }
示例#25
0
 private void Awake()
 {
     singleton       = this;
     diagnosticState = DiagnosticState.MakingPotion;
 }