// <summary>
        // Creates an instance of SelectionPath to the specified property that
        // this class knows how to interpret.
        // </summary>
        // <param name="property">Property to create a path to</param>
        // <returns>A new instance of SelectionPath to the specified property</returns>
        public SelectionPath ConstructSelectionPath(PropertyEntry property)
        {
            StringBuilder path = new StringBuilder();

            path.Append(ModelUtilities.GetCachedSubPropertyHierarchyPath(property));
            return(new SelectionPath(PathTypeId, path.ToString()));
        }
Beispiel #2
0
        public override void Process(MergeContactArgs args)
        {
            Log.Info("KickFire: ==== MERGING =====", "KickFire");

            Assert.ArgumentNotNull((object)args, "args");
            foreach (var name in args.DyingContact.Facets.Keys)
            {
                var source      = args.DyingContact.Facets[name];
                var destination = (IFacet)null;
                try
                {
                    destination = args.SurvivingContact.GetFacet <IFacet>(name);
                }
                catch (FacetNotAvailableException ex)
                {
                }

                // Check if the name of the Facet is the name of our custom Facet
                if (name.Equals(Strings.Analytics.CompanyData,
                                StringComparison.InvariantCultureIgnoreCase) && destination != null && !source.IsEmpty)
                {
                    AnalyticsHelper.DeepCopyFacet(source, destination);
                }
                else if (destination != null && destination.IsEmpty && !source.IsEmpty)
                {
                    ModelUtilities.DeepCopyFacet(source, destination);
                }
            }
        }
Beispiel #3
0
 public SqlServerModelConfigurationFactory(
     [NotNull] IRelationalAnnotationProvider extensionsProvider,
     [NotNull] CSharpUtilities cSharpUtilities,
     [NotNull] ModelUtilities modelUtilities)
     : base(extensionsProvider, cSharpUtilities, modelUtilities)
 {
 }
        public ReverseEngineeringMetadataModelProvider([NotNull] ILogger logger, [NotNull] ModelUtilities modelUtilities)
        {
            Check.NotNull(logger, nameof(logger));
            Check.NotNull(modelUtilities, nameof(modelUtilities));

            Logger         = logger;
            ModelUtilities = modelUtilities;
        }
            new Dictionary<EntityType, Dictionary<string, List<Property>>>(); // string is ConstraintId

        public SqlServerMetadataModelProvider([NotNull] IServiceProvider serviceProvider)
        {
            Check.NotNull(serviceProvider, nameof(serviceProvider));

            _logger = serviceProvider.GetRequiredService<ILogger>();
            _modelUtilities = serviceProvider.GetRequiredService<ModelUtilities>();
            _sqlServerLiteralUtilities = new SqlServerLiteralUtilities(_logger);
        }
Beispiel #6
0
            new Dictionary <EntityType, Dictionary <string, List <Property> > >(); // string is ConstraintId

        public SqlServerMetadataModelProvider([NotNull] ILogger logger, [NotNull] ModelUtilities modelUtilities)
        {
            Check.NotNull(logger, nameof(logger));
            Check.NotNull(modelUtilities, nameof(modelUtilities));

            _logger                    = logger;
            _modelUtilities            = modelUtilities;
            _sqlServerLiteralUtilities = new SqlServerLiteralUtilities(_logger);
        }
Beispiel #7
0
 public SqlServerModelConfiguration(
     [NotNull] IModel model,
     [NotNull] CustomConfiguration customConfiguration,
     [NotNull] IRelationalAnnotationProvider extensionsProvider,
     [NotNull] CSharpUtilities cSharpUtilities,
     [NotNull] ModelUtilities modelUtilities)
     : base(model, customConfiguration, extensionsProvider, cSharpUtilities, modelUtilities)
 {
 }
Beispiel #8
0
        protected virtual void VisitNavigationProperties([NotNull] ModelBuilder modelBuilder)
        {
            Check.NotNull(modelBuilder, nameof(modelBuilder));

            // TODO perf cleanup can we do this in 1 loop instead of 2?
            var model          = modelBuilder.Model;
            var modelUtilities = new ModelUtilities();


            var entityTypeToExistingIdentifiers = new Dictionary <IEntityType, List <string> >();

            foreach (var entityType in model.GetEntityTypes())
            {
                var existingIdentifiers = new List <string>();
                entityTypeToExistingIdentifiers.Add(entityType, existingIdentifiers);
                existingIdentifiers.Add(entityType.Name);
                existingIdentifiers.AddRange(
                    modelUtilities.OrderedProperties(entityType).Select(p => p.Name));
            }

            foreach (var entityType in model.GetEntityTypes())
            {
                var dependentEndExistingIdentifiers = entityTypeToExistingIdentifiers[entityType];
                foreach (var foreignKey in entityType.GetForeignKeys())
                {
                    // set up the name of the navigation property on the dependent end of the foreign key
                    var dependentEndNavigationPropertyCandidateName =
                        modelUtilities.GetDependentEndCandidateNavigationPropertyName(foreignKey);
                    var dependentEndNavigationPropertyName =
                        CSharpUtilities.Instance.GenerateCSharpIdentifier(
                            dependentEndNavigationPropertyCandidateName,
                            dependentEndExistingIdentifiers,
                            NavigationUniquifier);
                    foreignKey.Scaffolding().DependentEndNavigation = dependentEndNavigationPropertyName;
                    dependentEndExistingIdentifiers.Add(dependentEndNavigationPropertyName);

                    // set up the name of the navigation property on the principal end of the foreign key
                    var principalEndExistingIdentifiers =
                        entityTypeToExistingIdentifiers[foreignKey.PrincipalEntityType];
                    var principalEndNavigationPropertyCandidateName =
                        foreignKey.IsSelfReferencing()
                            ? string.Format(
                            CultureInfo.CurrentCulture,
                            SelfReferencingPrincipalEndNavigationNamePattern,
                            dependentEndNavigationPropertyName)
                            : modelUtilities.GetPrincipalEndCandidateNavigationPropertyName(foreignKey);
                    var principalEndNavigationPropertyName =
                        CSharpUtilities.Instance.GenerateCSharpIdentifier(
                            principalEndNavigationPropertyCandidateName,
                            principalEndExistingIdentifiers,
                            NavigationUniquifier);
                    foreignKey.Scaffolding().PrincipalEndNavigation = principalEndNavigationPropertyName;
                    principalEndExistingIdentifiers.Add(principalEndNavigationPropertyName);
                }
            }
        }
        public SqliteMetadataModelProvider(
            [NotNull] ILogger logger,
            [NotNull] ModelUtilities modelUtilities,
            [NotNull] SqliteReverseTypeMapper typeMapper)
            : base(logger, modelUtilities)
        {
            Check.NotNull(typeMapper, nameof(typeMapper));

            _typeMapper = typeMapper;
        }
        protected RelationalMetadataModelProvider([NotNull] ILoggerFactory loggerFactory,
                                                  [NotNull] ModelUtilities modelUtilities, [NotNull] CSharpUtilities cSharpUtilities)
        {
            Check.NotNull(loggerFactory, nameof(loggerFactory));
            Check.NotNull(modelUtilities, nameof(modelUtilities));

            Logger          = loggerFactory.CreateCommandsLogger();
            CSharpUtilities = cSharpUtilities;
            ModelUtilities  = modelUtilities;
        }
Beispiel #11
0
        public void correct_number_of_forecast_errors(short numberOfDays)
        {
            // Act
            var forecastErrors = ModelUtilities.GenerateTotalForecastErrors(
                _installationIds, _startDate, numberOfDays)
                                 .ToList();

            // Assert
            Assert.Equal(_installationIds.Count + 1, forecastErrors.Count);
        }
        public void GetGameFilterByDateTestsSearchDateBeforeStartDateReturnsError()
        {
            var modelUtils  = new ModelUtilities();
            var initializer = new ModelDataInitializer();
            List <GameFilter> gameFilters = initializer.InitializeGameFilters();

            var actual = modelUtils.GetGameFilterByDate(gameFilters, new DateTime(2011, 07, 4));

            Assert.AreEqual(null, actual);
        }
        public void GetGameFilterByDateTestsSearchDateEqualsEndDateReturnsCorrect()
        {
            var modelUtils  = new ModelUtilities();
            var initializer = new ModelDataInitializer();
            List <GameFilter> gameFilters = initializer.InitializeGameFilters();

            var actual = modelUtils.GetGameFilterByDate(gameFilters, new DateTime(2012, 09, 24, 23, 59, 59));

            Assert.AreEqual("Week 03", actual.GameFilterName);
        }
        private void AddDependentAndPrincipalNavigationPropertyAnnotations([NotNull] IModel codeGenModel)
        {
            Check.NotNull(codeGenModel, nameof(codeGenModel));

            var entityTypeToExistingIdentifiers = new Dictionary <IEntityType, List <string> >();

            foreach (var entityType in codeGenModel.EntityTypes)
            {
                var existingIdentifiers = new List <string>();
                entityTypeToExistingIdentifiers.Add(entityType, existingIdentifiers);
                existingIdentifiers.Add(entityType.Name);
                existingIdentifiers.AddRange(
                    ModelUtilities.OrderedProperties(entityType).Select(p => p.Name));
            }

            foreach (var entityType in codeGenModel.EntityTypes)
            {
                var dependentEndExistingIdentifiers = entityTypeToExistingIdentifiers[entityType];
                foreach (var foreignKey in entityType.GetForeignKeys().Cast <ForeignKey>())
                {
                    // set up the name of the navigation property on the dependent end of the foreign key
                    var dependentEndNavigationPropertyCandidateName =
                        ModelUtilities.GetDependentEndCandidateNavigationPropertyName(foreignKey);
                    var dependentEndNavigationPropertyName =
                        CSharpUtilities.Instance.GenerateCSharpIdentifier(
                            dependentEndNavigationPropertyCandidateName,
                            dependentEndExistingIdentifiers,
                            NavigationUniquifier);
                    foreignKey.AddAnnotation(
                        AnnotationNameDependentEndNavPropName,
                        dependentEndNavigationPropertyName);
                    dependentEndExistingIdentifiers.Add(dependentEndNavigationPropertyName);

                    // set up the name of the navigation property on the principal end of the foreign key
                    var principalEndExistingIdentifiers =
                        entityTypeToExistingIdentifiers[foreignKey.PrincipalEntityType];
                    var principalEndNavigationPropertyCandidateName =
                        foreignKey.IsSelfReferencing()
                            ? string.Format(
                            CultureInfo.CurrentCulture,
                            SelfReferencingPrincipalEndNavigationNamePattern,
                            dependentEndNavigationPropertyName)
                            : ModelUtilities.GetPrincipalEndCandidateNavigationPropertyName(foreignKey);
                    var principalEndNavigationPropertyName =
                        CSharpUtilities.Instance.GenerateCSharpIdentifier(
                            principalEndNavigationPropertyCandidateName,
                            principalEndExistingIdentifiers,
                            NavigationUniquifier);
                    foreignKey.AddAnnotation(
                        AnnotationNamePrincipalEndNavPropName,
                        principalEndNavigationPropertyName);
                    principalEndExistingIdentifiers.Add(principalEndNavigationPropertyName);
                }
            }
        }
        public virtual void AddEntityPropertiesConfiguration([NotNull] EntityConfiguration entityConfiguration)
        {
            Check.NotNull(entityConfiguration, nameof(entityConfiguration));

            foreach (var property in ModelUtilities.OrderedProperties(entityConfiguration.EntityType))
            {
                var propertyConfiguration = new PropertyConfiguration(entityConfiguration, property);
                AddPropertyConfiguration(propertyConfiguration);
                entityConfiguration.PropertyConfigurations.Add(propertyConfiguration);
            }
        }
        public void GetPlacedBetsTestsAlmostAllPlacedBetsReturnsMinCorrectly()
        {
            var modelUtils  = new ModelUtilities();
            var initializer = new ModelDataInitializer();
            List <UserGameSelection> userGameSelections = initializer.InitializeUserGameSelections();

            userGameSelections = userGameSelections.Where(ugs => ugs.UserId == 1 && ugs.GameSpreadId >= 1 && ugs.GameSpreadId <= 16).ToList();

            var actual = modelUtils.GetPlacedBets(userGameSelections);

            Assert.AreEqual(14, actual);
        }
        public void GetSpentPointsTestsAllSpentPointsReturnsMinCorrectly()
        {
            var modelUtils  = new ModelUtilities();
            var initializer = new ModelDataInitializer();
            List <UserGameSelection> userGameSelections = initializer.InitializeUserGameSelections();

            userGameSelections = userGameSelections.Where(ugs => ugs.UserId == 2 && ugs.GameSpreadId >= 17 && ugs.GameSpreadId <= 32).ToList();

            var actual = modelUtils.GetSpentPoints(userGameSelections);

            Assert.AreEqual(26, actual);
        }
        public void GetSpentPointsTests0SpentPointsReturnsCorrectly()
        {
            var modelUtils  = new ModelUtilities();
            var initializer = new ModelDataInitializer();
            List <UserGameSelection> userGameSelections = initializer.InitializeUserGameSelections();

            userGameSelections = userGameSelections.Where(ugs => ugs.UserId == -1).ToList();

            var actual = modelUtils.GetSpentPoints(userGameSelections);

            Assert.AreEqual(0, actual);
        }
        // Converts an instance of PropertyValue to its appropriate display name
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (typeof(string).IsAssignableFrom(targetType))
            {
                PropertyValue propertyValue = value as PropertyValue;
                if (propertyValue != null)
                {
                    ModelPropertyEntryBase propertyEntry = propertyValue.ParentProperty as ModelPropertyEntryBase;

                    // Figure out the value type name
                    string valueTypeName = string.Empty;
                    if (propertyEntry != null)
                    {
                        valueTypeName = propertyEntry.CommonValueType == null ? string.Empty : propertyEntry.CommonValueType.Name;
                    }
                    else
                    {
                        Debug.Fail("PropertyValueToDisplayNameConverter is being used for something other than ModelPropertyValues.  Re-evaluate the correctness of its logic.");

                        // Fallback mechanism
                        object rawPropertyValue = propertyValue.Value;
                        if (rawPropertyValue != null)
                        {
                            valueTypeName = rawPropertyValue.GetType().Name;
                        }
                    }

                    // See if there is a regular name
                    string propertyName = ModelUtilities.GetPropertyName(propertyValue);

                    if (string.IsNullOrEmpty(propertyName))
                    {
                        // Type only
                        return(string.Format(
                                   culture,
                                   Resources.PropertyEditing_CollectionItemDisplayFormatType,
                                   valueTypeName));
                    }
                    else
                    {
                        // Type and name
                        return(string.Format(
                                   culture,
                                   Resources.PropertyEditing_CollectionItemDisplayFormatTypeAndName,
                                   valueTypeName,
                                   propertyName));
                    }
                }
            }

            return(string.Empty);
        }
Beispiel #20
0
        public void correct_end_date_of_forecast_errors(short numberOfDays)
        {
            // Arrange
            var endDate = _startDate.AddDays(numberOfDays);

            // Act
            var forecastErrors = ModelUtilities.GenerateTotalForecastErrors(
                _installationIds, _startDate, numberOfDays)
                                 .ToList();

            // Assert
            Assert.Equal(endDate.ToLocalTime(), forecastErrors.Last().TillDateTime);
        }
Beispiel #21
0
        public void correct_period_of_forecast_errors()
        {
            // Arrange
            const short numberOfDays = 10;

            // Act
            var forecastErrors = ModelUtilities.GenerateTotalForecastErrors(
                _installationIds, _startDate, numberOfDays)
                                 .ToList();

            // Assert
            Assert.Equal(ForecastErrorPeriod.Total, forecastErrors[0].Period);
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <Point3d> points = new List <Point3d>();

            if (!DA.GetDataList(0, points))
            {
                return;
            }

            List <Line> lines = new List <Line>(ModelUtilities.PointsToLines(points));

            DA.SetDataList(0, lines);
        }
Beispiel #23
0
        public void returns_list_of_measurements_from_one_day()
        {
            // Arrange
            const int numberOfMeasurements = 20;

            // Act
            var measurements = ModelUtilities.GenerateMeasurements(
                _installationId, _startDate, numberOfMeasurements)
                               .ToList();

            // Assert
            Assert.Equal(numberOfMeasurements, measurements.Count);
        }
Beispiel #24
0
        public ModelConfigurationFactory(
            [NotNull] IRelationalAnnotationProvider extensionsProvider,
            [NotNull] CSharpUtilities cSharpUtilities,
            [NotNull] ModelUtilities modelUtilities)
        {
            Check.NotNull(extensionsProvider, nameof(extensionsProvider));
            Check.NotNull(cSharpUtilities, nameof(cSharpUtilities));
            Check.NotNull(modelUtilities, nameof(modelUtilities));

            ExtensionsProvider = extensionsProvider;
            CSharpUtilities    = cSharpUtilities;
            ModelUtilities     = modelUtilities;
        }
        public void GetBonusPointsTests16PlacedBetsReturnsMinRequired()
        {
            var modelUtils  = new ModelUtilities();
            var initializer = new ModelDataInitializer();
            List <UserGameSelection> userGameSelections = initializer.InitializeUserGameSelections();

            userGameSelections = userGameSelections.Where(ugs => ugs.UserId == 2 && ugs.GameSpreadId >= 17 && ugs.GameSpreadId <= 32).ToList();
            int minPointsRequired             = 6;
            int extraPointFactorPerBetOverMin = 2;

            var actual = modelUtils.GetBonusPoints(userGameSelections, minPointsRequired, extraPointFactorPerBetOverMin);

            Assert.AreEqual(26, actual);
        }
        // Get the first parent ModelItem that has a view
        internal static ModelItem GetParentModelItemWithView(ModelItem modelItem, EditingContext context, bool allowDrillIn)
        {
            if (modelItem == null || modelItem.Parent == null)
            {
                return(null);
            }

            WorkflowViewService viewService = GetViewService(context);

            return(ModelUtilities.ReverseFindFirst(modelItem.Parent, (ModelItem current) =>
            {
                return HasView(current, viewService, allowDrillIn);
            }));
        }
Beispiel #27
0
        public SqlServerMetadataModelProvider(
            [NotNull] ILoggerFactory loggerFactory,
            [NotNull] ModelUtilities modelUtilities,
            [NotNull] CSharpUtilities cSharpUtilities,
            [NotNull] IRelationalAnnotationProvider extensionsProvider,
            [NotNull] SqlServerLiteralUtilities sqlServerLiteralUtilities)
            : base(loggerFactory, modelUtilities, cSharpUtilities)
        {
            Check.NotNull(extensionsProvider, nameof(extensionsProvider));
            Check.NotNull(sqlServerLiteralUtilities, nameof(sqlServerLiteralUtilities));

            ExtensionsProvider         = extensionsProvider;
            _sqlServerLiteralUtilities = sqlServerLiteralUtilities;
        }
Beispiel #28
0
        public void correct_end_date_of_measurements_from_one_day()
        {
            // Arrange
            const int numberOfMeasurements = 24;
            var       endDate = _startDate.AddDays(1);

            // Act
            var measurements = ModelUtilities.GenerateMeasurements(
                _installationId, _startDate, numberOfMeasurements)
                               .ToList();

            // Assert
            Assert.Equal(endDate.ToLocalTime(), measurements.Last().TillDateTime);
        }
        public void correct_period_of_forecast_errors_from_one_day()
        {
            // Arrange
            const int numberOfForecastErrors = 20;

            // Act
            var forecastErrors = ModelUtilities.GenerateHourlyForecastErrors(
                _installationId,
                _startDate,
                numberOfForecastErrors)
                                 .ToList();

            // Assert
            Assert.Equal(ForecastErrorPeriod.Hour, forecastErrors[0].Period);
        }
        // <summary>
        // Stores the current ActiveEditMode for the specified property
        // </summary>
        // <param name="property">Property to key off of</param>
        // <param name="editMode">ActiveEditMode value to store</param>
        public void StoreActiveEditMode(PropertyEntry property, PropertyContainerEditMode editMode)
        {
            string path = ModelUtilities.GetCachedSubPropertyHierarchyPath(property);

            // We only care about storing the ExtendedPinned state.  Everything
            // else is transitory and shouldn't be persisted.
            //
            if (editMode == PropertyContainerEditMode.ExtendedPinned)
            {
                _expandedPropertyEditors[path] = null;
            }
            else
            {
                _expandedPropertyEditors.Remove(path);
            }
        }
        protected virtual void VisitNavigationProperties([NotNull] ModelBuilder modelBuilder)
        {
            Check.NotNull(modelBuilder, nameof(modelBuilder));

            // TODO perf cleanup can we do this in 1 loop instead of 2?
            var model = modelBuilder.Model;
            var modelUtilities = new ModelUtilities();

            var entityTypeToExistingIdentifiers = new Dictionary<IEntityType, List<string>>();
            foreach (var entityType in model.GetEntityTypes())
            {
                var existingIdentifiers = new List<string>();
                entityTypeToExistingIdentifiers.Add(entityType, existingIdentifiers);
                existingIdentifiers.Add(entityType.Name);
                existingIdentifiers.AddRange(entityType.GetProperties().Select(p => p.Name));
            }

            foreach (var entityType in model.GetEntityTypes())
            {
                var dependentEndExistingIdentifiers = entityTypeToExistingIdentifiers[entityType];
                foreach (var foreignKey in entityType.GetForeignKeys())
                {
                    // set up the name of the navigation property on the dependent end of the foreign key
                    var dependentEndNavigationPropertyCandidateName =
                        modelUtilities.GetDependentEndCandidateNavigationPropertyName(foreignKey);
                    var dependentEndNavigationPropertyName =
                        CSharpUtilities.Instance.GenerateCSharpIdentifier(
                            dependentEndNavigationPropertyCandidateName,
                            dependentEndExistingIdentifiers,
                            NavigationUniquifier);
                    foreignKey.Scaffolding().DependentEndNavigation = dependentEndNavigationPropertyName;
                    dependentEndExistingIdentifiers.Add(dependentEndNavigationPropertyName);

                    // set up the name of the navigation property on the principal end of the foreign key
                    var principalEndExistingIdentifiers =
                        entityTypeToExistingIdentifiers[foreignKey.PrincipalEntityType];
                    var principalEndNavigationPropertyCandidateName =
                        foreignKey.IsSelfReferencing()
                            ? string.Format(
                                CultureInfo.CurrentCulture,
                                SelfReferencingPrincipalEndNavigationNamePattern,
                                dependentEndNavigationPropertyName)
                            : modelUtilities.GetPrincipalEndCandidateNavigationPropertyName(
                                foreignKey, dependentEndNavigationPropertyName);
                    var principalEndNavigationPropertyName =
                        CSharpUtilities.Instance.GenerateCSharpIdentifier(
                            principalEndNavigationPropertyCandidateName,
                            principalEndExistingIdentifiers,
                            NavigationUniquifier);
                    foreignKey.Scaffolding().PrincipalEndNavigation = principalEndNavigationPropertyName;
                    principalEndExistingIdentifiers.Add(principalEndNavigationPropertyName);
                }
            }
        }