コード例 #1
0
        public override IReadOnlyList <string> Parse()
        {
            var messages = new List <string>();

            foreach (var item in base.Parse())
            {
                var temp = item.Trim();

                if (InvalidFileName.IsMatch(temp))
                {
                    messages.Add("Invalid file name '" + temp + "' provided as a 'need'.");
                    continue;
                }

                if (temp.EndsWith(ScriptConstants.SqlExtension, StringComparison.InvariantCultureIgnoreCase))
                {
                    _files.Add(temp.Replace(ScriptConstants.SqlExtension, string.Empty));
                }
                else
                {
                    _files.Add(temp);
                }
            }

            IsValid = messages.Count == 0;

            return(messages);
        }
コード例 #2
0
        private static void InitializeInvalidFileNameData()
        {
            char[] invalidFileNameChars = System.IO.Path.GetInvalidFileNameChars();

            // Validations that depend on Path.GetFileName fails with these characters. For example:
            // if user entered name for WebRole as "My/WebRole", then Path.GetFileName get file name as WebRole.
            //
            char[] ignoreSet = { ':', '\\', '/' };

            for (int i = 0, j = 0; i < invalidFileNameChars.Length; i++, j++)
            {
                if (ignoreSet.Contains <char>(invalidFileNameChars[i]))
                {
                    continue;
                }
                j %= ValidServiceRootNames.Count - 1;
                StringBuilder invalidFile = new StringBuilder(ValidServiceRootNames[j]);
                invalidFile[invalidFile.Length / 2] = invalidFileNameChars[i];
                InvalidFileName.Add(invalidFile.ToString());
            }
        }