public IActionResult SaveImportFile(IFormCollection collection) { //try { var selectedItems = collection["treeViewNodes"]; List <TreeViewNode> treeViewNodes = JsonConvert.DeserializeObject <List <TreeViewNode> >(selectedItems); var value = HttpContext.Session.GetString("ExportSchema"); var valueab = HttpContext.Session.GetString("ExportSchemaab"); Export ex = JsonConvert.DeserializeObject <Export>(value); //update export.object.action with the user consent //foreach entity, baseview, list in export, check and update consent if (treeViewNodes.Count != 0) { foreach (var item in ex.Entities.Entity) { TreeViewNode n = treeViewNodes.Where(e => e.id == item.Id).FirstOrDefault(); if (n != null) { if (item.action == SynapseHelpers.MigrationAction.Update) { List <Action> createActionsAttribute = item.attributeActions.Where(x => x.migrationAction == SynapseHelpers.MigrationAction.New && x.sourceContextId == item.Id && x.dbTableName.Equals("entitysettings.entityattribute")).ToList(); List <Action> createActionsRelations = item.attributeActions.Where(x => x.migrationAction == SynapseHelpers.MigrationAction.New && x.sourceContextId == item.Id && x.dbTableName.Equals("entitysettings.entityrelation")).ToList(); if (createActionsAttribute.Count != 0) { foreach (var action in createActionsAttribute) { TreeViewNode n1 = treeViewNodes.Where(e => e.id == "newattributes").FirstOrDefault(); if (n1 == null) { action.migrationAction = SynapseHelpers.MigrationAction.Skip; } } } if (createActionsRelations.Count != 0) { foreach (var action in createActionsRelations) { TreeViewNode n1 = treeViewNodes.Where(e => e.id == "newrelations").FirstOrDefault(); //TreeNode n1 = tv.FindNode("entities/entitiesupdate/" + item.Id + "/newrelations/" + action.sourceComponentId); if (n1 == null) { action.migrationAction = SynapseHelpers.MigrationAction.Skip; } } } } //item.action = SynapseHelpers.MigrationAction.Skip; } } foreach (Baseview b in ex.Baseviews.Baseview) { TreeViewNode n = treeViewNodes.Where(e => e.id == b.Id).FirstOrDefault(); //TreeNode n = tv.FindNode("baseviews/baseviews" + b.action.ToString().ToLower() + "/" + b.Id); if (n == null) { b.action = SynapseHelpers.MigrationAction.Skip; } } foreach (SList l in ex.SLists.SList) { TreeViewNode n = treeViewNodes.Where(e => e.id == l.Id).FirstOrDefault(); // TreeNode n = tv.FindNode("lists/lists" + l.action.ToString().ToLower() + "/" + l.Id); if (n == null) { l.action = SynapseHelpers.MigrationAction.Skip; } } //Task task = new Task(() => SynapseHelpers.ApplySchemaChanges(ex)); //task.Start(); new TaskFactory().StartNew(() => SynapseHelpers.ApplySchemaChanges(ex)); //showProcessMsgs(); ViewBag.Json = new List <TreeViewNode>(); this.toastNotification.AddSuccessToastMessage("Successfully migrated the schema."); } else { //lblErrorSelectObjects.Text = "Looks like there is nothing to import!"; this.toastNotification.AddInfoToastMessage("Looks like there is nothing to import!"); } } /*catch (Exception exception) * { * //lblError.Text = "There was an error processing the export. Please try again. "; * //lblError.Text += exception.Message; * //tv.Nodes.Clear(); * //showFileUpload(); * ViewBag.Json = new List<TreeViewNode>(); * }*/ return(RedirectToAction("SchemaImport", new { import = "yes" })); }
protected void btnImport_Click(object sender, EventArgs e) { if (Session["export"] == null) { lblError.Text = "There was an error generating export object. Please try again."; tv.Nodes.Clear(); showFileUpload(); return; } try { Export ex = (Export)Session["export"]; //update export.object.action with the user consent //foreach entity, baseview, list in export, check and update consent if (tv.Nodes.Count != 0) { foreach (var item in ex.Entities.Entity) { TreeNode n = tv.FindNode("entities/entities" + item.action.ToString().ToLower() + "/" + item.Id); if (n != null && !n.Checked) { if (item.action == SynapseHelpers.MigrationAction.Update) { List <SchemaMigration.Action> createActionsAttribute = item.attributeActions.Where(x => x.migrationAction == SynapseHelpers.MigrationAction.New && x.sourceContextId == item.Id && x.dbTableName.Equals("entitysettings.entityattribute")).ToList(); List <SchemaMigration.Action> createActionsRelations = item.attributeActions.Where(x => x.migrationAction == SynapseHelpers.MigrationAction.New && x.sourceContextId == item.Id && x.dbTableName.Equals("entitysettings.entityrelation")).ToList(); if (createActionsAttribute.Count != 0) { foreach (var action in createActionsAttribute) { TreeNode n1 = tv.FindNode("entities/entitiesupdate/" + item.Id + "/newattributes/" + action.sourceComponentId); if (!n1.Checked) { action.migrationAction = SynapseHelpers.MigrationAction.Skip; } } } if (createActionsRelations.Count != 0) { foreach (var action in createActionsRelations) { TreeNode n1 = tv.FindNode("entities/entitiesupdate/" + item.Id + "/newrelations/" + action.sourceComponentId); if (!n1.Checked) { action.migrationAction = SynapseHelpers.MigrationAction.Skip; } } } } item.action = SynapseHelpers.MigrationAction.Skip; } } foreach (Baseview b in ex.Baseviews.Baseview) { TreeNode n = tv.FindNode("baseviews/baseviews" + b.action.ToString().ToLower() + "/" + b.Id); if (n != null && !n.Checked) { b.action = SynapseHelpers.MigrationAction.Skip; } } foreach (SList l in ex.SLists.SList) { TreeNode n = tv.FindNode("lists/lists" + l.action.ToString().ToLower() + "/" + l.Id); if (n != null && !n.Checked) { l.action = SynapseHelpers.MigrationAction.Skip; } } Session["export"] = ex; Task task = new Task(() => SynapseHelpers.ApplySchemaChanges(ex)); task.Start(); showProcessMsgs(); //try //{ // Thread thread = new Thread(() => SynapseHelpers.ApplySchemaChanges(ex)); // thread.Start(); //}catch(Exception exx) //{ // SynapseHelpers.AddImportMsg(exx.Message); //} //while (thread.ThreadState.Equals(ThreadState.Running)) //{ // lblMsg.Text = DateTime.Now.Second.ToString(); // Response.Flush(); //} // SynapseHelpers.ApplySchemaChanges(ex); tv.Nodes.Clear(); } else { lblErrorSelectObjects.Text = "Looks like there is nothing to import!"; } } catch (Exception exception) { lblError.Text = "There was an error processing the export. Please try again. "; lblError.Text += exception.Message; tv.Nodes.Clear(); showFileUpload(); } }