Skip to content

Commit

Permalink
change the file accessing method in MiningRuleProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
yaad96 committed Mar 3, 2024
1 parent 4564e1e commit 13e8ff3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/FileChangeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class FileChangeManager {
if (error) {
console.error(`Error sending XML for file ${javaFilePath}:`, error);
}
else { console.log(`Successfully sent XML for file ${javaFilePath}`); }
//else { console.log(`Successfully sent XML for file ${javaFilePath}`); }
});

const check_rule_messaage = JSON.stringify({
Expand All @@ -144,7 +144,7 @@ export class FileChangeManager {
if (error) {
console.error(`Error sending check_rule_message for file ${javaFilePath}:`, error);
}
else { console.log(`Successfully sent check_rule_message for file ${javaFilePath}`); }
//else { console.log(`Successfully sent check_rule_message for file ${javaFilePath}`); }
});

// sendMessage(MessageProcessor.encodeData(new Object[]{WebSocketConstants.SEND_CHECK_RULES_FOR_FILE_MSG,
Expand Down
14 changes: 7 additions & 7 deletions src/MiningRulesProcessor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import WebSocket from 'ws';
import * as fs from 'fs/promises'; // Use fs/promises for readFile
import * as fs from 'fs'; // Use fs/promises for readFile
import * as path from 'path';
import { WebSocketConstants } from './WebSocketConstants';
//import { MessageProcessor } from './MessageProcessor';
Expand Down Expand Up @@ -61,21 +61,21 @@ export class MiningRulesProcessor {
//const directoryName = path.join(this.projectPath, this.directory);
const filePath = path.join(this.learningDRPath, fileName);

console.log(filePath);
console.log("File Path: ",filePath);

try {
// Ensure the directory exists, if not, creates a one
await fs.mkdir(this.learningDRPath, { recursive: true });
fs.mkdirSync(this.learningDRPath, { recursive: true });

// Decide to append or overwrite based on file existence
try {
await fs.access(filePath); // Check if file exists
fs.accessSync(filePath); // Check if file exists
// If no error, file exists. Append to the file.
await fs.appendFile(filePath, content, { encoding: 'utf8' });
fs.appendFileSync(filePath, content, { encoding: 'utf8' });
console.log(`Data successfully appended to ${fileName}`);
} catch {
// If error, file does not exist. Overwrite/create the file.
await fs.writeFile(filePath, content, { encoding: 'utf8' });
fs.writeFileSync(filePath, content, { encoding: 'utf8' });
console.log(`Data successfully written to ${fileName}`);
}
} catch (err) {
Expand All @@ -92,7 +92,7 @@ export class MiningRulesProcessor {
//delete the content of the directory, the directory = drlearning in the root directory
case WebSocketConstants.RECEIVE_REFRESH_LEARN_DESIGN_RULES_DIRECTORY_MSG:
try {
await fs.rm(this.learningDRPath, { recursive: true, force: true });
fs.rmSync(this.learningDRPath, { recursive: true, force: true });
console.log(`${this.learningDRPath} was successfully deleted.`);
} catch (err) {
console.error(`Failed to delete ${this.learningDRPath}:`, err);
Expand Down
10 changes: 5 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { DoiProcessing } from './DoiProcessing';

//const readFileAsync = promisify(fs.readFile);

const port = 9000;
const port = 8887;



Expand Down Expand Up @@ -175,17 +175,17 @@ export function activate(context: vscode.ExtensionContext) {
})().catch(error => console.error('Error in WebSocket connection handler:', error));

ws.on('message', (message: string) => {
console.log(`Received message: ${message}`);
//console.log(`Received message: ${message}`);
const faw = FollowAndAuthorRulesProcessor.getInstance();
const mr = MiningRulesProcessor.getInstance();
try {
const json = JSON.parse(message.toString());
console.log("Command:", json.command);
console.log("Data:", json.data);
//console.log("Command:", json.command);
//console.log("Data:", json.data);


if (faw.wsMessages.includes(json.command)) {
console.log('Received a recognized command:', json.command);
//console.log('Received a recognized command:', json.command);
faw.processReceivedMessages(message);
// Handle the command as needed
}
Expand Down

0 comments on commit 13e8ff3

Please sign in to comment.