public ActionResult <HttpResponse> AddTimeReport([FromBody] Registries newRegistries) { try { for (int i = 0; i < newRegistries.RegistriesToReport.Count; i++) { if (newRegistries.RegistriesToReport[i].UserId != user.UserId) { throw new AccessViolationException(ErrorMessage.InvalidEditingRights); } if (newRegistries.RegistriesToReport[i].RegistryId == 0) { unitOfWork.RegistryRepository.Insert(newRegistries.RegistriesToReport[i]); } else { unitOfWork.RegistryRepository.Update(newRegistries.RegistriesToReport[i]); } } unitOfWork.RegistryRepository.Save(); return(Ok()); } catch (AccessViolationException e) { return(StatusCode(403, new { message = e.Message })); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, ErrorMessage.DatabaseCommunicationError)); } }
public static void Register(HttpConfiguration config) { //******Dependency Registries.Register(config); //****** // Web API configuration and services config.Services.Add(typeof(IExceptionLogger), new SimpleExceptionLogger(WebContainerManager.Get <INapLogger>())); config.Services.Replace(typeof(IExceptionHandler), new GlobalExceptionHandler()); config.EnableSystemDiagnosticsTracing(); config.Services.Replace(typeof(ITraceWriter), new TraceWriter(WebContainerManager.Get <INapLogger>())); var traceWriter = config.Services.GetTraceWriter(); traceWriter.Trace(null, "Application Startup: Nap.Logger.WebApi", TraceLevel.Info, "{0}", "Application Startup: Nap.Logger.WebApi."); var constraintsResolver = new DefaultInlineConstraintResolver(); constraintsResolver.ConstraintMap.Add("apiVersionConstraint", typeof(ApiVersionConstraint)); constraintsResolver.ConstraintMap.Add("valuerangeWithStatus", typeof(ValueRangeWithStatusRouteConstraint)); config.MapHttpAttributeRoutes(constraintsResolver); var naplogger = (INapLogger)config.DependencyResolver.GetService(typeof(INapLogger)); naplogger.Fatal("Application Startup: " + ConfigurationManager.AppSettings["LogName"]); }
public void Unregister(Registries registries) { registries.Registry <Plugin>().Unregister(this); registries.Registry <DeviceTypeAddOn>().UnregisterAll(DeviceTypes); registries.Registry <AppEntryAddOn>().UnregisterAll(AppEntries); registries.Registry <ParadigmTemplate>().UnregisterAll(Paradigms); registries.Registry <DeviceTemplate>().UnregisterAll(Devices); registries.Registry <ConsumerTemplate>().UnregisterAll(Consumers); MarkerDefinitions.MarkerRegistry.UnregisterAll(CustomMarkers.Values); }
public EdgeRuntime(string deviceId, Option <string> agentImage, Option <string> hubImage, Option <Uri> proxy, Registries registries, bool optimizeForPerformance, IotHub iotHub) { this.agentImage = agentImage; this.deviceId = deviceId; this.hubImage = hubImage; this.iotHub = iotHub; this.optimizeForPerformance = optimizeForPerformance; this.proxy = proxy; this.registries = registries; }
internal void MergeChanges(long commitId) { lock (this) { bool allMerged = Registries.MergeChanges(commitId); // If all journal entries merged then schedule deleted row collection. if (allMerged && !IsReadOnly) { CheckForCleanup(); } } }
public void ImportRegistry(Type type) { if (Registries.Any(x => x.GetType() == type)) { return; } var registry = (Registry)Activator.CreateInstance(type); registry.ConfigurePluginGraph(this); }
public override void Entry(IModHelper helper) { modHelper = helper; reflection = helper.Reflection; logger = new Log(this); random = new Random(); StardewModHooksWrapper.CreateWrapper(); PatchManager patchManager = new PatchManager(); Registries.LoadInjectors(); }
public void ImportRegistry(Registry registry) { var all = Registries.Concat(QueuedRegistries).ToArray(); if (Registry.RegistryExists(all, registry)) { return; } QueuedRegistries.Enqueue(registry); }
public void AddTimeReport_ThrowsAccessViolationException(Registries newRegistries) { newRegistries.RegistriesToReport[0].UserId = 2; Mock <IUnitOfWork> mockUOF = new Mock <IUnitOfWork>(); var controller = new ReportingController(mockUOF.Object, httpContextAccessorMock); //Act var result = controller.AddTimeReport(newRegistries); //Assert Assert.IsType <ActionResult <HttpResponse> >(result); Assert.Equal((int)HttpStatusCode.Forbidden, (result.Result as ObjectResult).StatusCode); }
public static IReadOnlyCollection <Plugin> ScanPlugins(Registries registries, Action <string, Exception> exceptionHandler) { var plugins = new LinkedList <Plugin>(); foreach (var file in Directory.GetFiles(Path.GetFullPath(FileUtils.ExecutableDirectory), PluginFileNamePattern)) { Logger.Info("ScanPlugins - loading plugin", "assemblyFile", file); try { var plugin = new Plugin(Assembly.LoadFile(file)); plugins.AddLast(plugin); plugin.LoadMarkers(); plugin.LoadDeviceTypes(); plugin.LoadAppEntries(); plugin.LoadExperiments(); plugin.LoadDevices(); plugin.LoadStreamConsumers(); registries.Registry <Plugin>().Register(plugin); foreach (var deviceType in plugin.DeviceTypes) { registries.Registry <PluginDeviceType>().Register(deviceType); } foreach (var appEntry in plugin.AppEntries) { registries.Registry <PluginAppEntry>().Register(appEntry); } foreach (var experiment in plugin.Experiments) { registries.Registry <PluginExperiment>().Register(experiment); } foreach (var device in plugin.Devices) { registries.Registry <PluginDevice>().Register(device); } foreach (var streamConsumer in plugin.StreamConsumers) { registries.Registry <PluginStreamConsumer>().Register(streamConsumer); } } catch (Exception e) { Logger.Error("ScanPlugins - failed to load assembly", e, "assemblyFile", file); exceptionHandler(file, e); } } return(plugins); }
public override void EnsureSeeded() { if (!Registries.Any()) { var data = SeedDataReader.ReadCsv <Registry>(typeof(RegistryContext).Assembly); AddRange(data); } if (!ExtractRequests.Any()) { var data = SeedDataReader.ReadCsv <ExtractRequest>(typeof(RegistryContext).Assembly); AddRange(data); } SaveChanges(); }
public static string P3Dv1Path() { var lm = Registries.TryGetRegistry( RegistryHive.LocalMachine, @"Software\LockheedMartin\Prepar3d", "SetupPath", RegistryView.Registry32); // P3Dv1 is 32-bit. var cu = Registries.TryGetRegistry( RegistryHive.CurrentUser, @"Software\LockheedMartin\Prepar3D", "AppPath", RegistryView.Registry32); // P3Dv1 is 32-bit. return(lm ?? cu); }
// All methods in this class returns null if the registry cannot be found. public static string FsxPath() { var lm = Registries.TryGetRegistry( RegistryHive.LocalMachine, @"SOFTWARE\Microsoft\microsoft games\flight simulator\10.0", "SetupPath", RegistryView.Registry32); // FSX is 32-bit. var cu = Registries.TryGetRegistry( RegistryHive.CurrentUser, @"SOFTWARE\Microsoft\microsoft games\flight simulator\10.0", "AppPath", RegistryView.Registry32); return(lm ?? cu); }
public static string P3Dv4Path() { var lm = Registries.TryGetRegistry( RegistryHive.LocalMachine, @"SOFTWARE\Lockheed Martin\Prepar3D v4", "SetupPath", RegistryView.Registry64); // P3Dv4 is 64-bit. var cu = Registries.TryGetRegistry( RegistryHive.CurrentUser, @"SOFTWARE\Lockheed Martin\Prepar3D v4", "AppPath", RegistryView.Registry64); // P3Dv4 is 64-bit. return(lm ?? cu); }
public static string FsxSteamPath() { var lm = Registries.TryGetRegistry( RegistryHive.LocalMachine, @"Software\Dovetail Games\FSX\10.0", "Install_Path", RegistryView.Registry32); // FSX:SE is 32-bit. var cu = Registries.TryGetRegistry( RegistryHive.CurrentUser, @"Software\Microsoft\Microsoft Games\Flight Simulator - Steam Edition\10.0", "AppPath", RegistryView.Registry32); // FSX:SE is 32-bit. return(lm ?? cu); }
public void AddRegistry <TType, TEntry>(IRegistry <TEntry> registry) where TType : class, IRegistryEntry <TEntry> where TEntry : class { var type = typeof(TEntry); var location = registry.RegistryName; if (Registries.ContainsKey(location)) { throw new DuplicateNameException(); } if (TypeToRegistry.ContainsKey(type)) { throw new Exception("A registry for this type already registered!"); } Registries.Add(location, registry); TypeToRegistry.Add(type, registry); }
/// <summary> /// Adds a Registry by type. Requires that the Registry class have a no argument /// public constructor /// </summary> /// <param name="type"></param> public void ImportRegistry(Type type) { if (Registries.Any(x => x.GetType() == type) || QueuedRegistries.Any(x => x.GetType() == type)) { return; } try { var registry = (Registry)Activator.CreateInstance(type); QueuedRegistries.Enqueue(registry); } catch (Exception e) { throw new StructureMapException("Unable to create an instance for Registry type '{0}'. Please check the inner exception for details".ToFormat(type.GetFullName()), e); } //registry.As<IPluginGraphConfiguration>().Configure(this); }
/// <summary> /// Adds a Registry by type. Requires that the Registry class have a no argument /// public constructor /// </summary> /// <param name="type"></param> public void ImportRegistry(Type type) { var all = Registries.Concat(QueuedRegistries); if (all.Any(x => x.GetType() == type)) { return; } try { var registry = (Registry)Activator.CreateInstance(type); QueuedRegistries.Enqueue(registry); } catch (Exception e) { throw new StructureMapException( "Unable to create an instance for Registry type '{0}'. Please check the inner exception for details" .ToFormat(type.GetFullName()), e); } }
public void Dispose() { if (FieldCache != null) { FieldCache.Clear(); } if (headerArea != null) { headerArea.Dispose(); } if (recordList != null) { recordList.Dispose(); } if (Registries != null) { Registries.Dispose(); } if (indexSetStore != null) { indexSetStore.Dispose(); } if (Store != null) { if (StoreSystem.CloseStore(Store)) { Store.Dispose(); } } headerArea = null; recordList = null; Registries = null; indexSetStore = null; }
public void AddTimeReport_SuccessTest(Registries newRegistries) { //Arrange Mock <IRegistryRepository> registryRepoMock = new Mock <IRegistryRepository>(); registryRepoMock.Setup(r => r.Insert(It.IsAny <Registry>())); registryRepoMock.Setup(r => r.Update(It.IsAny <Registry>())); registryRepoMock.Setup(r => r.Save()); Mock <IUnitOfWork> mockUOF = new Mock <IUnitOfWork>(); mockUOF.Setup(uow => uow.RegistryRepository).Returns(registryRepoMock.Object); var controller = new ReportingController(mockUOF.Object, httpContextAccessorMock); //Act var result = controller.AddTimeReport(newRegistries); //Assert Assert.IsType <ActionResult <HttpResponse> >(result); Assert.Equal((int)HttpStatusCode.OK, (result.Result as StatusCodeResult).StatusCode); }
public void AddTimeReport_ThrowsInternalServerErrorException(Registries newRegistries) { //Arrange newRegistries.RegistriesToReport[0].RegistryId = 1; Mock <IRegistryRepository> registryRepoMock = new Mock <IRegistryRepository>(); registryRepoMock.Setup(r => r.Insert(It.IsAny <Registry>())); registryRepoMock.Setup(r => r.Update(It.IsAny <Registry>())).Throws <Exception>(); registryRepoMock.Setup(r => r.Save()); Mock <IUnitOfWork> mockUOF = new Mock <IUnitOfWork>(); mockUOF.Setup(uow => uow.RegistryRepository).Returns(registryRepoMock.Object); var controller = new ReportingController(mockUOF.Object, httpContextAccessorMock); //Act var result = controller.AddTimeReport(newRegistries); //Assert Assert.IsType <ActionResult <HttpResponse> >(result); Assert.Equal((int)HttpStatusCode.InternalServerError, (result.Result as ObjectResult).StatusCode); }
internal IEnumerable <ITableEventRegistry> FindChangesSinceCommit(long commitId) { lock (this) { return(Registries.FindSinceCommit(commitId)); } }
/// <summary> /// Clears any sensitive properties like the Docker registry credentials. /// </summary> public void ClearSecrets() { Registries.Clear(); }
internal void CommitTransactionChange(long commitId, ITableEventRegistry change, IRowIndexSet indexSet) { lock (this) { // ASSERT: Can't do this if source is Read only. if (IsReadOnly) { throw new InvalidOperationException("Can't commit transaction journal, table is Read only."); } // CHECK! // TODO: change.CommitId = commitId; try { // Add this registry to the multi version table indices log Registries.AddRegistry(change); // Write the modified index set to the index store // (Updates the index file) CommitIndexSet(indexSet); // Update the state of the committed added data to the file system. // (Updates data to the allocation file) // // ISSUE: This can add up to a lot of changes to the allocation file and // the runtime could potentially be terminated in the middle of // the update. If an interruption happens the allocation information // may be incorrectly flagged. The type of corruption this would // result in would be; // + From an 'update' the updated record may disappear. // + From a 'delete' the deleted record may not delete. // + From an 'insert' the inserted record may not insert. // // Note, the possibility of this type of corruption occuring has been // minimized as best as possible given the current architecture. // Also note that is not possible for a table file to become corrupted // beyond recovery from this issue. foreach (var entry in change) { if (entry is TableRowEvent) { var rowEvent = (TableRowEvent)entry; var rowIndex = rowEvent.RowNumber; if (rowEvent.EventType == TableRowEventType.Add) { // Record commit added var oldType = WriteRecordState(rowIndex, RecordState.CommittedAdded); // Check the record was in an uncommitted state before we changed // it. if (oldType != RecordState.Uncommitted) { WriteRecordState(rowIndex, oldType); throw new InvalidOperationException($"Record {rowIndex} of table {TableName} was not in an uncommitted state!"); } } else if (rowEvent.EventType == TableRowEventType.Remove) { // Record commit removed var oldType = WriteRecordState(rowIndex, RecordState.CommittedRemoved); // Check the record was in an added state before we removed it. if (oldType != RecordState.CommittedAdded) { WriteRecordState(rowIndex, oldType); throw new InvalidOperationException($"Record {rowIndex} of table {TableName} was not in an added state!"); } // Notify collector that this row has been marked as deleted. GC.DeleteRow(rowIndex); } } } } catch (IOException e) { throw new InvalidOperationException("IO Error: " + e.Message, e); } } }