Skip to content

Commit

Permalink
clean project registry before create new project (microsoft#2716)
Browse files Browse the repository at this point in the history
  • Loading branch information
boydc2014 committed Apr 21, 2020
1 parent dd7f39f commit 212e4f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions Composer/packages/server/src/controllers/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ async function createProject(req: Request, res: Response) {
log('Attempting to create project at %s', path);

try {
await BotProjectService.cleanProject(locationRef);
const newProjRef = await AssectService.manager.copyProjectTemplateTo(templateId, locationRef, user);
const id = await BotProjectService.openProject(newProjRef, user);
const currentProject = await BotProjectService.getProjectById(id, user);
Expand Down
10 changes: 10 additions & 0 deletions Composer/packages/server/src/services/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ export class BotProjectService {
return projectId.toString();
};

// clean project registry based on path to avoid reuseing the same id
public static cleanProject = async (location: LocationRef): Promise<void> => {
for (const key in BotProjectService.projectLocationMap) {
if (BotProjectService.projectLocationMap[key] === location.path) {
delete BotProjectService.projectLocationMap[key];
}
}
Store.set('projectLocationMap', BotProjectService.projectLocationMap);
};

public static generateProjectId = async (path: string): Promise<string> => {
const projectId = (Math.random() * 100000).toString();
BotProjectService.projectLocationMap[projectId] = path;
Expand Down

0 comments on commit 212e4f6

Please sign in to comment.