Beispiel #1
0
        public async Task Export(R4UDeck deck, IExportInfo info)
        {
            Log.Information("Serializing: {name}", deck.Name);

            /*
             * using (var db = _database())
             * {
             *  Log.Information("Replacing all foils with non-foils...");
             *  foreach (var card in deck.Ratios.Keys)
             *      if (card.IsFoil) deck.ReplaceCard(card, await db.FindNonFoil(card));
             * }
             */

            Log.Information("Creating deck.cod...");
            var cckDeck = new CockatriceDeck();

            cckDeck.DeckName      = deck.Name;
            cckDeck.Comments      = deck.Remarks;
            cckDeck.Ratios        = new CockatriceDeckRatio();
            cckDeck.Ratios.Ratios = deck.Ratios.Select(Translate).ToList();

            var resultDeck = Path.CreateDirectory(info.Destination).Combine($"{deck.Name?.AsFileNameFriendly() ?? "deck"}.cod");

            resultDeck.Open(s => _serializer.Serialize(s, cckDeck),
                            System.IO.FileMode.Create,
                            System.IO.FileAccess.Write,
                            System.IO.FileShare.ReadWrite
                            );
            Log.Information($"Saved: {resultDeck.FullPath}");
            await Task.CompletedTask;
        }
Beispiel #2
0
        public bool TryExtractExport(ICustomAttributeProvider memberInfo, out IExportInfo exportInfo)
        {
            exportInfo = null;

            foreach (CustomAttribute customAttribute in memberInfo.CustomAttributes)
            {
                if (customAttribute.Constructor.DeclaringType.FullName == DllExportAttributeFullName)
                {
                    exportInfo = new ExportInfo();
                    IExportInfo ei = exportInfo;
                    //((IExportInfoEx)exportInfo).CustomAttr = customAttribute;

                    int index = -1;
                    foreach (CustomAttributeArgument constructorArgument in customAttribute.ConstructorArguments)
                    {
                        ++index;
                        ParameterDefinition parameterDefinition = customAttribute.Constructor.Parameters[index];
                        ExportAssemblyInspector.SetParamValue(ei, parameterDefinition.ParameterType.FullName, constructorArgument.Value);
                    }
                    using (var enumerator = customAttribute.Fields.Concat <CustomAttributeNamedArgument>((IEnumerable <CustomAttributeNamedArgument>)customAttribute.Properties).Select(arg => new {
                        Name = arg.Name,
                        Value = arg.Argument.Value
                    }).Distinct().GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            var current = enumerator.Current;
                            ExportAssemblyInspector.SetFieldValue(ei, current.Name, current.Value);
                        }
                        break;
                    }
                }
            }
            return(exportInfo != null);
        }
        public async Task Export(R4UDeck deck, IExportInfo info)
        {
            Log.Information("Exporting as Deck JSON.");
            var jsonFilename = Path.CreateDirectory(info.Destination).Combine($"deck_{deck.Name.AsFileNameFriendly()}.json");

            await Export(deck, info, jsonFilename);
        }
Beispiel #4
0
    public async Task Export(WeissSchwarzDeck deck, IExportInfo info, CancellationToken cancellationToken = default)
    {
        Log.Information("Exporting as Deck JSON.");
        var report   = DeckExportProgressReport.Starting(deck.Name, ".dek Exporter");
        var progress = info.Progress;

        progress.Report(report);

        var jsonFilename   = Path.CreateDirectory(info.Destination).Combine($"deck_{deck.Name.AsFileNameFriendly()}.json");
        var simplifiedDeck = new
        {
            Name    = deck.Name,
            Remarks = deck.Remarks,
            Ratios  = deck.AsSimpleDictionary()
        };

        jsonFilename.Open(
            async s => await JsonSerializer.SerializeAsync(s, simplifiedDeck, options: _defaultOptions, cancellationToken),
            System.IO.FileMode.Create,
            System.IO.FileAccess.Write,
            System.IO.FileShare.ReadWrite
            );

        Log.Information($"Done: {jsonFilename.FullPath}");
        report = report.Done(jsonFilename.FullPath);
        progress.Report(report);

        if (!String.IsNullOrWhiteSpace(info.OutCommand))
        {
            await _focProcessor().Process(info.OutCommand, jsonFilename.FullPath, cancellationToken);
        }
    }
Beispiel #5
0
 public void AssignFrom(IExportInfo info)
 {
     if (info == null)
     {
         return;
     }
     this.CallingConvention = info.CallingConvention != (CallingConvention)0 ? info.CallingConvention : CallingConvention.StdCall;
     this.ExportName        = info.ExportName;
 }
Beispiel #6
0
        public void AssignFrom(IExportInfo info, IInputValues input)
        {
            if (info == null || String.IsNullOrWhiteSpace(input.MetaLib))
            {
                throw new ArgumentNullException("IExportInfo or path to MetaLib cannot be null.");
            }

            setDefaultValues(input);
            setUserValues(info);
        }
Beispiel #7
0
        protected void setUserValues(IExportInfo info)
        {
            if (info.CallingConvention != 0)
            {
                CallingConvention = info.CallingConvention;
            }

            if (info.ExportName != null)
            {
                ExportName = info.ExportName;
            }
        }
Beispiel #8
0
 private static void SetParamValue(IExportInfo ei, string name, object value)
 {
     if (name == null)
     {
         return;
     }
     if (name != "System.String")
     {
         if (!(name == "System.Runtime.InteropServices.CallingConvention"))
         {
             return;
         }
         ei.CallingConvention = (CallingConvention)value;
     }
     else
     {
         ei.ExportName = value.NullSafeCall <object, string>((Func <object, string>)(v => v.ToString()));
     }
 }
Beispiel #9
0
        private static void SetFieldValue(IExportInfo ei, string name, object value)
        {
            string upperInvariant = name.NullSafeToUpperInvariant();

            if (upperInvariant == null)
            {
                return;
            }
            if (upperInvariant != "NAME" && upperInvariant != "EXPORTNAME")
            {
                if (!(upperInvariant == "CALLINGCONVENTION") && !(upperInvariant == "CONVENTION"))
                {
                    return;
                }
                ei.CallingConvention = (CallingConvention)value;
            }
            else
            {
                ei.ExportName = value.NullSafeToString();
            }
        }
        public async Task Export(R4UDeck deck, IExportInfo info, Path jsonFilename)
        {
            var simplifiedDeck = new
            {
                Name    = deck.Name,
                Remarks = deck.Remarks,
                Ratios  = deck.AsSimpleDictionary()
            };

            jsonFilename.Open(
                async s => await JsonSerializer.SerializeAsync(s, simplifiedDeck, options: _defaultOptions),
                System.IO.FileMode.Create,
                System.IO.FileAccess.Write,
                System.IO.FileShare.ReadWrite
                );
            Log.Information($"Done: {jsonFilename.FullPath}");

            if (!String.IsNullOrWhiteSpace(info?.OutCommand))
            {
                await ExecuteCommandAsync(info.OutCommand, jsonFilename);
            }
        }
Beispiel #11
0
        public async Task Export(WeissSchwarzDeck deck, IExportInfo info)
        {
            Log.Information("Exporting as Deck JSON.");
            var jsonFilename   = Path.CreateDirectory(info.Destination).Combine($"deck_{deck.Name.AsFileNameFriendly()}.json");
            var simplifiedDeck = new
            {
                Name    = deck.Name,
                Remarks = deck.Remarks,
                Ratios  = deck.AsSimpleDictionary()
            };

            jsonFilename.Open(
                async s => await JsonSerializer.SerializeAsync(s, simplifiedDeck, options: _defaultOptions),
                System.IO.FileMode.Create,
                System.IO.FileAccess.Write,
                System.IO.FileShare.ReadWrite
                );
            Log.Information($"Done: {jsonFilename.FullPath}");

            if (!String.IsNullOrWhiteSpace(info.OutCommand))
            {
                await ExecuteCommandAsync(info.OutCommand, jsonFilename);
            }
        }
Beispiel #12
0
    public async Task Export(WeissSchwarzDeck deck, IExportInfo info, CancellationToken cancellationToken = default)
    {
        Log.Information("Serializing: {name}", deck.Name);
        var progress = info.Progress;
        var report   = DeckExportProgressReport.Starting(deck.Name, "Cockatrice");

        progress.Report(report);

        using (var db = _database())
        {
            Log.Information("Replacing all foils with non-foils...");
            report = report with
            {
                Percentage    = 1,
                ReportMessage = new MultiLanguageString {
                    EN = "Replacing foils with non-foils..."
                }
            };
            progress.Report(report);

            foreach (var card in deck.Ratios.Keys)
            {
                if (card.IsFoil)
                {
                    deck.ReplaceCard(card, await db.FindNonFoil(card, cancellationToken));
                }
            }
        }

        report = report with
        {
            Percentage    = 30,
            ReportMessage = new MultiLanguageString {
                EN = "Creating Deck for COD format."
            }
        };
        progress.Report(report);

        Log.Information("Creating deck.cod...");
        var cckDeck = new CockatriceDeck();

        cckDeck.DeckName      = deck.Name;
        cckDeck.Comments      = deck.Remarks;
        cckDeck.Ratios        = new CockatriceDeckRatio();
        cckDeck.Ratios.Ratios = deck.Ratios.Select(Translate).ToList();

        report = report with
        {
            Percentage    = 30,
            ReportMessage = new MultiLanguageString {
                EN = "Saving COD file..."
            }
        };
        progress.Report(report);

        var deckFilename = deck.Name?.AsFileNameFriendly();

        if (String.IsNullOrEmpty(deckFilename))
        {
            deckFilename = "deck";
        }
        var resultDeck = Path.CreateDirectory(info.Destination).Combine($"{deckFilename}.cod");
        await resultDeck.WriteAsync(s => _serializer.Serialize(s, cckDeck), cancellationToken);

        Log.Information($"Saved: {resultDeck.FullPath}");

        report = report.Done(resultDeck.FullPath);
        progress.Report(report);
    }
Beispiel #13
0
 public Task Export(R4UDeck deck, IExportInfo info)
 {
     return(Task.CompletedTask);
 }