public SyncService(IMirrorStore mirrorStore) { this.mirrorStore = mirrorStore; this.pool = new ConcurrentDictionary <string, ISynchronizationProcess>(); }
public QueryRepository(IWebApiConfiguration webApiConfiguration, IMirrorStore mirrorStore, string collectionName) : base(webApiConfiguration, collectionName) { this.mirrorStore = mirrorStore; }
public SyncStore(IWebApiConfiguration webApiConfiguration, IMirrorStore mirrorStore) { this.query = new QueryRepository(webApiConfiguration, mirrorStore, webApiConfiguration.MongoSyncCollection); this.command = new CommandRepository(webApiConfiguration, mirrorStore, webApiConfiguration.MongoSyncCollection); }
public EventHandler(ISvcRepositoryStore repositoryStore, IMirrorStore mirrorStore, ISyncStore syncStore) { this.repositoryStore = repositoryStore; this.mirrorStore = mirrorStore; this.syncStore = syncStore; }
public MirrorModule(IAuthenticationProvider authenticationProvider, IMirrorStore mirrorStore, ISyncStore syncStore, IReflectionStore reflectionStore) : base(authenticationProvider, "/mirror") { this.Get["/"] = parameters => { try { var userId = this.CurrentUser.Id; var response = mirrorStore.GetAll(); if (response == null) { return(HttpStatusCode.NotFound); } return(this.Response.AsJson(response)); } catch (Exception e) { return(this.ResponseFromException(e)); } }; this.Get["/{id}"] = parameters => { try { var user = this.CurrentUser; string id = parameters.id; var mirror = mirrorStore.GetById(id); return(this.Response.AsJson(mirror)); } catch (Exception e) { return(this.ResponseFromException(e)); } }; this.Get["/{id}/reflections"] = parameters => { try { var user = this.CurrentUser; string id = parameters.id; int take; var mirror = mirrorStore.GetById(id); var reflections = Int32.TryParse(this.Request.Query["take"].ToString(), out take) ? reflectionStore.GetByMirror(mirror, take) : reflectionStore.GetByMirror(mirror); return(this.Response.AsJson(reflections)); } catch (Exception e) { return(this.ResponseFromException(e)); } }; this.Get["/{id}/sync"] = parameters => { try { var user = this.CurrentUser; string id = parameters.id; //Thread.Sleep(1000); int take; var mirror = mirrorStore.GetById(id); var reflections = Int32.TryParse(this.Request.Query["take"].ToString(), out take) ? syncStore.GetByMirror(mirror, take) : syncStore.GetByMirror(mirror); return(this.Response.AsJson(reflections)); } catch (Exception e) { return(this.ResponseFromException(e)); } }; this.Post["/"] = parameters => { try { var user = this.CurrentUser; var dto = this.Bind <MirrorDto>(); if (string.IsNullOrEmpty(dto.OwnerId)) { dto.OwnerId = user.Id; } var mirror = mirrorStore.Add(dto); return(this.Response.AsJson(mirror)); } catch (Exception e) { return(this.ResponseFromException(e)); } }; this.Put["/{id}"] = parameters => { try { var user = this.CurrentUser; string id = parameters.id; var dto = this.Bind <MirrorDto>(); if (string.IsNullOrEmpty(dto.SourceRepositoryId)) { dto.SourceRepositoryId = dto.SourceRepository.Id; } if (string.IsNullOrEmpty(dto.TargetRepositoryId)) { dto.TargetRepositoryId = dto.TargetRepository.Id; } if (string.IsNullOrEmpty(dto.OwnerId)) { dto.OwnerId = dto.Owner.Id; } var mirror = mirrorStore.GetById(id); if (mirror == null) { return(HttpStatusCode.NotFound); } mirrorStore.Update(id, dto); return(HttpStatusCode.OK); } catch (Exception e) { return(this.ResponseFromException(e)); } }; this.Delete["/{id}"] = parameters => { var user = this.CurrentUser; string id = parameters.id; try { mirrorStore.Delete(id); return(HttpStatusCode.OK); } catch (Exception e) { return(this.ResponseFromException(e)); } }; }