public bool TryDeserialize(out FullProjectSnapshotHandle handle)
        {
            if (Kind == RazorFileChangeKind.Removed)
            {
                // There's no file to represent the snapshot handle.
                handle = null;
                return(false);
            }

            lock (_projectSnapshotHandleLock)
            {
                if (!_deserialized)
                {
                    // We use a deserialized flag instead of checking if _projectSnapshotHandle is null because if we're reading an old snapshot
                    // handle that doesn't deserialize properly it could be expected that it would be null.
                    _deserialized          = true;
                    _projectSnapshotHandle = _jsonFileDeserializer.Deserialize <FullProjectSnapshotHandle>(ConfigurationFilePath);
                }
            }

            handle = _projectSnapshotHandle;
            if (handle == null)
            {
                // Deserialization failed
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        public bool TryDeserialize([NotNullWhen(true)] out ProjectRazorJson?projectRazorJson)
        {
            if (Kind == RazorFileChangeKind.Removed)
            {
                // There's no file to represent the snapshot handle.
                projectRazorJson = null;
                return(false);
            }

            lock (_projectSnapshotHandleLock)
            {
                if (!_deserialized)
                {
                    // We use a deserialized flag instead of checking if _projectSnapshotHandle is null because if we're reading an old snapshot
                    // handle that doesn't deserialize properly it could be expected that it would be null.
                    _deserialized = true;
                    var deserializedProjectRazorJson = _jsonFileDeserializer.Deserialize <ProjectRazorJson>(ConfigurationFilePath);
                    if (deserializedProjectRazorJson is null)
                    {
                        projectRazorJson = null;
                        return(false);
                    }

                    var normalizedSerializedFilePath = FilePathNormalizer.Instance.Normalize(deserializedProjectRazorJson.SerializedFilePath);
                    var normalizedDetectedFilePath   = FilePathNormalizer.Instance.Normalize(ConfigurationFilePath);
                    if (string.Equals(normalizedSerializedFilePath, normalizedDetectedFilePath, FilePathComparison.Instance))
                    {
                        _projectRazorJson = deserializedProjectRazorJson;
                    }
                    else
                    {
                        // Stale project configuration file, most likely a user copy & pasted the project configuration file and it hasn't
                        // been re-computed yet. Fail deserialization.
                        projectRazorJson = null;
                        return(false);
                    }
                }
            }

            projectRazorJson = _projectRazorJson;
            if (projectRazorJson is null)
            {
                // Deserialization failed
                return(false);
            }

            return(true);
        }