Esempio n. 1
0
            public Id <T> GetResultId <T>(
                string edgeKind,
                Func <T> vertexCreator,
                ILsifJsonWriter lsifJsonWriter,
                IdFactory idFactory
                ) where T : Vertex
            {
                lock (_edgeKindToVertexId)
                {
                    if (_edgeKindToVertexId.TryGetValue(edgeKind, out var existingId))
                    {
                        if (!existingId.HasValue)
                        {
                            throw new Exception(
                                      $"This ResultSet already has an edge of {edgeKind} as {nameof(ResultSetNeedsInformationalEdgeAdded)} was called with this edge kind."
                                      );
                        }

                        // TODO: this is a violation of the type system here, really: we're assuming that all calls to this function with the same edge kind
                        // will have the same type parameter. If that's violated, the Id returned here isn't really the right type.
                        return(new Id <T>(existingId.Value.NumericId));
                    }

                    var vertex = vertexCreator();
                    _edgeKindToVertexId.Add(edgeKind, vertex.GetId().As <T, Vertex>());

                    lsifJsonWriter.Write(vertex);
                    lsifJsonWriter.Write(Edge.Create(edgeKind, Id, vertex.GetId(), idFactory));

                    return(vertex.GetId());
                }
            }
        public void Create_WithValidData_ReturnsPersistableWaternetCreatorSettingsCollection()
        {
            // Setup
            MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(
                new TestHydraulicBoundaryLocation());
            MacroStabilityInwardsInput input = calculation.InputParameters;

            RoundedDouble normativeAssessmentLevel = RoundedDouble.NaN;

            var idFactory = new IdFactory();
            var registry  = new MacroStabilityInwardsExportRegistry();

            PersistableGeometryFactory.Create(input.SoilProfileUnderSurfaceLine, idFactory, registry);

            // Call
            IEnumerable <PersistableWaternetCreatorSettings> waternetCreatorSettingsCollection = PersistableWaternetCreatorSettingsFactory.Create(input, normativeAssessmentLevel,
                                                                                                                                                  idFactory, registry);

            // Assert
            var stages = new[]
            {
                MacroStabilityInwardsExportStageType.Daily,
                MacroStabilityInwardsExportStageType.Extreme
            };

            PersistableDataModelTestHelper.AssertWaternetCreatorSettings(input, waternetCreatorSettingsCollection, normativeAssessmentLevel, stages);
            AssertRegistry(registry, stages, waternetCreatorSettingsCollection);
        }
Esempio n. 3
0
        public void Create_WithValidData_ReturnsPersistableCalculationSettingsCollection()
        {
            // Setup
            MacroStabilityInwardsSlidingCurve slidingCurve = MacroStabilityInwardsOutputTestFactory.CreateOutput().SlidingCurve;
            var idFactory = new IdFactory();
            var registry  = new MacroStabilityInwardsExportRegistry();

            // Call
            IEnumerable <PersistableCalculationSettings> settingsCollection = PersistableCalculationSettingsFactory.Create(slidingCurve, idFactory, registry);

            // Assert
            PersistableDataModelTestHelper.AssertCalculationSettings(slidingCurve, settingsCollection);

            var stages = new[]
            {
                MacroStabilityInwardsExportStageType.Daily,
                MacroStabilityInwardsExportStageType.Extreme
            };

            Assert.AreEqual(2, registry.Settings.Count);

            for (var i = 0; i < stages.Length; i++)
            {
                Assert.AreEqual(registry.Settings[stages[i]], settingsCollection.ElementAt(i).Id);
            }
        }
Esempio n. 4
0
        public Actor(String id, String asset_name, Vector2 starting, Stage Parent)  // Basic constructor.
        {
            this.objectId = IdFactory.GetNextId();
            asset_Name    = asset_name;
            speed         = 100;
            Location      = new Vector3(starting.X, starting.Y, 0);

            parent = Parent;
            name   = id;
            learnAction(new Actionstate("Talking"));
            learnAction(new Stand());
            learnAction(new Walk());
            learnAction(new Limp());
            learnAction(new Jump());
            learnAction(new Run());
            learnAction(new UseItem());
            learnAction(new Dead());
            learnAction(new Unconcious());
            learnAction(new FallForward());
            learnAction(new StandUp());
            learnAction(new Prone());
            learnAction(new Rest());

            defaultAction = knownActions["Standing"];
            SetAction("Standing");
        }
Esempio n. 5
0
 public Moniker(string scheme, string identifier, string?kind, IdFactory idFactory)
     : base(label: "moniker", idFactory)
 {
     Scheme     = scheme;
     Identifier = identifier;
     Kind       = kind;
 }
Esempio n. 6
0
        public void Create_SoilProfileWithMultiplePreconsolidationStressesOnOneLayer_ReturnsPersistableStates()
        {
            // Setup
            MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(
                new TestHydraulicBoundaryLocation());

            calculation.InputParameters.StochasticSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D(new[]
            {
                MacroStabilityInwardsPreconsolidationStressTestFactory.CreateMacroStabilityInwardsPreconsolidationStress(new Point2D(2, 1)),
                MacroStabilityInwardsPreconsolidationStressTestFactory.CreateMacroStabilityInwardsPreconsolidationStress(new Point2D(2, 2))
            });

            IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfile = calculation.InputParameters.SoilProfileUnderSurfaceLine;

            var idFactory = new IdFactory();
            var registry  = new MacroStabilityInwardsExportRegistry();

            PersistableGeometryFactory.Create(soilProfile, idFactory, registry);

            // Call
            IEnumerable <PersistableState> states = PersistableStateFactory.Create(soilProfile, idFactory, registry);

            // Assert
            Assert.AreEqual(1, states.Count());

            PersistableState state = states.First();

            Assert.IsNotNull(state.Id);
            CollectionAssert.IsEmpty(state.StateLines);
            CollectionAssert.IsEmpty(state.StatePoints);
        }
        }                                              //percentage discount

        public ValuedCustomer(string newCustFirstName, string newCustLastName)
        {
            customerId             = IdFactory.generateNewId();
            firstName              = newCustFirstName;
            lastName               = newCustLastName;
            valuedCustomerDiscount = 10;
        }
Esempio n. 8
0
 protected ItemContainer(IItemService itemService, IdFactory idFactory, ItemTable itemTable)
 {
     ItemService = itemService;
     _idFactory  = idFactory;
     _itemTable  = itemTable;
     Items       = new List <L2Item>();
 }
Esempio n. 9
0
        public void Create_WithValidData_ReturnsPersistableStates()
        {
            // Setup
            MacroStabilityInwardsCalculationScenario   calculation           = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());
            MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D(new[]
            {
                MacroStabilityInwardsPreconsolidationStressTestFactory.CreateMacroStabilityInwardsPreconsolidationStress(new Point2D(2, 1))
            });

            IMacroStabilityInwardsSoilLayer lastLayer = stochasticSoilProfile.SoilProfile.Layers.Last();

            lastLayer.Data.UsePop = true;
            lastLayer.Data.Pop    = new VariationCoefficientLogNormalDistribution
            {
                Mean = (RoundedDouble)1,
                CoefficientOfVariation = (RoundedDouble)2
            };
            calculation.InputParameters.StochasticSoilProfile = stochasticSoilProfile;

            IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfile = calculation.InputParameters.SoilProfileUnderSurfaceLine;

            var idFactory = new IdFactory();
            var registry  = new MacroStabilityInwardsExportRegistry();

            PersistableGeometryFactory.Create(soilProfile, idFactory, registry);

            // Call
            IEnumerable <PersistableState> states = PersistableStateFactory.Create(soilProfile, idFactory, registry);

            // Assert
            PersistableDataModelTestHelper.AssertStates(soilProfile, states);
            PersistableState state = states.First();

            Assert.AreEqual(registry.States[MacroStabilityInwardsExportStageType.Daily], state.Id);
        }
Esempio n. 10
0
        public Room BinaryTreeDungeon(int i)
        {
            Room room;

            if (i == 0)
            {
                room = new Room("RS", RoomType.STARTroom, 0);
            }
            else if (i == _numberOfRooms - 1)
            {
                room     = new Room("RE", RoomType.EXITroom, 0);
                ExitRoom = room;
            }
            else
            {
                room = new Room(IdFactory.GetRoomId(), RoomType.ORDINARYroom, RoomCap());
            }
            rooms.Add(room);

            int j = 2 * i + 1;
            int k = 2 * i + 2;

            if (j < _numberOfRooms)
            {
                room.Connect(BinaryTreeDungeon(j));
            }
            if (k < _numberOfRooms)
            {
                room.Connect(BinaryTreeDungeon(k));
            }

            return(room);
        }
Esempio n. 11
0
        private Option ParseOption(XElement root)
        {
            var option = new Option();

            option.Name         = CreateName(root, OptionElement.Attrs.Name);
            option.Id           = IdFactory.CreateId(option.Name);
            option.DisplayName  = ReplaceConstants(root.TryGetAttributeValue(OptionElement.Attrs.DisplayName, OptionElement.Attrs.Defaults.DisplayName));
            option.Description  = ReplaceConstants(root.TryGetAttributeValue(OptionElement.Attrs.Description, OptionElement.Attrs.Defaults.Description));
            option.DefaultValue = ReplaceConstants(root.TryGetAttributeValue <string>(OptionElement.Attrs.DefaultValue, null));
            option.ValueType    = root.TryGetAttributeValue(OptionElement.Attrs.ValueType, OptionElement.Attrs.Defaults.ValueType);
            var optionValue = _optionValueFactory.Create(option.ValueType);

            option.Behaviour = CreateBehaviour(root, optionValue);

            var defaultValueElement = root.Elements().FirstOrDefault(o => o.Name == OptionElement.Attrs.DefaultValue);

            if (defaultValueElement != null)
            {
                if (root.IsAttributeExists(OptionElement.Attrs.DefaultValue))
                {
                    _optionSetValidator.AddError($"Option '{option.Name}' has two defaultValue's.", root);
                }

                var dataElement = defaultValueElement.Elements().First();
                if (dataElement.NodeType != XmlNodeType.CDATA)
                {
                    _optionSetValidator.AddError("DefaultValue element doesn't contains CData.", dataElement);
                }

                option.DefaultValue = dataElement.Value.Trim();
            }

            return(option);
        }
Esempio n. 12
0
        private void ParseSuggestions(XElement root, IDictionary <string, Suggestion> suggestions)
        {
            root.Elements(SuggestionElement.ElementName)
            .ForEach(element =>
            {
                var suggestionElements = CreateSuggestion(element);

                if (suggestionElements.Count != 0)
                {
                    var suggestion = new Suggestion();

                    suggestion.Name = CreateName(element, SuggestionElement.Attrs.Name);
                    suggestion.Id   = IdFactory.CreateId(suggestion.Name);

                    foreach (var kv in suggestionElements)
                    {
                        suggestion.Params.Add(kv);
                    }

                    if (KeyIsUnique(suggestion.Name, suggestions))
                    {
                        suggestions[suggestion.Name] = suggestion;
                    }
                }
            });
        }
Esempio n. 13
0
            private static void ConfigureApplicationInsights(IAppBuilder app)
            {
                Channel = new MockTelemetryChannel();

                var config = new TelemetryConfigurationBuilder()
                             .WithChannel(Channel)
                             .WithTelemetryInitializer(new OperationIdTelemetryInitializer())
                             .Build();

                DependencyTrackingTelemetryModule = new DependencyTrackingTelemetryModule();
                DependencyTrackingTelemetryModule.Initialize(config);

                app.UseApplicationInsights(
                    new RequestTrackingConfiguration
                {
                    TelemetryConfiguration         = config,
                    GetAdditionalContextProperties = async ctx =>
                    {
                        // do some async stuff
                        await Task.Delay(100).ConfigureAwait(false);
                        return(Enumerable.Empty <KeyValuePair <string, string> >());
                    }
                },
                    new OperationIdContextMiddlewareConfiguration
                {
                    OperationIdFactory = IdFactory.FromHeader(Consts.OperationIdHeaderName)
                }
                    );
            }
Esempio n. 14
0
        public void Create_WithWaternetsWithoutLines_ReturnsPersistableWaternetCollection()
        {
            // Setup
            var dailyWaternet   = new MacroStabilityInwardsWaternet(new MacroStabilityInwardsPhreaticLine[0], new MacroStabilityInwardsWaternetLine[0]);
            var extremeWaternet = new MacroStabilityInwardsWaternet(new MacroStabilityInwardsPhreaticLine[0], new MacroStabilityInwardsWaternetLine[0]);

            var idFactory = new IdFactory();
            var registry  = new MacroStabilityInwardsExportRegistry();

            // Call
            IEnumerable <PersistableWaternet> persistableWaternets = PersistableWaternetFactory.Create(dailyWaternet, extremeWaternet, new GeneralMacroStabilityInwardsInput(), idFactory, registry);

            // Assert
            PersistableDataModelTestHelper.AssertWaternets(new[]
            {
                dailyWaternet,
                extremeWaternet
            }, persistableWaternets);

            var stages = new[]
            {
                MacroStabilityInwardsExportStageType.Daily,
                MacroStabilityInwardsExportStageType.Extreme
            };

            Assert.AreEqual(2, registry.Waternets.Count);

            for (var i = 0; i < stages.Length; i++)
            {
                Assert.AreEqual(registry.Waternets[stages[i]], persistableWaternets.ElementAt(i).Id);
            }
        }
Esempio n. 15
0
        private OrderDto CreateOrderDto()
        {
            var     id        = IdFactory.Next();
            decimal unitPrice = id + 0.99m;
            var     order     = new OrderDto
            {
                Customer            = (CustomerIdentifier)_customer,
                Store               = (StoreIdentifier)_store,
                ShippingAddress     = $"{id} Main Street",
                ShippingCity        = $"{id}ville",
                ShippingProvince    = $"Distinct {id}",
                ShippingCountry     = $"{id}land",
                ShippingPostalCode  = $"zip{id}",
                CustomerPhoneNumber = $"({id}) {id}-{id}",
                TotalPrice          = 3 * unitPrice,
                LineItems           = new List <OrderLineItemDto>()
                {
                    new OrderLineItemDto {
                        Product    = (ProductIdentifier)_product,
                        UnitPrice  = unitPrice,
                        Quantity   = 2,
                        TotalPrice = 2 * unitPrice
                    }
                }
            };

            return(order);
        }
Esempio n. 16
0
 public PlayerService(IUnitOfWork unitOfWork, IItemService itemService, IdFactory idFactory, ItemTable itemTable, Config.Config config)
 {
     _unitOfWork  = unitOfWork;
     _itemService = itemService;
     _idFactory   = idFactory;
     _itemTable   = itemTable;
     _config      = config;
 }
Esempio n. 17
0
        public UsersService(IDocumentStore documentStore, IdFactory idFactory)
        {
            Guard.IsNotNull(documentStore, nameof(documentStore));
            Guard.IsNotNull(idFactory, nameof(idFactory));

            this._documentStore = documentStore;
            this._idFactory     = idFactory;
        }
Esempio n. 18
0
        public void idsAreConsecutive()
        {
            IdFactory IdFactory = new IdFactory();

            Assert.AreEqual(100, IdFactory.getNextID());
            Assert.AreEqual(101, IdFactory.getNextID());
            Assert.AreEqual(102, IdFactory.getNextID());
        }
Esempio n. 19
0
 public MenuItem(String ID)
 {
     objectId  = IdFactory.GetNextId();
     id        = ID;
     iconColor = Color.NavajoWhite;
     textColor = Color.Black;
     iconName  = "BlankIcon";
 }
Esempio n. 20
0
 public PlayerService(IPlayerRepository playerRepository, IItemService itemService, ISkillRepository skillRepository, IdFactory idFactory, ItemTable itemTable, Config.Config config)
 {
     _itemService      = itemService;
     _idFactory        = idFactory;
     _itemTable        = itemTable;
     _config           = config;
     _skillRepository  = skillRepository;
     _playerRepository = playerRepository;
 }
Esempio n. 21
0
 public MenuItem()
 {
     objectId  = IdFactory.GetNextId();
     id        = "Default ID";
     display   = "Default";
     iconColor = Color.NavajoWhite;
     textColor = Color.Black;
     iconName  = "BlankIcon";
 }
Esempio n. 22
0
 public L2Item(ICrudService <ItemContract> itemCrudService, IdFactory idFactory, ItemTemplate template, int objectId) : base(objectId)
 {
     _itemCrudService = itemCrudService;
     _idFactory       = idFactory;
     ObjectId         = objectId != 0 ? objectId : _idFactory.NextId();
     Template         = template;
     Count            = 1;
     Location         = ItemLocation.Void;
 }
Esempio n. 23
0
 public SymbolHoldingResultSetTracker(
     ILsifJsonWriter lsifJsonWriter,
     Compilation sourceCompilation,
     IdFactory idFactory
     )
 {
     _lsifJsonWriter    = lsifJsonWriter;
     _sourceCompilation = sourceCompilation;
     _idFactory         = idFactory;
 }
Esempio n. 24
0
        public Person(string name, string password, string bio, string likes, VeryDependentActions act)
        {
            actions  = act;
            Name     = name;
            Password = password;
            Bio      = bio;
            Likes    = likes;

            Id = IdFactory.GetNextId();
        }
Esempio n. 25
0
        protected ItemContainer(L2Character owner)
        {
            Owner = owner;

            _itemService     = GameServer.ServiceProvider.GetService <IItemService>();
            _itemTable       = GameServer.ServiceProvider.GetService <ItemTable>();
            _idFactory       = GameServer.ServiceProvider.GetService <IdFactory>();
            _itemCrudService = GameServer.ServiceProvider.GetService <ICrudService <ItemContract> >();

            Items = new List <L2Item>();
        }
Esempio n. 26
0
File: Item.cs Progetto: belav/roslyn
 public Item(
     Id <Vertex> outVertex,
     Id <Range> range,
     Id <LsifDocument> document,
     IdFactory idFactory,
     string?property = null
     ) : base(label: "item", outVertex, new[] { range.As <Range, Vertex>() }, idFactory)
 {
     Document = document;
     Property = property;
 }
Esempio n. 27
0
        public void Create_Always_ReturnsUniqueId()
        {
            // Setup
            var idFactory = new IdFactory();

            // Call
            string firstId  = idFactory.Create();
            string secondId = idFactory.Create();

            // Assert
            Assert.AreNotEqual(firstId, secondId);
        }
Esempio n. 28
0
        public Actor(String Id, String asset_name, Vector2 starting)  // Basic constructor.
        {
            this.objectId = IdFactory.GetNextId();
            asset_Name    = asset_name;
            speed         = 100;
            Location      = new Vector3(starting.X, starting.Y, 0);
            name          = Id;
            height        = 60;
            radius        = 60;

            currentProfile = new AIPFullRandom();
        }
Esempio n. 29
0
        /// <summary>
        /// Generates the LSIF content for a single document.
        /// </summary>
        /// <returns>The ID of the outputted Document vertex.</returns>
        /// <remarks>
        /// The high level algorithm here is we are going to walk across each token, produce a <see cref="Graph.Range"/> for that token's span,
        /// bind that token, and then link up the various features. So we'll link that range to the symbols it defines or references,
        /// will link it to results like Quick Info, and more. This method has a <paramref name="topLevelSymbolsResultSetTracker"/> that
        /// lets us link symbols across files, and will only talk about "top level" symbols that aren't things like locals that can't
        /// leak outside a file.
        /// </remarks>
        private static async Task <Id <Graph.LsifDocument> > GenerateForDocumentAsync(
            SemanticModel semanticModel,
            HostLanguageServices languageServices,
            GeneratorOptions options,
            IResultSetTracker topLevelSymbolsResultSetTracker,
            ILsifJsonWriter lsifJsonWriter,
            IdFactory idFactory)
        {
            var syntaxTree           = semanticModel.SyntaxTree;
            var sourceText           = semanticModel.SyntaxTree.GetText();
            var syntaxFactsService   = languageServices.GetRequiredService <ISyntaxFactsService>();
            var semanticFactsService = languageServices.GetRequiredService <ISemanticFactsService>();

            string?contentBase64Encoded = null;

            var uri = syntaxTree.FilePath;

            // TODO: move to checking the enum member mentioned in https://github.com/dotnet/roslyn/issues/49326 when that
            // is implemented. In the mean time, we'll use a heuristic of the path being a relative path as a way to indicate
            // this is a source generated file.
            if (!PathUtilities.IsAbsolute(syntaxTree.FilePath))
            {
                var text = semanticModel.SyntaxTree.GetText();

                // We always use UTF-8 encoding when writing out file contents, as that's expected by LSIF implementations.
                // TODO: when we move to .NET Core, is there a way to reduce allocations here?
                contentBase64Encoded = Convert.ToBase64String(Encoding.UTF8.GetBytes(text.ToString()));

                // There is a triple slash here, so the "host" portion of the URI is empty, similar to
                // how file URIs work.
                uri = "source-generated:///" + syntaxTree.FilePath.Replace('\\', '/');
            }

            var documentVertex = new Graph.LsifDocument(new Uri(uri, UriKind.RelativeOrAbsolute), GetLanguageKind(semanticModel.Language), contentBase64Encoded, idFactory);

            lsifJsonWriter.Write(documentVertex);
            lsifJsonWriter.Write(new Event(Event.EventKind.Begin, documentVertex.GetId(), idFactory));

            // As we are processing this file, we are going to encounter symbols that have a shared resultSet with other documents like types
            // or methods. We're also going to encounter locals that never leave this document. We don't want those locals being held by
            // the topLevelSymbolsResultSetTracker, so we'll make another tracker for document local symbols, and then have a delegating
            // one that picks the correct one of the two.
            var documentLocalSymbolsResultSetTracker = new SymbolHoldingResultSetTracker(lsifJsonWriter, semanticModel.Compilation, idFactory);
            var symbolResultsTracker = new DelegatingResultSetTracker(symbol =>
            {
                if (symbol.Kind is SymbolKind.Local or
                    SymbolKind.RangeVariable or
                    SymbolKind.Label)
                {
                    // These symbols can go in the document local one because they can't escape methods
                    return(documentLocalSymbolsResultSetTracker);
                }
Esempio n. 30
0
        private Group ParseGroup(XElement root)
        {
            var group = new Group();

            group.Name        = CreateName(root, GroupElement.Attrs.Name);
            group.Id          = IdFactory.CreateId(group.Name);
            group.DisplayName = ReplaceConstants(root.TryGetAttributeValue(GroupElement.Attrs.DisplayName, GroupElement.Attrs.Defaults.DisplayName));
            group.Description = ReplaceConstants(root.TryGetAttributeValue(GroupElement.Attrs.Description, GroupElement.Attrs.Defaults.Description));
            ParseGroupOptions(root, group.GroupOptions);
            ParseGroups(root, group.Groups);

            return(group);
        }