public OutputController(IReportConfiguration configuration, IMessageSink diagnosticMessageSink) { _configuration = configuration; _diagnosticMessageSink = diagnosticMessageSink; IReportWriter writer; if (!configuration.WriteOutput) { _diagnosticMessageSink.OnMessage(new DiagnosticMessage("Output is disabled")); writer = new NullWriter(); } else { _diagnosticMessageSink.OnMessage(new DiagnosticMessage($"Creating report at {configuration.XmlReportFile}")); _fileStream = new FileStream(configuration.XmlReportFile, FileMode.Create, FileAccess.Write, FileShare.None, 4096, true); _sw = new StreamWriter(_fileStream); XmlWriterSettings xws = new XmlWriterSettings(); xws.Async = true; _xw = XmlWriter.Create(_sw, xws); writer = new ReportWriter(_xw); } Report = new ScenarioReport(configuration.AssemblyName, writer, _diagnosticMessageSink); }
public void NullWriter() { NullWriter writer = new NullWriter(); writer.Write(new NullTemplate(), this.output); Assert.AreEqual("null", this.output.ToString()); }
public static string SerializeCSToPythonJson(object value) { StringBuilder sb = new StringBuilder(256); StringWriter sw = new StringWriter(sb, CultureInfo.InvariantCulture); using (var nWriter = new NullWriter(sw)) { serializer.Serialize(nWriter, value); } return(sw.ToString()); }
public void Test_NotImplementedException() { // 这个方法验证所有Writer中所有没有实现的方法 int count = 0; FileWriter fileWriter = new FileWriter(); count = Test_Get_GetList(fileWriter, count); // + 2 MailWriter mailWriter = new MailWriter(); count = Test_Get_GetList(mailWriter, count); // + 2 MsmqWriter msmqWriter = new MsmqWriter(); count = Test_Get_GetList(msmqWriter, count); // + 2 WinLogWriter winLogWriter = new WinLogWriter(); count = Test_Get_GetList(winLogWriter, count); // + 2 NullWriter nullWriter = new NullWriter(); nullWriter.Init(null); count = Test_Get_GetList(nullWriter, count); // + 2 try { // 这个是空调用,不应该有异常 ExceptionInfo info = new ExceptionInfo(); nullWriter.Write <ExceptionInfo>(info); } catch (NotImplementedException) { count++; } try { // 这个是空调用,不应该有异常 List <ExceptionInfo> list = new List <ExceptionInfo>(); nullWriter.Write(list); } catch (NotImplementedException) { count++; } Assert.AreEqual(10, count); }
protected override void Load(ContainerBuilder builder) { if (!builder.Properties.ContainsKey("Process")) { return; } var process = (Process)builder.Properties["Process"]; // connections foreach (var connection in process.Connections.Where(c => c.Provider == Access)) { // Connection Factory builder.Register <IConnectionFactory>(ctx => { switch (connection.Provider) { case "access": return(new AccessConnectionFactory(connection)); default: return(new NullConnectionFactory()); } }).Named <IConnectionFactory>(connection.Key).InstancePerLifetimeScope(); // Schema Reader builder.Register <ISchemaReader>(ctx => { var factory = ctx.ResolveNamed <IConnectionFactory>(connection.Key); return(new AdoSchemaReader(ctx.ResolveNamed <IConnectionContext>(connection.Key), factory)); }).Named <ISchemaReader>(connection.Key); } // entity input foreach (var entity in process.Entities.Where(e => process.Connections.First(c => c.Name == e.Input).Provider == Access)) { // INPUT READER builder.Register <IRead>(ctx => { var input = ctx.ResolveNamed <InputContext>(entity.Key); var rowFactory = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", input.RowCapacity)); switch (input.Connection.Provider) { case "access": return(new AdoInputReader( input, input.InputFields, ctx.ResolveNamed <IConnectionFactory>(input.Connection.Key), rowFactory )); default: return(new NullReader(input, false)); } }).Named <IRead>(entity.Key); // INPUT VERSION DETECTOR builder.Register <IInputProvider>(ctx => { var input = ctx.ResolveNamed <InputContext>(entity.Key); switch (input.Connection.Provider) { case "access": return(new AdoInputProvider(input, ctx.ResolveNamed <IConnectionFactory>(input.Connection.Key))); default: return(new NullInputProvider()); } }).Named <IInputProvider>(entity.Key); } // entity output if (process.GetOutputConnection().Provider == Access) { var calc = process.ToCalculatedFieldsProcess(); // PROCESS OUTPUT CONTROLLER builder.Register <IOutputController>(ctx => { var output = ctx.Resolve <OutputContext>(); if (process.Mode != "init") { return(new NullOutputController()); } switch (output.Connection.Provider) { case "access": var actions = new List <IAction> { new AdoStarViewCreator(output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key)) }; if (process.Flatten) { actions.Add(new AdoFlatTableCreator(output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key))); } return(new AdoStarController(output, actions)); default: return(new NullOutputController()); } }).As <IOutputController>(); // PROCESS CALCULATED READER builder.Register <IRead>(ctx => { var calcContext = new PipelineContext(ctx.Resolve <IPipelineLogger>(), calc, calc.Entities.First()); var outputContext = new OutputContext(calcContext); var cf = ctx.ResolveNamed <IConnectionFactory>(outputContext.Connection.Key); var capacity = outputContext.Entity.Fields.Count + outputContext.Entity.CalculatedFields.Count; var rowFactory = new RowFactory(capacity, false, false); return(new AdoStarParametersReader(outputContext, process, cf, rowFactory)); }).As <IRead>(); // PROCESS CALCULATED FIELD WRITER builder.Register <IWrite>(ctx => { var calcContext = new PipelineContext(ctx.Resolve <IPipelineLogger>(), calc, calc.Entities.First()); var outputContext = new OutputContext(calcContext); var cf = ctx.ResolveNamed <IConnectionFactory>(outputContext.Connection.Key); return(new AdoCalculatedFieldUpdater(outputContext, process, cf)); }).As <IWrite>(); // PROCESS INITIALIZER builder.Register <IInitializer>(ctx => { var output = ctx.Resolve <OutputContext>(); var adoInit = new AdoInitializer(output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key)); switch (output.Connection.Provider) { case "access": return(new AccessInitializer(adoInit, output)); default: return(adoInit); } }).As <IInitializer>(); // ENTITIES foreach (var entity in process.Entities) { builder.Register <IOutputProvider>(ctx => { IWrite writer; var output = ctx.ResolveNamed <OutputContext>(entity.Key); var cf = ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key); var rowFactory = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", output.GetAllEntityFields().Count())); // matcher determines what's an update vs. and insert var matcher = entity.Update ? (IBatchReader) new AdoEntityMatchingKeysReader(output, cf, rowFactory) : new NullBatchReader(); switch (output.Connection.Provider) { case "access": writer = new AdoEntityWriter( output, matcher, new AdoEntityInserter(output, cf), entity.Update ? (IWrite) new AdoEntityUpdater(output, cf) : new NullWriter(output) ); break; default: writer = new NullWriter(output); break; } return(new AdoOutputProvider(output, cf, writer)); }).Named <IOutputProvider>(entity.Key); // ENTITY OUTPUT CONTROLLER builder.Register <IOutputController>(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); var initializer = process.Mode == "init" ? (IAction) new AdoEntityInitializer(output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key)) : new NullInitializer(); switch (output.Connection.Provider) { case "access": return(new AdoOutputController( output, new AccessInitializer(initializer, output), ctx.ResolveNamed <IInputProvider>(entity.Key), ctx.ResolveNamed <IOutputProvider>(entity.Key), ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key) )); default: return(new NullOutputController()); } }).Named <IOutputController>(entity.Key); // MASTER UPDATE QUERY builder.Register <IWriteMasterUpdateQuery>(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); var factory = ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key); return(new AccessUpdateMasterKeysQueryWriter(output, factory)); }).Named <IWriteMasterUpdateQuery>(entity.Key + "MasterKeys"); // MASTER UPDATER builder.Register <IUpdate>(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); switch (output.Connection.Provider) { case "access": return(new AdoMasterUpdater( output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key), ctx.ResolveNamed <IWriteMasterUpdateQuery>(entity.Key + "MasterKeys") )); default: return(new NullMasterUpdater()); } }).Named <IUpdate>(entity.Key); // DELETE HANDLER if (entity.Delete) { // register input keys and hashcode reader if necessary builder.Register(ctx => { var inputContext = ctx.ResolveNamed <InputContext>(entity.Key); var rowCapacity = inputContext.Entity.GetPrimaryKey().Count(); var rowFactory = new RowFactory(rowCapacity, false, true); switch (inputContext.Connection.Provider) { case "access": return(new AdoReader( inputContext, entity.GetPrimaryKey(), ctx.ResolveNamed <IConnectionFactory>(inputContext.Connection.Key), rowFactory, ReadFrom.Input )); default: return(ctx.IsRegisteredWithName <IReadInputKeysAndHashCodes>(entity.Key) ? ctx.ResolveNamed <IReadInputKeysAndHashCodes>(entity.Key) : new NullReader(inputContext)); } }).Named <IReadInputKeysAndHashCodes>(entity.Key); // register output keys and hash code reader if necessary builder.Register((ctx => { var context = ctx.ResolveNamed <OutputContext>(entity.Key); var rowCapacity = context.Entity.GetPrimaryKey().Count(); var rowFactory = new RowFactory(rowCapacity, false, true); var outputConnection = process.GetOutputConnection(); switch (outputConnection.Provider) { case "access": var ocf = ctx.ResolveNamed <IConnectionFactory>(outputConnection.Key); return(new AdoReader(context, entity.GetPrimaryKey(), ocf, rowFactory, ReadFrom.Output)); default: return(ctx.IsRegisteredWithName <IReadOutputKeysAndHashCodes>(entity.Key) ? ctx.ResolveNamed <IReadOutputKeysAndHashCodes>(entity.Key) : new NullReader(context)); } })).Named <IReadOutputKeysAndHashCodes>(entity.Key); builder.Register(ctx => { var outputConnection = process.GetOutputConnection(); var outputContext = ctx.ResolveNamed <OutputContext>(entity.Key); switch (outputConnection.Provider) { case "access": var ocf = ctx.ResolveNamed <IConnectionFactory>(outputConnection.Key); return(new AdoDeleter(outputContext, ocf)); default: return(ctx.IsRegisteredWithName <IDelete>(entity.Key) ? ctx.ResolveNamed <IDelete>(entity.Key) : new NullDeleter(outputContext)); } }).Named <IDelete>(entity.Key); builder.Register <IEntityDeleteHandler>(ctx => { var context = ctx.ResolveNamed <IContext>(entity.Key); var primaryKey = entity.GetPrimaryKey(); var handler = new DefaultDeleteHandler( context, ctx.ResolveNamed <IReadInputKeysAndHashCodes>(entity.Key), ctx.ResolveNamed <IReadOutputKeysAndHashCodes>(entity.Key), ctx.ResolveNamed <IDelete>(entity.Key) ); // since the primary keys from the input may have been transformed into the output, you have to transform before comparing // feels a lot like entity pipeline on just the primary keys... may look at consolidating handler.Register(new DefaultTransform(context, entity.GetPrimaryKey().ToArray())); handler.Register(TransformFactory.GetTransforms(ctx, context, primaryKey)); handler.Register(new StringTruncateTransfom(context, primaryKey)); return(handler); }).Named <IEntityDeleteHandler>(entity.Key); } } } }
static int Main(string[] args) { // Get a reference to the language file ResourceManager text = Language.ResourceManager; // Parse the command line options _options = new Options(); if (!Parser.Default.ParseArguments(args, _options)) { Console.WriteLine(_options.GetUsage()); return(255); } // Make sure an archive file is given if (_options.ArchiveFile == null) { Console.WriteLine(_options.GetUsage()); return(255); } // Display a banner if (!_options.Silent) { Console.WriteLine("Akeeba eXtract CLI v. " + Assembly.GetCallingAssembly().GetName().Version); Console.WriteLine($"Copyright (c)2006-{DateTime.Now.Year} Nicholas K. Dionysopoulos / Akeeba Ltd"); Console.WriteLine("-------------------------------------------------------------------------------"); Console.WriteLine("This is free software. You may redistribute copies of it under the terms of"); Console.WriteLine("the MIT License <http://www.opensource.org/licenses/mit-license.php>."); Console.WriteLine(""); } // If no output directory is given we assume the current workign directory if (_options.TargetFolder == null) { _options.TargetFolder = Directory.GetCurrentDirectory(); } try { // Make sure the file exists if (!File.Exists(_options.ArchiveFile)) { throw new FileNotFoundException(String.Format(text.GetString("ERR_NOT_FOUND"), _options.ArchiveFile)); } // Make sure the file can be read try { using (FileStream stream = File.Open(_options.ArchiveFile, FileMode.Open, FileAccess.Read)) { } } catch { throw new FileNotFoundException(String.Format(text.GetString("ERR_CANNOT_READ"), _options.ArchiveFile)); } // Try to extract using (Unarchiver.Unarchiver extractor = Unarchiver.Unarchiver.CreateForFile(_options.ArchiveFile, _options.Password)) { // Attach event subscribers extractor.ProgressEvent += OnProgressHandler; extractor.EntityEvent += onEntityHandler; // Create a cancelation token (it's required by the unarchiver) CancellationTokenSource cts = new CancellationTokenSource(); var token = cts.Token; Task t = Task.Factory.StartNew( () => { if (extractor == null) { throw new Exception("Internal state consistency violation: extractor object is null"); } // Get the appropriate writer IDataWriter writer = new NullWriter(); if (!_options.Test) { writer = new DirectFileWriter(_options.TargetFolder); } // Test the extraction extractor.Extract(token, writer); }, token, TaskCreationOptions.None, TaskScheduler.Default ); t.Wait(token); } } catch (Exception e) { Exception targetException = (e.InnerException == null) ? e : e.InnerException; if (!_options.Silent || _options.Verbose) { Console.WriteLine(""); Console.WriteLine(text.GetString("ERR_HEADER")); Console.WriteLine(""); Console.WriteLine(targetException.Message); } if (_options.Verbose) { Console.WriteLine(""); Console.WriteLine("Stack trace:"); Console.WriteLine(""); Console.WriteLine(targetException.StackTrace); } return(250); } return(0); }
/// <summary> /// Test the archive by using the NullWrite data writer which doesn't create any files / folders /// </summary> /// <param name="token">A CancellationToken used by the caller to cancel the execution before it's complete.</param> public void Test(CancellationToken token) { IDataWriter myDataWriter = new NullWriter(); Extract(token, myDataWriter); }
private static void TestGeneral() { TextWriter tout = new NullWriter(); LPProblem p = new LPProblem(); tout.WriteLine(p.AddRows(4)); tout.WriteLine(p.AddCols(5)); p.Name = "yoyoyo"; tout.WriteLine(p.Name); p.ObjectiveName = "monobj"; tout.WriteLine(p.ObjectiveName); p.ObjectiveDirection = OptimisationDirection.MINIMISE; tout.WriteLine(p.ObjectiveDirection); p.ObjectiveDirection = OptimisationDirection.MAXIMISE; tout.WriteLine(p.ObjectiveDirection); p.SetRowName(1, "ert"); tout.WriteLine(p.GetRowName(1)); tout.WriteLine(p.GetRowName(2)); p.SetRowName(1, null); tout.WriteLine(p.GetRowName(1)); p.SetColName(1, "colk"); tout.WriteLine(p.GetColName(1)); p.SetColName(1, null); tout.WriteLine(p.GetColName(1)); tout.WriteLine(p.GetColName(2)); p.SetRowBounds(1, BOUNDSTYPE.Upper, 4, 6); p.SetColBounds(2, BOUNDSTYPE.Upper, 3, 7); p.SetMatRow(1, new int[] { 0, 1, 2, 4 }, new double[] { 0, 2.2, 3.3, 4.4 }); int[] ind; double[] val; p.GetMatRow(1, out ind, out val); tout.WriteLine(ind.Length + " " + ind[1]); tout.WriteLine(val.Length + " " + val[1]); p.SetObjCoef(2, 3.6); tout.WriteLine(p.GetObjCoef(2)); tout.WriteLine(p.GetNonZeroCount()); tout.WriteLine(p.GetColBoundType(2)); tout.WriteLine(p.GetColLb(2)); tout.WriteLine(p.GetColUb(2)); p.SetColKind(1, COLKIND.Integer); tout.WriteLine(p.GetColsCount()); tout.WriteLine(p.GetRowsCount()); Console.Out.WriteLine(p.GetVersion()); p.TermHook(new TermHookDelegate(Hook)); p.ModelClass = MODELCLASS.MIP; BnCCallback.SetCallback(p, new BranchAndCutDelegate( delegate(BranchTree t, Object o) { Console.WriteLine(t.GetReason().ToString()); } )); p.SolveSimplex(); p.SolveInteger(); p.WriteSol("c:\\sol.txt"); KKT kkt = p.CheckKKT(0); int count; int cpeak; double total; double tpeak; p.GetMemoryUsage(out count, out cpeak, out total, out tpeak); Console.Out.WriteLine(count); Console.Out.WriteLine(cpeak); Console.Out.WriteLine(total); Console.Out.WriteLine(tpeak); LPProblem copy = p.Clone(true); p.Clear(); Console.Out.WriteLine("tapez une touche."); Console.In.ReadLine(); //Console.In.Read(); }
/// <summary> /// Start the archive extraction asynchronously. /// </summary> /// <returns></returns> private async Task StartExtractionAsync() { string archiveFile = _gateway.GetBackupArchivePath(); string outputDirectory = _gateway.GetOutputFolderPath(); string password = _gateway.GetPassword(); bool ignoreWriteErrors = _gateway.GetIgnoreFileWriteErrors(); bool dryRun = _gateway.GetDryRun(); _tokenSource = new CancellationTokenSource(); CancellationToken token = _tokenSource.Token; try { using (Unarchiver extractor = Unarchiver.CreateForFile(archiveFile, password)) { // Wire events _totalArchiveSize = 0; extractor.ArchiveInformationEvent += onArchiveInformationHandler; extractor.ProgressEvent += OnProgressHandler; extractor.EntityEvent += onEntityHandler; Task t = Task.Factory.StartNew( () => { if (extractor == null) { throw new Exception("Internal state consistency violation: extractor object is null"); } // Get the appropriate writer IDataWriter writer = new NullWriter(); if (!dryRun) { writer = new DirectFileWriter(outputDirectory); if (ignoreWriteErrors) { // TODO Use a different file writer when we are asked to ignore write errorss writer = new DirectFileWriter(outputDirectory); } } // Test the extraction extractor.Extract(token, writer); }, token, TaskCreationOptions.None, TaskScheduler.Default ); await t; } } catch (Exception e) { Exception targetException = (e.InnerException == null) ? e : e.InnerException; _gateway.SetTaskbarProgressState(TaskBarProgress.TaskbarStates.Error); // Show error message _gateway.showErrorMessage(_languageResource.GetString("LBL_ERROR_CAPTION"), targetException.Message); } _gateway.SetExtractionOptionsState(true); ResetProgress(); }