Beispiel #1
0
        public StandaloneAzureBlockBlob(string containerDirectory, string blobName)
        {
            StringValidation.NotNullOrWhitespace(containerDirectory, "containerDirectory");
            StringValidation.NotNullOrWhitespace(blobName, "blobName");

            _blobName     = blobName;
            _blobPath     = Path.Combine(containerDirectory, blobName);
            _metadataPath = Path.Combine(containerDirectory, ".meta", blobName);

            var blobDirectory = Path.GetDirectoryName(_blobPath);

            if (blobDirectory == null)
            {
                throw new InvalidOperationException("Could not determine the blob directory");
            }
            if (blobDirectory != containerDirectory)
            {
                if (!Directory.Exists(blobDirectory))
                {
                    _blobDirectory = blobDirectory;
                }
                var metadataDirectory = Path.GetDirectoryName(_metadataPath);
                if (metadataDirectory != null && !Directory.Exists(metadataDirectory))
                {
                    _metadataDirectory = metadataDirectory;
                }
            }

            _metadata   = new Dictionary <string, string>();
            _properties = new StandaloneAzureBlobProperties {
                Length = -1, ContentType = null
            };
        }
        public StandaloneAzureBlobContainer(string blobStorageDirectory, string containerName)
        {
            StringValidation.NotNullOrWhitespace(blobStorageDirectory, "blobStorageDirectory");
            StringValidation.NotNullOrWhitespace(containerName, "containerName");

            _containerDirectory = Path.Combine(blobStorageDirectory, containerName);
        }
Beispiel #3
0
        /// <summary>
        /// Initializes the list of classes belonging to the library.
        /// </summary>
        /// <param name="classTable">Valid class names.</param>
        /// <param name="errorList">List of errors found.</param>
        /// <returns>True if initialization succeeded.</returns>
        public virtual bool InitLibraryTables(ISealableDictionary <string, ISealableDictionary <string, IClass> > classTable, IErrorList errorList)
        {
            bool Success = true;

            foreach (IIdentifier ClassIdentifier in ClassIdentifierList)
            {
                // Verify the class identifier is a valid string.
                if (!StringValidation.IsValidIdentifier(ClassIdentifier, ClassIdentifier.Text, out string ValidClassIdentifier, out IErrorStringValidity StringError))
                {
                    Success = false;
                    errorList.AddError(StringError);
                    continue;
                }

                if (ValidClassIdentifier.ToUpperInvariant() == LanguageClasses.Any.Name.ToUpperInvariant())
                {
                    // 'Any' is implicit and just ignored.
                }
                else
                {
                    // Check that the class name is known.
                    if (!classTable.ContainsKey(ValidClassIdentifier))
                    {
                        Success = false;
                        errorList.AddError(new ErrorUnknownIdentifier(ClassIdentifier, ValidClassIdentifier));
                        continue;
                    }

                    ISealableDictionary <string, IClass> SourceNameTable = classTable[ValidClassIdentifier];

                    // And it's from the same source.
                    if (!SourceNameTable.ContainsKey(ValidSourceName))
                    {
                        Success = false;
                        errorList.AddError(new ErrorUnknownIdentifier(ClassIdentifier, ValidClassIdentifier));
                        continue;
                    }

                    // The class must be imported only once.
                    if (ImportedClassTable.ContainsKey(ValidClassIdentifier))
                    {
                        Success = false;
                        errorList.AddError(new ErrorIdentifierAlreadyListed(ClassIdentifier, ValidClassIdentifier));
                        continue;
                    }

                    // Add it, leaving the import mode open for now.
                    IImportedClass Imported = new ImportedClass(SourceNameTable[ValidSourceName]);
                    ImportedClassTable.Add(ValidClassIdentifier, Imported);

#if COVERAGE
                    string ImportString = Imported.ToString();
#endif
                }
            }

            Debug.Assert(Success || !errorList.IsEmpty);
            return(Success);
        }
 public void Validate()
 {
     if (CanValidate())
     {
         var test = StringValidation.Test(entry.Value);
         SetInvalidStatus(test);
     }
 }
Beispiel #5
0
        public StandaloneAzureQueueStorageClient(string storageAccountDirectory)
        {
            StringValidation.NotNullOrWhitespace(storageAccountDirectory, "storageAccountDirectory");

            _queueStorageDirectory = Path.Combine(storageAccountDirectory, "queues");

            Directory.CreateDirectory(_queueStorageDirectory);
        }
Beispiel #6
0
        public void StringWithBothOpenAndClosedBracketsInOrder()
        {
            string sentence = "(if (taken? x) median (1 x))";

            bool result = StringValidation.IsStringValid(sentence, '(', ')');

            Assert.IsTrue(result);
        }
Beispiel #7
0
        public void StringWithOneOpenBracket()
        {
            string sentence = "(-:";

            bool result = StringValidation.IsStringValid(sentence, '(', ')');

            Assert.IsFalse(result);
        }
Beispiel #8
0
        public void StringStartingWithClosedBracket()
        {
            string sentence = ") The quick brown ().";

            bool result = StringValidation.IsStringValid(sentence, '(', ')');

            Assert.IsFalse(result);
        }
Beispiel #9
0
        public void StringWithOneOpenBracketMissingClosedBracket()
        {
            string sentence = "The (quick) brown fox jumped over the (blue wall.";

            bool result = StringValidation.IsStringValid(sentence, '(', ')');

            Assert.IsFalse(result);
        }
        public StandaloneAzureBlobDirectory(string containerDirectory, string directoryName)
        {
            StringValidation.NotNullOrWhitespace(containerDirectory, "containerDirectory");
            StringValidation.NotNullOrWhitespace(directoryName, "directoryName");

            _containerDirectory = containerDirectory;
            _directoryPath      = Path.Combine(_containerDirectory, directoryName);
        }
Beispiel #11
0
        public void ValidationString()
        {
            var expected         = new ValidationResult(true, null);
            var value            = "lalalala";
            StringValidation val = new StringValidation();
            var actual           = val.Validate(value, null);

            Assert.AreEqual(actual, expected);
        }
 public static string[] ValidateFreeTextInput(string value)
 {
     return(Task.WhenAll <string>(
                Task.Run(() => StringValidation.RequiredString(value)),
                Task.Run(() => StringValidation.Min3LengthString(value))
                )
            .GetAwaiter()
            .GetResult()
            .Where(err => !string.IsNullOrEmpty(err))
            .ToArray());
 }
Beispiel #13
0
 private void tbNewName_KeyPress(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar == '\r')
     {
         this.btnOK_Click(sender, e);
         e.Handled = true;
     }
     else if (!StringValidation.isValidChar(e.KeyChar))
     {
         e.Handled = true;
     }
 }
 public static string[] ValidateDOBInput(string value)
 {
     return(Task.WhenAll <string>(
                Task.Run(() => StringValidation.RequiredString(value)),
                Task.Run(() => DateValidation.IsDate(value)),
                Task.Run(() => BirthDayValidation.IsAlive(value)),
                Task.Run(() => BirthDayValidation.Over18(value))
                )
            .GetAwaiter()
            .GetResult()
            .Where(err => !string.IsNullOrEmpty(err))
            .ToArray());
 }
Beispiel #15
0
        /// <summary>
        /// Validates an import and return the matching library.
        /// </summary>
        /// <param name="libraryTable">Table of valid library names and their sources, updated upon return.</param>
        /// <param name="matchingLibrary">The matching library upon return.</param>
        /// <param name="errorList">List of errors found.</param>
        /// <returns>True if library names are valid.</returns>
        public virtual bool CheckImportConsistency(ISealableDictionary <string, ISealableDictionary <string, ILibrary> > libraryTable, out ILibrary matchingLibrary, IErrorList errorList)
        {
            IErrorStringValidity StringError;
            string      ValidFromIdentifier;
            IIdentifier ImportLibraryIdentifier = (IIdentifier)LibraryIdentifier;
            ISealableDictionary <string, ILibrary> SourceNameTable;

            matchingLibrary = null;

            if (!StringValidation.IsValidIdentifier(ImportLibraryIdentifier, LibraryIdentifier.Text, out string ValidLibraryIdentifier, out StringError))
            {
                errorList.AddError(StringError);
                return(false);
            }

            // Match the library name and source name.
            if (!libraryTable.ContainsKey(ValidLibraryIdentifier))
            {
                errorList.AddError(new ErrorUnknownIdentifier(ImportLibraryIdentifier, ValidLibraryIdentifier));
                return(false);
            }

            SourceNameTable = libraryTable[ValidLibraryIdentifier];

            if (FromIdentifier.IsAssigned)
            {
                IIdentifier ImportFromIdentifier = (IIdentifier)FromIdentifier.Item;

                if (!StringValidation.IsValidIdentifier(ImportFromIdentifier, FromIdentifier.Item.Text, out ValidFromIdentifier, out StringError))
                {
                    errorList.AddError(StringError);
                    return(false);
                }
            }
            else
            {
                ValidFromIdentifier = string.Empty;
            }

            if (!SourceNameTable.ContainsKey(ValidFromIdentifier))
            {
                errorList.AddError(new ErrorUnknownIdentifier(ImportLibraryIdentifier, ValidLibraryIdentifier));
                return(false);
            }

            matchingLibrary = SourceNameTable[ValidFromIdentifier];
            return(true);
        }
Beispiel #16
0
        private void Delete()
        {
            OutputService.DisplayConsole("Enter Id of Service:");
            string    choice    = ReadDataFromConsole();
            int       i         = StringValidation.ValidatePositiveInt(choice);
            DBService dbService = new DBService();

            if (i > 0 && dbService.ServiceExist(i))
            {
                dbService.RemoveService(i);
            }
            else
            {
                OutputService.DisplayConsole("Id is not valid");
            }
            dbService.Dispose();
        }
Beispiel #17
0
    public void NewMap()
    {
        //TODO: 检查输入
        string mapName = mapNameInput.text;

        if (StringValidation.IsValidFileName(mapName))
        {
            SaveSystem.CreateNewWorld(mapName);
            //重载刷新选择栏
            ClearMapElements();
            LoadMapFiles();
        }
        else
        {
            //TODO:提示输入不合法
            Debug.Log("Invalid Input");
        }
    }
        private bool ValidateLoginInput(UserLoginModel user)
        {
            ValidationResult lengthResult         = StringValidation.ValidatePhoneNumberLength(user.PhoneNumber);
            ValidationResult inputResult          = StringValidation.ValidatePhoneNumberInput(user.PhoneNumber);
            ValidationResult passwordLengthResult = StringValidation.ValidatePasswordLength(user.Password);

            if (!lengthResult.Result)
            {
                // write to log - lengthResult.Description;
                return(false);
            }
            if (!inputResult.Result)
            {
                // write to log - inputResult.Description;
                return(false);
            }
            if (!passwordLengthResult.Result)
            {
                // write to log - passwordLengthResult.Description;
                return(false);
            }
            return(true);
        }
Beispiel #19
0
        private void Edit()
        {
            OutputService.DisplayConsole("Enter Id of Service:");
            string    choice    = ReadDataFromConsole();
            int       i         = StringValidation.ValidatePositiveInt(choice);
            DBService dbService = new DBService();

            if (i > 0 && dbService.ServiceExist(i))
            {
                OutputService.DisplayConsole("Your service to edit:");
                OutputService.DisplayConsole(dbService.GetService(i));
                ServiceHandler serviceHandler = new ServiceHandler();
                Service        newService     = serviceHandler.CreateServiceFromConsole();
                newService.Id = i;

                dbService.Update(newService);
            }
            else
            {
                OutputService.DisplayConsole("Id is not valid");
            }
            dbService.Dispose();
        }
Beispiel #20
0
        private IEnumerable <ValidationCheckResult> ValidateEnumerable(object propertyValue, PropertyInfo propertyInfo, ValidationCheckParameters validationParameter)
        {
            var results  = new List <ValidationCheckResult>();
            var dataType = propertyInfo.PropertyType.GetDataTypeFromIEnumerable();

            if (dataType.IsClass && propertyValue is IEnumerable elements)
            {
                if (dataType == typeof(string))
                {
                    results.AddRange(elements.Cast <string>().Select(s =>
                    {
                        validationParameter.PropertyValue = s;

                        return(StringValidation.CheckStringLength(validationParameter));
                    }).ToList());
                }
                else
                {
                    results.AddRange(elements.Cast <object>().Select(Validate).ToList());
                }
            }

            return(results);
        }
        public StandaloneAzureBlobContainer(string containerDirectory)
        {
            StringValidation.NotNullOrWhitespace(containerDirectory, "containerDirectory");

            _containerDirectory = containerDirectory;
        }
Beispiel #22
0
 public void IsEmail_NullValue_Throws()
 {
     Assert.That(() => StringValidation.IsEmail(null), Throws.InstanceOf <ArgumentNullException>());
 }
 public void update()
 {
     this.sidebar.update();
     if ((((this.tbFactionShortName.Text.Length > 3) && (this.tbFactionName.Text.Length > 3)) && ((this.tbMotto.Text.Length > 3) && StringValidation.isValidGameString(this.tbFactionShortName.Text))) && ((StringValidation.notAllSpaces(this.tbFactionShortName.Text) && StringValidation.isValidGameString(this.tbFactionName.Text)) && StringValidation.notAllSpaces(this.tbFactionName.Text)))
     {
         this.createButton.Enabled = true;
     }
     else
     {
         this.createButton.Enabled = false;
     }
 }
 private void tbFactionName_TextChanged(object sender, EventArgs e)
 {
     if ((((this.tbFactionShortName.Text.Length > 3) && (this.tbFactionName.Text.Length > 3)) && ((this.tbMotto.Text.Length > 3) && StringValidation.isValidGameString(this.tbFactionShortName.Text))) && ((StringValidation.notAllSpaces(this.tbFactionShortName.Text) && StringValidation.isValidGameString(this.tbFactionName.Text)) && StringValidation.notAllSpaces(this.tbFactionName.Text)))
     {
         this.createButton.Enabled = true;
     }
     else
     {
         this.createButton.Enabled = false;
     }
 }
 public void createClick()
 {
     if ((((this.tbFactionShortName.Text.Length > 3) && (this.tbFactionName.Text.Length > 3)) && ((this.tbMotto.Text.Length > 3) && StringValidation.isValidGameString(this.tbFactionShortName.Text))) && ((StringValidation.notAllSpaces(this.tbFactionShortName.Text) && StringValidation.isValidGameString(this.tbFactionName.Text)) && StringValidation.notAllSpaces(this.tbFactionName.Text)))
     {
         this.createFaction(this.tbFactionName.Text, this.tbFactionShortName.Text, this.tbMotto.Text);
     }
 }
Beispiel #26
0
 /// <summary>
 /// Validates a given string against a regular expression to determine if it's a valid e-mail.
 /// </summary>
 public static bool IsEmail(this string email)
 {
     return(StringValidation.IsEmail(email));
 }
Beispiel #27
0
        /// <summary>
        /// Validates the library name and library source name, and update <see cref="ValidLibraryName"/> and <see cref="ValidSourceName"/>.
        /// </summary>
        /// <param name="libraryTable">Table of valid library names and their sources, updated upon return.</param>
        /// <param name="validatedLibraryList">List of classes with valid names, updated upon return.</param>
        /// <param name="errorList">List of errors found.</param>
        /// <returns>True if library names are valid.</returns>
        public virtual bool CheckLibraryNames(ISealableDictionary <string, ISealableDictionary <string, ILibrary> > libraryTable, IList <ILibrary> validatedLibraryList, IErrorList errorList)
        {
            IErrorStringValidity StringError;
            IName LibraryEntityName = (IName)EntityName;

            // Verify the library name is a valid string.
            if (!StringValidation.IsValidIdentifier(LibraryEntityName, EntityName.Text, out string ValidEntityName, out StringError))
            {
                errorList.AddError(StringError);
                return(false);
            }

            ValidLibraryName = ValidEntityName;

            if (FromIdentifier.IsAssigned)
            {
                // Verify the library source name is a valid string.
                IIdentifier LibraryFromIdentifier = (IIdentifier)FromIdentifier.Item;

                if (!StringValidation.IsValidIdentifier(LibraryFromIdentifier, FromIdentifier.Item.Text, out string ValidFromIdentifier, out StringError))
                {
                    errorList.AddError(StringError);
                    return(false);
                }

                ValidSourceName = ValidFromIdentifier;
            }
            else
            {
                ValidSourceName = string.Empty;
            }

            // Add this library with valid names to the list.
            validatedLibraryList.Add(this);

            if (libraryTable.ContainsKey(ValidLibraryName))
            {
                ISealableDictionary <string, ILibrary> SourceNameTable = libraryTable[ValidLibraryName];

                if (SourceNameTable.ContainsKey(ValidSourceName))
                {
                    // Report a source name collision if the class has one.
                    if (FromIdentifier.IsAssigned)
                    {
                        errorList.AddError(new ErrorDuplicateName(LibraryEntityName, ValidLibraryName));
                        return(false);
                    }
                }
                else
                {
                    SourceNameTable.Add(ValidSourceName, this);
                }
            }
            else
            {
                ISealableDictionary <string, ILibrary> SourceNameTable = new SealableDictionary <string, ILibrary>
                {
                    { ValidSourceName, this }
                };

                libraryTable.Add(ValidLibraryName, SourceNameTable);
            }

            return(true);
        }
Beispiel #28
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     GameEngine.Instance.playInterfaceSound("RenameVillagePopup_rename");
     if ((((this.tbNewName.Text.Length > 0) && (this.tbNewName.Text.Length <= 0x20)) && (StringValidation.isValidGameString(this.tbNewName.Text) && StringValidation.notAllSpaces(this.tbNewName.Text))) && (this.tbNewName.Text != this.tbOldName.Text))
     {
         if ((this.m_villageID >= 0) && !this.parishNameMode)
         {
             RemoteServices.Instance.set_VillageRename_UserCallBack(new RemoteServices.VillageRename_UserCallBack(this.testCallback));
             RemoteServices.Instance.VillageRename(this.m_villageID, this.tbNewName.Text);
         }
         base.Close();
     }
 }
        public IAzureBlockBlob GetBlockBlobReference(string blobName)
        {
            StringValidation.NotNullOrEmpty(blobName, "blobName");

            return(new StandaloneAzureBlockBlob(_directoryPath, blobName));
        }
Beispiel #30
0
 private void tbNewName_TextChanged(object sender, EventArgs e)
 {
     if (((this.tbNewName.Text.Length > 0) && (this.tbNewName.Text.Length <= 0x20)) && (StringValidation.isValidGameString(this.tbNewName.Text) && StringValidation.notAllSpaces(this.tbNewName.Text)))
     {
         this.btnOK.Enabled = true;
     }
     else
     {
         this.btnOK.Enabled = false;
     }
 }