示例#1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NameString"/> struct.
 /// </summary>
 /// <param name="value">The actual type name string</param>
 /// <exception cref="ArgumentException"></exception>
 public NameString(string value)
 {
     if (!NameUtils.IsValidGraphQLName(value))
     {
         throw new ArgumentException(
                   string.Format(CultureInfo.InvariantCulture,
                                 AbstractionResources.Type_NameIsNotValid,
                                 value ?? "null"),
                   nameof(value));
     }
     Value = value;
 }
示例#2
0
        public static bool IsValidResourceName(string name, string dataDirectory, out string errorMessage)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                errorMessage = "An empty name is forbidden for use!";
                return(false);
            }
            if (NameUtils.IsValidResourceName(name) == false)
            {
                errorMessage = $"The name '{name}' is not permitted. Only letters, digits and characters ('_', '.', '-') are allowed.";
                return(false);
            }
            if (name.Length > Constants.Documents.MaxDatabaseNameLength)
            {
                errorMessage = $"The name '{name}' exceeds '{Constants.Documents.MaxDatabaseNameLength}' characters!";
                return(false);
            }
            if (name.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
            {
                errorMessage = $"The name '{name}' contains characters that are forbidden for use!";
                return(false);
            }
            if (WindowsReservedFileNames.Any(x => string.Equals(x, name, StringComparison.OrdinalIgnoreCase)))
            {
                errorMessage = $"The name '{name}' is forbidden for use!";
                return(false);
            }
            if (name.Contains(".") && NameUtils.IsDotCharSurroundedByOtherChars(name) == false)
            {
                errorMessage = $"The name '{name}' is not permitted. If a name contains '.' character then it must be surrounded by other allowed characters.";
                return(false);
            }

            dataDirectory = dataDirectory ?? string.Empty;
            if (Path.Combine(dataDirectory, name).Length > WindowsMaxPath)
            {
                int maxfileNameLength = WindowsMaxPath - dataDirectory.Length;
                errorMessage = $"Invalid name! Name cannot exceed {maxfileNameLength} characters";
                return(false);
            }
            if ((RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) &&
                ((name.Length > LinuxMaxFileNameLength) ||
                 (dataDirectory.Length + name.Length > LinuxMaxPath)))
            {
                int theoreticalMaxFileNameLength = LinuxMaxPath - dataDirectory.Length;
                int maxfileNameLength            = theoreticalMaxFileNameLength > LinuxMaxFileNameLength ? LinuxMaxFileNameLength : theoreticalMaxFileNameLength;
                errorMessage = $"Invalid name! Name cannot exceed {maxfileNameLength} characters";
                return(false);
            }

            errorMessage = null;
            return(true);
        }
 void componentNameTextBox_TextChanged(object sender, TextChangedEventArgs e)
 {
     if (allowUpdater.IsUpdateAllowed)
     {
         if (NameUtils.CheckComponentName(componentNameTextBox.Text))
         {
             component.Name = componentNameTextBox.Text;
             AutosarApplication.GetInstance().UpdateNamesOfConnectionLines();
             treeView.UpdateAutosarTreeView();
         }
     }
 }
示例#4
0
 /// <summary>
 /// Gets type mask corresponding to <c>self</c> with <c>includesSubclasses</c> flag set whether type is not final.
 /// </summary>
 private TypeRefMask GetTypeCtxMask(AST.TypeDecl typeCtx)
 {
     if (typeCtx != null)
     {
         var typeIsFinal = (typeCtx.MemberAttributes & PhpMemberAttributes.Final) != 0;
         return(GetTypeMask(new ClassTypeRef(NameUtils.MakeQualifiedName(typeCtx)), !typeIsFinal));
     }
     else
     {
         return(TypeRefMask.AnyType);
     }
 }
示例#5
0
        public IActionResult Index(
            long topic                 = -1,
            int topicPage              = 1,
            int vocabularyPage         = 1,
            string topicSearchKey      = "",
            string vocabularySearchKey = "")
        {
            #region For topic
            int topicStart = (topicPage - 1) * Config.PAGE_PAGINATION_LIMIT;

            var topics = _TopicManager.GetByPagination(topicStart, Config.PAGE_PAGINATION_LIMIT);
            ViewBag.Topics = topics;

            // Tạo đối tượng phân trang cho Category
            ViewBag.TopicPagination = new Pagination(nameof(Index), NameUtils.ControllerName <DictionaryManagerController>())
            {
                PageKey     = nameof(topicPage),
                PageCurrent = topicPage,
                NumberPage  = PaginationUtils.TotalPageCount(
                    _TopicManager.Count().ToInt(),
                    Config.PAGE_PAGINATION_LIMIT),
                Offset = Config.PAGE_PAGINATION_LIMIT
            };
            #endregion

            #region For vocabulary
            int vocabularyStart = (vocabularyPage - 1) * Config.PAGE_PAGINATION_LIMIT;

            int total = _VocabularyManager.CountFor(topic).ToInt();

            // Tạo đối tượng phân trang cho Câu hỏi
            ViewBag.VocabularyPagination = new Pagination(nameof(Index), NameUtils.ControllerName <ReadingManagerController>())
            {
                PageKey     = nameof(vocabularyPage),
                PageCurrent = vocabularyPage,
                TypeKey     = nameof(topic),
                Type        = "0",
                NumberPage  = PaginationUtils.TotalPageCount(total, Config.PAGE_PAGINATION_LIMIT),
                Offset      = Config.PAGE_PAGINATION_LIMIT
            };

            ViewBag.TopicName = _TopicManager.Get(topic)?.Name ?? "";

            if (topic <= 0)
            {
                ViewBag.TopicName = "ALL";
            }

            ViewBag.Vocabularies = _VocabularyManager.GetByPagination(topic, vocabularyStart, Config.PAGE_PAGINATION_LIMIT);
            #endregion

            return(View());
        }
示例#6
0
 /// <summary>
 /// Gets type full qualified name.
 /// </summary>
 public static QualifiedName MakeQualifiedName(this NamedTypeSymbol type)
 {
     if (string.IsNullOrEmpty(type.NamespaceName))
     {
         return(new QualifiedName(new Name(type.Name)));
     }
     else
     {
         var ns = type.NamespaceName.Replace('.', QualifiedName.Separator);
         return(NameUtils.MakeQualifiedName(ns + QualifiedName.Separator + type.Name, true));
     }
 }
 void nameTextBox_TextChanged(object sender, TextChangedEventArgs e)
 {
     if (allowUpdater.IsUpdateAllowed)
     {
         String newName = (sender as TextBox).Text;
         if (NameUtils.CheckComponentName(newName))
         {
             datatype.Name = newName;
             autosarTree.UpdateAutosarTreeView(null);
         }
     }
 }
        public override void Process(IReflector reflector, MethodInfo actionMethod, IMethodRemover methodRemover, ISpecificationBuilder action)
        {
            string capitalizedName = NameUtils.CapitalizeName(actionMethod.Name);

            Type             type       = actionMethod.DeclaringType;
            var              facets     = new List <IFacet>();
            ITypeSpecBuilder onType     = reflector.LoadSpecification(type);
            var              returnSpec = reflector.LoadSpecification <IObjectSpecBuilder>(actionMethod.ReturnType);

            IObjectSpecImmutable elementSpec = null;
            bool isQueryable = IsQueryOnly(actionMethod) || CollectionUtils.IsQueryable(actionMethod.ReturnType);

            if (returnSpec != null && returnSpec.IsCollection)
            {
                Type elementType = CollectionUtils.ElementType(actionMethod.ReturnType);
                elementSpec = reflector.LoadSpecification <IObjectSpecImmutable>(elementType);
            }

            RemoveMethod(methodRemover, actionMethod);
            facets.Add(new ActionInvocationFacetViaMethod(actionMethod, onType, returnSpec, elementSpec, action, isQueryable));

            MethodType methodType = actionMethod.IsStatic ? MethodType.Class : MethodType.Object;

            Type[] paramTypes = actionMethod.GetParameters().Select(p => p.ParameterType).ToArray();
            FindAndRemoveValidMethod(reflector, facets, methodRemover, type, methodType, capitalizedName, paramTypes, action);

            DefaultNamedFacet(facets, actionMethod.Name, action); // must be called after the checkForXxxPrefix methods

            AddHideForSessionFacetNone(facets, action);
            AddDisableForSessionFacetNone(facets, action);
            FindDefaultHideMethod(reflector, facets, methodRemover, type, methodType, "ActionDefault", action);
            FindAndRemoveHideMethod(reflector, facets, methodRemover, type, methodType, capitalizedName, action);
            FindDefaultDisableMethod(reflector, facets, methodRemover, type, methodType, "ActionDefault", action);
            FindAndRemoveDisableMethod(reflector, facets, methodRemover, type, methodType, capitalizedName, action);

            var actionSpecImmutable = action as IActionSpecImmutable;

            if (actionSpecImmutable != null)
            {
                // Process the action's parameters names, descriptions and optional
                // an alternative design would be to have another facet factory processing just ActionParameter, and have it remove these
                // supporting methods.  However, the FacetFactory API doesn't allow for methods of the class to be removed while processing
                // action parameters, only while processing Methods (ie actions)
                IActionParameterSpecImmutable[] actionParameters = actionSpecImmutable.Parameters;
                string[] paramNames = actionMethod.GetParameters().Select(p => p.Name).ToArray();

                FindAndRemoveParametersAutoCompleteMethod(reflector, methodRemover, type, capitalizedName, paramTypes, actionParameters);
                FindAndRemoveParametersChoicesMethod(reflector, methodRemover, type, capitalizedName, paramTypes, paramNames, actionParameters);
                FindAndRemoveParametersDefaultsMethod(reflector, methodRemover, type, capitalizedName, paramTypes, paramNames, actionParameters);
                FindAndRemoveParametersValidateMethod(reflector, methodRemover, type, capitalizedName, paramTypes, paramNames, actionParameters);
            }
            FacetUtils.AddFacets(facets);
        }
示例#9
0
        public static void InitializeComponents(ref GameObject prefab)
        {
            if (ComponentUtils.GetModComponent(prefab) != null)
            {
                return;
            }

            string      name = NameUtils.RemoveGearPrefix(prefab.name);
            string      data = JsonHandler.GetJsonText(name);
            ProxyObject dict = JSON.Load(data) as ProxyObject;

            InitializeComponents(ref prefab, dict);
        }
        private void Name_TextEdit_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox box   = sender as TextBox;
            int     index = SystemErrorsGrid.SelectedIndex;

            if ((index < SystemErrorsGrid.Items.Count) && (index >= 0))
            {
                if (NameUtils.CheckMacroName(box.Text))
                {
                    autosarApp.SystemErrors[index].Name = box.Text;
                }
            }
        }
        public void RenameFieldTextEdit(TextBox textbox)
        {
            int index = grid.SelectedIndex;

            if ((index < grid.Items.Count) && (index >= 0))
            {
                if (NameUtils.CheckComponentName(textbox.Text))
                {
                    gridElements[index].Name = textbox.Text;
                    tree.UpdateAutosarTreeView();
                }
            }
        }
 void nameTextBox_TextChanged(object sender, TextChangedEventArgs e)
 {
     if (allowUpdater.IsUpdateAllowed)
     {
         String newName = (sender as TextBox).Text;
         if (NameUtils.CheckComponentName(newName))
         {
             datatype.Name = newName;
             AutosarApplication.GetInstance().SyncronizePerInstanceMemory(null, true);
             autosarTree.UpdateAutosarTreeView(null);
         }
     }
 }
示例#13
0
 /// <summary>
 /// Enqueues initializers of a class fields and constants.
 /// </summary>
 void EnqueueFieldsInitializer(SourceTypeSymbol type)
 {
     type.GetMembers().OfType <SourceFieldSymbol>().Foreach(f =>
     {
         if (f.Initializer != null)
         {
             EnqueueExpression(
                 f.Initializer,
                 TypeRefFactory.CreateTypeRefContext(type), //the context will be lost, analysis resolves constant values only and types are temporary
                 NameUtils.GetNamingContext(type.Syntax));
         }
     });
 }
示例#14
0
        protected internal MemberSpecAbstract(string id, IMemberSpecImmutable memberSpec, ISession session, ILifecycleManager lifecycleManager, IMetamodelManager metamodelManager) {
            AssertArgNotNull(id, Resources.NakedObjects.NameNotSetMessage);
            AssertArgNotNull(memberSpec);
            AssertArgNotNull(session);
            AssertArgNotNull(lifecycleManager);

            this.id = id;
            NameUtils.NaturalName(id);
            memberSpecImmutable = memberSpec;
            this.session = session;
            this.lifecycleManager = lifecycleManager;
            this.metamodelManager = metamodelManager;
        }
示例#15
0
        public string GetActionId(string propertyName, IActionFacade actionContextActionFacade, IObjectFacade actionObjectFacade, IObjectFacade targetObjectFacade, IActionFacade targetActionFacade)
        {
            IActionSpec         actionContextAction       = actionContextActionFacade == null ? null :  actionContextActionFacade.WrappedSpec();
            INakedObjectAdapter actionContextTarget       = actionObjectFacade == null ? null : actionObjectFacade.WrappedAdapter();
            IActionSpec         targetActionContextAction = targetActionFacade == null ? null : targetActionFacade.WrappedSpec();
            INakedObjectAdapter targetActionContextTarget = targetObjectFacade == null ? null : targetObjectFacade.WrappedAdapter();

            string contextActionName    = actionContextAction == null ? "" : actionContextAction.Id + Sep;
            string contextNakedObjectId = actionContextTarget == null || actionContextTarget == targetActionContextTarget ? "" : GetObjectId(actionObjectFacade) + Sep;
            string propertyId           = string.IsNullOrEmpty(propertyName) ? "" : NameUtils.CapitalizeName(propertyName) + Sep;

            return(contextNakedObjectId + contextActionName + propertyId + GetObjectId(targetObjectFacade) + Sep + targetActionContextAction.Id);
        }
示例#16
0
        void DecompileUnknown(IFileTreeNodeData node)
        {
            var decompileSelf = node as IDecompileSelf;

            if (decompileSelf != null && decompileNodeContext != null)
            {
                if (decompileSelf.Decompile(decompileNodeContext))
                {
                    return;
                }
            }
            language.WriteCommentLine(output, NameUtils.CleanName(node.ToString(language)));
        }
        public IActionResult SubmitToolResultForWriting(WritingTestPaper wtp, WritingPartTwoDTO wp2DTO)
        {
            // Định nghĩa đích đến
            var dest = RedirectToAction(nameof(TestPaperController.ReviewHandler), NameUtils.ControllerName <TestPaperController>(), new { id = wtp.PiceOfTestId });

            // Nếu không xác định được bài thi
            if (wtp == null || wtp.PiceOfTestId <= 0)
            {
                this.NotifyError("Cannot determine the test");
                return(dest);
            }

            // Nếu nội dung đánh giá rỗng
            if (wp2DTO == null || string.IsNullOrEmpty(wp2DTO.TeacherReviewParagraph))
            {
                this.NotifyError("You must correct paragraph for your student");
                return(dest);
            }

            // Điểm cho bài thi
            if (wp2DTO.Scores < 0 || wp2DTO.Scores > Config.SCORES_FULL_WRITING_PART_2)
            {
                this.NotifyError("Score invalid");
                return(dest);
            }

            // Nếu tất cả đã hợp lệ, tiến hành lấy bản ghi
            var pot = _PieceOfTestManager.Get(wtp.PiceOfTestId);

            // Lấy dữ liệu gốc
            var constWtp = JsonConvert.DeserializeObject <WritingTestPaper>(pot.ResultOfUserJson) as WritingTestPaper;

            // Cập nhật điểm số mới
            pot.Scores = constWtp.WritingPartOnes.Scores + wp2DTO.Scores;

            // Cập nhật điểm số
            constWtp.WritingPartTwos.Scores = wp2DTO.Scores;
            constWtp.WritingPartTwos.TeacherReviewParagraph = wp2DTO.TeacherReviewParagraph;

            // Lưu lại json
            pot.ResultOfUserJson = JsonConvert.SerializeObject(constWtp);

            // Cập nhật vào CSDL
            _PieceOfTestManager.Update(pot);

            // Gửi thông báo thành công
            this.NotifySuccess("Update your review to student success!");

            // Về điểm đích đã khai báo
            return(dest);
        }
示例#18
0
        internal static object Pack(MemberInfo member)
        {
            if (member.DeclaringType == null)
            {
                return(null);
            }

            var memberName = (object)NameUtils.RemoveGenericSuffix(member.Name);

            if (member is MethodBase)
            {
                var methodBase = (MethodBase)member;
                if (methodBase.IsGenericMethod)
                {
                    var typeArguments  = methodBase.GetGenericArguments();
                    var methodNameTree = new Dictionary <string, object>(3)
                    {
                        { Constants.EXPRESSION_TYPE_ATTRIBUTE, Constants.EXPRESSION_TYPE_MEMBER_REFERENCE },
                        { Constants.NAME_ATTRIBUTE, memberName },
                        { Constants.ARGUMENTS_ATTRIBUTE, Pack(typeArguments) }
                    };
                    memberName = methodNameTree;
                }

                var parameters = methodBase.GetParameters();
                var arguments  = new Dictionary <string, object>(parameters.Length);
                foreach (var parameterInfo in parameters)
                {
                    var key   = Constants.GetIndexAsString(parameterInfo.Position);
                    var value = parameterInfo.Name ?? key;
                    arguments[key] = value;
                }

                return(new Dictionary <string, object>(4)
                {
                    { Constants.EXPRESSION_TYPE_ATTRIBUTE, Constants.EXPRESSION_TYPE_MEMBER_REFERENCE },
                    { Constants.TYPE_ATTRIBUTE, Pack(methodBase.DeclaringType) },
                    { Constants.NAME_ATTRIBUTE, memberName },
                    { Constants.ARGUMENTS_ATTRIBUTE, arguments }
                });
            }
            else
            {
                return(new Dictionary <string, object>(3)
                {
                    { Constants.EXPRESSION_TYPE_ATTRIBUTE, Constants.EXPRESSION_TYPE_MEMBER_REFERENCE },
                    { Constants.TYPE_ATTRIBUTE, Pack(member.DeclaringType) },
                    { Constants.NAME_ATTRIBUTE, memberName },
                });
            }
        }
示例#19
0
        public void ObjectActionInvoked(IPrincipal byPrincipal, string actionName, object onObject, bool queryOnly, object[] withParameters)
        {
            if (queryOnly && !AppSettings.AuditQueryOnlyActions())
            {
                return;
            }

            var ae = NewTransientAuditedEvent <ObjectAction>(byPrincipal);

            ae.Object     = onObject as IDomainInterface;
            ae.Action     = NameUtils.NaturalName(actionName);
            ae.Parameters = ParamsAsString(withParameters);
            Container.Persist(ref ae);
        }
示例#20
0
        public void Write(ISyntaxHighlightOutput output, ILanguage language, IDnSpyFile file)
        {
            var filename = GetFilename(file);
            var peImage  = file.PEImage;

            if (peImage != null)
            {
                output.Write(NameUtils.CleanName(filename), IsExe(peImage) ? TextTokenKind.AssemblyExe : TextTokenKind.Assembly);
            }
            else
            {
                output.Write(NameUtils.CleanName(filename), TextTokenKind.Text);
            }
        }
示例#21
0
        private INamedFacet SaveDefaultName(ISpecification holder)
        {
            string name = NameUtils.NaturalName(SafeGetName(holder));

            if (!namesScratchPad.Contains(name))
            {
                if (!TypeUtils.IsNakedObjects(currentType) && !IsAlwaysHidden(holder) && !string.IsNullOrWhiteSpace(name))
                {
                    namesScratchPad.Add(name);
                }
                return(null);
            }
            return(CreateAnnotation(name, holder));
        }
示例#22
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            bool nameChecked = NameUtils.CheckComponentName(portNameTextBox.Text);

            if (nameChecked == false)
            {
                MessageBox.Show("Wrong port name", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
            }
            else
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
示例#23
0
    public static string GetGraphQLName(this MethodInfo method)
    {
        if (method is null)
        {
            throw new ArgumentNullException(nameof(method));
        }

        string name = method.IsDefined(
            typeof(GraphQLNameAttribute), false)
            ? method.GetCustomAttribute <GraphQLNameAttribute>() !.Name
            : NormalizeMethodName(method);

        return(NameUtils.MakeValidGraphQLName(name) !);
    }
示例#24
0
    public static string GetGraphQLName(this ParameterInfo parameter)
    {
        if (parameter is null)
        {
            throw new ArgumentNullException(nameof(parameter));
        }

        string name = parameter.IsDefined(
            typeof(GraphQLNameAttribute), false)
            ? parameter.GetCustomAttribute <GraphQLNameAttribute>() !.Name
            : NormalizeName(parameter.Name !);

        return(NameUtils.MakeValidGraphQLName(name) !);
    }
示例#25
0
    public static string GetGraphQLName(this PropertyInfo property)
    {
        if (property is null)
        {
            throw new ArgumentNullException(nameof(property));
        }

        string name = property.IsDefined(
            typeof(GraphQLNameAttribute), false)
            ? property.GetCustomAttribute <GraphQLNameAttribute>() !.Name
            : NormalizeName(property.Name);

        return(NameUtils.MakeValidGraphQLName(name) !);
    }
示例#26
0
    public static string GetGraphQLName(this Type type)
    {
        if (type is null)
        {
            throw new ArgumentNullException(nameof(type));
        }

        TypeInfo typeInfo = type.GetTypeInfo();
        string   name     = typeInfo.IsDefined(typeof(GraphQLNameAttribute), false)
            ? typeInfo.GetCustomAttribute <GraphQLNameAttribute>() !.Name
            : GetFromType(typeInfo);

        return(NameUtils.MakeValidGraphQLName(name) !);
    }
示例#27
0
 public void RenamePortTextEdit(string newName)
 {
     if (allowUpdater.IsUpdateAllowed)
     {
         int index = portsGrid.SelectedIndex;
         if ((index < portsGrid.Items.Count) && (index >= 0))
         {
             if (NameUtils.CheckComponentName(newName))
             {
                 _componentDefenition.Ports[index].Name = newName;
                 tree.UpdateAutosarTreeView(tree.SelectedItem);
             }
         }
     }
 }
示例#28
0
        public override bool IsInstanceOfType(IValueNode literal)
        {
            if (literal == null)
            {
                throw new ArgumentNullException(nameof(literal));
            }

            if (literal is NullValueNode)
            {
                return(true);
            }

            return(literal is StringValueNode s &&
                   NameUtils.IsValidName(s.Value));
        }
 public void editName_TextBox_TextChanged(object sender)
 {
     if (allowUpdater.IsUpdateAllowed)
     {
         int index = osTaskGrid.SelectedIndex;
         if ((index < osTaskGrid.Items.Count) && (index >= 0))
         {
             String newName = (sender as TextBox).Text;
             if (NameUtils.CheckComponentName(newName) == true)
             {
                 AutosarApplication.GetInstance().OsTasks[index].Name = newName;
             }
         }
     }
 }
        public static string GetGraphQLName(this MethodInfo method)
        {
            string name;

            if (method.Name.StartsWith("Get", StringComparison.Ordinal) &&
                method.Name.Length > 3)
            {
                name = NormalizeName(method.Name.Substring(3));
            }
            else
            {
                name = NormalizeName(method.Name);
            }

            return(NameUtils.RemoveInvalidCharacters(name));
        }