Exemplo n.º 1
0
 public static void Update(this FeatureEntry entry, FeatureUpdateParams prms)
 {
     if (prms.Enabled.HasValue)
     {
         entry.Disabled = !prms.Enabled.Value;
     }
     if (prms.RequiredRoles != null)
     {
         entry.RequiredRoles = prms.RequiredRoles;
     }
     if (prms.Users != null)
     {
         entry.Users = prms.Users;
     }
     if (prms.Countries != null)
     {
         entry.Countries = prms.Countries;
     }
     if (prms.Continents != null)
     {
         entry.Continents = prms.Continents;
     }
     if (prms.AllowedIPs != null)
     {
         entry.AllowedIPs = prms.AllowedIPs.Select(CreyIPAddress.ParseNetwork).ToList();
     }
     if (prms.Description != null)
     {
         entry.Description = prms.Description;
     }
 }
Exemplo n.º 2
0
        public async Task <FeatureDetail> GetFeaturesbyName(string name)
        {
            if (newGates_)
            {
                var          table   = featureStore_.Value.Storage;
                FeatureEntry feature = (await table.RetrieveAsync <FeatureEntryTableEntity>(FeatureGateStore.GatePartitionKey, name)).To <FeatureEntry>();
                if (feature == null)
                {
                    throw new ItemNotFoundException($"Feature gate [{name}] not found");
                }


                return(feature.ToFeatureDetail());
            }
            else
            {
                var table   = featureStore_.Value.GatesTable;
                var feature = await table.GetRowAsync <LegacyFeatureEntry>(FeatureGateStore.GatePartitionKey, name);

                if (feature == null)
                {
                    throw new ItemNotFoundException($"Feature gate [{name}] not found");
                }

                return(feature.ToFeatureDetail());
            }
        }
Exemplo n.º 3
0
        private FeatureEntry[] LoadFeatureEntryData(string fileName)
        {
            using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                using (var reader = new BinaryReader(stream))
                {
                    var entries = reader.ReadInt16();
                    var featureEntryDataTable = new FeatureEntry[entries];
                    for (var i = 0; i < featureEntryDataTable.Length; i++)
                    {
                        var entry = new FeatureEntry();
                        entry.Index  = reader.ReadInt16();
                        entry.Flags  = reader.ReadUInt16();
                        entry.eClass = reader.ReadBytes(8);
                        entry.Value  = reader.ReadByte();
                        reader.ReadBytes(3); //padding
                        entry.Offset = new vector
                        {
                            x = reader.ReadSingle(),
                            y = reader.ReadSingle(),
                            z = reader.ReadSingle()
                        };

                        entry.Facing = reader.ReadInt16();
                        reader.ReadBytes(2); //padding
                        featureEntryDataTable[i] = entry;
                    }
                    return(featureEntryDataTable);
                }
        }
Exemplo n.º 4
0
        private void DoIgnoreNewsProviderToggle(Vector2 togglePos, FeatureEntry entry)
        {
            var ownerId = entry.def.OwningModId;
            var wasOn   = !ignoredNewsProviders.Contains(ownerId);
            var isOn    = wasOn;

            Widgets.Checkbox(togglePos, ref isOn);
            if (wasOn != isOn)
            {
                void ToggleIgnoredState()
                {
                    ignoredNewsProviders.SetIgnored(ownerId, !isOn);
                }

                if (isOn || HugsLibUtility.ShiftIsHeld)
                {
                    ToggleIgnoredState();
                }
                else
                {
                    Find.WindowStack.Add(new Dialog_Confirm("HugsLib_features_confirmIgnore".Translate(entry.def.modNameReadable),
                                                            ToggleIgnoredState, false, "HugsLib_features_confirmIgnoreTitle".Translate()));
                }
            }
            var tooltipRect = new Rect(togglePos.x, togglePos.y, Widgets.CheckboxSize, Widgets.CheckboxSize);

            TooltipHandler.TipRegion(tooltipRect, ignoreToggleTip);
        }
Exemplo n.º 5
0
 private void DrawEntryTitle(FeatureEntry entry, float width, ref float curY, bool skipDrawing)
 {
     if (!skipDrawing)
     {
         const float toggleSize = Widgets.CheckboxSize;
         var         togglePos  = new Vector2(EntryTitleLabelPadding, curY + (EntryTitleLabelHeight / 2f - toggleSize / 2f));
         DoIgnoreNewsProviderToggle(togglePos, entry);
         var labelRect = new Rect(togglePos.x + toggleSize, curY,
                                  width, EntryTitleLabelHeight).ContractedBy(EntryTitleLabelPadding);
         Text.Font = GameFont.Medium;
         var titleText = entry.def.titleOverride ?? "HugsLib_features_update".Translate(entry.def.modNameReadable, entry.def.assemblyVersion);
         Widgets.Label(labelRect, $"<size={EntryTitleFontSize}>{titleText}</size>");
         Text.Font = GameFont.Small;
         DrawEntryTitleWidgets(new Rect(0, curY, width, EntryTitleLabelHeight), entry.def);
     }
     curY += EntryTitleLabelHeight;
     if (!skipDrawing)
     {
         var color = GUI.color;
         GUI.color = TitleLineColor;
         Widgets.DrawLineHorizontal(0f, curY, width);
         GUI.color = color;
     }
     curY += EntryTitleLabelPadding;
 }
Exemplo n.º 6
0
        public async Task <FeatureDetail> CreateFeature(string name, FeatureUpdateParams prms)
        {
            var sessionInfo = idInfo_.GetSessionInfo();

            if (!sessionInfo.IsUser)
            {
                throw new AccessDeniedException($"Login required");
            }

            if (newGates_)
            {
                var entry = new FeatureEntry()
                {
                    Name     = name,
                    Issuer   = sessionInfo.AccountId,
                    Disabled = true,
                };

                entry.Update(prms);

                try
                {
                    var tableResult = await featureStore_.Value.Storage.ExecuteAsync(Microsoft.Azure.Cosmos.Table.TableOperation.Insert(entry.To <FeatureEntryTableEntity>()));

                    var newEntry = (FeatureEntryTableEntity)tableResult.Result;
                    return(newEntry.To <FeatureEntry>().ToFeatureDetail());
                }
                catch (Microsoft.Azure.Cosmos.Table.StorageException e) when(e.RequestInformation.HttpStatusCode == 409)
                {
                    throw new HttpStatusErrorException(HttpStatusCode.Conflict, $"Faild to create feature, already created");
                }
            }
            else
            {
                var entry = new LegacyFeatureEntry()
                {
                    PartitionKey = FeatureGateStore.GatePartitionKey,
                    Name         = name,
                    Issuer       = sessionInfo.AccountId,
                    Disabled     = true,
                };

                entry.Update(prms);

                try
                {
                    TableResult tableResult = await featureStore_.Value.GatesTable.Table.ExecuteAsync(TableOperation.Insert(entry));

                    var newEntry = (LegacyFeatureEntry)tableResult.Result;
                    return(newEntry.ToFeatureDetail());
                }
                catch (StorageException e) when(e.RequestInformation.HttpStatusCode == 409)
                {
                    throw new HttpStatusErrorException(HttpStatusCode.Conflict, $"Faild to create feature, already created");
                }
            }
        }
Exemplo n.º 7
0
 private static DependencyBlueprint BuildModule(Type type, FeatureEntry feature)
 {
     return(new DependencyBlueprint
     {
         Type = type,
         Feature = feature.FeatureInfo,
         Parameters = Enumerable.Empty <ShellParameter>()
     });
 }
Exemplo n.º 8
0
 private static DependencyBlueprint BuildDependency(Type type, FeatureEntry feature, ShellDescriptor descriptor)
 {
     return(new DependencyBlueprint
     {
         Type = type,
         Feature = feature.FeatureInfo,
         Parameters = descriptor.Parameters.Where(x => x.Component == type.FullName).ToArray()
     });
 }
Exemplo n.º 9
0
        protected IEnumerable <EntityEntry> HarvestClrEntityInFeature(FeatureEntry feature)
        {
            var entityTypes = feature.ExportedTypes.Where(x => this.IsEntityType(x));

            foreach (var et in entityTypes)
            {
                var entity = GetEntityInfo(feature.FeatureInfo, et);
                yield return(entity);
            }
        }
Exemplo n.º 10
0
        public async Task <FeatureDetail> UpdateFeature(string name, FeatureUpdateParams prms)
        {
            if (newGates_)
            {
                var          table = featureStore_.Value.Storage;
                FeatureEntry entry = (await table.RetrieveAsync <FeatureEntryTableEntity>(FeatureGateStore.GatePartitionKey, name)).To <FeatureEntry>();
                if (entry == null)
                {
                    throw new ItemNotFoundException($"Feature gate [{name}] not found");
                }

                entry.Update(prms);

                try
                {
                    var tableResult = await featureStore_.Value.Storage.ExecuteAsync(Microsoft.Azure.Cosmos.Table.TableOperation.Replace(entry.To <FeatureEntryTableEntity>()));

                    var newEntry = (FeatureEntryTableEntity)tableResult.Result;
                    return(newEntry.To <FeatureEntry>().ToFeatureDetail());
                }
                catch (Microsoft.Azure.Cosmos.Table.StorageException e) when(e.RequestInformation.HttpStatusCode == 409)
                {
                    throw new HttpStatusErrorException(HttpStatusCode.Conflict, $"Faild to update feature, already removed or modified");
                }
            }
            else
            {
                var table = featureStore_.Value.GatesTable;
                var entry = await table.GetRowAsync <LegacyFeatureEntry>(FeatureGateStore.GatePartitionKey, name);

                if (entry == null)
                {
                    throw new ItemNotFoundException($"Feature gate [{name}] not found");
                }

                entry.Update(prms);

                try
                {
                    TableResult tableResult = await featureStore_.Value.GatesTable.Table.ExecuteAsync(TableOperation.Replace(entry));

                    var newEntry = (LegacyFeatureEntry)tableResult.Result;
                    return(newEntry.ToFeatureDetail());
                }
                catch (StorageException e) when(e.RequestInformation.HttpStatusCode == 409)
                {
                    throw new HttpStatusErrorException(HttpStatusCode.Conflict, $"Faild to update feature, already removed or modified");
                }
            }
        }
Exemplo n.º 11
0
 public static FeatureDetail ToFeatureDetail(this FeatureEntry entry)
 {
     return(new FeatureDetail
     {
         Name = entry.Name,
         Enabled = !entry.Disabled,
         RequiredRoles = entry.RequiredRoles,
         Users = entry.Users.ToList(),
         Countries = entry.Countries,
         Continents = entry.Continents,
         AllowedIPs = entry.AllowedIPs?.Select(x => x.ToIPString()).ToList(),
         ReleaseDate = entry.ReleaseDate,
         LastModification = entry.Timestamp,
         Issuer = entry.Issuer,
         Description = entry.Description,
     });
 }
Exemplo n.º 12
0
 private void DrawEntryTitle(FeatureEntry entry, float width, ref float curY, bool skipDrawing)
 {
     if (!skipDrawing)
     {
         const float toggleSize = Widgets.CheckboxSize;
         var         togglePos  = new Vector2(EntryTitleLabelPadding, curY + (EntryTitleLabelHeight / 2f - toggleSize / 2f));
         DoIgnoreNewsProviderToggle(togglePos, entry);
         var labelRect = new Rect(togglePos.x + toggleSize, curY,
                                  width - EntryTitleLinkWidth, EntryTitleLabelHeight).ContractedBy(EntryTitleLabelPadding);
         Text.Font = GameFont.Medium;
         var titleText = entry.def.titleOverride ?? "HugsLib_features_update".Translate(entry.def.modNameReadable, entry.def.assemblyVersion);
         Widgets.Label(labelRect, string.Format("<size={0}>{1}</size>", EntryTitleFontSize, titleText));
         Text.Font = GameFont.Small;
         if (entry.def.linkUrl != null)
         {
             Text.Anchor = TextAnchor.MiddleCenter;
             var linkRect  = new Rect(width - EntryTitleLinkWidth, curY, EntryTitleLinkWidth, EntryTitleLabelHeight);
             var prevColor = GUI.color;
             GUI.color = LinkTextColor;
             Widgets.Label(linkRect, "HugsLib_features_link".Translate());
             GUI.color = prevColor;
             GenUI.ResetLabelAlign();
             if (Widgets.ButtonInvisible(linkRect, true))
             {
                 Application.OpenURL(entry.def.linkUrl);
             }
             if (Mouse.IsOver(linkRect))
             {
                 Widgets.DrawHighlight(linkRect);
                 TooltipHandler.TipRegion(linkRect, "HugsLib_features_linkDesc".Translate(entry.def.linkUrl));
             }
         }
     }
     curY += EntryTitleLabelHeight;
     if (!skipDrawing)
     {
         var color = GUI.color;
         GUI.color = TitleLineColor;
         Widgets.DrawLineHorizontal(0f, curY, width);
         GUI.color = color;
     }
     curY += EntryTitleLabelPadding;
 }
Exemplo n.º 13
0
        private void DoIgnoreNewsProviderToggle(Vector2 togglePos, FeatureEntry entry)
        {
            bool wasOn = !ignoredNewsProviders.Contains(entry.def.modIdentifier), isOn = wasOn;

            Widgets.Checkbox(togglePos, ref isOn);
            if (wasOn != isOn)
            {
                Action toggleAction = () => ignoredNewsProviders.SetIgnored(entry.def.modIdentifier, !isOn);
                if (isOn || HugsLibUtility.ShiftIsHeld)
                {
                    toggleAction();
                }
                else
                {
                    Find.WindowStack.Add(new Dialog_Confirm("HugsLib_features_confirmIgnore".Translate(entry.def.modNameReadable),
                                                            toggleAction, false, "HugsLib_features_confirmIgnoreTitle".Translate()));
                }
            }
            var tooltipRect = new Rect(togglePos.x, togglePos.y, Widgets.CheckboxSize, Widgets.CheckboxSize);

            TooltipHandler.TipRegion(tooltipRect, ignoreToggleTip);
        }