Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AssetResolver" /> class.
 /// </summary>
 /// <param name="containsLocation">The delegate used to check if an asset location is already used.</param>
 /// <param name="containsAssetWithId">The delegate used to check if an asset identifier is already used.</param>
 public AssetResolver(NamingHelper.ContainsLocationDelegate containsLocation, ContainsAssetWithIdDelegate containsAssetWithId)
 {
     ExistingIds = new HashSet<AssetId>();
     ExistingLocations = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
     ContainsLocation = containsLocation;
     ContainsAssetWithId = containsAssetWithId;
 }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AssetResolver" /> class.
 /// </summary>
 /// <param name="containsLocation">The delegate used to check if an asset location is already used.</param>
 /// <param name="containsAssetWithId">The delegate used to check if an asset identifier is already used.</param>
 public AssetResolver(NamingHelper.ContainsLocationDelegate containsLocation, ContainsAssetWithIdDelegate containsAssetWithId)
 {
     existingIds = new HashSet<Guid>();
     existingLocations = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
     ContainsLocation = containsLocation;
     ContainsAssetWithId = containsAssetWithId;
     this.containsLocation = DefaultContainsLocation;
     containsId = DefaultContainsId;
 }
 public override void Visit(AccessColumnNode node)
 {
     if (_aliases.ContainsKey(node.Alias))
     {
         base.Visit(new AccessColumnNode(NamingHelper.ToColumnName(node.Alias, node.Name), _aliases[node.Alias],
                                         node.ReturnType, TextSpan.Empty));
     }
     else
     {
         base.Visit(node);
     }
 }
        public static string DefaultScalarFieldTypeMapping(GraphQlType baseType, string valueName)
        {
            var propertyName = NamingHelper.ToPascalCase(valueName);

            if (propertyName == "From" || propertyName == "ValidFrom" || propertyName == "CreatedAt" ||
                propertyName == "To" || propertyName == "ValidTo" || propertyName == "ModifiedAt" || propertyName.EndsWith("Timestamp"))
            {
                return("DateTimeOffset?");
            }

            return("string");
        }
Пример #5
0
        public static MessageDescription CreateEmptyMessageDescription(OperationDescription operation, bool isResponse,
                                                                       MessageDirection direction, string overridingAction)
        {
            string             action = overridingAction ?? NamingHelper.GetMessageAction(operation, isResponse);
            MessageDescription result = new MessageDescription(action, direction);

            // Clear message wrapper
            result.Body.WrapperName      = null;
            result.Body.WrapperNamespace = null;

            return(result);
        }
Пример #6
0
        public static MessageDescription CreateFromMessageContract(OperationDescription operation, bool isResponse,
                                                                   MessageDirection direction, string overridingAction, Type messageContractType)
        {
            string action = overridingAction ?? NamingHelper.GetMessageAction(operation, isResponse);

            //

            TypeLoader typeLoader = new TypeLoader();

            return(typeLoader.CreateTypedMessageDescription(messageContractType, null, null,
                                                            operation.DeclaringContract.Namespace, action, direction));
        }
Пример #7
0
        public void GetUniqueName_EmptyCollection_ReturnNameBase()
        {
            // Setup
            const string nameBase = "The basic name";

            IEnumerable <ObjectWithName> existingObjects = Enumerable.Empty <ObjectWithName>();

            // Call
            string name = NamingHelper.GetUniqueName(existingObjects, nameBase, namedObject => namedObject.Name);

            // Assert
            Assert.AreEqual(nameBase, name);
        }
Пример #8
0
        public static FaultDescription CreateFaultDescription(OperationDescription operation, Type faultType, string overridingAction)
        {
            string           name        = NamingHelper.TypeName(faultType) + "Fault";
            string           action      = overridingAction ?? (NamingHelper.GetMessageAction(operation, false) + name);
            FaultDescription description = new FaultDescription(action)
            {
                Namespace  = operation.DeclaringContract.Namespace,
                DetailType = faultType
            };

            description.SetNameOnly(new System.ServiceModel.Description.XmlName(name));
            return(description);
        }
Пример #9
0
        private static void AssertMetaData(IEnumerable <HydraulicBoundaryLocationCalculation> calculations, HydraulicBoundaryLocation hydraulicBoundaryLocation,
                                           MapFeature mapFeature, double targetProbability, string displayName, List <string> presentedMetaDataItems)
        {
            string uniqueName = NamingHelper.GetUniqueName(
                presentedMetaDataItems, string.Format(displayName, ProbabilityFormattingHelper.Format(targetProbability)),
                v => v);

            MapFeaturesMetaDataTestHelper.AssertMetaData(
                GetExpectedResult(calculations, hydraulicBoundaryLocation),
                mapFeature, uniqueName);

            presentedMetaDataItems.Add(uniqueName);
        }
Пример #10
0
 protected override void Initialize(ParameterLoadingAnalysisContext context)
 {
     context.RegisterSyntaxNodeActionInNonGenerated(
         c =>
     {
         var eventDeclaration = (EventStatementSyntax)c.Node;
         if (!NamingHelper.IsRegexMatch(eventDeclaration.Identifier.ValueText, Pattern))
         {
             c.ReportDiagnosticWhenActive(Diagnostic.Create(rule, eventDeclaration.Identifier.GetLocation(), Pattern));
         }
     },
         SyntaxKind.EventStatement);
 }
Пример #11
0
        public static FaultDescription CreateFaultDescription(OperationDescription operation, Type faultType, string overridingAction)
        {
            string           name   = NamingHelper.TypeName(faultType) + TypeLoader.FaultSuffix;
            string           action = overridingAction ?? NamingHelper.GetMessageAction(operation, false) + name;
            FaultDescription result = new FaultDescription(action)
            {
                Namespace  = operation.DeclaringContract.Namespace,
                DetailType = faultType
            };

            result.SetNameOnly(new XmlName(name));
            return(result);
        }
Пример #12
0
        public static void AddMessagePartDescription(OperationDescription operation, bool isResponse,
                                                     MessageDescription message, Type type, SerializerOption serializerOption)
        {
            if (type != null)
            {
                string partName;
                string partNamespace;

                if (serializerOption == SerializerOption.DataContractSerializer)
                {
                    XmlQualifiedName xmlQualifiedName = XsdDataContractExporter.GetRootElementName(type);
                    if (xmlQualifiedName == null)
                    {
                        xmlQualifiedName = XsdDataContractExporter.GetSchemaTypeName(type);
                    }

                    if (!xmlQualifiedName.IsEmpty)
                    {
                        partName      = xmlQualifiedName.Name;
                        partNamespace = xmlQualifiedName.Namespace;
                    }
                    else
                    {
                        // For anonymous type, we assign CLR type name and contract namespace to MessagePartDescription
                        partName      = type.Name;
                        partNamespace = operation.DeclaringContract.Namespace;
                    }
                }
                else
                {
                    XmlTypeMapping xmlTypeMapping = XmlReflectionImporter.ImportTypeMapping(type);
                    partName      = xmlTypeMapping.ElementName;
                    partNamespace = xmlTypeMapping.Namespace;
                }

                MessagePartDescription messagePart = new MessagePartDescription(NamingHelper.XmlName(partName), partNamespace)
                {
                    Index = 0,
                    Type  = type

                            // We do not infer MessagePartDescription.ProtectionLevel
                };

                message.Body.Parts.Add(messagePart);
            }

            if (isResponse)
            {
                SetReturnValue(message, operation);
            }
        }
        private static string CreateParameterName(ITypeSymbol typeSymbol, SemanticModel semanticModel)
        {
            string name = NamingHelper.CreateIdentifierName(
                typeSymbol,
                firstCharToLower: true);

            if (!string.IsNullOrEmpty(name) &&
                !string.Equals(typeSymbol.Name, name, StringComparison.Ordinal))
            {
                return(name);
            }

            return(null);
        }
    /// <summary>
    /// Returns initialized <see cref="SearchServiceClient"/> based on index name "sample-dancinggoat-coffee-azure".
    /// </summary>
    private ISearchIndexClient GetSearchClient()
    {
        var indexName = NamingHelper.GetValidIndexName("sample-dancinggoat-coffee-azure");
        var indexInfo = SearchIndexInfoProvider.GetSearchIndexInfo(indexName);

        if (indexInfo == null)
        {
            return(null);
        }

        var serviveClient = new SearchServiceClient(indexInfo.IndexSearchServiceName, new SearchCredentials(indexInfo.IndexAdminKey));

        return(serviveClient.Indexes.GetClient(indexName));
    }
Пример #15
0
 protected override void Initialize(ParameterLoadingAnalysisContext context)
 {
     context.RegisterSyntaxNodeActionInNonGenerated(
         c =>
     {
         var parameterDeclaration = (ParameterSyntax)c.Node;
         if (parameterDeclaration.Identifier != null &&
             !NamingHelper.IsRegexMatch(parameterDeclaration.Identifier.Identifier.ValueText, Pattern))
         {
             c.ReportDiagnostic(Diagnostic.Create(Rule, parameterDeclaration.Identifier.Identifier.GetLocation(), Pattern));
         }
     },
         SyntaxKind.Parameter);
 }
Пример #16
0
        private static void AddWaveConditionsCalculation(WaveImpactAsphaltCoverCalculationGroupContext nodeData)
        {
            var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation
            {
                Name = NamingHelper.GetUniqueName(nodeData.WrappedData.Children,
                                                  RiskeerCommonDataResources.Calculation_DefaultName,
                                                  c => c.Name)
            };

            WaveConditionsInputHelper.SetWaterLevelType(calculation.InputParameters,
                                                        nodeData.AssessmentSection.FailureMechanismContribution.NormativeProbabilityType);
            nodeData.WrappedData.Children.Add(calculation);
            nodeData.WrappedData.NotifyObservers();
        }
Пример #17
0
        private void GenerateWrapperClassDestructors(NodeJSTypeReference classToWrapTypeReference)
        {
            Class  classToWrap            = classToWrapTypeReference.Declaration as Class;
            string classNameWrap          = NamingHelper.GenerateClassWrapName(classToWrap.Name);
            string classNameWrapperMember = NamingHelper.GenerateClassWrapperMember(classToWrap.Name);

            // Destructor for wrapped class
            PushBlock(BlockKind.Method);
            WriteLine("{0}::~{0}()", classNameWrap);
            WriteStartBraceIndent();
            WriteLine("delete {0};", classNameWrapperMember);
            WriteCloseBraceIndent();
            PopBlock(NewLineKind.BeforeNextBlock);
        }
Пример #18
0
        public void TestNamespace()
        {
            Assert.True(NamingHelper.IsValidNamespace("a"));
            Assert.True(NamingHelper.IsValidNamespace("aThisIsOk"));
            Assert.True(NamingHelper.IsValidNamespace("aThis._IsOk"));
            Assert.True(NamingHelper.IsValidNamespace("a.b.c"));

            Assert.False(NamingHelper.IsValidNamespace(""));
            Assert.False(NamingHelper.IsValidNamespace("a   . w"));
            Assert.False(NamingHelper.IsValidNamespace("a e zaThis._IsOk"));
            Assert.False(NamingHelper.IsValidNamespace("9.b.c"));
            Assert.False(NamingHelper.IsValidNamespace("a.b."));
            Assert.False(NamingHelper.IsValidNamespace(".a."));
        }
        public override void Visit(DotNode node)
        {
            if (!(node.Root is DotNode) && node.Root is AccessColumnNode column)
            {
                Nodes.Pop();
                Nodes.Pop();

                var name = $"{NamingHelper.ToColumnName(column.Alias, column.Name)}.{node.Expression.ToString()}";
                Nodes.Push(new AccessColumnNode(name, string.Empty, node.ReturnType, TextSpan.Empty));
                return;
            }

            base.Visit(node);
        }
Пример #20
0
 protected override void Initialize(ParameterLoadingAnalysisContext context)
 {
     context.RegisterSyntaxNodeActionInNonGenerated(
         c =>
     {
         var typeParameter = (TypeParameterSyntax)c.Node;
         if (!NamingHelper.IsRegexMatch(typeParameter.Identifier.ValueText, Pattern))
         {
             c.ReportDiagnostic(Diagnostic.Create(rule, typeParameter.Identifier.GetLocation(),
                                                  typeParameter.Identifier.ValueText, Pattern));
         }
     },
         SyntaxKind.TypeParameter);
 }
 private void WriteTransitionProperty(IAttribute attribute)
 {
     cw.BeginProperty(AccessLevel.Public,
                      VirtualisationLevel.None,
                      interfacesEnvironment.ToTypeName(attribute, true),
                      NamingHelper.ToDTOPropertyName(attribute));
     cw.WritePropertyGet("return this.{0}.{1};",
                         NamingHelper.PropertyName_AdapterDTO,
                         NamingHelper.ToDTOPropertyName(attribute));
     cw.WritePropertySet("this.{0}.{1} = value; NotifyPropertyChanged(\"{1}\");",
                         NamingHelper.PropertyName_AdapterDTO,
                         NamingHelper.ToDTOPropertyName(attribute));
     cw.EndProperty();
 }
        private bool ExportCalculationGroup(CalculationGroup nestedGroup, string currentFolderPath, List <string> exportedGroups)
        {
            string uniqueGroupName = NamingHelper.GetUniqueName(exportedGroups, nestedGroup.Name, group => group);

            bool exportSucceeded = ExportCalculationItemsRecursively(nestedGroup, Path.Combine(currentFolderPath, uniqueGroupName));

            if (!exportSucceeded)
            {
                return(false);
            }

            exportedGroups.Add(uniqueGroupName);
            return(true);
        }
Пример #23
0
        public void GetUniqueName()
        {
            var item1 = mocks.Stub <INameable>();
            var item2 = mocks.Stub <INameable>();
            var item3 = mocks.Stub <INameable>();

            item1.Name = "one (1)";
            item2.Name = "one";
            item3.Name = "INameable1";

            var namedItems = new List <INameable>(new[] { item1, item2, item3 });

            Assert.AreEqual("INameable2", NamingHelper.GetUniqueName(null, namedItems, typeof(INameable)));
            Assert.AreEqual("one (2)", NamingHelper.GetUniqueName("one ({0})", namedItems, typeof(INameable)));
        }
Пример #24
0
        /// <summary>
        /// Formats the name of a database constraint according to the naming conventions configuration
        /// </summary>
        /// <param name="constraint">The constraint</param>
        /// <returns>The formatted constraint name</returns>
        public string ToConstraintName(string constraint)
        {
            string result = null;

            switch (namingConventions.ConstraintNamingConvention)
            {
            case ConstraintNamingConvention.Default: result = constraint; break;

            case ConstraintNamingConvention.Lowercase: result = NamingHelper.ToLowercase(constraint); break;

            case ConstraintNamingConvention.Uppercase: result = NamingHelper.ToUppercase(constraint); break;
            }

            return(result);
        }
Пример #25
0
 protected override void Initialize(ParameterLoadingAnalysisContext context)
 {
     context.RegisterSyntaxNodeActionInNonGenerated(
         c =>
     {
         var declaration     = (NamespaceStatementSyntax)c.Node;
         var declarationName = declaration.Name?.ToString();
         if (declarationName != null &&
             !NamingHelper.IsRegexMatch(declarationName, Pattern))
         {
             c.ReportDiagnosticWhenActive(Diagnostic.Create(rule, declaration.Name.GetLocation(), Pattern));
         }
     },
         SyntaxKind.NamespaceStatement);
 }
Пример #26
0
 protected override void Initialize(ParameterLoadingAnalysisContext context)
 {
     context.RegisterSyntaxNodeActionInNonGenerated(
         c =>
     {
         var methodDeclaration = (MethodStatementSyntax)c.Node;
         if (!NamingHelper.IsRegexMatch(methodDeclaration.Identifier.ValueText, Pattern) &&
             IsEventHandler(methodDeclaration, c.SemanticModel))
         {
             c.ReportDiagnosticWhenActive(Diagnostic.Create(rule, methodDeclaration.Identifier.GetLocation(),
                                                            methodDeclaration.Identifier.ValueText, Pattern));
         }
     },
         SyntaxKind.SubStatement);
 }
Пример #27
0
 public void TestCamelCase()
 {
     {
         var s = NamingHelper.CamelCaseFromString(" hello world, this is some long string ");
         Assert.AreEqual("HelloWorldThisIsSomeLongString", s);
     }
     {
         var s = NamingHelper.CamelCaseFromString("HelloWorld");
         Assert.AreEqual("HelloWorld", s);
     }
     {
         var s = NamingHelper.CamelCaseFromString("hi SQL world");
         Assert.AreEqual("HiSQLWorld", s);
     }
 }
Пример #28
0
        public void GetUniqueName_CollectionWithNamedObjectMatchingNameBase_ReturnNameBaseAppendedWithPostfixIncrement()
        {
            // Setup
            const string nameBase = "The basic name";

            var existingObjects = new[]
            {
                new ObjectWithName(nameBase)
            };

            // Call
            string name = NamingHelper.GetUniqueName(existingObjects, nameBase, namedObject => namedObject.Name);

            // Assert
            Assert.AreEqual(nameBase + " (1)", name);
        }
Пример #29
0
    public static ClassDeclarationSyntax ClassWithInjected<TInjected>(string className)
    {
        var (typeName, variableName) = NamingHelper.GetNames<TInjected>();

        var classCode = $@"class {className}
                          {{
                              private readonly {typeName} _{variableName};

                              public {className}( {typeName} {variableName})
                              {{
                                  _{variableName} = {variableName};
                              }}
                          }}";

        return ParseClass(classCode);
    }
Пример #30
0
        public ManyToOneRelation NewManyToOneRelation(ModelClass pkClass, ModelClass fkClass, string fkColumn)
        {
            ManyToOneRelation relation = new ManyToOneRelation(fkClass, pkClass);

            // TODO: Disabled to test server explorer drag drop bug of DeviceBuffer

            /*Log(
             *  String.Format("Relation: Type=ManyToOne, PKClass={0}, FKClass={1}, Column={2}", pkClass.Name,
             *                fkClass.Name, fkColumn));*/
            relation.SourceColumn       = fkColumn;
            relation.TargetColumnKey    = fkColumn;
            relation.TargetTable        = fkClass.Table;
            relation.TargetPropertyName = NamingHelper.GetPlural(fkClass.Name);

            return(relation);
        }
Пример #31
0
        public ScalarFieldTypeDescription GetCustomScalarFieldType(GraphQlGeneratorConfiguration configuration, GraphQlType baseType, GraphQlTypeBase valueType, string valueName)
        {
            valueName = NamingHelper.ToPascalCase(valueName);

            if (valueName == "From" || valueName == "ValidFrom" || valueName == "To" || valueName == "ValidTo" ||
                valueName == "CreatedAt" || valueName == "UpdatedAt" || valueName == "ModifiedAt" || valueName == "DeletedAt" ||
                valueName.EndsWith("Timestamp"))
            {
                return new ScalarFieldTypeDescription {
                           NetTypeName = "DateTimeOffset?"
                }
            }
            ;

            return(GetFallbackFieldType(configuration, valueType));
        }
Пример #32
0
        public void GetUniqueName_CollectionWithNamedObjectNotMatchingNameBase_ReturnNameBase()
        {
            // Setup
            const string nameBase = "The basic name";

            var existingObjects = new[]
            {
                new ObjectWithName("Something original!")
            };

            // Call
            string name = NamingHelper.GetUniqueName(existingObjects, nameBase, namedObject => namedObject.Name);

            // Assert
            Assert.AreEqual(nameBase, name);
        }