private async Task SendReportEmail(ProjectImport projectImport, List <string> outputLines) { var locale = projectImport.Owner.LocaleOrDefault(); string subject = await translator.TranslateAsync(locale, "importProject", "importProject.subject", null); string title = await translator.TranslateAsync(locale, "importProject", "importProject.title", null); string propertiesHeader = await translator.TranslateAsync(locale, "importProject", "importProject.propertiesHeader", null); string outputHeader = await translator.TranslateAsync(locale, "importProject", "importProject.outputHeader", null); var propertyLines = new List <string>(); await TranslateProperty(propertyLines, locale, "Owner", projectImport.Owner.Name); await TranslateProperty(propertyLines, locale, "Group", projectImport.Group.Name); await TranslateProperty(propertyLines, locale, "Organization", projectImport.Organization.Name); await TranslateProperty(propertyLines, locale, "Application Type", projectImport.Type.Description); var email = new Email { To = projectImport.Owner.Email, Subject = subject, ContentTemplate = "ProjectImport.txt", ContentModel = new { Title = title, PropertiesHeader = propertiesHeader, Properties = propertyLines, OutputHeader = outputHeader, Output = outputLines } }; await emailRepository.CreateAsync(email); }
/// <summary> /// Importe un projet. /// </summary> /// <param name="import">Les données à importer.</param> /// <param name="mergeReferentials"><c>true</c> pour fusionner les référentiels.</param> /// <param name="videosDirectory">Le dossier qui contient les vidéos.</param> public virtual async Task <Project> ImportProject(ProjectImport import, bool mergeReferentials, string videosDirectory) => await Task.Run(async() => { using (var context = ContextFactory.GetNewContext()) { return(await ImportProject(context, import, mergeReferentials, videosDirectory)); } });
/// <summary> /// Importe un projet. /// </summary> /// <param name="import">Les données à importer.</param> /// <param name="mergeReferentials"><c>true</c> pour fusionner les référentiels.</param> /// <param name="videosDirectory">Le dossier qui contient les vidéos.</param> public virtual async Task <Project> ImportProject(ProjectImport import, bool mergeReferentials, string videosDirectory) => await Task.Run(async() => { dynamic param = new ExpandoObject(); param.import = import; param.mergeReferentials = mergeReferentials; param.videosDirectory = videosDirectory; return(await _apiHttpClient.ServiceAsync <Project>(KL2_Server.API, nameof(ImportExportService), nameof(ImportProject), param)); });
public async Task <IHttpActionResult> ImportProject([DynamicBody] dynamic param) { try { ProjectImport import = param.allScenarios.ToObject <ProjectImport>(); bool mergeReferentials = param.allScenarios.ToObject <bool>(); string videosDirectory = param.allScenarios.ToObject <string>(); await _importExportService.ImportProject(import, mergeReferentials, videosDirectory); return(Ok()); } catch (Exception ex) { _traceManager.TraceError(ex, ex.Message); return(InternalServerError(ex)); } }
private void DrawAssetSelection() { CurrentPackage = (ProjectImport)EditorGUILayout.ObjectField(CurrentPackage, typeof(ProjectImport), true); if (CurrentPackage != null) { var explorer = CurrentPackage.Explorer; foreach (var resource in explorer.Resources) { if (!resource.Name.EndsWith(".bhvr")) { continue; } if (GUILayout.Button(resource.ToString())) { CurrentResource = resource; JObject editorTarget; using (var editorTargetData = CurrentResource.LoadStream()) using (var sr = new StreamReader(editorTargetData)) using (var reader = new JsonTextReader(sr)) { editorTarget = JObject.Load(reader); } var nodes = NodeManifest.Construct(new Type[] { typeof(AddNode), typeof(RollNode), typeof(OutputValueNode) }); var types = TypeManifest.ConstructBaseTypes(); var manifest = new BehaviourManifest() { Nodes = nodes, Types = types, }; Debug.Log(editorTarget); var graphEditor = new EditorSession(manifest, editorTarget, "SerializedGraph", Serializer); View.BeginSession(graphEditor); } } } }
public override void OnGUI() { if (resourceTreeViewState == null) { resourceTreeViewState = new TreeViewState(); } if (resourceTreeView == null) { resourceTreeView = new ResourceTreeView(resourceTreeViewState); } CurrentPackage = (ProjectImport)EditorGUILayout.ObjectField(CurrentPackage, typeof(ProjectImport), true, GUILayout.Width(180)); if (CurrentPackage == null) { return; } if (resourceTreeView != null) { resourceTreeView.SetTarget(CurrentPackage.Explorer); var treeViewRect = new Rect( 0, EditorGUIUtility.singleLineHeight + 6, 180, Position.height - EditorGUIUtility.singleLineHeight - 6); var remainingRect = new Rect( 184, 0, Position.width - 184, Position.height); resourceTreeView.OnGUI(treeViewRect); GUILayout.BeginArea(remainingRect); foreach (int selected in resourceTreeView.GetSelection()) { if (resourceTreeView.resourceMapping.TryGetValue(selected, out var resource)) { if (CurrentResource != resource) { CurrentResource = resource; CurrentResourceTabs.Clear(); try { CurrentResourceTabs.Add(new FrameTab() { Title = new GUIContent("Editor"), Frame = new EditorSessionFrame(CurrentResource) }); } catch { } CurrentResourceTabs.Add(new FrameTab() { Title = new GUIContent("Information"), Frame = new ResourceInformationFrame(CurrentResource) }); } } EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); for (int i = 0; i < CurrentResourceTabs.Count; i++) { var tab = CurrentResourceTabs[i]; if (GUILayout.Button(tab.Title, EditorStyles.toolbarButton)) { CurrentResourceTabIndex = i; } } EditorGUILayout.EndHorizontal(); if (CurrentResourceTabIndex >= 0 && CurrentResourceTabIndex < CurrentResourceTabs.Count) { var currentTab = CurrentResourceTabs[CurrentResourceTabIndex]; currentTab.Frame.OnGUI(); } } GUILayout.EndArea(); } }
public async Task <bool> IsValid(ProjectImport projectImport) { // Project and ProjectImport have the same base properties for Organization, // Owner, and Group. So we can reuse those checks. // If these fields aren't filled in, then let the foreign key failure // be reported if ((projectImport.OrganizationId != VALUE_NOT_SET) && (projectImport.OwnerId != VALUE_NOT_SET) && (projectImport.GroupId != VALUE_NOT_SET)) { Organization = await OrganizationRepository.Get() .Where(o => o.Id == projectImport.OrganizationId) .Include(o => o.OrganizationProductDefinitions) .Include(o => o.OrganizationStores) .FirstOrDefaultAsync(); Group = await GroupRepository.Get() .Where(g => g.Id == projectImport.GroupId) .Include(g => g.Owner).FirstOrDefaultAsync(); ProjectOwner = await UserRepository.Get() .Where(u => u.Id == projectImport.OwnerId) .Include(u => u.OrganizationMemberships) .ThenInclude(om => om.Organization) .FirstOrDefaultAsync(); CurrentUserOrgIds = CurrentUser.OrganizationIds.OrEmpty(); base.ValidateProject(); } if (base.IsValid()) { // Verify the Products var importData = JsonConvert.DeserializeObject <ImportData>(projectImport.ImportData); foreach (var importProduct in importData.Products) { var productDefinition = await ProductDefinitionRepository.Get() .Where(pd => pd.Name == importProduct.Name) .Include(pd => pd.Workflow) .FirstOrDefaultAsync(); if (productDefinition == null) { var message = $"The product.Name={importProduct.Name} was not found"; AddError(message); } else if (!Organization.ProductDefinitionIds.Contains(productDefinition.Id)) { var message = $"The product.Name={importProduct.Name} is not allowed for organization.Name={Organization.Name}"; AddError(message); } var store = await StoreRepository.Get() .Where(s => s.Name == importProduct.Store) .Include(s => s.StoreType) .ThenInclude(st => st.Languages) .FirstOrDefaultAsync(); if (store == null) { var message = $"The product.Store={importProduct.Store} was not found"; AddError(message); } else { if (!Organization.StoreIds.Contains(store.Id)) { var message = $"The product.Store={importProduct.Store} is not allowed for organization.Name={Organization.Name}"; AddError(message); } if (store.StoreTypeId != productDefinition.Workflow.StoreTypeId) { var message = "The store type values do not match for this product"; AddError(message); } // Not validating Product.StoreLanguageId since it will be coming // from the project's default-language and should be validated in SAB?? } } } return(base.IsValid()); }
/// <summary> /// Importe le projet spécifié. /// </summary> /// <param name="context">Le contexte.</param> /// <param name="import">Le projet exporté.</param> /// <param name="mergeReferentials"><c>true</c> pour fusionner les référentiels.</param> /// <param name="videosDirectory">Le dossier où se situent les vidéos.</param> /// <returns>Le projet créé.</returns> private async Task <Project> ImportProject(KsmedEntities context, ProjectImport import, bool mergeReferentials, string videosDirectory) { // Projet var p = import.ExportedProject.Project; p.ProjectId = default(int); MarkAsAdded(p); // Ajouter l'utilisateur courant en tant qu'analyste créateur var owner = await context.Users.FirstAsync(u => !u.IsDeleted && u.Username == _securityContext.CurrentUser.Username); p.Process.Owner = owner; p.Process.UserRoleProcesses.Add(new UserRoleProcess() { User = owner, RoleCode = KnownRoles.Analyst, }); // Videos foreach (var video in p.Process.Videos) { if (video.DefaultResourceId.HasValue && video.DefaultResource == null) { // Bug présent dans certains exports de la version 2.5.0.0. Supprimer le lien vers la ressource par défaut. video.DefaultResourceId = null; } video.VideoId = default(int); MarkAsAdded(video); video.FilePath = IOHelper.ChangeDirectory(video.FilePath, videosDirectory); } var referentialsToRemap = new Dictionary <IActionReferential, IActionReferential>(); if (!mergeReferentials) { // Référentiels process foreach (var refe in import.ExportedProject.ReferentialsProject) { MarkAsAdded(refe); } // Référentiels standard foreach (var refe in import.ExportedProject.ReferentialsStandard) { var refProject = ReferentialsFactory.CopyToNewProject(refe); // Associer au process refProject.Process = p.Process; referentialsToRemap[refe] = refProject; } } else { // Référentiels process foreach (var refe in import.ExportedProject.ReferentialsProject) { // Ajouter au tableau de remap s'il y a une correspondance. if (import.ProjectReferentialsMergeCandidates.ContainsKey(refe)) { referentialsToRemap[refe] = import.ProjectReferentialsMergeCandidates[refe]; } else { MarkAsAdded(refe); } } // Référentiels standard foreach (var refe in import.ExportedProject.ReferentialsStandard) { if (import.StandardReferentialsMergeCandidates.ContainsKey(refe)) { referentialsToRemap[refe] = import.StandardReferentialsMergeCandidates[refe]; } else { var refProject = ReferentialsFactory.CopyToNewProject(refe); // Associer au process refProject.Process = p.Process; referentialsToRemap[refe] = refProject; } } } // Scénarios foreach (var scenario in p.Scenarios.Where(s => s.OriginalScenarioId.HasValue)) { // Remapper l'original scenario.Original = p.Scenarios.Single(s => s.ScenarioId == scenario.OriginalScenarioId); } foreach (var scenario in p.Scenarios) { foreach (var action in scenario.Actions.Where(a => a.OriginalActionId.HasValue)) { // Remapper l'original action.Original = p.Scenarios.SelectMany(s => s.Actions).Single(a => a.ActionId == action.OriginalActionId); } } foreach (var scenario in p.Scenarios) { scenario.ScenarioId = default(int); MarkAsAdded(scenario); // Supprimer le WebPublicationGuid scenario.WebPublicationGuid = null; // Actions foreach (var action in scenario.Actions) { action.ActionId = default(int); MarkAsAdded(action); // Actions réduites if (action.IsReduced) { MarkAsAdded(action.Reduced); } } } // Remapper les référentiels du projet, des actions et des vidéos foreach (var oldReferential in referentialsToRemap.Keys) { ReferentialsHelper.UpdateReferentialReferences(p, oldReferential, referentialsToRemap[oldReferential]); } foreach (var scenario in p.Scenarios) { if (scenario.Original != null) { context.Scenarios.ApplyChanges(scenario); ObjectContextExt.SetRelationShipReferenceValue(context, scenario, scenario.Original, s => s.OriginalScenarioId); foreach (var action in scenario.Actions) { if (action.Original != null) { context.KActions.ApplyChanges(action); ObjectContextExt.SetRelationShipReferenceValue(context, action, action.Original, a => a.OriginalActionId); } } } } var resources = p.Scenarios.SelectMany(s => s.Actions).Select(a => a.Resource).Distinct().ToArray(); context.Projects.ApplyChanges(p); if (mergeReferentials) { ServicesDiagnosticsDebug.CheckNotInContext(context, referentialsToRemap.Keys); ServicesDiagnosticsDebug.CheckObjectStateManagerState(context, EntityState.Unchanged, referentialsToRemap.Values); } ServicesDiagnosticsDebug.CheckReferentialsState(); await context.SaveChangesAsync(); return(p); }
private void DrawAssetSelection() { CurrentPackage = (ProjectImport)EditorGUILayout.ObjectField(CurrentPackage, typeof(ProjectImport), true, GUILayout.Width(180)); if (CurrentPackage == null) { return; } var explorer = CurrentPackage.Explorer; foreach (var resource in explorer.Resources) { if (!resource.Name.EndsWith(".bhvr")) { continue; } if (GUILayout.Button(resource.ToString())) { CurrentResource = resource; JObject editorTarget; using (var editorTargetData = CurrentResource.LoadStream()) using (var sr = new StreamReader(editorTargetData)) using (var reader = new JsonTextReader(sr)) { editorTarget = JObject.Load(reader); } var nodes = NodeManifest.Construct(new Type[] { typeof(AddNode), typeof(RollNode), typeof(OutputValueNode), typeof(ItemInputNode), typeof(ActivatableItemNode), typeof(IterateNode), typeof(GetStatNode), }); var types = TypeManifest.Construct( new Type[] { typeof(bool), typeof(string), typeof(int), typeof(byte), typeof(long), typeof(short), typeof(uint), typeof(ulong), typeof(ushort), typeof(sbyte), typeof(char), typeof(float), typeof(double), typeof(decimal), typeof(InputSocket), typeof(LocalId), }, new Type[] { typeof(SerializedGraph), typeof(SerializedNode), typeof(PackageNodeEditor), typeof(PackageNodePosition), typeof(ExtraData) } ); var manifest = new BehaviourManifest() { Nodes = nodes, Types = types, }; Debug.Log(editorTarget); var graphEditor = new EditorSession(manifest, editorTarget, "SerializedGraph", Serializer); View.BeginSession(graphEditor, graphEditor.Root); } } }
public void OnGUI() { screenRect = new Rect(0, EditorGUIUtility.singleLineHeight + 1, position.width, position.height - (EditorGUIUtility.singleLineHeight + 1)); currentEvent = Event.current; // HandleDragAndDrop (screenRect); DrawBackground(screenRect, dragging_Position); DrawTopBar(); CurrentPackage = (ProjectImport)EditorGUILayout.ObjectField(CurrentPackage, typeof(ProjectImport), true); var explorer = CurrentPackage.Explorer; foreach (var resource in explorer.Resources) { if (!resource.Name.EndsWith(".bhvr")) { continue; } if (GUILayout.Button(resource.ToString())) { CurrentResource = resource; HasCurrentResource = true; HasEditor = false; } } if (HasCurrentResource && CurrentResource != null) { if (HasEditor == false) { Debug.Log(CurrentResource); var editorTargetData = CurrentResource.LoadStream(); using (var sr = new StreamReader(editorTargetData)) using (var reader = new JsonTextReader(sr)) { editorTarget = JObject.Load(reader); // editorTarget = serializer.Deserialize(reader); } var nodes = NodeManifest.Construct(new Type[] { typeof(AddNode), typeof(RollNode) }); var types = TypeManifest.ConstructBaseTypes(); var manifest = new BehaviourManifest() { Nodes = nodes, Types = types, }; Debug.Log(editorTarget); graphEditor = new EditorSession(manifest, editorTarget, "SerializedGraph"); HasEditor = true; } if (GUILayout.Button("Save")) { using (var file = CurrentResource.WriteStream()) { serializer.Serialize(new JsonTextWriter(file) { Formatting = Formatting.Indented }, editorTarget); } } foreach (var node in graphEditor.Root["Nodes"]) { var nodeEditor = node["Editor"]; var nodeEditorPosition = nodeEditor["Position"]; var nodeRect = new Rect( dragging_Position.x + nodeEditorPosition["x"].GetValue <int>(), dragging_Position.y + nodeEditorPosition["y"].GetValue <int>(), 200, 160 ); bool startDrag = false; if (Event.current.type == EventType.Repaint) { BehaviourGraphResources.Instance.NodeStyle.Draw(nodeRect, false, node.Name == selectedNode, false, false); } GUILayout.BeginArea(nodeRect); var nodeData = node.Json["Data"]; var nodeType = node["Type"]; object fieldObject; if (!node.ViewBag.TryGetValue("Generic", out fieldObject)) { var fieldInformation = new FieldInformation(); fieldInformation.Type = nodeType.Json.ToObject <string>(); fieldObject = new EditorField(graphEditor, nodeData, node.Name, fieldInformation); node.ViewBag["Generic"] = fieldObject; } var field = (EditorField)fieldObject; foreach (var childField in field) { DrawField(childField); } GUILayout.EndArea(); if (Event.current.type == EventType.MouseDown) { if (nodeRect.Contains(Event.current.mousePosition)) { selectedNode = node.Name; dragging_IsDragging = true; dragging_NodeDragging = true; GUI.UnfocusWindow(); GUI.FocusControl(""); Event.current.Use(); } } } foreach (var node in graphEditor.Root["Nodes"]) { var nodeEditor = node["Editor"]; var nodeEditorPosition = nodeEditor["Position"]; var nodePositionX = nodeEditorPosition["x"].GetValue <int>() + dragging_Position.x; var nodePositionY = nodeEditorPosition["y"].GetValue <int>() + dragging_Position.y; var nodeData = node.Json["Data"]; var nodeType = node["Type"]; object fieldObject; if (!node.ViewBag.TryGetValue("Generic", out fieldObject)) { var fieldInformation = new FieldInformation(); fieldInformation.Type = nodeType.Json.ToObject <string>(); fieldObject = new EditorField(graphEditor, nodeData, node.Name, fieldInformation); node.ViewBag["Generic"] = fieldObject; } var field = (EditorField)fieldObject; foreach (var childField in field) { if (childField.Field.Type == "InputSocket") { object renderPosObject; var renderPos = new Rect();; if (childField.ViewBag.TryGetValue("Position", out renderPosObject)) { renderPos = (Rect)renderPosObject; } else { Debug.LogError(childField.Name + " has no position"); } renderPos.x += nodePositionX; renderPos.y += nodePositionY; // EditorGUI.DrawRect(renderPos, Color.red); Vector3 start = new Vector3(renderPos.x, renderPos.y); Vector3 end = new Vector3(renderPos.x - 100, renderPos.y - 100); Vector3 startDir = new Vector3(-1, 0); Vector3 endDir = new Vector3(1, 0); DrawConnection(start, end, startDir, endDir); } } } } HandleInput(); }