コード例 #1
0
ファイル: Program.cs プロジェクト: malast88/gziptest-csharp
        static void Main(string[] args)
        {
            try
            {
                CompressThreadsCount           = Environment.ProcessorCount;
                ReaderProducerConsumerCapacity = CompressThreadsCount * 2;

                var argsResolver            = new ArgumentsResolver();
                var finishChain             = SetupFinishChain();
                var readerToProcessorsChain = SetupReaderToProcessorsChain();
                var uncompressedFileReader  = SetupUncompressedFileReader(readerToProcessorsChain,
                                                                          finishChain);
                var compressorOutputFactory = new BlockCompressorUowOutputFactory(ProcessorProducerConsumerCapacity);
                var blockCompressor         = SetupBlockCompressor(readerToProcessorsChain,
                                                                   compressorOutputFactory);
                var fileWriter = SetupFileWriter(compressorOutputFactory,
                                                 finishChain);
                var core = new Core(argsResolver,
                                    uncompressedFileReader,
                                    blockCompressor,
                                    fileWriter);
                core.Run(args);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Unexpected error: '{ex.Message}'");
            }
        }
コード例 #2
0
        public void _TestResolve(string str)
        {
            Console.WriteLine(str);
            var paras = new ArgumentsResolver(XElement.Parse("<Node Name=\"Node\"><Value Text=\"Text\"></Value></Node>")).Resolve(str);

            foreach (var p in paras)
            {
                Console.WriteLine("Parameter: " + p?.ToString() ?? "");
            }
            Console.WriteLine(new string('=', 100));
        }
コード例 #3
0
        public void ArgumentsResolverShouldThrowErrorWhenIncorrectArgs()
        {
            // Arrange
            var args = new string[1] {
                "asd"
            };
            var argResolver = new ArgumentsResolver();

            // Assert
            Assert.Throws(typeof(ArgumentException), new TestDelegate(() => argResolver.ResolveArgs(args)));
        }
コード例 #4
0
        public void ArgumentsResolverShouldResolveArgs()
        {
            // Arrange
            var args = new string[3] {
                "compress", "asd", "bsd"
            };
            var argResolver = new ArgumentsResolver();

            // Act
            argResolver.ResolveArgs(args);

            // Assert
            Assert.AreEqual(JobType.Compress, argResolver.JobType);
            Assert.AreEqual("asd", argResolver.InputFile);
            Assert.AreEqual("bsd", argResolver.OutputFile);
        }
コード例 #5
0
        static void ProcessWorkflow(string workflowFile, string workingFolder)
        {
            var doc = XDocument.Load(workflowFile);

            var mainSeq    = doc.Elements().First().Elements().Single(e => e.Name.LocalName == "Sequence");
            var activities = new List <XElement>()
            {
            };

            MainActivity = mainSeq;
            if (StartWorkflow == null)
            {
                StartWorkflow = doc;
            }
            DFSActvities(mainSeq, activities);
            activities.Add(mainSeq);

            #region process activities
            foreach (var activity in activities)
            {
                // Get existing attributes
                var attr  = activity.XAttribute("Annotation.AnnotationText", XMLExetension.ns_sap2010);
                var attrs = new List <Tuple <string, string> >();
                if (attr != null)
                {
                    foreach (var line in attr.Value.Split('\n'))
                    {
                        var match = Regex.Match(line.Trim(), @"^@(\S+)\((.*)\)$");
                        if (match.Length >= 3)
                        {
                            attrs.Add(Tuple.Create(match.Groups[1].Value, match.Groups[2].Value));
                        }
                    }
                }

                // Construct the work context
                var workContext = new WorkContext(activity)
                {
                    Doc            = doc,
                    FileName       = workflowFile,
                    WorkingPath    = workingFolder,
                    Attributes     = attrs,
                    IsMainActivity = activity == MainActivity,
                    IsStartWorflow = StartWorkflow == doc
                };

                // Typed hanlders
                foreach (var h in ActivityHandlers.TypedHandlers)
                {
                    h.WorkContext = workContext;
                    if (h.Test())
                    {
                        h.Handle();
                    }
                }

                // Attribute handlers
                foreach (var attrTuple in attrs)
                {
                    var attribute = attrTuple.Item1;
                    var h         = ActivityHandlers.AttributeHandlers.FirstOrDefault(h1 => h1.Name == attribute);
                    if (h == null)
                    {
                        Console.WriteLine("No handler for " + attribute);
                        continue;
                    }

                    Console.WriteLine("Processing attribute:" + attribute);
                    var method = h.GetType().GetMethod("Handle");
                    h.WorkContext = workContext;

                    var ps    = method.GetParameters();
                    var margs = new ArgumentsResolver(activity).Resolve(attrTuple.Item2);

                    if (ps.LastOrDefault()?.ParameterType?.IsArray ?? false)
                    {
                        var eleType   = ps.LastOrDefault().ParameterType.GetElementType();
                        var paramsLen = margs.Length - ps.Length + 1;
                        var paramsObj = Array.CreateInstance(eleType, paramsLen);
                        for (int i = ps.Length - 1; i < margs.Length; i++)
                        {
                            paramsObj.SetValue(margs[i], i - (ps.Length - 1));
                        }
                        var _args = margs.Take(ps.Length - 1).ToList();
                        _args.Add(paramsObj);
                        method.Invoke(h, _args.ToArray());
                    }
                    else
                    {
                        method.Invoke(h, margs);
                    }
                }
            }
            #endregion

            // Save files
            Console.WriteLine("Save file " + workflowFile);
            doc.Save(workflowFile);
            foreach (var file in Globals.ToSaveXMLFiles.Keys)
            {
                Console.WriteLine("Save file " + file);
                Globals.ToSaveXMLFiles[file].Save(file);
            }
            Globals.ToSaveXMLFiles.Clear();
        }
コード例 #6
0
 public SubscribedMethodInvoker(ArgumentsResolver argumentsResolver, ReturnValueHandler returnValueHandler, IServiceProvider serviceProvider)
 {
     _argumentsResolver  = argumentsResolver ?? throw new ArgumentNullException(nameof(argumentsResolver));
     _returnValueHandler = returnValueHandler ?? throw new ArgumentNullException(nameof(returnValueHandler));
     _serviceProvider    = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
 }