public static async Task <CreateEntityResult <Appearance> > CreateDefaultAsync ( [NotNull] Character character, [NotNull] TransformationService transformations ) { var getSpeciesResult = await transformations.GetSpeciesByNameAsync("template"); if (!getSpeciesResult.IsSuccess) { return(CreateEntityResult <Appearance> .FromError("Could not find the default species.")); } var templateSpecies = getSpeciesResult.Entity; var templateTransformations = new List <Transformation>(); var templateParts = new List <Bodypart> { Head, Body, Arms, Legs }; // Explode the composite parts into their components templateParts = templateParts.SelectMany(p => p.GetComposingParts()).Distinct().ToList(); foreach (var part in templateParts) { var getTFResult = await transformations.GetTransformationsByPartAndSpeciesAsync(part, templateSpecies); if (!getTFResult.IsSuccess) { // Allow skipping of missing composing parts - a composite part might not have all of them in a TF. if (part.IsComposingPart()) { continue; } return(CreateEntityResult <Appearance> .FromError(getTFResult)); } templateTransformations.AddRange(getTFResult.Entity); } var templateComponents = new List <AppearanceComponent>(); foreach (var tf in templateTransformations) { if (tf.Part.IsChiral()) { templateComponents.AddRange(AppearanceComponent.CreateFromChiral(tf)); } else { templateComponents.Add(AppearanceComponent.CreateFrom(tf)); } } var appearance = new Appearance(character); appearance.Components.AddRange(templateComponents); return(CreateEntityResult <Appearance> .FromSuccess(appearance)); }
public void AddComputerToOrder(string orderId, AddComputersToOrderDto computersToOrderDto) { User user = AuthenticationService.AuthenticateUser(_username, _password); ValidationService.ValidateAddComputersToOrderDto(computersToOrderDto); Order order = QueryService.FindOrder(orderId); if (!order.User.Username.Equals(user.Username)) { throw new Exception("Order doesn't belong to user. User: " + _username); } Entities entities = DatabaseContext.GetEntities(); foreach (var orderLineDto in computersToOrderDto.OrderLines) { OrderLine orderLine = order.OrderLines.FirstOrDefault(ol => ol.Computer.Guid == orderLineDto.ComputerId); if (orderLine != null) { orderLine.Quantity += orderLineDto.Quantity; } else { order.OrderLines.Add(TransformationService.AddOrderLineToOrderLine(orderLineDto)); } } entities.Save(); }
//TODO: string filename param not used public ActionResult TransformationGrid_Read([DataSourceRequest] DataSourceRequest request, string filename, int setId) { TransformationService demiService = new TransformationService(new DEMIContext()); IEnumerable <TransformationViewModel> transformations = demiService.Transformations_Read(setId); DataSourceResult result = transformations.ToDataSourceResult(request); return(Json(result)); }
public List <ComputerInfoDto> All() { var computers = QueryService.GetAllComputers(); List <ComputerInfoDto> computersDtos = new List <ComputerInfoDto>(); computers.ForEach(computer => computersDtos.Add(TransformationService.ComputerToResponseComputerDto(computer))); return(computersDtos); }
/// <summary> /// Initializes a new instance of the <see cref="CharacterServiceTestBase"/> class. /// </summary> protected CharacterServiceTestBase() { this.Commands = new CommandService(); var content = new ContentService(); this.Transformations = new TransformationService(content); this.Characters = new CharacterService(this.Commands, new OwnedEntityService(), content, this.Transformations); }
/// <summary> /// Step 1: auto-complete for drop down box /// </summary> public ActionResult GetTransformationSets(string text) { TransformationService demiService = new TransformationService(new DEMIContext()); IEnumerable <TransformationSetViewModel> result = demiService. TransformationSets_Read(UserName).Where(t => t.Name.Contains(text)).ToList(); return(Json(result, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Step 3: file download /// </summary> public void DownloadTransformedData(int setId) { TransformationService service = new TransformationService(new DEMIContext()); DataTable transformedData = service.RunTransformation(UserName, setId); string fileName = transformedData.TableName; string fileContents = transformedData.GetTableContent(); DownloadTextFile(fileContents, fileName); }
public void AddComputer(AddComputerDto addComputerDto) { AuthenticationService.AuthenticateRoot(_username, _password); ValidationService.ValidateRequestComputerDto(addComputerDto); Computer computer = TransformationService.RequestComputerToComputerDto(addComputerDto); var entities = DatabaseContext.GetEntities(); entities.Computers.Add(computer); entities.Save(); }
public ComputerInfoDto FindComputerByName(string name) { var computer = QueryService.FindComputerByName(name); if (computer == null) { throw new Exception("Computer not found, name: " + name); } return(TransformationService.ComputerToResponseComputerDto(computer)); }
public ComputerInfoDto GetComputerInfo(string id) { var computer = QueryService.FindComputerByGuid(id); if (computer == null) { throw new Exception("Computer not found, Id: " + id); } return(TransformationService.ComputerToResponseComputerDto(computer)); }
/// <summary> /// Initializes a new instance of the <see cref="TransformationListCommands"/> class. /// </summary> /// <param name="transformation">The transformation service.</param> /// <param name="feedback">The interactivity service.</param> /// <param name="context">The command context.</param> public TransformationListCommands ( TransformationService transformation, FeedbackService feedback, ICommandContext context ) { _transformation = transformation; _feedback = feedback; _context = context; }
/// <summary> /// Step 2: load ("Next Step" in Step 1) /// </summary> public ActionResult CreateTransformationSet(string setName, string fileName) { fileName = String.Format("{0}_{1}", UserName, Path.GetFileName(fileName)); string fullPath = Path.Combine(Settings.InputFilesPath, fileName); TransformationService demiService = new TransformationService(new DEMIContext()); int result = demiService.CreateTransformationSet(UserName, setName, fullPath); //TODO: return as int return(Content(result.ToString())); }
/// <summary> /// Initializes a new instance of the <see cref="PatternRemover"/> class. /// </summary> /// <param name="appearance">The appearance to shift.</param> /// <param name="transformations">The transformation service.</param> /// <param name="descriptionBuilder">The description builder.</param> public PatternRemover ( [NotNull] Appearance appearance, [NotNull] TransformationService transformations, [NotNull] TransformationDescriptionBuilder descriptionBuilder ) : base(appearance) { _transformations = transformations; _descriptionBuilder = descriptionBuilder; }
public static async Task <Result <IReadOnlyList <Transformation> > > DiscoverBundledTransformationsAsync ( this ContentService @this, TransformationService transformation, Species species ) { const string speciesFilename = "Species.yml"; var speciesDir = GetSpeciesDirectory(species); var transformationFiles = @this.FileSystem.EnumerateFiles(speciesDir) .Where(p => !p.ToString().EndsWith(speciesFilename)); var transformations = new List <Transformation>(); var deserializer = new DeserializerBuilder() .WithTypeConverter(new ColourYamlConverter()) .WithTypeConverter(new SpeciesYamlConverter(transformation)) .WithTypeConverter(new EnumYamlConverter <Pattern>()) .WithTypeConverter(new NullableEnumYamlConverter <Pattern>()) .WithNodeDeserializer(i => new ValidatingNodeDeserializer(i), s => s.InsteadOf <ObjectNodeDeserializer>()) .WithNamingConvention(UnderscoredNamingConvention.Instance) .Build(); foreach (var transformationFile in transformationFiles) { var getTransformationFileStream = @this.OpenLocalStream(transformationFile); if (!getTransformationFileStream.IsSuccess) { continue; } string content; await using (var transformationFileStream = getTransformationFileStream.Entity) { content = await AsyncIO.ReadAllTextAsync(transformationFileStream); } try { transformations.Add(deserializer.Deserialize <Transformation>(content)); } catch (YamlException yex) { if (yex.InnerException is SerializationException sex) { return(Result <IReadOnlyList <Transformation> > .FromError(sex)); } return(Result <IReadOnlyList <Transformation> > .FromError(yex)); } } return(Result <IReadOnlyList <Transformation> > .FromSuccess(transformations)); }
public UserInfoDto GetUser(string userId) { AuthenticationService.AuthenticateRoot(_username, _password); User user = QueryService.FindUserById(userId); if (user == null) { throw new Exception("User not found. Id: " + userId); } return(TransformationService.UserToUserInfoDto(user)); }
private Response <TResponse> ExecuteInternal(string json) { try { return(TransformationService.Deserialize <Response <TResponse> >(json)); } catch (Exception ex) { throw new DeserializeException( $"Ошибка десериализации ответа. Тип ответа: {typeof(TResponse).Name}.", ex); } }
/// <summary> /// Initializes a new instance of the <see cref="PatternColourShifter"/> class. /// </summary> /// <param name="appearance">The appearance to shift.</param> /// <param name="colour">The colour to shift into.</param> /// <param name="transformations">The transformation service.</param> /// <param name="descriptionBuilder">The description builder.</param> public PatternColourShifter ( [NotNull] Appearance appearance, [NotNull] Colour colour, [NotNull] TransformationService transformations, [NotNull] TransformationDescriptionBuilder descriptionBuilder ) : base(appearance) { _colour = colour; _transformations = transformations; _descriptionBuilder = descriptionBuilder; }
/// <summary> /// Initializes a new instance of the <see cref="SpeciesShifter"/> class. /// </summary> /// <param name="appearance">The appearance that is being shifted.</param> /// <param name="species">The species to shift into.</param> /// <param name="transformations">The transformation service.</param> /// <param name="descriptionBuilder">The description builder.</param> public SpeciesShifter ( Appearance appearance, Species species, TransformationService transformations, TransformationDescriptionBuilder descriptionBuilder ) : base(appearance) { _species = species; _transformations = transformations; _descriptionBuilder = descriptionBuilder; }
public void Initialize() { Logger.LogActivity("IDATests - TransformationServiceTests - Start"); _DemiContext = new DEMIContext(); _TransformationService = new TransformationService(_DemiContext); _ExcelService = new ExcelService(); DeleteTransformationSet("UnitTest_CreateTransformationSet"); DeleteTransformation("UnitTest_UpdateTransformationSetAddTwoFields", "Field5"); DeleteTransformation("UnitTest_UpdateTransformationSetAddTwoFields", "Field6"); DropTable(_DemiContext.GetTransformedDataTableName(USER_NAME)); }
/// <summary> /// Initializes a new instance of the <see cref="TransformationCommands"/> class. /// </summary> /// <param name="database">A database context from the context pool.</param> /// <param name="feedback">The feedback service.</param> /// <param name="characters">The character service.</param> /// <param name="transformation">The transformation service.</param> public TransformationCommands ( GlobalInfoContext database, UserFeedbackService feedback, CharacterService characters, TransformationService transformation ) { this.Database = database; this.Feedback = feedback; this.Characters = characters; this.Transformation = transformation; }
/// <summary> /// Initializes a new instance of the <see cref="TransformationSetCommands"/> class. /// </summary> /// <param name="characters">The character service.</param> /// <param name="transformation">The transformation service.</param> /// <param name="context">The command context.</param> /// <param name="feedback">The feedback service.</param> public TransformationSetCommands ( CharacterDiscordService characters, TransformationService transformation, ICommandContext context, FeedbackService feedback ) { _characters = characters; _transformation = transformation; _context = context; _feedback = feedback; }
public OrderInformationDto GetOrderInformation(string orderId) { User user = AuthenticationService.AuthenticateUser(_username, _password); Order order = QueryService.FindOrder(orderId); if (order == null) { throw new Exception($"Order not found. Id: {orderId}"); } if (!order.User.Username.Equals(user.Username)) { throw new Exception("Order doesn't belong to user. User: " + _username); } return(TransformationService.OrderToOrderInformationDto(order)); }
/// <summary> /// Initializes a new instance of the <see cref="TransformationCommands"/> class. /// </summary> /// <param name="feedback">The feedback service.</param> /// <param name="characters">The character service.</param> /// <param name="transformation">The transformation service.</param> /// <param name="content">The content service.</param> /// <param name="context">The command context.</param> public TransformationCommands ( FeedbackService feedback, CharacterDiscordService characters, TransformationService transformation, ContentService content, ICommandContext context ) { _feedback = feedback; _characters = characters; _transformation = transformation; _content = content; _context = context; }
/// <summary> /// Initializes a new instance of the <see cref="TransformationCommands"/> class. /// </summary> /// <param name="feedback">The feedback service.</param> /// <param name="characters">The character service.</param> /// <param name="transformation">The transformation service.</param> /// <param name="interactivity">The interactivity service.</param> /// <param name="content">The content service.</param> public TransformationCommands ( UserFeedbackService feedback, CharacterDiscordService characters, TransformationService transformation, InteractivityService interactivity, ContentService content ) { _feedback = feedback; _characters = characters; _transformation = transformation; _interactivity = interactivity; _content = content; }
public static void RunTest(string directoryName, string caseName) { // Arrange var sourceText = File.ReadAllText(Path.Combine(directoryName, caseName, "Source.cs")); var expected = File.ReadAllText(Path.Combine(directoryName, caseName, "Expected.gls")); // Act var transformation = TransformationService.TransformFile("Source.cs", sourceText); var actual = string.Join( Environment.NewLine, TransformationPrinter.Print(sourceText, transformation) ); // Assert #pragma warning disable xUnit2006 // The diffs are better from <string> Assert.Equal <string>(expected, actual); }
public NewUserIdDto CreateUser(NewUserDto newUserDto) { AuthenticationService.AuthenticateRoot(_username, _password); ValidationService.ValidatedNewUserDto(newUserDto); if (QueryService.FindUserByUsername(newUserDto.Username) != null) { throw new Exception("Cannot create user. Username is duplicate. Username: " + newUserDto.Username); } User user = TransformationService.NewUserDtoToUser(newUserDto); Entities entities = DatabaseContext.GetEntities(); entities.Users.Add(user); entities.Save(); return(new NewUserIdDto { Id = user.Guid }); }
/// <summary> /// Initializes a new instance of the <see cref="TransformationCommands"/> class. /// </summary> /// <param name="feedback">The feedback service.</param> /// <param name="characters">The character service.</param> /// <param name="transformation">The transformation service.</param> /// <param name="interactivity">The interactivity service.</param> /// <param name="users">The user service.</param> /// <param name="content">The content service.</param> public TransformationCommands ( [NotNull] UserFeedbackService feedback, [NotNull] CharacterService characters, [NotNull] TransformationService transformation, [NotNull] InteractivityService interactivity, [NotNull] UserService users, [NotNull] ContentService content ) { _feedback = feedback; _characters = characters; _transformation = transformation; _interactivity = interactivity; _users = users; _content = content; }
public ActionResult TransformationGrid_Update([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable <TransformationViewModel> transformations, int setId) { if (transformations != null && ModelState.IsValid) { try { TransformationService demiService = new TransformationService(new DEMIContext()); demiService.Transformations_Update(transformations); } catch (Exception ex) { Logger.LogException(ex); ModelState.AddModelError("", ex.Message); } } return(Json(transformations.ToDataSourceResult(request, ModelState))); }
public async Task <object> RunOperation() { using (var da = new WorkflowDataAccess(_conStr)) { var operations = await da.GetOperations(_workflowId); var transformationPayload = operations.Where(o => o.Name == "Transformation Payload").FirstOrDefault(); if (operations.Any()) { List <IDictionary <string, object> > transformedList = new List <IDictionary <string, object> >(); dynamic salesforceResult = null; foreach (var item in operations) { var excelList = new List <Dictionary <string, object> >(); switch (item.Type.ToString()) { case "Salesforce": if (item.Pos == 0) { var sfService = new SalesforceService(_conStr, _workflowId); var intermediateJson = JsonConvert.DeserializeObject <string>(item.Content); if (!string.IsNullOrWhiteSpace(intermediateJson) && intermediateJson.Contains("SELECT")) { salesforceResult = await sfService.ExecuteSourceOperation(intermediateJson); } } else if (item.Name == "Salesforce Target Object Selection") { var sfService = new SalesforceService(_conStr, _workflowId); salesforceResult = await sfService.ExecuteTargetOperation(item, transformedList); } break; case "Excel": var excelService = new ExcelService(_conStr, _workflowId); if (item.Pos == 0) { excelList = (await excelService.ExecuteSourceOperation(item)).ToList(); } else { var content = JsonConvert.DeserializeObject <ExcelConfig>(item.Content); if (!string.IsNullOrWhiteSpace(content.FileName)) { var blobFileName = await excelService.ExecuteTargetOperation(content.FileName, salesforceResult); if (!string.IsNullOrWhiteSpace(blobFileName)) { using (var ds = new DocumentService()) { await ds.CreateDocument(content.FileName, "", null, ".xls", _workflowId, blobFileName); return(new { localFileSystem = content.IsLocalFileSystem, fileName = blobFileName }); } } } } break; default: break; } if (item.Pos == 0 && excelList.Any()) { var tService = new TransformationService(_conStr, _workflowId); transformedList = (await tService.ExecuteOperation(transformationPayload, excelList)).Take(1).ToList(); } } } } return(new { Success = false, Message = "Operation Unsuccesfully" });; }
/// <summary> /// Initializes a new instance of the <see cref="SpeciesYamlConverter"/> class. /// </summary> /// <param name="transformation">The transformation service.</param> public SpeciesYamlConverter([NotNull] TransformationService transformation) { this.Transformation = transformation; }