public async Task <IActionResult> UpdateComment(int id, PostComment comment)
        {
            if (id != comment.Id)
            {
                return(BadRequest());
            }

            _context.Entry(comment).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            CommentWrapper commentWrapper = new CommentWrapper(comment, GetRequestedUrl());

            return(Ok(new
            {
                commentWrapper,
                updated = true
            }));
        }
        public CommentViewModel()
        {
            event_aggregator = Unity.Container.Resolve <IEventAggregator>();
            service_factory  = Unity.Container.Resolve <IServiceFactory>();

            CurrentComment = new CommentWrapper(new Comment());
            BindCommands();
        }
Пример #3
0
        public CommentViewModel()
        {
            event_aggregator = ServiceLocator.Current.GetInstance <IEventAggregator>();
            service_factory  = ServiceLocator.Current.GetInstance <IServiceFactory>();

            CurrentComment = new CommentWrapper(new Comment());
            BindCommands();
        }
Пример #4
0
        public void ParseAuthor()
        {
            string commentString = "[a:litvinov t:34] test";
            var    comment       = CommentWrapper.Parse(commentString);

            Assert.AreEqual("litvinov", comment.Author);
            commentString = "a:litvinov t:34] test";
            comment       = CommentWrapper.Parse(commentString);
            Assert.AreEqual(null, comment.Author);
        }
Пример #5
0
        public void ParseToken()
        {
            string commentString = "[a:litvinov t:34] test";
            var    comment       = CommentWrapper.Parse(commentString);

            Assert.AreEqual("34", comment.Token);
            commentString = "a:litvinov t:34] test";
            comment       = CommentWrapper.Parse(commentString);
            Assert.AreEqual(null, comment.Token);
        }
Пример #6
0
        public async Task <Result> FindAll(int speech, int page)
        {
            var result = await PaginatedList <Comment> .CreateAsync(db.comments.Where(x => x.speech == speech), page, ConstantUtil.COMMENT_PAGE_SIZE, t => t.id);

            Dictionary <string, object> map = new Dictionary <string, object>();

            map.Add("Total", result.TotalPages);
            map.Add("Current", result.PageIndex);
            map.Add("Data", CommentWrapper.WrapComment(result));

            return(ResultUtil.Success(map));
        }
Пример #7
0
        public void ParseComment()
        {
            string commentString = @"[a:litvinov t:34] test \r\n test2";
            var    comment       = CommentWrapper.Parse(commentString);

            Assert.AreEqual(@"test \r\n test2", comment.Comment);
            Assert.AreEqual("litvinov", comment.Author);
            Assert.AreEqual("34", comment.Token);
            commentString = "[a:litvinov t:34] test";
            comment       = CommentWrapper.Parse(commentString);
            Assert.AreEqual("test", comment.Comment);

            commentString = "[a:litvinov t:34] ";
            comment       = CommentWrapper.Parse(commentString);
            Assert.AreEqual("", comment.Comment);
        }
Пример #8
0
        public override async Task FinalizeGeneration(ProtocolGeneration proto)
        {
            if (proto.Protocol.Namespace.Equals("Bethesda"))
            {
                return;
            }
            bool           generate = false;
            FileGeneration fg       = new FileGeneration();

            var modObj = proto.ObjectGenerationsByID.Values.FirstOrDefault(o => o.GetObjectType() == ObjectType.Mod);

            fg.AppendLine("using System.Collections.Generic;");
            fg.AppendLine("using Mutagen.Bethesda.Plugins.Cache;");
            fg.AppendLine("using Mutagen.Bethesda.Plugins.Order;");
            fg.AppendLine("using Mutagen.Bethesda.Plugins.Order.Internals;");
            fg.AppendLine();
            using (var n = new NamespaceWrapper(fg, proto.DefaultNamespace))
            {
                using (var c = new ClassWrapper(fg, "TypeOptionSolidifierMixIns"))
                {
                    c.Static = true;
                }
                using (new BraceWrapper(fg))
                {
                    using (new RegionWrapper(fg, "Normal"))
                    {
                        foreach (var obj in proto.ObjectGenerationsByName
                                 .OrderBy(x => x.Key)
                                 .Select(x => x.Value))
                        {
                            if (!await obj.IsMajorRecord())
                            {
                                continue;
                            }

                            var topLevel = modObj.Fields.Any(x =>
                            {
                                if (x is not GroupType grup)
                                {
                                    return(false);
                                }
                                var grupTarget = grup.GetGroupTarget();
                                if (grupTarget == obj)
                                {
                                    return(true);
                                }
                                return(obj.BaseClassTrail().Any(b => b == grupTarget));
                            });
                            var topLevelStr = topLevel ? "TopLevel" : string.Empty;

                            using (var comment = new CommentWrapper(fg))
                            {
                                comment.Summary.AppendLine($"Scope a load order query to {obj.Name}");
                                comment.Parameters.GetOrAdd("listings").AppendLine("ModListings to query");
                                comment.Return.AppendLine($"A typed object to do further queries on {obj.Name}");
                            }
                            using (var args = new FunctionWrapper(fg,
                                                                  $"public static {topLevelStr}TypedLoadOrderAccess<I{proto.Protocol.Namespace}Mod, I{proto.Protocol.Namespace}ModGetter, {obj.Interface(getter: false)}, {obj.Interface(getter: true)}> {obj.Name}"))
                            {
                                args.Add($"this IEnumerable<IModListingGetter<I{proto.Protocol.Namespace}ModGetter>> listings");
                            }
                            using (new BraceWrapper(fg))
                            {
                                using (var args = new ArgsWrapper(fg,
                                                                  $"return new {topLevelStr}TypedLoadOrderAccess<I{proto.Protocol.Namespace}Mod, I{proto.Protocol.Namespace}ModGetter, {obj.Interface(getter: false)}, {obj.Interface(getter: true)}>"))
                                {
                                    args.Add($"(bool includeDeletedRecords) => listings.WinningOverrides<{obj.Interface(getter: true)}>(includeDeletedRecords: includeDeletedRecords)");
                                    args.Add($"({nameof(ILinkCache)} linkCache, bool includeDeletedRecords) => listings.WinningOverrideContexts<I{proto.Protocol.Namespace}Mod, I{proto.Protocol.Namespace}ModGetter, {obj.Interface(getter: false)}, {obj.Interface(getter: true)}>(linkCache, includeDeletedRecords: includeDeletedRecords)");
                                }
                            }
                            fg.AppendLine();

                            using (var comment = new CommentWrapper(fg))
                            {
                                comment.Summary.AppendLine($"Scope a load order query to {obj.Name}");
                                comment.Parameters.GetOrAdd("mods").AppendLine("Mods to query");
                                comment.Return.AppendLine($"A typed object to do further queries on {obj.Name}");
                            }
                            using (var args = new FunctionWrapper(fg,
                                                                  $"public static {topLevelStr}TypedLoadOrderAccess<I{proto.Protocol.Namespace}Mod, I{proto.Protocol.Namespace}ModGetter, {obj.Interface(getter: false)}, {obj.Interface(getter: true)}> {obj.Name}"))
                            {
                                args.Add($"this IEnumerable<I{proto.Protocol.Namespace}ModGetter> mods");
                            }
                            using (new BraceWrapper(fg))
                            {
                                using (var args = new ArgsWrapper(fg,
                                                                  $"return new {topLevelStr}TypedLoadOrderAccess<I{proto.Protocol.Namespace}Mod, I{proto.Protocol.Namespace}ModGetter, {obj.Interface(getter: false)}, {obj.Interface(getter: true)}>"))
                                {
                                    args.Add($"(bool includeDeletedRecords) => mods.WinningOverrides<{obj.Interface(getter: true)}>(includeDeletedRecords: includeDeletedRecords)");
                                    args.Add($"({nameof(ILinkCache)} linkCache, bool includeDeletedRecords) => mods.WinningOverrideContexts<I{proto.Protocol.Namespace}Mod, I{proto.Protocol.Namespace}ModGetter, {obj.Interface(getter: false)}, {obj.Interface(getter: true)}>(linkCache, includeDeletedRecords: includeDeletedRecords)");
                                }
                            }
                            fg.AppendLine();
                            generate = true;
                        }
                    }

                    using (new RegionWrapper(fg, "Link Interfaces"))
                    {
                        if (LinkInterfaceModule.ObjectMappings.TryGetValue(proto.Protocol, out var interfs))
                        {
                            foreach (var interf in interfs)
                            {
                                var getter = $"{interf.Key}Getter";
                                using (var comment = new CommentWrapper(fg))
                                {
                                    comment.Summary.AppendLine($"Scope a load order query to {interf.Key}");
                                    comment.Parameters.GetOrAdd("listings").AppendLine("ModListings to query");
                                    comment.Return.AppendLine($"A typed object to do further queries on {interf.Key}");
                                }
                                using (var args = new FunctionWrapper(fg,
                                                                      $"public static TypedLoadOrderAccess<I{proto.Protocol.Namespace}Mod, I{proto.Protocol.Namespace}ModGetter, {interf.Key}, {getter}> {interf.Key}"))
                                {
                                    args.Add($"this IEnumerable<IModListingGetter<I{proto.Protocol.Namespace}ModGetter>> listings");
                                }
                                using (new BraceWrapper(fg))
                                {
                                    using (var args = new ArgsWrapper(fg,
                                                                      $"return new TypedLoadOrderAccess<I{proto.Protocol.Namespace}Mod, I{proto.Protocol.Namespace}ModGetter, {interf.Key}, {getter}>"))
                                    {
                                        args.Add($"(bool includeDeletedRecords) => listings.WinningOverrides<{getter}>(includeDeletedRecords: includeDeletedRecords)");
                                        args.Add($"({nameof(ILinkCache)} linkCache, bool includeDeletedRecords) => listings.WinningOverrideContexts<I{proto.Protocol.Namespace}Mod, I{proto.Protocol.Namespace}ModGetter, {interf.Key}, {getter}>(linkCache, includeDeletedRecords: includeDeletedRecords)");
                                    }
                                }
                                fg.AppendLine();

                                using (var comment = new CommentWrapper(fg))
                                {
                                    comment.Summary.AppendLine($"Scope a load order query to {interf.Key}");
                                    comment.Parameters.GetOrAdd("mods").AppendLine("Mods to query");
                                    comment.Return.AppendLine($"A typed object to do further queries on {interf.Key}");
                                }
                                using (var args = new FunctionWrapper(fg,
                                                                      $"public static TypedLoadOrderAccess<I{proto.Protocol.Namespace}Mod, I{proto.Protocol.Namespace}ModGetter, {interf.Key}, {getter}> {interf.Key}"))
                                {
                                    args.Add($"this IEnumerable<I{proto.Protocol.Namespace}ModGetter> mods");
                                }
                                using (new BraceWrapper(fg))
                                {
                                    using (var args = new ArgsWrapper(fg,
                                                                      $"return new TypedLoadOrderAccess<I{proto.Protocol.Namespace}Mod, I{proto.Protocol.Namespace}ModGetter, {interf.Key}, {getter}>"))
                                    {
                                        args.Add($"(bool includeDeletedRecords) => mods.WinningOverrides<{getter}>(includeDeletedRecords: includeDeletedRecords)");
                                        args.Add($"({nameof(ILinkCache)} linkCache, bool includeDeletedRecords) => mods.WinningOverrideContexts<I{proto.Protocol.Namespace}Mod, I{proto.Protocol.Namespace}ModGetter, {interf.Key}, {getter}>(linkCache, includeDeletedRecords: includeDeletedRecords)");
                                    }
                                }
                                fg.AppendLine();
                            }
                        }
                    }
                }
            }

            if (!generate)
            {
                return;
            }
            var path = Path.Combine(proto.DefFileLocation.FullName, $"TypeSolidifier{Loqui.Generation.Constants.AutogeneratedMarkerString}.cs");

            fg.Generate(path);
            proto.GeneratedFiles.Add(path, ProjItemType.Compile);
        }
Пример #9
0
        public override async Task GenerateInVoid(ObjectGeneration obj, FileGeneration fg)
        {
            if (obj.GetObjectType() != ObjectType.Mod)
            {
                return;
            }
            using (new NamespaceWrapper(fg, obj.Namespace))
            {
                var objData = obj.GetObjectData();
                fg.AppendLine("public class GroupMask");
                using (new BraceWrapper(fg))
                {
                    foreach (var field in obj.IterateFields())
                    {
                        if (!(field is LoquiType loqui))
                        {
                            continue;
                        }
                        if (loqui.TargetObjectGeneration == null)
                        {
                            continue;
                        }
                        if (loqui.TargetObjectGeneration.GetObjectType() != ObjectType.Group)
                        {
                            continue;
                        }
                        fg.AppendLine($"public bool {loqui.Name};");
                    }

                    fg.AppendLine("public GroupMask()");
                    using (new BraceWrapper(fg))
                    {
                    }

                    fg.AppendLine("public GroupMask(bool defaultValue)");
                    using (new BraceWrapper(fg))
                    {
                        foreach (var field in obj.IterateFields())
                        {
                            if (!(field is LoquiType loqui))
                            {
                                continue;
                            }
                            if (loqui.TargetObjectGeneration == null)
                            {
                                continue;
                            }
                            if (loqui.TargetObjectGeneration.GetObjectType() != ObjectType.Group)
                            {
                                continue;
                            }
                            fg.AppendLine($"{loqui.Name} = defaultValue;");
                        }
                    }
                }
                fg.AppendLine();

                fg.AppendLine($"public interface I{obj.Name}DisposableGetter : {obj.Interface(getter: true, internalInterface: true)}, IModDisposeGetter");
                using (new BraceWrapper(fg))
                {
                }
                fg.AppendLine();

                if (objData.GameReleaseOptions != null)
                {
                    using (var comment = new CommentWrapper(fg))
                    {
                        comment.Summary.AppendLine($"Different game release versions a {ModName(obj)} mod can have");
                    }
                    fg.AppendLine($"public enum {ReleaseEnumName(obj)}");
                    using (new BraceWrapper(fg))
                    {
                        using (var comma = new CommaWrapper(fg))
                        {
                            foreach (var opt in objData.GameReleaseOptions)
                            {
                                comma.Add($"{opt} = {(int)opt}");
                            }
                        }
                    }
                    fg.AppendLine();

                    using (var c = new ClassWrapper(fg, $"{ReleaseEnumName(obj)}Ext"))
                    {
                        c.Static = true;
                    }
                    using (new BraceWrapper(fg))
                    {
                        using (var args = new FunctionWrapper(fg,
                                                              $"public static {nameof(GameRelease)} ToGameRelease"))
                        {
                            args.Add($"this {ReleaseEnumName(obj)} release");
                        }
                        using (new BraceWrapper(fg))
                        {
                            fg.AppendLine("return release switch");
                            using (new BraceWrapper(fg)
                            {
                                AppendSemicolon = true
                            })
                            {
                                using (var comma = new CommaWrapper(fg))
                                {
                                    foreach (var item in objData.GameReleaseOptions)
                                    {
                                        comma.Add($"{ReleaseEnumName(obj)}.{item} => {nameof(GameRelease)}.{item}");
                                    }
                                    comma.Add("_ => throw new ArgumentException()");
                                }
                            }
                        }
                        fg.AppendLine();

                        using (var args = new FunctionWrapper(fg,
                                                              $"public static {ReleaseEnumName(obj)} To{ReleaseEnumName(obj)}"))
                        {
                            args.Add($"this {nameof(GameRelease)} release");
                        }
                        using (new BraceWrapper(fg))
                        {
                            fg.AppendLine("return release switch");
                            using (new BraceWrapper(fg)
                            {
                                AppendSemicolon = true
                            })
                            {
                                using (var comma = new CommaWrapper(fg))
                                {
                                    foreach (var item in objData.GameReleaseOptions)
                                    {
                                        comma.Add($"{nameof(GameRelease)}.{item} => {ReleaseEnumName(obj)}.{item}");
                                    }
                                    comma.Add("_ => throw new ArgumentException()");
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #10
0
        public override async Task FinalizeGeneration(ProtocolGeneration proto)
        {
            await base.FinalizeGeneration(proto);

            if (proto.Protocol.Namespace == "Bethesda")
            {
                return;
            }

            bool all = proto.Protocol.Namespace == "All";

            FileGeneration fg = new FileGeneration();

            ObjectGeneration.AddAutogenerationComment(fg);
            fg.AppendLine("using Loqui;");
            fg.AppendLine("using Mutagen.Bethesda.Plugins.Records.Internals;");
            fg.AppendLine();

            using (new NamespaceWrapper(fg, proto.DefaultNamespace, fileScoped: false))
            {
                using (var comment = new CommentWrapper(fg))
                {
                    comment.Summary.AppendLine("A static class to house initialization warmup logic");
                }
                using (var c = new ClassWrapper(fg, $"Warmup{proto.Protocol.Namespace}"))
                {
                    c.Static  = true;
                    c.Partial = true;
                }
                using (new BraceWrapper(fg))
                {
                    using (var comment = new CommentWrapper(fg))
                    {
                        comment.Summary.AppendLine("Will initialize internals in a more efficient way that avoids reflection.");
                        comment.Summary.AppendLine("Not required to call, but can be used to warm up ahead of time.");
                        if (!all)
                        {
                            comment.Summary.AppendLine("<br/><br/>NOTE: Calling this warmup which is for a single game, will require you warm up");
                            comment.Summary.AppendLine("other games in the same fashion.  Use WarmupAll if you want all games to be warmed.");
                        }
                    }
                    using (var args = new FunctionWrapper(fg,
                                                          "public static void Init"))
                    {
                    }
                    using (new BraceWrapper(fg))
                    {
                        if (all)
                        {
                            using (var args = new ArgsWrapper(fg,
                                                              $"Loqui.Initialization.SpinUp"))
                            {
                                args.Add($"new ProtocolDefinition_Bethesda()");
                            }
                            foreach (var otherProto in proto.Gen.Protocols.Values
                                     .Where(p => p.DefaultNamespace.Contains("Mutagen.Bethesda"))
                                     .Where(p => !p.DefaultNamespace.Contains("Mutagen.Bethesda.Plugins.Records"))
                                     .Where(p => !object.ReferenceEquals(p, proto)))
                            {
                                fg.AppendLine($"{otherProto.DefaultNamespace}.Warmup{otherProto.Protocol.Namespace}.Init();");
                            }
                        }
                        else
                        {
                            using (var args = new ArgsWrapper(fg,
                                                              $"Loqui.Initialization.SpinUp"))
                            {
                                args.Add($"new ProtocolDefinition_Bethesda()");
                                args.Add($"new ProtocolDefinition_{proto.Protocol.Namespace}()");
                            }
                            fg.AppendLine($"LinkInterfaceMapping.AutomaticRegistration = false;");
                            using (var args = new ArgsWrapper(fg,
                                                              $"LinkInterfaceMapping.Register"))
                            {
                                args.Add($"new {proto.DefaultNamespace}.Internals.LinkInterfaceMapping()");
                            }
                            fg.AppendLine("InitCustom();");
                        }
                    }

                    fg.AppendLine("static partial void InitCustom();");
                }
            }
            var path = Path.Combine(proto.DefFileLocation.FullName, $"../Warmup{proto.Protocol.Namespace}{Loqui.Generation.Constants.AutogeneratedMarkerString}.cs");

            fg.Generate(path);
            proto.GeneratedFiles.Add(path, ProjItemType.Compile);
        }
Пример #11
0
        public override async Task FinalizeGeneration(ProtocolGeneration proto)
        {
            if (proto.Protocol.Namespace.Equals("All") ||
                proto.Protocol.Namespace.Equals("Bethesda"))
            {
                return;
            }
            FileGeneration fg = new FileGeneration();

            fg.AppendLine("using System.Collections.Generic;");
            fg.AppendLine("using Mutagen.Bethesda.Plugins.Order;");
            fg.AppendLine("using Mutagen.Bethesda.Cache.Implementations;");

            fg.AppendLine();
            using (var n = new NamespaceWrapper(fg, proto.DefaultNamespace))
            {
                var setterName = $"I{proto.Protocol.Namespace}Mod";
                var getterName = $"I{proto.Protocol.Namespace}ModGetter";
                var generic    = $"<{setterName}, {getterName}>";
                using (var c = new ClassWrapper(fg, "LinkCacheMixIns"))
                {
                    c.Static = true;
                }
                using (new BraceWrapper(fg))
                {
                    using (var comment = new CommentWrapper(fg))
                    {
                        comment.Summary.AppendLine($"Creates a Link Cache using a single mod as its link target. <br/>");
                        comment.Summary.AppendLine($"Modification of the target Mod is not safe.  Internal caches can become incorrect if ");
                        comment.Summary.AppendLine($"modifications occur on content already cached.");
                        comment.Parameters.GetOrAdd("mod").AppendLine("Mod to construct the package relative to");
                        comment.Return.AppendLine($"LinkPackage attached to given mod");
                    }
                    using (var args = new FunctionWrapper(fg,
                                                          $"public static ImmutableModLinkCache{generic} ToImmutableLinkCache"))
                    {
                        args.Add($"this {getterName} mod");
                    }
                    using (new BraceWrapper(fg))
                    {
                        fg.AppendLine($"return mod.ToImmutableLinkCache{generic}();");
                    }
                    fg.AppendLine();

                    using (var comment = new CommentWrapper(fg))
                    {
                        comment.Summary.AppendLine($"Creates a Link Cache using a single mod as its link target.  Mod is allowed to be modified afterwards, but");
                        comment.Summary.AppendLine($"this comes at a performance cost of not allowing much caching to be done.  If the mod is not expected to");
                        comment.Summary.AppendLine($"be modified afterwards, use ImmutableModLinkCache instead.<br/>");
                        comment.Parameters.GetOrAdd("mod").AppendLine("Mod to construct the package relative to");
                        comment.Return.AppendLine($"LinkPackage attached to given mod");
                    }
                    using (var args = new FunctionWrapper(fg,
                                                          $"public static MutableModLinkCache{generic} ToMutableLinkCache"))
                    {
                        args.Add($"this {getterName} mod");
                    }
                    using (new BraceWrapper(fg))
                    {
                        fg.AppendLine($"return mod.ToMutableLinkCache{generic}();");
                    }
                    fg.AppendLine();

                    using (var comment = new CommentWrapper(fg))
                    {
                        comment.Summary.AppendLine($"Creates a new linking package relative to a load order.<br/>");
                        comment.Summary.AppendLine($"Will resolve links to the highest overriding mod containing the record being sought. <br/>");
                        comment.Summary.AppendLine($"Modification of the target LoadOrder, or Mods on the LoadOrder is not safe.  Internal caches can become");
                        comment.Summary.AppendLine($"incorrect if modifications occur on content already cached.");
                        comment.Parameters.GetOrAdd("loadOrder").AppendLine("LoadOrder to construct the package relative to");
                        comment.Return.AppendLine($"LinkPackage attached to given LoadOrder");
                    }
                    using (var args = new FunctionWrapper(fg,
                                                          $"public static ImmutableLoadOrderLinkCache{generic} ToImmutableLinkCache"))
                    {
                        args.Add($"this ILoadOrderGetter<{getterName}> loadOrder");
                    }
                    using (new BraceWrapper(fg))
                    {
                        fg.AppendLine($"return loadOrder.ToImmutableLinkCache{generic}();");
                    }
                    fg.AppendLine();

                    using (var comment = new CommentWrapper(fg))
                    {
                        comment.Summary.AppendLine($"Creates a new linking package relative to a load order.<br/>");
                        comment.Summary.AppendLine($"Will resolve links to the highest overriding mod containing the record being sought. <br/>");
                        comment.Summary.AppendLine($"Modification of the target LoadOrder, or Mods on the LoadOrder is not safe.  Internal caches can become");
                        comment.Summary.AppendLine($"incorrect if modifications occur on content already cached.");
                        comment.Parameters.GetOrAdd("loadOrder").AppendLine("LoadOrder to construct the package relative to");
                        comment.Return.AppendLine($"LinkPackage attached to given LoadOrder");
                    }
                    using (var args = new FunctionWrapper(fg,
                                                          $"public static ImmutableLoadOrderLinkCache{generic} ToImmutableLinkCache"))
                    {
                        args.Add($"this ILoadOrderGetter<IModListingGetter<{getterName}>> loadOrder");
                    }
                    using (new BraceWrapper(fg))
                    {
                        fg.AppendLine($"return loadOrder.ToImmutableLinkCache{generic}();");
                    }
                    fg.AppendLine();

                    using (var comment = new CommentWrapper(fg))
                    {
                        comment.Summary.AppendLine($"Creates a new linking package relative to a load order.<br/>");
                        comment.Summary.AppendLine($"Will resolve links to the highest overriding mod containing the record being sought. <br/>");
                        comment.Summary.AppendLine($"Modification of the target LoadOrder, or Mods on the LoadOrder is not safe.  Internal caches can become");
                        comment.Summary.AppendLine($"incorrect if modifications occur on content already cached.");
                        comment.Parameters.GetOrAdd("loadOrder").AppendLine("LoadOrder to construct the package relative to");
                        comment.Return.AppendLine($"LinkPackage attached to given LoadOrder");
                    }
                    using (var args = new FunctionWrapper(fg,
                                                          $"public static ImmutableLoadOrderLinkCache{generic} ToImmutableLinkCache"))
                    {
                        args.Add($"this IEnumerable<IModListingGetter<{getterName}>> loadOrder");
                    }
                    using (new BraceWrapper(fg))
                    {
                        fg.AppendLine($"return loadOrder.ToImmutableLinkCache{generic}();");
                    }
                    fg.AppendLine();

                    using (var comment = new CommentWrapper(fg))
                    {
                        comment.Summary.AppendLine($"Creates a new linking package relative to a load order.<br/>");
                        comment.Summary.AppendLine($"Will resolve links to the highest overriding mod containing the record being sought. <br/>");
                        comment.Summary.AppendLine($"Modification of the target LoadOrder, or Mods on the LoadOrder is not safe.  Internal caches can become");
                        comment.Summary.AppendLine($"incorrect if modifications occur on content already cached.");
                        comment.Parameters.GetOrAdd("loadOrder").AppendLine("LoadOrder to construct the package relative to");
                        comment.Return.AppendLine($"LinkPackage attached to given LoadOrder");
                    }
                    using (var args = new FunctionWrapper(fg,
                                                          $"public static ImmutableLoadOrderLinkCache{generic} ToImmutableLinkCache"))
                    {
                        args.Add($"this IEnumerable<{getterName}> loadOrder");
                    }
                    using (new BraceWrapper(fg))
                    {
                        fg.AppendLine($"return loadOrder.ToImmutableLinkCache{generic}();");
                    }
                    fg.AppendLine();

                    using (var comment = new CommentWrapper(fg))
                    {
                        comment.Summary.AppendLine($"Creates a mutable load order link cache by combining an existing immutable load order cache,");
                        comment.Summary.AppendLine($"plus a set of mods to be put at the end of the load order and allow to be mutable.");
                        comment.Parameters.GetOrAdd("immutableBaseCache").AppendLine("LoadOrderCache to use as the immutable base");
                        comment.Parameters.GetOrAdd("mutableMods").AppendLine("Set of mods to place at the end of the load order, which are allowed to be modified afterwards");
                        comment.Return.AppendLine($"LinkPackage attached to given LoadOrder");
                    }
                    using (var args = new FunctionWrapper(fg,
                                                          $"public static MutableLoadOrderLinkCache{generic} ToMutableLinkCache"))
                    {
                        args.Add($"this ILoadOrderGetter<{getterName}> immutableBaseCache");
                        args.Add($"params {setterName}[] mutableMods");
                    }
                    using (new BraceWrapper(fg))
                    {
                        fg.AppendLine($"return immutableBaseCache.ToMutableLinkCache{generic}(mutableMods);");
                    }
                    fg.AppendLine();

                    using (var comment = new CommentWrapper(fg))
                    {
                        comment.Summary.AppendLine($"Creates a mutable load order link cache by combining an existing immutable load order cache,");
                        comment.Summary.AppendLine($"plus a set of mods to be put at the end of the load order and allow to be mutable.");
                        comment.Parameters.GetOrAdd("immutableBaseCache").AppendLine("LoadOrderCache to use as the immutable base");
                        comment.Parameters.GetOrAdd("mutableMods").AppendLine("Set of mods to place at the end of the load order, which are allowed to be modified afterwards");
                        comment.Return.AppendLine($"LinkPackage attached to given LoadOrder");
                    }
                    using (var args = new FunctionWrapper(fg,
                                                          $"public static MutableLoadOrderLinkCache{generic} ToMutableLinkCache"))
                    {
                        args.Add($"this ILoadOrderGetter<IModListingGetter<{getterName}>> immutableBaseCache");
                        args.Add($"params {setterName}[] mutableMods");
                    }
                    using (new BraceWrapper(fg))
                    {
                        fg.AppendLine($"return immutableBaseCache.ToMutableLinkCache{generic}(mutableMods);");
                    }
                    fg.AppendLine();

                    using (var comment = new CommentWrapper(fg))
                    {
                        comment.Summary.AppendLine($"Creates a mutable load order link cache by combining an existing immutable load order cache,");
                        comment.Summary.AppendLine($"plus a set of mods to be put at the end of the load order and allow to be mutable.");
                        comment.Parameters.GetOrAdd("immutableBaseCache").AppendLine("LoadOrderCache to use as the immutable base");
                        comment.Parameters.GetOrAdd("mutableMods").AppendLine("Set of mods to place at the end of the load order, which are allowed to be modified afterwards");
                        comment.Return.AppendLine($"LinkPackage attached to given LoadOrder");
                    }
                    using (var args = new FunctionWrapper(fg,
                                                          $"public static MutableLoadOrderLinkCache{generic} ToMutableLinkCache"))
                    {
                        args.Add($"this IEnumerable<{getterName}> immutableBaseCache");
                        args.Add($"params {setterName}[] mutableMods");
                    }
                    using (new BraceWrapper(fg))
                    {
                        fg.AppendLine($"return immutableBaseCache.ToMutableLinkCache{generic}(mutableMods);");
                    }
                    fg.AppendLine();
                }
            }

            var path = Path.Combine(proto.DefFileLocation.FullName, $"LinkCacheMixIns{Loqui.Generation.Constants.AutogeneratedMarkerString}.cs");

            fg.Generate(path);
            proto.GeneratedFiles.Add(path, ProjItemType.Compile);
        }
 private async Task getComments()
 {
     WebRequest request = WebRequest.Create("https://public-api.wordpress.com/rest/v1/sites/bellyofauthority.wordpress.com/posts/" + currentpost.ID+"/replies/");
     request.Method = "GET";
     WebResponse response = await request.GetResponseAsync();
     StreamReader reader = new StreamReader(response.GetResponseStream());
     string responsestr = reader.ReadToEnd();
     commentWrapper = JsonConvert.DeserializeObject<CommentWrapper>(responsestr);
 }
Пример #13
0
        /// <summary>
        /// Executes command
        /// </summary>
        /// <param name="parameter">
        /// Current comment
        /// <para/>
        /// An array of values :
        /// <para/>
        /// 1 — bool value. True if like, false if dislike <para/>
        /// 2 — current comments wrapper
        /// </param>
        public override void Execute(object parameter)
        {
            Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, $"Execute {nameof(LikeCommentCommand)}");

            // gets value
            bool           isLike         = System.Convert.ToBoolean((parameter as System.Array).GetValue(0));
            CommentWrapper commentWrapper = (CommentWrapper)(parameter as System.Array).GetValue(1);

            DataAccess.Entities.User user = Services.DataStorage.Instance.LoggedUser;
            CommentLike commentLike       = photoInsideViewModel.UnitOfWork.CommentLikeRepository.TryGetUserLike(commentWrapper.Comment, user);

            // suitable for likes and dislikes
            // STEPS
            // 1. if like is new -> add it
            // 2. else if there is like or dislike
            //      2.1. if click on the same button type -> remove like
            //      2.2  else if click on the opposite button type -> toggle like

            Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, isLike ? "Liking" : "Disliking");

            if (commentLike == null)// 1. add like
            {
                Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Add like");
                Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Add to data base");

                // update data base
                DataAccess.Context.UnitOfWork.Instance.CommentLikeRepository.Insert(new CommentLike
                {
                    IsLiked = isLike,
                    Comment = commentWrapper.Comment,
                    User    = user
                });

                // update view
                Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Update View");
                if (isLike)
                {
                    ++commentWrapper.LikesAmount;
                }
                else
                {
                    ++commentWrapper.DisLikesAmount;
                }
            }
            else// 2. there is a like
            {
                if (commentLike.IsLiked == isLike)// 2.1 remove like
                {
                    Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Remove like");
                    Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Update valuse in data base");

                    // updata data base
                    DataAccess.Context.UnitOfWork.Instance.CommentLikeRepository.Delete(commentLike);
                    DataAccess.Context.UnitOfWork.Instance.CommentRepository.Update(commentWrapper.Comment);

                    // update view
                    Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Update View");
                    if (isLike)
                    {
                        --commentWrapper.LikesAmount;
                    }
                    else
                    {
                        --commentWrapper.DisLikesAmount;
                    }
                }
                else// 2.2 toggle dislike to like
                {
                    Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Toggle like");
                    Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Update valuse in data base");

                    // updata database
                    commentLike.IsLiked = isLike; // toggle
                    DataAccess.Context.UnitOfWork.Instance.CommentLikeRepository.Update(commentLike);


                    // update view, toggle value
                    Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Update View");
                    if (isLike)
                    {
                        ++commentWrapper.LikesAmount;
                        --commentWrapper.DisLikesAmount;
                    }
                    else
                    {
                        --commentWrapper.LikesAmount;
                        ++commentWrapper.DisLikesAmount;
                    }
                }
            }

            // save changes to database
            Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Save changes to data base");
            DataAccess.Context.UnitOfWork.Instance.Save();
        }