/// <summary>
 /// Create a new lossless transform instance with the given parameters.
 /// </summary>
 /// <param name="x">The left boundary of the cropping region. This must be evenly divisible by the MCU block 
 /// width (see <see cref="TurboJpegUtilities.GetMcuWidth" />).</param>
 /// <param name="y">The upper boundary of the cropping region. This must be evenly divisible by the MCU block 
 /// height (see <see cref="TurboJpegUtilities.GetMcuHeight" />).</param>
 /// <param name="width">The width of the cropping region. Setting this to 0 is the equivalent of setting it to 
 /// (width of the source JPEG image - <paramref name="x"/>).</param>
 /// <param name="height">The height of the cropping region. Setting this to 0 is the equivalent of setting it to 
 /// (height of the source JPEG image - <paramref name="y"/>).</param>
 /// <param name="operation">The transform operation.</param>
 /// <param name="options">One or more of the transform options.</param>
 /// <param name="customFilter">An instance of an object that implements the <see cref="ICustomFilter"/> 
 /// interface, or <c>null</c> if no custom filter is needed.</param>
 public TurboJpegTransform(int x,
                           int y,
                           int width,
                           int height,
                           TransformOperation operation,
                           TransformOptions options,
                           ICustomFilter customFilter = null)
     : this(new Rectangle(x, y, width, height), operation, options, customFilter)
 {
     Contract.Requires(x >= 0, "x must be non-negative");
     Contract.Requires(y >= 0, "y must be non-negative");
     Contract.Requires(width >= 0, "width must be non-negative");
     Contract.Requires(height >= 0, "height must be non-negative");
     Contract.Requires(Enum.IsDefined(typeof(TransformOperation), operation));
     Contract.Requires(Enum.IsDefined(typeof(TransformOptions), options));
 }
Esempio n. 2
0
 /// <summary>
 /// Create a new lossless transform instance with the given parameters.
 /// </summary>
 /// <param name="x">The left boundary of the cropping region. This must be evenly divisible by the MCU block
 /// width (see <see cref="TurboJpegUtilities.GetMcuWidth" />).</param>
 /// <param name="y">The upper boundary of the cropping region. This must be evenly divisible by the MCU block
 /// height (see <see cref="TurboJpegUtilities.GetMcuHeight" />).</param>
 /// <param name="width">The width of the cropping region. Setting this to 0 is the equivalent of setting it to
 /// (width of the source JPEG image - <paramref name="x"/>).</param>
 /// <param name="height">The height of the cropping region. Setting this to 0 is the equivalent of setting it to
 /// (height of the source JPEG image - <paramref name="y"/>).</param>
 /// <param name="operation">The transform operation.</param>
 /// <param name="options">One or more of the transform options.</param>
 /// <param name="customFilter">An instance of an object that implements the <see cref="ICustomFilter"/>
 /// interface, or <c>null</c> if no custom filter is needed.</param>
 public TurboJpegTransform(int x,
                           int y,
                           int width,
                           int height,
                           TransformOperation operation,
                           TransformOptions options,
                           ICustomFilter customFilter = null)
     : this(new Rectangle(x, y, width, height), operation, options, customFilter)
 {
     Contract.Requires(x >= 0, "x must be non-negative");
     Contract.Requires(y >= 0, "y must be non-negative");
     Contract.Requires(width >= 0, "width must be non-negative");
     Contract.Requires(height >= 0, "height must be non-negative");
     Contract.Requires(Enum.IsDefined(typeof(TransformOperation), operation));
     Contract.Requires(Enum.IsDefined(typeof(TransformOptions), options));
 }
Esempio n. 3
0
        protected override TransformOptions CreateTransformOptions([NotNull] GlobalContext globalContext,
                                                                   [CanBeNull] string transformOptionsString, Func <string, IEnumerable <Dependency> > findOtherWorkingGraph)
        {
            var transformOptions = new TransformOptions();

            Option.Parse(globalContext, transformOptionsString, BackwardsOption.Action((args, j) => {
                transformOptions.Backwards = true;
                return(j);
            }), MaxPathLengthOption.Action((args, j) => {
                transformOptions.MaxPathLength = Option.ExtractIntOptionValue(args, ref j, "Invalid maximum path length");
                return(j);
            }), AddMarkerOption.Action((args, j) => {
                transformOptions.Marker = Option.ExtractRequiredOptionValue(args, ref j, "missing marker name");
                return(j);
            }), AddIndexedMarkerOption.Action((args, j) => {
                transformOptions.Marker   = Option.ExtractRequiredOptionValue(args, ref j, "missing marker name");
                transformOptions.AddIndex = true;
                return(j);
            }), KeepOnlyPathsOption.Action((args, j) => {
                transformOptions.KeepOnlyPathEdges = true;
                return(j);
            }), IgnorePrefixPathsOption.Action((args, j) => {
                transformOptions.IgnorePrefixPaths = true;
                return(j);
            }), IgnoreSubpathsOption.Action((args, j) => {
                transformOptions.IgnoreSubpaths = true;
                return(j);
            }), AddDependencyOption.Action((args, j) => {
                transformOptions.AddTransitiveDependencyInsteadOfMarking = true;
                return(j);
            }), DefineDependencyMatchOption.Action((args, j) => {
                string name    = Option.ExtractRequiredOptionValue(args, ref j, "missing name");
                string pattern = Option.ExtractNextRequiredValue(args, ref j, "missing pattern");
                transformOptions.DefinedDependencyMatches[name] = DependencyMatch.Create(pattern, globalContext.IgnoreCase);
                return(j);
            }), DefineItemMatchOption.Action((args, j) => {
                string name    = Option.ExtractRequiredOptionValue(args, ref j, "missing name");
                string pattern = Option.ExtractNextRequiredValue(args, ref j, "missing pattern");
                transformOptions.DefinedItemMatches[name] = new ItemMatch(pattern, globalContext.IgnoreCase, anyWhereMatcherOk: true);
                return(j);
            }), RegexOption.Action((args, j) => {
                transformOptions.Regex = Option.ExtractRequiredOptionValue(args, ref j, "missing regex");
                return(j);
            }));

            return(transformOptions);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="options"></param>
        /// <param name="expando"></param>
        /// <returns></returns>
        public dynamic Transform(TransformOptions options, dynamic expando)
        {
            // Add Columns
            if (options?.NewColumns?.Count > 0)
            {
                options.NewColumns.ForEach(column =>
                {
                    if (column.CalcRule == ColumnCalcRule.Sum)
                    {
                        var sum = SumOfColumns(expando, column.CalcColumns);
                        ((IDictionary <string, object>)expando).Add(column.ColumnName, sum);
                    }
                });
            }

            return(expando);
        }
        /// <summary>Create a new lossless transform instance with the given parameters.</summary>
        /// <param name="r">A <see cref="Rectangle"/>> instance that specifies the cropping region. See 
        /// <see cref="TurboJpegTransform (int, int, int, int, TransformOperation, TransformOptions, ICustomFilter)"/> 
        /// for more detail.</param>
        /// <param name="operation">The transform operation.</param>
        /// <param name="options">One or more of the transform options.</param>
        /// <param name="customFilter">An instance of an object that implements the <see cref="ICustomFilter"/> 
        /// interface, or <c>null</c> if no custom filter is needed.</param>
        public TurboJpegTransform(Rectangle r,
                                  TransformOperation operation,
                                  TransformOptions options,
                                  ICustomFilter customFilter = null)
        {
            Contract.Requires(r.X >= 0, "Rectangle X must be non-negative");
            Contract.Requires(r.Y >= 0, "Rectangle Y must be non-negative");
            Contract.Requires(r.Width >= 0, "Rectangle width must be non-negative");
            Contract.Requires(r.Height >= 0, "Rectangle height must be non-negative");
            Contract.Requires(Enum.IsDefined(typeof(TransformOperation), operation));
            Contract.Requires(Enum.IsDefined(typeof(TransformOptions), options));

            this.rect = r;
            this.operation = operation;
            this.options = options;
            this.customFilter = customFilter;
        }
Esempio n. 6
0
        /// <summary>Create a new lossless transform instance with the given parameters.</summary>
        /// <param name="r">A <see cref="Rectangle"/>> instance that specifies the cropping region. See
        /// <see cref="TurboJpegTransform (int, int, int, int, TransformOperation, TransformOptions, ICustomFilter)"/>
        /// for more detail.</param>
        /// <param name="operation">The transform operation.</param>
        /// <param name="options">One or more of the transform options.</param>
        /// <param name="customFilter">An instance of an object that implements the <see cref="ICustomFilter"/>
        /// interface, or <c>null</c> if no custom filter is needed.</param>
        public TurboJpegTransform(Rectangle r,
                                  TransformOperation operation,
                                  TransformOptions options,
                                  ICustomFilter customFilter = null)
        {
            Contract.Requires(r.X >= 0, "Rectangle X must be non-negative");
            Contract.Requires(r.Y >= 0, "Rectangle Y must be non-negative");
            Contract.Requires(r.Width >= 0, "Rectangle width must be non-negative");
            Contract.Requires(r.Height >= 0, "Rectangle height must be non-negative");
            Contract.Requires(Enum.IsDefined(typeof(TransformOperation), operation));
            Contract.Requires(Enum.IsDefined(typeof(TransformOptions), options));

            this.rect         = r;
            this.operation    = operation;
            this.options      = options;
            this.customFilter = customFilter;
        }
Esempio n. 7
0
        protected override TransformOptions CreateTransformOptions([NotNull] GlobalContext globalContext,
                                                                   [CanBeNull] string transformOptionsString, Func <string, IEnumerable <Dependency> > findOtherWorkingGraph)
        {
            var transformOptions = new TransformOptions();

            Option.Parse(globalContext, transformOptionsString,
                         BackProjectionGraphOption.Action((args, j) => {
                string backProjectionGraphName = Option.ExtractOptionValue(args, ref j);
                transformOptions.BackProjectionDependencies = findOtherWorkingGraph(backProjectionGraphName);
                if (transformOptions.BackProjectionDependencies == null)
                {
                    throw new ArgumentException($"Could not find graph '{backProjectionGraphName}'");
                }
                return(j);
            })
                         );
            return(transformOptions);
        }
Esempio n. 8
0
        public override int Transform([NotNull] GlobalContext globalContext, [NotNull] ConfigureOptions configureOptions,
                                      [NotNull] TransformOptions transformOptions, [NotNull][ItemNotNull] IEnumerable <Dependency> dependencies,
                                      [NotNull] List <Dependency> transformedDependencies)
        {
            if (!configureOptions.OrderedActions.Any())
            {
                Log.WriteWarning($"No actions configured for {GetType().Name}");
            }
            else
            {
                Dictionary <Item, Dependency[]> items2incoming =
                    Item.CollectIncomingDependenciesMap(dependencies);
                Dictionary <Item, Dependency[]> items2outgoing =
                    Item.CollectOutgoingDependenciesMap(dependencies);

                var allItems = new HashSet <Item>(items2incoming.Keys.Concat(items2outgoing.Keys));

                foreach (var i in allItems.ToArray())
                {
                    Dependency[] incoming;
                    items2incoming.TryGetValue(i, out incoming);
                    Dependency[] outgoing;
                    items2outgoing.TryGetValue(i, out outgoing);

                    ItemAction firstMatchingAction = configureOptions.OrderedActions.FirstOrDefault(a => a.Matches(incoming, i, outgoing));
                    if (firstMatchingAction == null)
                    {
                        Log.WriteWarning("No match in actions for item " + i + " - item is deleted");
                        allItems.Remove(i);
                    }
                    else
                    {
                        if (!firstMatchingAction.Apply(i))
                        {
                            allItems.Remove(i);
                        }
                    }
                }

                transformedDependencies.AddRange(
                    dependencies.Where(d => allItems.Contains(d.UsingItem) && allItems.Contains(d.UsedItem)));
            }
            return(Program.OK_RESULT);
        }
        private static async Task <string> DowloadFileContent(TransformOptions options, HttpClient httpClient, TransformFile file)
        {
            var uri = new Uri(options.Source + file.Src);

            try
            {
                Console.WriteLine($"Dowloading file {uri}");
                var content = await httpClient.GetStringAsync(uri);

                await File.WriteAllTextAsync($"sources/{file.Src}", content);

                return(content);
            }
            catch (HttpRequestException ex)
            {
                Console.WriteLine($"ERROR: The file {uri} can´t be dowloaded check you internet connection, the underlyin exeption was: {ex.Message}");
                return(null);
            }
        }
Esempio n. 10
0
        internal static async Task Structure(Options o)
        {
            if (!Directory.Exists(SourceFolder))
            {
                ConsolePrint.HelpAddSourceFiles(o.Quiet,
                                                Directory.CreateDirectory(SourceFolder));
            }
            if (Directory.Exists(TargetFolder) && o.Reset)
            {
                ConsolePrint.ClearTargetFolder(o.Quiet);
                Directory.Delete(TargetFolder, true);
            }
            if (!Directory.Exists(TargetFolder))
            {
                Directory.CreateDirectory(TargetFolder);
            }

            await TransformOptions.Create(o);
        }
Esempio n. 11
0
        protected override TransformOptions CreateTransformOptions([NotNull] GlobalContext globalContext,
                                                                   [CanBeNull] string transformOptionsString, Func <string, IEnumerable <Dependency> > findOtherWorkingGraph)
        {
            var transformOptions = new TransformOptions();

            PathOptions.Parse(globalContext, transformOptionsString, out transformOptions.Backwards,
                              out transformOptions.PathAnchor, out transformOptions.PathAnchorIsCountMatch,
                              transformOptions.ExpectedPathMatches, out transformOptions.CountMatch, out transformOptions.MaxPathLength,
                              AddMarkerOption.Action((args, j) => {
                transformOptions.Marker = Option.ExtractRequiredOptionValue(args, ref j, "missing marker name");
                return(j);
            })
                              ////KeepOnlyPathsOption.Action((args, j) => {
                              ////    keepOnlyPathEdges = true;
                              ////    return j;
                              ////})
                              );
            return(transformOptions);
        }
Esempio n. 12
0
        public async Task TransformStateSql2SqlDbAsyncTests()
        {
            var connectionManager  = ApplicationServices.GetService <IConnectionManager>();
            var hostingEnvironment = ApplicationServices.GetService <IWebHostEnvironment>();
            var configFilePath     = Path.Combine(hostingEnvironment.WebRootPath, "configs", "StateSql2SqlTest.json");
            var configuration      = new ConfigurationBuilder().AddJsonFile(configFilePath).Build();
            var options            = new TransformOptions();

            configuration.Bind(nameof(TransformOptions), options);


            var sqlTransformTask = new SqlTransformTask(options, connectionManager, CancellationToken.None);

            var context = options.CreateSqlTransformContexts(CancellationToken.None);

            await sqlTransformTask.InvokeAsync(context.ToArray());

            Assert.True(true);
        }
Esempio n. 13
0
        public override int Transform([NotNull] GlobalContext globalContext, Ignore Ignore,
                                      [NotNull] TransformOptions transformOptions, [NotNull][ItemNotNull] IEnumerable <Dependency> dependencies,
                                      [NotNull] List <Dependency> transformedDependencies)
        {
            var dependenciesOnCycles = new HashSet <Dependency>();
            Action <int, Stack <Dependency>, string> recordNewCycleToRoot = (cycleIndex, cycle, addIndexToMarkerFormat) => dependenciesOnCycles.UnionWith(cycle);

            if (transformOptions.IndexedMarkerPrefix != null)
            {
                recordNewCycleToRoot += (cycleIndex, cycle, addIndexToMarkerFormat) => {
                    string       indexedMarker     = transformOptions.IndexedMarkerPrefix + cycleIndex.ToString(addIndexToMarkerFormat);
                    Dependency[] cycleDependencies = cycle.Reverse().ToArray();
                    cycleDependencies[0].UsingItem.MarkPathElement(indexedMarker, 0, isStart: true, isEnd: false, isMatchedByCountSymbol: false, isLoopBack: false);
                    for (var i = 0; i < cycleDependencies.Length; i++)
                    {
                        Dependency d     = cycleDependencies[i];
                        bool       isEnd = i == cycleDependencies.Length - 1;
                        d.MarkPathElement(indexedMarker, i, isStart: i == 0, isEnd: isEnd, isMatchedByCountSymbol: false, isLoopBack: isEnd);
                        // Currently no reachability counts, as no path match options are implemented
                    }
                };
            }

            var cycleFinder = new FindCycleDepsPathFinder <Dependency, Item>(dependencies, transformOptions.CycleAnchorsMatch, transformOptions.IgnoreSelfCycles,
                                                                             transformOptions.MaxCycleLength, recordNewCycleToRoot, new AbstractPathMatch <Dependency, Item> [0], // TODO: Cycles via path matches would also be a nice feature ...
                                                                             globalContext.CheckAbort);

            Log.WriteInfo($"... found {cycleFinder.FoundCycleCount} cycles");

            if (transformOptions.Effects.Contains(DependencyEffectOptions.DELETE_ACTION_MARKER))
            {
                var deps = new HashSet <Dependency>(dependencies);
                deps.ExceptWith(dependenciesOnCycles);
                transformedDependencies.AddRange(deps);
            }
            else
            {
                DependencyEffectOptions.Execute(transformOptions.Effects, dependenciesOnCycles);
                transformedDependencies.AddRange(transformOptions.KeepOnlyCycleDependencies ? dependenciesOnCycles : dependencies);
            }
            return(Program.OK_RESULT);
        }
Esempio n. 14
0
        protected override TransformOptions CreateTransformOptions([NotNull] GlobalContext globalContext,
                                                                   [CanBeNull] string transformOptionsString, Func <string, IEnumerable <Dependency> > findOtherWorkingGraph)
        {
            var transformOptions = new TransformOptions();

            DependencyMatchOptions.Parse(globalContext, transformOptionsString, globalContext.IgnoreCase, transformOptions.Matches, transformOptions.Excludes,
                                         IdempotentOption.Action((args, j) => {
                transformOptions.Idempotent = true;
                return(j);
            }),
                                         RemoveOriginalOption.Action((args, j) => {
                transformOptions.RemoveOriginal = true;
                return(j);
            }),
                                         AddMarkerOption.Action((args, j) => {
                transformOptions.MarkerToAdd = Option.ExtractRequiredOptionValue(args, ref j, "missing marker name").Trim('\'').Trim();
                return(j);
            }));

            return(transformOptions);
        }
Esempio n. 15
0
        public override int Transform([NotNull] GlobalContext globalContext, Ignore Ignore,
                                      [NotNull] TransformOptions transformOptions, [NotNull][ItemNotNull] IEnumerable <Dependency> dependencies,
                                      [NotNull] List <Dependency> transformedDependencies)
        {
            AbstractPathMatch <Dependency, Item>[] expectedPathMatchesArray = transformOptions.ExpectedPathMatches.ToArray();
            var c = new AddPathDepsTraverser <Dependency, Item>(
                transformOptions.MaxPathLength ?? 1 + expectedPathMatchesArray.Length * 2,
                transformOptions.Backwards, transformOptions.CountMatch, globalContext.CheckAbort);
            List <FromTo <Item, Dependency> > fromTos = c.Traverse(dependencies, transformOptions.PathAnchor, transformOptions.PathAnchorIsCountMatch, expectedPathMatchesArray);

            transformedDependencies.AddRange(dependencies);

            foreach (var r in fromTos)
            {
                transformedDependencies.Add(globalContext.CurrentGraph.CreateDependency(r.From, r.To, null, transformOptions.Marker ?? "", 0 /*TODO: Sum of edges????*/));
            }

            Log.WriteInfo($"... added {fromTos.Count} dependencies");

            return(Program.OK_RESULT);
        }
Esempio n. 16
0
        protected override TransformOptions CreateTransformOptions(GlobalContext globalContext,
                                                                   string transformOptionsString, Func <string, IEnumerable <Dependency> > findOtherWorkingGraph)
        {
            var options = new TransformOptions();

            options.ShowUnusedQuestionableRules = options.ShowUnusedRules = options.AddMarker = false;

            Option.Parse(globalContext, transformOptionsString,
                         ShowUnusedQuestionableRulesOption.Action((args, j) => {
                options.ShowUnusedQuestionableRules = true;
                return(j);
            }), ShowAllUnusedRulesOption.Action((args, j) => {
                options.ShowUnusedRules = true;
                return(j);
            }), AddMarkersForBadGroups.Action((args, j) => {
                options.AddMarker = true;
                return(j);
            }));

            return(options);
        }
Esempio n. 17
0
        public override int Transform([NotNull] GlobalContext globalContext, Ignore Ignore,
                                      [NotNull] TransformOptions transformOptions, [NotNull][ItemNotNull] IEnumerable <Dependency> dependencies,
                                      [NotNull] List <Dependency> transformedDependencies)
        {
            DependencyPattern idempotentPattern     = transformOptions.MarkerToAdd == null ? null : new DependencyPattern("'" + transformOptions.MarkerToAdd, globalContext.IgnoreCase);
            Dictionary <FromTo, Dependency> fromTos = transformOptions.Idempotent ? FromTo.AggregateAllDependencies(globalContext.CurrentGraph, dependencies) : null;

            int added   = 0;
            int removed = 0;

            foreach (var d in dependencies)
            {
                if (!transformOptions.RemoveOriginal)
                {
                    transformedDependencies.Add(d);
                }
                else
                {
                    removed++;
                }
                if (d.IsMarkerMatch(transformOptions.Matches, transformOptions.Excludes))
                {
                    if (fromTos == null ||
                        !FromTo.ContainsMatchingDependency(fromTos, d.UsedItem, d.UsingItem, idempotentPattern))
                    {
                        var newDependency = globalContext.CurrentGraph.CreateDependency(d.UsedItem, d.UsingItem, d.Source, d.MarkerSet, d.Ct,
                                                                                        d.QuestionableCt, d.BadCt, d.NotOkReason, d.ExampleInfo);
                        if (transformOptions.MarkerToAdd != null)
                        {
                            newDependency.IncrementMarker(transformOptions.MarkerToAdd);
                        }
                        transformedDependencies.Add(newDependency);
                        added++;
                    }
                }
            }
            Log.WriteInfo($"... added {added}{(removed > 0 ? " removed " + removed : "")} dependencies");
            return(Program.OK_RESULT);
        }
Esempio n. 18
0
        public override int Transform([NotNull] GlobalContext globalContext, Ignore Ignore,
                                      [NotNull] TransformOptions transformOptions, [NotNull][ItemNotNull] IEnumerable <Dependency> dependencies,
                                      [NotNull] List <Dependency> transformedDependencies)
        {
            _transformRunCt++;
            MutableMarkerSet.AddComputedMarkerIfNoMarkers(transformOptions.MarkersToAdd,
                                                          transformOptions.FromItemMatches, transformOptions.ToItemMatches, "" + _transformRunCt);

            WorkingGraph currentWorkingGraph = globalContext.CurrentGraph;

            DependencyPattern idempotentPattern           = new DependencyPattern("'" + string.Join("+", transformOptions.MarkersToAdd), globalContext.IgnoreCase);
            Dictionary <FromTo, Dependency> checkPresence = transformOptions.Idempotent
                ? FromTo.AggregateAllDependencies(currentWorkingGraph, dependencies)
                : new Dictionary <FromTo, Dependency>();
            Dictionary <Item, Dependency[]> outgoing = Item.CollectOutgoingDependenciesMap(dependencies);
            IEnumerable <Item> matchingFroms         = outgoing.Keys.Where(i => IsMatch(transformOptions.FromItemMatches, i));

            Dictionary <string, int> markersToAddAsDictionary = transformOptions.MarkersToAdd.Distinct().ToDictionary(s => s, s => 1);

            var result = new List <Dependency>();

            foreach (var from in matchingFroms)
            {
                RecursivelyFlood(from, from, new HashSet <Item> {
                    from
                }, checkPresence, idempotentPattern, outgoing,
                                 transformOptions.ToItemMatches, transformOptions.Matches, transformOptions.Excludes,
                                 markersToAddAsDictionary, result, null, globalContext.CheckAbort,
                                 currentWorkingGraph, globalContext.IgnoreCase);
            }

            transformedDependencies.AddRange(dependencies);
            transformedDependencies.AddRange(result);
            Log.WriteInfo($"... added {result.Count} new dependencies");

            return(Program.OK_RESULT);
        }
Esempio n. 19
0
        public void Transform_WithHighVersionParam_MatchesExpected(string version, string highVer, string expected)
        {
            // Arrange
            var json = new JObject()
            {
                { "spec_version", "v1.4" },
                { "identifier", "AwesomeMod" },
                { "version", version },
            };
            ITransformer     sut  = new EpochTransformer();
            TransformOptions opts = new TransformOptions(
                1,
                string.IsNullOrEmpty(highVer)
                    ? null
                    : new ModuleVersion(highVer)
                );

            // Act
            var result          = sut.Transform(new Metadata(json), opts).First();
            var transformedJson = result.Json();

            // Assert
            Assert.AreEqual(expected, (string)transformedJson["version"]);
        }
Esempio n. 20
0
 public SimpleSpectrumGener(ISignal origin, TransformOptions opts)
 {
     analyzer = new SimpleAnalyzer(origin);
     Options  = opts;
 }
Esempio n. 21
0
        private SendMessageBatchRequestEntry inflationMessage(Metadata ckan, Metadata netkan, TransformOptions opts, bool success, string err = null)
        {
            bool   staged        = netkan.Staged || opts.Staged;
            string stagingReason =
                !string.IsNullOrEmpty(netkan.StagingReason) ? netkan.StagingReason
                : !string.IsNullOrEmpty(opts.StagingReason)   ? opts.StagingReason
                : null;
            var attribs = new Dictionary <string, MessageAttributeValue>()
            {
                {
                    "ModIdentifier",
                    new MessageAttributeValue()
                    {
                        DataType    = "String",
                        StringValue = netkan.Identifier
                    }
                },
                {
                    "Staged",
                    new MessageAttributeValue()
                    {
                        DataType    = "String",
                        StringValue = staged.ToString()
                    }
                },
                {
                    "Success",
                    new MessageAttributeValue()
                    {
                        DataType    = "String",
                        StringValue = success.ToString()
                    }
                },
                {
                    "CheckTime",
                    new MessageAttributeValue()
                    {
                        DataType    = "String",
                        StringValue = DateTime.UtcNow.ToString("s", CultureInfo.InvariantCulture)
                    }
                }
            };

            if (ckan != null)
            {
                attribs.Add(
                    "FileName",
                    new MessageAttributeValue()
                {
                    DataType    = "String",
                    StringValue = Program.CkanFileName(ckan)
                }
                    );
            }
            if (!string.IsNullOrEmpty(err))
            {
                attribs.Add(
                    "ErrorMessage",
                    new MessageAttributeValue()
                {
                    DataType    = "String",
                    StringValue = err
                }
                    );
            }
            if (warningAppender.Warnings.Any())
            {
                attribs.Add(
                    "WarningMessages",
                    new MessageAttributeValue()
                {
                    DataType    = "String",
                    StringValue = string.Join("\r\n", warningAppender.Warnings),
                }
                    );
                warningAppender.Warnings.Clear();
            }
            if (staged && stagingReason != null)
            {
                attribs.Add(
                    "StagingReason",
                    new MessageAttributeValue()
                {
                    DataType    = "String",
                    StringValue = stagingReason,
                }
                    );
            }
            return(new SendMessageBatchRequestEntry()
            {
                Id = (responseId++).ToString(),
                MessageGroupId = "1",
                MessageDeduplicationId = Path.GetRandomFileName(),
                MessageBody = serializeCkan(ckan),
                MessageAttributes = attribs,
            });
        }
Esempio n. 22
0
 public void SwitchOptions(TransformOptions newOptions)
 {
     generator.SwitchOptions(newOptions);
 }
Esempio n. 23
0
        public override int Transform([NotNull] GlobalContext globalContext, Ignore Ignore,
                                      [NotNull] TransformOptions transformOptions, [NotNull][ItemNotNull] IEnumerable <Dependency> dependencies,
                                      [NotNull] List <Dependency> transformedDependencies)
        {
            var items       = new HashSet <Item>(dependencies.SelectMany(d => new[] { d.UsingItem, d.UsedItem }));
            var sourceItems = new List <Item>(items.Where(i => transformOptions.SourceMatches.Any(m => m.Matches(i).Success)));
            var targetItems = new HashSet <Item>(items.Where(i => transformOptions.TargetMatches.Any(m => m.Matches(i).Success)));

            if (!sourceItems.Any())
            {
                throw new ApplicationException("No source items found - minimal cut cannot be computed");
            }
            else if (!targetItems.Any())
            {
                throw new ApplicationException("No target items found - minimal cut cannot be computed");
            }
            else if (targetItems.Overlaps(sourceItems))
            {
                throw new ApplicationException("Source and target items overlap - minimal cut cannot be computed");
            }

            // According to the "Max-flow min-cut theorem" (see e.g.
            // http://www.cs.princeton.edu/courses/archive/spr04/cos226/lectures/maxflow.4up.pdf,
            // http://web.stanford.edu/class/cs97si/08-network-flow-problems.pdf,
            // https://en.wikipedia.org/wiki/Max-flow_min-cut_theorem), we first find the maximum
            // flow; then the residual graph; and from this the minimal cut.

            // Find maximal flow from sources to targets via the Ford-Fulkerson algorithm - see e.g.
            // http://www.cs.princeton.edu/courses/archive/spr04/cos226/lectures/maxflow.4up.pdf;
            Dictionary <Dependency, EdgeWithFlow> edges = dependencies.ToDictionary(d => d,
                                                                                    d => new EdgeWithFlow(d, transformOptions.WeightForCut));

            Dictionary <Item, List <EdgeWithFlow> > outgoing = Item.CollectMap(dependencies, d => d.UsingItem, d => edges[d]);

            SortByFallingCapacity(outgoing);

            Dictionary <Item, List <EdgeWithFlow> > incoming = Item.CollectMap(dependencies, d => d.UsedItem, d => edges[d]);

            SortByFallingCapacity(incoming);

            bool flowIncreased;

            do
            {
                flowIncreased = false;
                foreach (var i in sourceItems)
                {
                    int increase = IncreaseFlow(i, int.MaxValue, new HashSet <Item> {
                        i
                    }, outgoing, incoming, targetItems);
                    flowIncreased |= increase > 0;
                }
            } while (flowIncreased);

            // Find residual graph (only on sources side)
            var reachableFromSources = new HashSet <Item>(sourceItems);

            foreach (var i in sourceItems)
            {
                AddReachableInResidualGraph(i, reachableFromSources, outgoing, incoming);
            }

            // Find minimal cut and add markers
            foreach (var s in reachableFromSources)
            {
                if (transformOptions.MarkerToAddToSourceSide != null)
                {
                    s.IncrementMarker(transformOptions.MarkerToAddToSourceSide);
                }
                foreach (var d in GetList(outgoing, s).Where(e => !reachableFromSources.Contains(e.UsedItem)))
                {
                    d.Dependency.IncrementMarker(transformOptions.MarkerToAddToCut);
                }
            }

            transformedDependencies.AddRange(dependencies);

            return(Program.OK_RESULT);
        }
Esempio n. 24
0
 public TransformViewOptions(TransformOptions state)
 {
     Options = state;
 }
Esempio n. 25
0
 public TransformBuilder(TransformOptions options, dynamic expando)
 {
     _expando = expando;
     _options = options;
 }
Esempio n. 26
0
        public async void ImageButton_Click(object sender, RoutedEventArgs e)
        {
            Parser       parser      = new Parser();
            GraphObject  graphObject = parser.ParseFile(filePath);
            List <Pixel> pixels      = new List <Pixel>();

            if (!isApplyOptions)
            {
                double      value            = 5 * Math.PI / 180;
                GraphObject graphObject_copy = (GraphObject)graphObject.Clone();

                Matrix4x4 result;
                foreach (Group group in graphObject.Groups)
                {
                    while (value < 10000)
                    {
                        WriteableBitmap source = new WriteableBitmap(windowWidth, windowHeight, 96, 96, PixelFormats.Bgra32, null);
                        Bgr24Bitmap     bitmap = new Bgr24Bitmap(source);
                        bitmap.Source.Lock();
                        result           = GetResultMatrix(Matrix4x4.CreateTranslation(0, 0, 0), Matrix4x4.CreateRotationX(0), Matrix4x4.CreateRotationY((float)(value)), Matrix4x4.CreateRotationZ(0), Matrix4x4.CreateScale((float)scale * 2, (float)scale * 2, (float)scale * 2));
                        graphObject_copy = (GraphObject)graphObject.Clone();
                        for (int i = 0; i < graphObject_copy.Groups[0].Vertices.Count; i++)
                        {
                            Vertex  vertex       = graphObject_copy.Groups[0].Vertices[i];
                            Vector4 vector       = new Vector4(vertex.X, vertex.Y, vertex.Z, vertex.W);
                            Vector4 vectorResult = Vector4.Transform(vector, result);
                            vertex.X = vectorResult.X;
                            vertex.Y = vectorResult.Y;
                            vertex.Z = vectorResult.Z;
                            vertex.W = vectorResult.W;
                        }
                        for (int i = 0; i < graphObject_copy.Groups[0].VertexNormals.Count; i++)
                        {
                            VertexNormal vertexNormal = graphObject_copy.Groups[0].VertexNormals[i];
                            Vector3      vector       = new Vector3(vertexNormal.X, vertexNormal.Y, vertexNormal.Z);
                            Vector3      vectorResult = Vector3.Normalize(Vector3.TransformNormal(vector, result));
                            vertexNormal.X = vectorResult.X;
                            vertexNormal.Y = vectorResult.Y;
                            vertexNormal.Z = vectorResult.Z;
                        }
                        pixels = await GetListAsync(graphObject_copy.Groups[0], maxDx, maxDy, -1, windowWidth, windowHeight, bitmap);

                        //GraphicModel.Source = PixelDrawing.GetBitmap(windowWidth, windowHeight, pixels);
                        value += 1 * Math.PI / 180;
                        GraphicModel.Source = bitmap.Source;
                        bitmap.Source.Unlock();
                    }
                }
            }
            else
            {
                TransformOptions options          = GetUserOptions(scale * 2);
                GraphObject      graphObject_copy = (GraphObject)graphObject.Clone();

                Matrix4x4 result, viewport;
                foreach (Group group in graphObject.Groups)
                {
                    WriteableBitmap source = new WriteableBitmap(windowWidth, windowHeight, 96, 96, PixelFormats.Bgra32, null);
                    Bgr24Bitmap     bitmap = new Bgr24Bitmap(source);
                    bitmap.Source.Lock();
                    result           = GetOptionsMatrix(options, windowWidth, windowHeight);
                    viewport         = GetViewPort(0, 0, windowWidth, windowHeight);
                    graphObject_copy = (GraphObject)graphObject.Clone();
                    for (int i = 0; i < graphObject_copy.Groups[0].Vertices.Count; i++)
                    {
                        Vertex  vertex       = graphObject_copy.Groups[0].Vertices[i];
                        Vector4 vector       = new Vector4(vertex.X, vertex.Y, vertex.Z, vertex.W);
                        Vector4 vectorResult = Vector4.Transform(vector, result);
                        vectorResult /= vertex.W;
                        //vectorResult = Vector4.Transform(vectorResult, viewport);
                        vertex.X = vectorResult.X;
                        vertex.Y = vectorResult.Y;
                        vertex.Z = vectorResult.Z;
                        vertex.W = vectorResult.W;
                    }
                    for (int i = 0; i < graphObject_copy.Groups[0].VertexNormals.Count; i++)
                    {
                        VertexNormal vertexNormal = graphObject_copy.Groups[0].VertexNormals[i];
                        Vector3      vector       = new Vector3(vertexNormal.X, vertexNormal.Y, vertexNormal.Z);
                        Vector3      vectorResult = Vector3.Normalize(Vector3.TransformNormal(vector, result));
                        vertexNormal.X = vectorResult.X;
                        vertexNormal.Y = vectorResult.Y;
                        vertexNormal.Z = vectorResult.Z;
                    }
                    pixels = await GetListAsync(graphObject_copy.Groups[0], maxDx, maxDy, -1, windowWidth, windowHeight, bitmap);

                    GraphicModel.Source = bitmap.Source;
                    bitmap.Source.Unlock();

                    //if (pixels != null) { GraphicModel.Source = PixelDrawing.GetBitmap(windowWidth, windowHeight, pixels); }
                }
            }
        }
Esempio n. 27
0
        private int CheckDependencies([NotNull] GlobalContext globalContext, [NotNull] TransformOptions transformOptions,
                                      [NotNull, ItemNotNull] IEnumerable <Dependency> dependencies,
                                      [CanBeNull] string containerName, [CanBeNull] DependencyRuleSet ruleSetForAssembly)
        {
            if (!dependencies.Any())
            {
                return(Program.OK_RESULT);
            }

            if (ruleSetForAssembly == null)
            {
                Log.WriteError("No rule set found for checking " + containerName);
                return(Program.NO_RULE_SET_FOUND_FOR_FILE);
            }

            DependencyRuleGroup[] checkedGroups = ruleSetForAssembly.GetAllDependencyGroupsWithRules(globalContext.IgnoreCase).ToArray();
            if (checkedGroups.Any())
            {
                int badCount          = 0;
                int questionableCount = 0;

                foreach (var group in checkedGroups)
                {
                    int matchCount = group.Check(dependencies, transformOptions.AddMarker, ref badCount, ref questionableCount);

                    if (!_matchesByGroup.ContainsKey(group.GroupName))
                    {
                        _matchesByGroup[group.GroupName] = matchCount;
                    }
                    else
                    {
                        _matchesByGroup[group.GroupName] += matchCount;
                    }
                }
                _allCheckedGroups.UnionWith(checkedGroups);

                if (Log.IsVerboseEnabled)
                {
                    string msg =
                        $"{containerName}: {badCount} bad dependencies, {questionableCount} questionable dependecies";
                    if (badCount > 0)
                    {
                        Log.WriteError(msg);
                    }
                    else if (questionableCount > 0)
                    {
                        Log.WriteWarning(msg);
                    }
                }

                _allFilesCt++;
                if (badCount > 0)
                {
                    return(Program.DEPENDENCIES_NOT_OK);
                }
                else
                {
                    _okFilesCt++;
                    return(Program.OK_RESULT);
                }
            }
            else
            {
                Log.WriteInfo("No rule groups found for " + containerName + " - no dependency checking is done for its dependencies");
                return(Program.NO_RULE_GROUPS_FOUND);
            }
        }
Esempio n. 28
0
        public override int TransformContainer([NotNull] GlobalContext globalContext,
                                               [NotNull] ConfigureOptions configureOptions, [NotNull] TransformOptions transformOptions,
                                               [NotNull, ItemNotNull] IEnumerable <Dependency> dependencies, [CanBeNull] string containerName,
                                               [NotNull] List <Dependency> transformedDependencies)
        {
            transformedDependencies.AddRange(dependencies);

            var fullRuleFileNames = new List <string>();

            foreach (var root in configureOptions.SearchRootsForRuleFiles)
            {
                try {
                    fullRuleFileNames.AddRange(
                        root.GetFiles(Path.GetFileName(containerName) + configureOptions.RuleFileExtension,
                                      SearchOption.AllDirectories).Select(fi => fi.FullName));
                } catch (IOException ex) {
                    Log.WriteWarning($"Cannot access files in {root} ({ex.Message})");
                }
            }

            fullRuleFileNames = fullRuleFileNames.Distinct().ToList();

            if (!fullRuleFileNames.Any() && containerName != null)
            {
                fullRuleFileNames = new List <string> {
                    Path.GetFullPath(containerName) + configureOptions.RuleFileExtension
                };
            }

            DependencyRuleSet ruleSetForAssembly;

            if (fullRuleFileNames.Count > 1)
            {
                string allFilenames = string.Join(", ", fullRuleFileNames.Select(fi => $"'{fi}'"));
                throw new ApplicationException(
                          $"More than one dependency rule file found for input file {containerName}" +
                          $"{InAndBelow(configureOptions.SearchRootsForRuleFiles)}: {allFilenames}");
            }
            else if (!fullRuleFileNames.Any())
            {
                ruleSetForAssembly = null;
            }
            else
            {
                string fullRuleFileName = fullRuleFileNames[0];
                ruleSetForAssembly = File.Exists(fullRuleFileName)
                    ? GetOrReadChildConfiguration(globalContext, () => new StreamReader(fullRuleFileName),
                                                  fullRuleFileName, globalContext.IgnoreCase, "...", forceReload: false, localVars: configureOptions.LocalVars)
                    : null;
            }

            // Nothing found - we take the default set.
            if (ruleSetForAssembly == null)
            {
                if (configureOptions.DefaultRuleSet == null)
                {
                    throw new ApplicationException(
                              $"No dependency rule file found for input file {containerName}" +
                              $"{InAndBelow(configureOptions.SearchRootsForRuleFiles)}, and no default rules provided");
                }
                else
                {
                    ruleSetForAssembly = configureOptions.DefaultRuleSet;
                }
            }

            // TODO: !!!!!!!!!!!!!!!!!! How to reset all "unused counts"?
            // (a) remember counts before and check after - but how to find all checked rules???
            // (b) reset counts in all rules (that are read in)
            // (c) keep a callback list of checked rules ...

            return(CheckDependencies(globalContext, transformOptions, dependencies, containerName, ruleSetForAssembly));
        }
Esempio n. 29
0
 public ConfigTransformer(string basePath, TransformOptions options)
 {
     _basePath = basePath;
     _merger   = new XmlMerger(options);
 }
Esempio n. 30
0
 public void SwitchOptions(TransformOptions opts)
 {
     Options = opts;
 }
Esempio n. 31
0
        public override void AfterAllTransforms([NotNull] GlobalContext globalContext,
                                                [NotNull] ConfigureOptions configureOptions, [NotNull] TransformOptions transformOptions)
        {
            foreach (var kvp in _matchesByGroup.OrderBy(kvp => kvp.Key))
            {
                Log.WriteInfo($"Checked {kvp.Value} dependencies matching group {kvp.Key}");
            }

            foreach (var r in _allCheckedGroups.SelectMany(g => g.AllRules)
                     .Select(r => r.Source)
                     .Distinct()
                     .OrderBy(r => r.RuleSourceName)
                     .ThenBy(r => r.LineNo))
            {
                if (transformOptions.ShowUnusedQuestionableRules && r.IsQuestionableRule && !r.WasHit)
                {
                    Log.WriteInfo("Questionable rule " + r + " was never matched - maybe you can remove it!");
                }
                else if (transformOptions.ShowUnusedRules && !r.WasHit)
                {
                    Log.WriteInfo("Rule " + r + " was never matched - maybe you can remove it!");
                }
                else
                {
                    if (Log.IsChattyEnabled)
                    {
                        Log.WriteInfo("Rule " + r + " was hit " + r.HitCount + " times.");
                    }
                }
            }

            if (_allFilesCt == 1)
            {
                Log.WriteInfo(_okFilesCt == 1 ? "Input file is without violations." : "Input file has violations.");
            }
            else if (_okFilesCt == _allFilesCt)
            {
                Log.WriteInfo($"All {_okFilesCt} input files are without violations.");
            }
            else if (_okFilesCt == 0)
            {
                Log.WriteInfo($"All {_allFilesCt} input files have violations.");
            }
            else
            {
                Log.WriteInfo($"{_allFilesCt - _okFilesCt} input files have violations, {_okFilesCt} are without violations.");
            }
        }
Esempio n. 32
0
        public override int Transform([NotNull] GlobalContext globalContext, [NotNull] ConfigureOptions configureOptions,
                                      [NotNull] TransformOptions transformOptions, [NotNull][ItemNotNull] IEnumerable <Dependency> dependencies,
                                      [NotNull] List <Dependency> transformedDependencies)
        {
            var leftSideCache  = new Dictionary <Item, Item>();
            var rightSideCache = new Dictionary <Item, Item>();

            if (transformOptions.BackProjectionDependencies != null)
            {
                Dictionary <FromTo, Dependency> dependenciesForBackProjection = dependencies.ToDictionary(
                    d => new FromTo(d.UsingItem, d.UsedItem), d => d);

                var backProjected = new List <Dependency>();

                int missingPatternCount = 0;
                //int notBackProjected = 0;
                var localCollector = new Dictionary <FromTo, Dependency>(dependencies.Count());
                var mapItems       = new Dictionary <Item, Item>();
                int dependencyProjectCountForLogging = 0;
                foreach (var d in transformOptions.BackProjectionDependencies)
                {
                    FromTo f = ProjectDependency(globalContext.CurrentGraph, d, leftSideCache, rightSideCache, localCollector,
                                                 ++dependencyProjectCountForLogging, onMissingPattern: () => OnMissingPattern(ref missingPatternCount));

                    if (f != null)
                    {
                        Dependency projected;
                        if (dependenciesForBackProjection.TryGetValue(f, out projected))
                        {
                            //d.ResetBad(); <-- option
                            //d.ResetQuestionable(); <-- option
                            d.AggregateMarkersAndCounts(projected);
                            mapItems[d.UsedItem]  = projected.UsedItem;
                            mapItems[d.UsingItem] = projected.UsingItem;
                            backProjected.Add(d);
                        }
                        else
                        {
                            //notBackProjected++;
                        }
                    }
                }

                foreach (var kvp in mapItems)
                {
                    Item target = kvp.Key;
                    Item source = kvp.Value;
                    target.MergeWithMarkers(source.MarkerSet);
                }

                transformedDependencies.AddRange(backProjected);
            }
            else
            {
                // Forward projection
                var localCollector      = new Dictionary <FromTo, Dependency>();
                int missingPatternCount = 0;
                int dependencyProjectCountForLogging = 0;
                foreach (var d in dependencies)
                {
                    ProjectDependency(globalContext.CurrentGraph, d, leftSideCache, rightSideCache,
                                      localCollector, ++dependencyProjectCountForLogging, () => OnMissingPattern(ref missingPatternCount));
                }
                transformedDependencies.AddRange(localCollector.Values);
            }

            AfterAllTransforms();

            return(Program.OK_RESULT);
        }