private static OnepNetwork CreateNetworkForLEReset_01() { // This network and its corresponding LE Reset is causing // Deleted object would be re-saved exception OnepNetwork onepNetwork; { onepNetwork = new OnepNetwork() { McpProjectId = Guid.NewGuid().ToString(), Name = "Test 01" }; var onepFiberTL1 = new OnepFibertl() { Name = "FS01_1", Length = 30, Loss = 30 * 0.25, OnepNetwork = onepNetwork }; var onepFiberTL2 = new OnepFibertl() { Name = "FS01_2", Length = 30, Loss = 30 * 0.25, OnepNetwork = onepNetwork }; onepFiberTL1.OnepTopologicallinkMemberByUniMate = onepFiberTL2; onepFiberTL2.OnepTopologicallinkMemberByUniMate = onepFiberTL1; onepNetwork.OnepFibertls.Add(onepFiberTL1); onepNetwork.OnepFibertls.Add(onepFiberTL2); ///////// var onepTP1 = new OnepTerminationpoint() { Name = "TP 01", Ptp = 1, Role = 2, OnepNetwork = onepNetwork }; var onepTP2 = new OnepTerminationpoint() { Name = "TP 02", Ptp = 1, Role = 2, OnepNetwork = onepNetwork }; onepNetwork.OnepTerminationpoints.Add(onepTP1); onepNetwork.OnepTerminationpoints.Add(onepTP2); onepTP1.OnepTopologicallinksForAEndTP.Add(onepFiberTL1); onepTP1.OnepTopologicallinksForZEndTP.Add(onepFiberTL2); onepFiberTL1.OnepTerminationpointByAEndTP = onepTP1; onepFiberTL2.OnepTerminationpointByAEndTP = onepTP2; onepTP2.OnepTopologicallinksForAEndTP.Add(onepFiberTL2); onepTP2.OnepTopologicallinksForZEndTP.Add(onepFiberTL1); onepFiberTL1.OnepTerminationpointByZEndTP = onepTP2; onepFiberTL2.OnepTerminationpointByZEndTP = onepTP1; var onepAmpTP1 = new OnepAmptp() { TargetGain = 2.1, OnepNetwork = onepNetwork, OnepTerminationpoint = onepTP1 }; onepTP1.OnepAmpRole = onepAmpTP1; onepNetwork.OnepAmptps.Add(onepAmpTP1); var onepAmpTP2 = new OnepAmptp() { TargetGain = 1.9, OnepNetwork = onepNetwork, OnepTerminationpoint = onepTP2 }; onepTP2.OnepAmpRole = onepAmpTP2; onepNetwork.OnepAmptps.Add(onepAmpTP2); var onepValidationResult01 = new OnepValidationresult { Status = 1, OnepNetwork = onepNetwork }; var onepVP01_1 = new OnepValidochpath { Name = "VP 01_1", OnepNetwork = onepNetwork, Pmd = 2.3, OnepValidationresult = onepValidationResult01 }; onepNetwork.OnepValidochpaths.Add(onepVP01_1); var onepVP01_2 = new OnepValidochpath { Name = "VP 01_2", OnepNetwork = onepNetwork, Pmd = 2.4, OnepValidationresult = onepValidationResult01 }; onepNetwork.OnepValidochpaths.Add(onepVP01_2); onepValidationResult01.OnepValidochpaths.Add(onepVP01_1); onepValidationResult01.OnepValidochpaths.Add(onepVP01_2); onepNetwork.OnepValidationresults.Add(onepValidationResult01); // Create another Validation result var onepValidationResult02 = new OnepValidationresult { Status = 1, OnepNetwork = onepNetwork }; onepNetwork.OnepValidationresults.Add(onepValidationResult02); } return(onepNetwork); }
public OnepAmptp(OnepAmptp rhs) { this._targetGain = rhs._targetGain; CopyOnepAmptpVolatileProperties(rhs); }
partial void CopyOnepAmptpVolatileProperties(OnepAmptp rhs);
public async Task <object> Post() { OnepNetwork onepNetwork = null; { onepNetwork = new OnepNetwork() { McpProjectId = Guid.NewGuid().ToString(), Name = "Test 01" }; var onepFiberTL1 = new OnepFibertl() { Name = "FS01_1", Length = 30, Loss = 30 * 0.25, OnepNetwork = onepNetwork }; var onepFiberTL2 = new OnepFibertl() { Name = "FS01_2", Length = 30, Loss = 30 * 0.25, OnepNetwork = onepNetwork }; onepFiberTL1.OnepTopologicallinkMemberByUniMate = onepFiberTL2; onepFiberTL2.OnepTopologicallinkMemberByUniMate = onepFiberTL1; onepNetwork.OnepFibertls.Add(onepFiberTL1); onepNetwork.OnepFibertls.Add(onepFiberTL2); ///////// var onepTP1 = new OnepTerminationpoint() { Name = "TP 01", Ptp = 1, Role = 2, OnepNetwork = onepNetwork }; var onepTP2 = new OnepTerminationpoint() { Name = "TP 02", Ptp = 1, Role = 2, OnepNetwork = onepNetwork }; onepNetwork.OnepTerminationpoints.Add(onepTP1); onepNetwork.OnepTerminationpoints.Add(onepTP2); onepTP1.OnepTopologicallinksForAEndTP.Add(onepFiberTL1); onepTP1.OnepTopologicallinksForZEndTP.Add(onepFiberTL2); onepFiberTL1.OnepTerminationpointByAEndTP = onepTP1; onepFiberTL2.OnepTerminationpointByAEndTP = onepTP2; onepTP2.OnepTopologicallinksForAEndTP.Add(onepFiberTL2); onepTP2.OnepTopologicallinksForZEndTP.Add(onepFiberTL1); onepFiberTL1.OnepTerminationpointByZEndTP = onepTP2; onepFiberTL2.OnepTerminationpointByZEndTP = onepTP1; var onepAmpTP1 = new OnepAmptp() { TargetGain = 2.1, OnepNetwork = onepNetwork, OnepTerminationpoint = onepTP1 }; onepTP1.OnepAmpRole = onepAmpTP1; onepNetwork.OnepAmptps.Add(onepAmpTP1); var onepAmpTP2 = new OnepAmptp() { TargetGain = 1.9, OnepNetwork = onepNetwork, OnepTerminationpoint = onepTP2 }; onepTP2.OnepAmpRole = onepAmpTP2; onepNetwork.OnepAmptps.Add(onepAmpTP2); } // TODO : Json serialization not working due to circular references //var onepNetworkAsJsonString = JsonConvert.SerializeObject(onepNetwork); //Debug.WriteLine(onepNetworkAsJsonString); using (var tx = _session.BeginTransaction()) { try { await _session.SaveOrUpdateAsync(onepNetwork).ConfigureAwait(false); tx.Commit(); } catch (Exception ex) { Debugger.Break(); Debug.WriteLine(ex.ToString()); tx.Rollback(); throw; } } // Simulate LE Run Debugger.Break(); _session.Close(); var session2 = _sessionFactory.OpenSession(); var onepNetwork_x = session2.Get <OnepNetwork>(onepNetwork.Id); // Apply object Updates // Replace TP01 by new TP03, but move the same AmpRole object to TP03 { var onepTP3 = new OnepTerminationpoint() { Name = "TP 03", Ptp = 1, Role = 2, OnepNetwork = onepNetwork_x }; var onepTP1 = onepNetwork_x.OnepTerminationpoints.Where(p => p.Name == "TP 01").FirstOrDefault(); onepNetwork_x.OnepTerminationpoints.Remove(onepTP1); onepNetwork_x.OnepTerminationpoints.Add(onepTP3); var onepFiberTL1 = onepNetwork_x.OnepFibertls.Where(p => p.Name == "FS01_1").FirstOrDefault(); var onepFiberTL2 = onepNetwork_x.OnepFibertls.Where(p => p.Name == "FS01_2").FirstOrDefault(); onepFiberTL1.OnepTerminationpointByAEndTP = null; onepFiberTL2.OnepTerminationpointByZEndTP = null; onepTP3.OnepTopologicallinksForAEndTP.Add(onepFiberTL1); onepTP3.OnepTopologicallinksForZEndTP.Add(onepFiberTL2); onepFiberTL1.OnepTerminationpointByAEndTP = onepTP3; onepFiberTL2.OnepTerminationpointByZEndTP = onepTP3; var onepAmpTP1 = onepTP1.OnepAmpRole; onepTP3.OnepAmpRole = onepAmpTP1; //onepTP1.OnepAmpRole = null; // This is not required //onepTP1.OnepNetwork = null; //onepTP1.OnepTopologicallinksForAEndTP.Clear(); onepTP1.OnepTopologicallinksForAEndTP = null; // These are required, otherwise we get an exception "deleted entity will be resaved" //onepTP1.OnepTopologicallinksForZEndTP.Clear(); onepTP1.OnepTopologicallinksForZEndTP = null; // These are required, otherwise we get an exception "deleted entity will be resaved" } //{ // var onepTP1 = onepNetwork_x.OnepTerminationpoints.Where(p => p.Name == "TP 01").FirstOrDefault(); // onepNetwork_x.OnepTerminationpoints.Remove(onepTP1); // var amptp = onepTP1.OnepAmpRole; // onepNetwork_x.OnepAmptps.Remove(amptp); //} Debugger.Break(); session2.Close(); var session3 = _sessionFactory.OpenSession(); using (var tx = session3.BeginTransaction()) { try { await session3.SaveOrUpdateAsync(onepNetwork_x).ConfigureAwait(false); tx.Commit(); } catch (Exception ex) { Debugger.Break(); Debug.WriteLine(ex.ToString()); tx.Rollback(); throw; } } return(new { Id = onepNetwork.Id }); }