public static void Delete(string sourceDirName) { if (ValidationSchema.IsDirectory(sourceDirName)) { Directory.Delete(sourceDirName); } else { File.Delete(sourceDirName); } }
public static void MoveFromPathToPath(string sourceDirName, string destDirName) { if (ValidationSchema.IsDirectory(sourceDirName)) { Directory.Move(sourceDirName, destDirName); } else { File.Move(sourceDirName, destDirName); } }
public static void Copy(string sourceDirName, string destDirName) { if (ValidationSchema.IsDirectory(sourceDirName)) { throw new Exception(Exceptions.CannotCopyFolderError); } else { File.Copy(sourceDirName, destDirName); } }
DatasetResultSchema GetShapedSchema(DemographicExecutionContext context, SqlDataReader reader) { var shape = context.Shape; var actualSchema = GetResultSchema(shape, reader); var validationSchema = ValidationSchema.For(shape); var result = validationSchema.Validate(actualSchema); switch (result.State) { case SchemaValidationState.Warning: log.LogWarning("Demographic Schema Validation Warning. Messages:{Messages}", result.Messages); break; case SchemaValidationState.Error: log.LogError("Demographic Schema Validation Error. Messages:{Messages}", result.Messages); throw new LeafCompilerException($"Demographic query failed schema validation"); } return(validationSchema.GetShapedSchema(actualSchema)); }
public static void Zip(string sourceDirName, string compressTo) { if (ValidationSchema.IsDirectory(sourceDirName)) { throw new Exception(Exceptions.ArchiveError); } else { using (FileStream sourceStream = new FileStream(sourceDirName, FileMode.OpenOrCreate)) { using (FileStream targetStream = File.Create(compressTo)) { using (GZipStream compressionStream = new GZipStream(targetStream, CompressionMode.Compress)) { sourceStream.CopyTo(compressionStream); MessageBox.Show(String.Format("Файл был заархивирован в {0}", compressTo)); } } } } }
public static void UnZip(string compressedFile, string decompressTo) { if (!ValidationSchema.IsZipArchive(compressedFile)) { throw new Exception(Exceptions.UnarchiveError); } else { using (FileStream sourceStream = new FileStream(compressedFile, FileMode.OpenOrCreate)) { using (FileStream targetStream = File.Create(decompressTo)) { using (GZipStream decompressionStream = new GZipStream(sourceStream, CompressionMode.Decompress)) { decompressionStream.CopyTo(targetStream); MessageBox.Show(String.Format("Файл был разархивирован в {0}", decompressTo)); } } } } }
public EditWindow(string path) { if (!ValidationSchema.IsTextFile(path)) { throw new Exception(Exceptions.IsNotTextFileError); } InitializeComponent(); using (FileStream fstream = File.OpenRead(path)) { byte[] beforeBytes = new byte[fstream.Length]; fstream.Read(beforeBytes, 0, beforeBytes.Length); TextField.Text = System.Text.Encoding.Default.GetString(beforeBytes); } TextField.TextChanged += (s, e) => { using (FileStream fstream = new FileStream(path, FileMode.Open)) { byte[] beforeBytes = System.Text.Encoding.Default.GetBytes(TextField.Text); fstream.Write(beforeBytes, 0, beforeBytes.Length); } }; }
public ValidationSchemaDTO(ValidationSchema schema) { Fields = schema.Fields.Select(f => new SchemaFieldSelectorDTO(f)); }
public ModelStateDictionary Validate <TEntity>(TEntity entity, ValidationSchema schema) where TEntity : class { var entityType = typeof(TEntity); string entityName = entityType.Name; if (entity == null) { _validationErrors.AddModelError("Entity", "Entity object cann not be null"); return(_validationErrors); } //convert entity into json object var entityRawJson = JsonConvert.SerializeObject(entity, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, TypeNameHandling = TypeNameHandling.None }); var jsonEntity = JsonConvert.DeserializeObject <JObject>(entityRawJson, new JsonConverter[] { new MGSurveyJsonConverter() }); var _jsonEntityProperties = jsonEntity.Properties(); //validate schema if (schema == null) { //_validationErrors.AddModelError("Schema", "Provided schema for given entity can not be null"); return(_validationErrors); } //convert schema entity into json object var schemaRawJson = JsonConvert.SerializeObject(schema, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, TypeNameHandling = TypeNameHandling.None }); var jsonSchemaEntity = JsonConvert.DeserializeObject <JObject>(schemaRawJson, new JsonConverter[] { new MGSurveyJsonConverter() }); if (jsonSchemaEntity[Dynamic_Field_Name] == null || jsonSchemaEntity.SelectToken($"{Dynamic_Field_Name}.Schema") == null || jsonSchemaEntity.SelectToken($"{Dynamic_Field_Name}.Schema.Fields") == null) { _validationErrors.AddModelError("SchemaFields", "Field definitions are not defined on provided schema"); return(_validationErrors); } var schemaFields = JsonConvert.DeserializeObject <List <Field> >(jsonSchemaEntity.SelectToken($"{Dynamic_Field_Name}.Schema.Fields").ToString()); var rootFields = schemaFields.Where(f => f.Name != Dynamic_Field_Name && (string.IsNullOrWhiteSpace(f.Path) || f.Path == f.Name)); //validate root properties foreach (var field in rootFields) { var _eProp = _jsonEntityProperties.FirstOrDefault(p => p.Name == field.Name); if (_eProp == null && field.Required) { _validationErrors.AddModelError(field.Name, $"The ({field.Name}) field is not defined at (Root) path on entity ({entityName})"); continue; } ValidateJsonProperty(_eProp, field); } //check dynamic field is defined on entity var dProp = _jsonEntityProperties.FirstOrDefault(p => p.Name == Dynamic_Field_Name); if (dProp == null && dProp.Value != null) { // dynamic field is optional return(_validationErrors); } //convert dynamic propert to json object var dJsonObject = JObject.Parse(dProp.Value.ToString()); var dJonProperties = dJsonObject.Properties(); //validate open/dynamic fields var openSchemaFields = schemaFields.Where(f => !string.IsNullOrWhiteSpace(f.Path)).ToList(); foreach (var field in openSchemaFields) { var eProp = dJonProperties.FirstOrDefault(p => p.Name == field.Name); if (eProp == null && field.Required) { _validationErrors.AddModelError(field.Name, $"The ({field.Name}) field is missing on path ({field.Path})"); continue; } ValidateJsonProperty(eProp, field); } return(_validationErrors); }