Пример #1
0
        private async void OnMetaFileChanged(object sender, FileSystemEventArgs e)
        {
            if (IsDisposed)
            {
                return;
            }

            using (await connectionSem.UseAsync())
            {
                if (IsDisposed)
                {
                    return;
                }

                if (!File.Exists(MetaFilePath))
                {
                    return;
                }

                var metadata = ReadMetadataFile();

                if (metadata != null && metadata != godotIdeMetadata)
                {
                    godotIdeMetadata = metadata.Value;
                    _ = Task.Run(ConnectToServer);
                }
            }
        }
Пример #2
0
        private async void OnMetaFileDeleted(object sender, FileSystemEventArgs e)
        {
            if (IsDisposed)
            {
                return;
            }

            if (IsConnected)
            {
                using (await connectionSem.UseAsync())
                    peer?.Dispose();
            }

            // The file may have been re-created

            using (await connectionSem.UseAsync())
            {
                if (IsDisposed)
                {
                    return;
                }

                if (IsConnected || !File.Exists(MetaFilePath))
                {
                    return;
                }

                var lastWriteTime = File.GetLastWriteTime(MetaFilePath);

                if (lastWriteTime == metaFileModifiedTime)
                {
                    return;
                }

                metaFileModifiedTime = lastWriteTime;

                var metadata = ReadMetadataFile();

                if (metadata != null)
                {
                    godotIdeMetadata = metadata.Value;
                    _ = Task.Run(ConnectToServer);
                }
            }
        }
Пример #3
0
        // ReSharper disable once UnusedMember.Global
        public async void Start()
        {
            fsWatcher.Created            += OnMetaFileChanged;
            fsWatcher.Changed            += OnMetaFileChanged;
            fsWatcher.Deleted            += OnMetaFileDeleted;
            fsWatcher.EnableRaisingEvents = true;

            using (await connectionSem.UseAsync())
            {
                if (IsDisposed)
                {
                    return;
                }

                if (IsConnected)
                {
                    return;
                }

                if (!File.Exists(MetaFilePath))
                {
                    logger.LogInfo("There is no Godot Ide Server running");
                    return;
                }

                var metadata = ReadMetadataFile();

                if (metadata != null)
                {
                    godotIdeMetadata = metadata.Value;
                    _ = Task.Run(ConnectToServer);
                }
                else
                {
                    logger.LogError("Failed to read Godot Ide metadata file");
                }
            }
        }