private void Analyze(TaskSnp taskSnp, ConsumerParams cpParams) { SNP temp = new SNP(taskSnp.SnpPath, SNPPort.X1324); // Thread.Sleep(2000); foreach (var testItem in taskSnp.AnalyzeItem) { object tempChart = cpParams.ChartDic[testItem]; plotData offset = new plotData(); if (cpParams.Spec.ContainsKey(testItem + "_OFFSET")) { offset = cpParams.Spec[testItem + "_OFFSET"]; } plotData plotData = GetPlotdata(temp, testItem, taskSnp, cpParams, offset); string savePath = cpParams.SaveTxtPath + "\\" + testItem + ".txt"; SaveTxt(plotData, savePath); cpParams.FormUi.AddStatus(savePath + " " + LanguageHelper.GetMsgText("写入成功")); InsertTestData(plotData, testItem, taskSnp.PairName); DrawSpec(testItem, cpParams, tempChart); bool result = Code.Utility.Convert.Judge(cpParams.Spec, plotData, testItem); cpParams.FormUi.AddStatus(testItem + " " + taskSnp.PairName + ":" + (result ? "PASS" : "Fail")); InsertTestJudge(testItem, result, taskSnp.PairName); cpParams.FormUi.SetCheckItem(taskSnp.PairName, taskSnp.ClbType); cpParams.FormUi.SetCheckItem(testItem, ClbType.TestItem); cpParams.AChart.DrawLine(tempChart, plotData, taskSnp.PairName, testItem.StartsWith("TDD") ? LineType.Time : LineType.Fre); } }
public static void Main(String[] args) { string hostname = "127.0.0.1"; int hostport = 9887; string appName = "HelloSnarlApp"; string icon = "http://a0.twimg.com/profile_images/1100695109/snarl_logo_2008a_normal.png"; string title = "Notification from"; string message = "HelloSnarl"; string timeout = "5"; SNP snarl_object = new SNP(hostname, hostport); if (snarl_object.isSnarlRunning()) { Console.WriteLine("Yes snarl is running"); snarl_object.register(appName); snarl_object.notify(appName, null, title, message, timeout, icon); /*According to Snarl Developer Guide "When your application exits, it should unregister with Snarl." * If you want you can remove snarl_object.unregister because when you * quit snarl it will automatically unregister your application.*/ snarl_object.unregister(appName); } else { Console.WriteLine("Snarl not running"); } }
private static void WaitForInput(CSocket connected) { while (true) { Tuple <String, Object> received = connected.ReceiveObject(); String parameter = received.Item1; Object receivedObject = received.Item2; if (parameter.Equals(CONNECTION_REQEST_FROM_CC) || parameter.Equals(DELETE_CONNECTION_REQUEST)) { Tuple <SNP, SNP> pathToAssign = (Tuple <SNP, SNP>)received.Item2; SNP first = pathToAssign.Item1; SNP second = pathToAssign.Item2; if (!first.Deleting) { LogClass.CyanLog("Received request to SET CONNECTION between " + first.Address + " and " + second.Address); } else { LogClass.CyanLog("Received request to DELETE CONNECTION between " + first.Address + " and " + second.Address); } bool response = connectionController.ConnectionRequestIn(pathToAssign.Item1, pathToAssign.Item2); connected.SendACK(); LogClass.CyanLog("[ACK] Sending confirmation to Connection Controller"); Console.WriteLine(""); } } }
private void SNPNegotiationResponse(int negotiationID, bool isAccepted, SNP allocatedSnp) { //ocznaczam, że otrzymałem wiadomość powrotną _isSnpNegotiationAnswerBack[negotiationID] = true; //wrzucam wiadomość zwrotną do słownika skojarzoną z tym samym negotiationID co reszta zmiennych w innych słownikach _snpNegotiationAnswerBack.Add(negotiationID, new SignalMessage { IsAccepted = isAccepted, Negotiation_AllocatedSNP = allocatedSnp }); }
public async Task Begin_ReadsFileToToEndOfHeader() { using (StreamReader sr = new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(MY_HERITAGE_SAMPLE)))) { MyHeritageV2Reader reader = new MyHeritageV2Reader(sr); await reader.Begin(); SNP snp = await reader.ReadNext(); Assert.NotNull(snp); Assert.Equal("rs547237130", snp.Rsid); } }
getDiff(Dictionary <string, string[]> testItems, string snpFilepath, SNPPort snpPort, Dictionary <string, plotData> spec, ref bool action, ref string msg) { //System.GC.Collect(); Dictionary <string, plotData[]> ret = new Dictionary <string, plotData[]>(); try { SNP snpClass = new SNP(snpFilepath, snpPort); foreach (var item in testItems) { formatedData fData = snpClass.getDiff(item.Value); int columns = fData.dB.GetLength(1); int rows = fData.dB.GetLength(0); float[] offset = new float[rows]; if (spec.ContainsKey(item.Key + "_OFFSET")) { for (int row = 0; row < rows; row++) { offset[row] = spec[item.Key + "_OFFSET"].yData[row]; } } plotData[] singleItem = new plotData[columns]; for (int curveNo = 0; curveNo < columns; curveNo++) { float[] y = new float[rows]; for (int row = 0; row < rows; row++) { y[row] = fData.dB[row, curveNo] + offset[row]; } singleItem[curveNo].yData = y; singleItem[curveNo].xData = fData.fre; y = null; } ret.Add(item.Key, singleItem); singleItem = null; fData = new formatedData(); } snpClass = null; //System.GC.Collect(); action = true; return(ret); } catch (Exception ex) { action = false; msg = ex.Message; //MessageBoxEx.Show(ex.Message); return(null); } }
public async Task ReadNext_ReturnsNull_WhenEndOfStream() { using (StreamReader sr = new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(MY_HERITAGE_SAMPLE)))) { IFormatReader reader = new MyHeritageV2Reader(sr); await reader.Begin(); sr.ReadToEnd(); SNP snp1 = await reader.ReadNext(); Assert.Null(snp1); } }
private void ConnectionRequest_Analyse(int connectionID, SNP snpIn, SNP snpOut, int callingCapacity) { #region CC_nie_jest_końcowym_ogniwem(nie_jest_w_routerze) if (!_isInLsrSubnetwork) { //dodajemy wpis w tablicy dla danego connectionID _connectionsList.Add( new ConnectionTableRecord { ConnectionID = connectionID, AllocatedCapacity = callingCapacity, AllocatedSnps = new List <List <SNP> >(), AllocatedSnpAreaName = new List <string>(), Status = "inProgress" }); //dodajemy wpis w słowniku dzięki czemu będziemy wiedzieć, że to connection ID odpowieada temu indexowi w liście _indexInListOfConnection.Add(connectionID, _connectionsList.Count - 1); //wysyłamy wiadomosć RouteQuery do RC RouteQuery( connectionID, new SignalMessage.Pair { first = snpIn._snppID, second = snpOut._snppID }, callingCapacity); } #endregion #region CC_jest_końcowym_ogniwem(jest_w_routerze) else { //tutaj wywołaj funkcję, żeby robić odpowiednie wpisyw do fiba int indexInFibTable = MakeNewFibRecords( snpIn._snppID, snpIn._allocatedLabel, snpOut._snppID, snpOut._allocatedLabel, "swap"); //dodaj wpis do słownika, związany z connectionID i indexemWpisuWFibie _connectionIdToFibIndex.Add(connectionID, indexInFibTable); //znajdź adres wyższego bloku funckyjnego, z którego musiało pochodzic dane żądanie string destinationIpAddress = _connectedCcDestinationAddrress[_higherAreaName]; //wyslij wiadomość potwierdzającą wykonanie zadania ConnectionResponse(connectionID, true, destinationIpAddress); } #endregion }
public async Task ReadNext_ReadsSNPRecord() { using (StreamReader sr = new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(MY_HERITAGE_SAMPLE)))) { IFormatReader reader = new MyHeritageV2Reader(sr); await reader.Begin(); SNP snp1 = await reader.ReadNext(); SNP snp2 = await reader.ReadNext(); Assert.NotNull(snp1); Assert.NotNull(snp2); Assert.Equal("rs547237130", snp1.Rsid); Assert.Equal("rs562180473", snp2.Rsid); } }
private void ConnectionRequest(int connectionID, SNP snpIn, SNP snpOut, int callingCapacity, string destinationIpAddress) { SignalMessage message = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.ConnectionResponse, General_SourceIpAddress = _localPcIpAddress, General_DestinationIpAddress = destinationIpAddress, General_SourceModule = "CC", General_DestinationModule = "CC", ConnnectionID = connectionID, SnpIn = snpIn, SnpOut = snpOut, CallingCapacity = callingCapacity }; //wysyłamy żądanie do RC _pc.SendSignallingMessage(message); }
getAnalyzedData(List <TestItem> testItems, string snpFilepath, SNPPort snpPort, Dictionary <string, plotData> spec, TDD[] tdds, ref bool action, ref string msg, ref Dictionary <string, string[]> pairNameDictionary) { int pairNum = 8; pairNameDictionary.Clear(); string[] pairNames = new string[pairNum]; Dictionary <string, plotData[]> ret = new Dictionary <string, plotData[]>(); try { SNP snpClass = new SNP(snpFilepath, snpPort); foreach (var testItem in testItems) { string item = testItem.testName.ToUpper(); if (item.StartsWith("T")) { TDD tdd = item.Equals("TDD11") ? tdds[0] : tdds[1]; timeDomainData tData = snpClass.EasyGetTimeData(item, out pairNames, double.Parse(tdd.riseTime), (double.Parse(tdd.stopTime) - double.Parse(tdd.startTime)) / (tdd.points - 1), tdd.points, double.Parse(tdd.offset)); int tColumns = tData.resistance.GetLength(1); int tRows = tData.resistance.GetLength(0); float[] offset = new float[tRows]; if (spec.ContainsKey(item + "_OFFSET")) { for (int row = 0; row < tRows; row++) { offset[row] = spec[item + "_OFFSET"].yData[row]; } } plotData[] tItem = new plotData[tColumns]; for (int curveNo = 0; curveNo < tColumns; curveNo++) { float[] y = new float[tRows]; for (int row = 0; row < tRows; row++) { y[row] = tData.resistance[row, curveNo] + offset[row]; } tItem[curveNo].yData = y; tItem[curveNo].xData = tData.time; y = null; } ret.Add(item, tItem); pairNameDictionary.Add(item, pairNames); } else if (item.Equals("SINGLE")) { string[] pairNameSingles = new[] { "S1_17", "S2_18", "S3_19", "S4_20", "S5_21", "S6_22", "S7_23", "S8_24", "S9_25", "S10_26", "S11_27", "S12_28", "S13_29", "S14_30", "S15_31", "S16_32" }; formatedData sfData = snpClass.getSingle(pairNameSingles); int sColumns = sfData.dB.GetLength(1); int sRows = sfData.dB.GetLength(0); plotData[] singleItem = new plotData[sColumns]; for (int curveNo = 0; curveNo < sColumns; curveNo++) { float[] y = new float[sRows]; for (int row = 0; row < sRows; row++) { y[row] = sfData.dB[row, curveNo]; } singleItem[curveNo].yData = y; singleItem[curveNo].xData = sfData.fre; y = null; } ret.Add(item, singleItem); pairNameDictionary.Add(item, pairNameSingles); } else if (item.Equals("ILD")) { formatedData fData = snpClass.EasyGetILD(testItem.IldSpec, out pairNames); int columns = fData.dB.GetLength(1); int rows = fData.dB.GetLength(0); float[] offset = new float[rows]; if (spec.ContainsKey(item + "_OFFSET")) { for (int row = 0; row < rows; row++) { offset[row] = spec[item + "_OFFSET"].yData[row]; } } plotData[] diffItem = new plotData[columns]; for (int curveNo = 0; curveNo < columns; curveNo++) { float[] y = new float[rows]; for (int row = 0; row < rows; row++) { y[row] = fData.dB[row, curveNo] + offset[row]; } diffItem[curveNo].yData = y; diffItem[curveNo].xData = fData.fre; y = null; } ret.Add(item, diffItem); diffItem = null; fData = new formatedData(); pairNameDictionary.Add(item, pairNames); } else { formatedData fData = snpClass.EasyGetfreData(item, out pairNames); int columns = fData.dB.GetLength(1); int rows = fData.dB.GetLength(0); float[] offset = new float[rows]; if (spec.ContainsKey(item + "_OFFSET")) { for (int row = 0; row < rows; row++) { offset[row] = spec[item + "_OFFSET"].yData[row]; } } plotData[] diffItem = new plotData[columns]; for (int curveNo = 0; curveNo < columns; curveNo++) { float[] y = new float[rows]; for (int row = 0; row < rows; row++) { if (!float.IsNaN(offset[row])) { y[row] = fData.dB[row, curveNo] + offset[row]; } else { y[row] = fData.dB[row, curveNo]; } } diffItem[curveNo].yData = y; diffItem[curveNo].xData = fData.fre; y = null; } ret.Add(item, diffItem); diffItem = null; fData = new formatedData(); pairNameDictionary.Add(item, pairNames); } } snpClass = null; //System.GC.Collect(); action = true; return(ret); } catch (Exception ex) { action = false; msg = ex.Message; //MessageBoxEx.Show(ex.Message); return(null); } }
public bool ConnectionRequestIn(SNP firstSNP, SNP secondSNP) { int inputPort = 0, outputPort = 0; //LogClass.WhiteLog("Przyszły takie snp: " + firstSNP.Address + " " + firstSNP.Label + " i " + secondSNP.Address + " " + secondSNP.Label); foreach (string[] translation in addressTranslation) { if (translation[0] == firstSNP.Address) { inputPort = Int32.Parse(translation[1]); } else if (translation[0] == secondSNP.Address) { outputPort = Int32.Parse(translation[1]); } } if (firstSNP.Label == 0) { foreach (string[] translation in addressTranslation) { if (translation[0] == firstSNP.PathBegin) { if (firstSNP.Deleting) { fib.RemoveEntry(inputPort, firstSNP.Label, outputPort, secondSNP.Label); fib.RemoveEntry(outputPort, secondSNP.Label, inputPort, firstSNP.Label); fib.UpdatePortsRoutingTables(inPorts); } else { fib.AddEntry(inputPort, firstSNP.Label, outputPort, secondSNP.Label, 0, 0, firstSNP.PathEnd); fib.AddEntry(outputPort, secondSNP.Label, inputPort, firstSNP.Label, 0, 0, "0"); fib.UpdatePortsRoutingTables(inPorts); } } else if (translation[0] == firstSNP.PathEnd) { if (firstSNP.Deleting) { fib.RemoveEntry(inputPort, firstSNP.Label, outputPort, secondSNP.Label); fib.RemoveEntry(outputPort, secondSNP.Label, inputPort, firstSNP.Label); fib.UpdatePortsRoutingTables(inPorts); } else { fib.AddEntry(inputPort, firstSNP.Label, outputPort, secondSNP.Label, 0, 0, firstSNP.PathBegin); fib.AddEntry(outputPort, secondSNP.Label, inputPort, firstSNP.Label, 0, 0, "0"); fib.UpdatePortsRoutingTables(inPorts); } } } } else if (secondSNP.Label == 0) { foreach (string[] translation in addressTranslation) { if (translation[0] == secondSNP.PathBegin) { if (secondSNP.Deleting) { fib.RemoveEntry(inputPort, firstSNP.Label, outputPort, secondSNP.Label); fib.RemoveEntry(outputPort, secondSNP.Label, inputPort, firstSNP.Label); fib.UpdatePortsRoutingTables(inPorts); } else { fib.AddEntry(inputPort, firstSNP.Label, outputPort, secondSNP.Label, 0, 0, secondSNP.PathEnd); fib.AddEntry(outputPort, secondSNP.Label, inputPort, firstSNP.Label, 0, 0, "0"); fib.UpdatePortsRoutingTables(inPorts); } } else if (translation[0] == secondSNP.PathEnd) { if (secondSNP.Deleting) { fib.RemoveEntry(inputPort, firstSNP.Label, outputPort, secondSNP.Label); fib.RemoveEntry(outputPort, secondSNP.Label, inputPort, firstSNP.Label); fib.UpdatePortsRoutingTables(inPorts); } else { fib.AddEntry(inputPort, firstSNP.Label, outputPort, secondSNP.Label, 0, 0, secondSNP.PathBegin); fib.AddEntry(outputPort, secondSNP.Label, inputPort, firstSNP.Label, 0, 0, "0"); fib.UpdatePortsRoutingTables(inPorts); } } } } else { if (firstSNP.Deleting) { fib.RemoveEntry(inputPort, firstSNP.Label, outputPort, secondSNP.Label); fib.RemoveEntry(outputPort, secondSNP.Label, inputPort, firstSNP.Label); fib.UpdatePortsRoutingTables(inPorts); } else { fib.AddEntry(inputPort, firstSNP.Label, outputPort, secondSNP.Label, 0, 0, "0"); fib.AddEntry(outputPort, secondSNP.Label, inputPort, firstSNP.Label, 0, 0, "0"); fib.UpdatePortsRoutingTables(inPorts); } } return(true); }
private void LinkConnectionResponse(int connectionID, bool isAccepted, List <SNP> receivedSnps, List <string> receivedSnpsAreaNames) { //wyszukujemy wskaźnik na odpowiednią tablicę ConnectionTableRecord record = _connectionsList[_indexInListOfConnection[connectionID]]; //zwiększ liczbę otrzymanych wiadomości record.NumberOfResponse++; #region Step_1-Sprawdz_status_odpowiedzi if (isAccepted) { //odpowiedź jest pozytywna - udało się zaalokować łącze //uzupełniam odpowiednie listy danymi zawartymi w odpowiedzi for (int i = 0; i < receivedSnpsAreaNames.Count; i++) { int index = record.AllocatedSnpAreaName.IndexOf(receivedSnpsAreaNames[i]); record.AllocatedSnps[index].Add(receivedSnps[i]); } } else { //odpowiedź jest negatywna - nie udało się zaalowkować łącza SignallingNodeDeviceClass.MakeSignallingLog("CC", "ERROR - LinkConnectionRequest is not accepted"); SignallingNodeDeviceClass.MakeSignallingConsoleLog("CC", "ERROR - LinkConnectionRequest is not accepted"); //dopisać kod, który wykonuje sie w sytuacji odmowy alokacji return; } #endregion #region Step_2-Sprawdź_czy_odebrałem_wszystkie_odpowiedzi_czy_mam_czekac_dalej if (record.NumberOfResponse == record.NumberOfRequest) { //otrzymałem wszystkie odpowiedzi //ustaw nowy status rekordu oznaczający, że wszystkie lokalne linki zostały ustawione record.Status = "localLinksAllocated"; //sprawdź, czy nasze połaczenie przechodzi przez jakieś podsieci if (record.AllocatedSnpAreaName.Count > 1) //zawsze będzie nasza podsieć { //ustaw nowe wartości Response i Request record.NumberOfRequest = record.AllocatedSnpAreaName.Count - 1; record.NumberOfResponse = 0; //wyślij do każdego areaName != localAreaName wiadomosć ConnectionRequest //pierwszy wiersz dotyczy lokalnej sytuacji więc go omijamy for (int i = 1; i < record.NumberOfRequest + 1; i++) { SNP snpIn = record.AllocatedSnps[i][0]; SNP snpOut = record.AllocatedSnps[i][1]; //znajdź adres docelowy PC obsługującego CC niższego rzędu związanego z daną areaname string destinationIpAddress = _connectedCcDestinationAddrress[record.AllocatedSnpAreaName[i]]; //wyślij do CC niższego rzędu wiadomośc connectionRequest ConnectionRequest(connectionID, snpIn, snpOut, record.AllocatedCapacity, destinationIpAddress); } } else { //jak nie ma już żadnej podsieci to znaczy, że zakończyliśmy działania tego CC i wysyłamy ConnectionResponse do CC wyższego //znajdź adres docelowy PC obsługującego CC wyższego rzędu związanego z daną areaname string destinationIpAddress = _connectedCcDestinationAddrress[_higherAreaName]; ConnectionResponse(connectionID, true, destinationIpAddress); //zmień status na established record.Status = "established"; } } else { //nie otrzymałem wszystkich więc czekam na pozostałe return; } #endregion //if (record.IsInterdomain && record.Status == "establishingInterdomainLink") //{ // //Wyslij do RC pierwsza parę złożoną ze zmiennych boudaryFirst boundarySecond znajdującej się w rekordzie // SignalMessage message = new SignalMessage() // { // General_SignalMessageType = SignalMessage.SignalType.RouteQuery, // General_SourceIpAddress = _localPcIpAddress, // General_DestinationIpAddress = _localPcIpAddress, // General_SourceModule = "CC", // General_DestinationModule = "RC", // ConnnectionID = record.ConnectionID, // SnppIdPair = new SignalMessage.Pair // { // first = record.LocalBoundaryFirstSnppID, // second = record.LocalBoundarySecondSnppID // }, // CallingCapacity = record.AllocatedCapacity // }; //} //else //{ // //ustaw nowy status rekordu oznaczający, że wszystkie lokalne linki zostały ustawione // record.Status = "localLinksAllocated"; // //sprawdź, czy nasze połaczenie przechodzi przez jakieś podsieci // if (record.AllocatedSnpAreaName.Count > 1) //zawsze będzie nasza podsieć // { // //zaalokuj nowe listy // record.NumberOfCcConnectionRequestToSend = record.AllocatedSnpAreaName.Count; // int // //tworzę listę odpowiedzi // record.IsConnectionResponse = new List<bool>(listCount); // record.ConnectionResponseStatus = new List<bool>(listCount); // //wyślij do każdego areaName != localAreaName wiadomosć ConnectionRequest // //pierwszy wiersz dotyczy lokalnej sytuacji więc go omijamy // for (int i = 1; i < listCount; i++) // { // SNP snpIn = record.AllocatedSnps[i][0]; // SNP snpOut = record.AllocatedSnps[i][1]; // ConnectionRequest(connectionID, snpIn, snpOut); // } // } // else // { // //jak nie ma już żadnej podsieci to znaczy, że zakończyliśmy działania tego CC i wysyłamy ConnectionResponse // ConnectionResponse(connectionID, true); // //zmień status na established // record.Status = "established"; // } //} //#endregion }
private void SNPNegotiation_Analyse(int negotiationID, int connectionID, int label, int snppID, int connectionCapacity, string sourcePcIpAddress) { #region Odszukuje_obiekt_SNPP_o_zadanym_id SNPP requestedSnpp = null; for (int i = 0; i < _snppList.Count; i++) { if (_snppList[i]._localID == snppID) { requestedSnpp = _snppList[i]; break; } } //jeżeli nie ma takiego obiektu to zwróć błąd if (requestedSnpp == null) { //jest jakiś błąd i trzeba to zakomunikować SignallingNodeDeviceClass.MakeSignallingLog("LRM", "ERROR (SnppNegotiation)- Cannot find the SNPP with ID equals " + snppID); SignallingNodeDeviceClass.MakeSignallingConsoleLog("LRM", "ERROR (SnppNegotiation)- Cannot find the SNPP with ID equals " + snppID); //zwróć odpowiedź negatywną SignalMessage rejectedMessage = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.SNPNegotiationResponse, General_DestinationIpAddress = sourcePcIpAddress, General_SourceIpAddress = _localPcIpAddress, General_SourceModule = "LRM", General_DestinationModule = "LRM", Negotiation_ID = negotiationID, IsAccepted = false }; //wyslij wiadomość i wyjdź z metody SendMessageToPC(rejectedMessage); return; } #endregion #region Sprawdzam_czy_etykieta_jest_wolna_i_wyslij_odpowiednia_wiadomosc if (requestedSnpp._availableLabels.Contains(label)) { //etykieta jest wolna int index = requestedSnpp._allocatedSNP.Count; SNP allocatedSnp = new SNP { _snpID = index, _snppID = requestedSnpp._localID, _allocatedCapacity = connectionCapacity, _allocatedLabel = label, _connectionID = connectionID }; requestedSnpp._allocatedSNP.Add(allocatedSnp); //wyślij odpowiedź zawierającą zaalokowane SNP SignalMessage accepteddMessage = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.SNPNegotiationResponse, General_DestinationIpAddress = sourcePcIpAddress, General_SourceIpAddress = _localPcIpAddress, General_SourceModule = "LRM", General_DestinationModule = "LRM", Negotiation_ID = negotiationID, IsAccepted = true, Negotiation_AllocatedSNP = allocatedSnp }; //wyslij wiadomość i wyjdź z metody SendMessageToPC(accepteddMessage); } else { //etykieta jest zajęta SignallingNodeDeviceClass.MakeSignallingLog("LRM", "ERROR (SnppNegotiation)- Lable already in use: " + label); SignallingNodeDeviceClass.MakeSignallingConsoleLog("LRM", "ERROR (SnppNegotiation)- Lable already in use: " + label); //zwróć odpowiedź negatywną SignalMessage rejectedMessage = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.SNPNegotiationResponse, General_DestinationIpAddress = sourcePcIpAddress, General_SourceIpAddress = _localPcIpAddress, General_SourceModule = "LRM", General_DestinationModule = "LRM", Negotiation_ID = negotiationID, IsAccepted = false }; //wyslij wiadomość i wyjdź z metody SendMessageToPC(rejectedMessage); return; } #endregion }
private void LinkConnectionDealocation(int connectionID, SignalMessage.Pair snpp_id_pair) { #region Odnajdywanie_SNPP_i_sprawdzenie_czy_istnieją //odnajdz pierwszy i drugi SNPP SNPP first = null; SNPP second = null; //wyszukuje pierwszą wartość w liście for (int i = 0; i < _snppList.Count; i++) { if (_snppList[i]._localID == snpp_id_pair.first) { first = _snppList[i]; break; } } //jeżeli nie ma takiego elementu to zwróć bład if (first == null) { SignallingNodeDeviceClass.MakeSignallingLog("LRM", "ERROR - Cannot find the SNPP with ID equals " + snpp_id_pair.first); SignallingNodeDeviceClass.MakeSignallingConsoleLog("LRM", "ERROR - Cannot find the SNPP with ID equals " + snpp_id_pair.first); } else { //wyszukuje drugą wartość w liście for (int i = 0; i < _snppList.Count; i++) { if (_snppList[i]._localID == snpp_id_pair.second) { second = _snppList[i]; break; } } //jeżeli nie ma takiego elementu to zwróć bład if (second == null) { SignallingNodeDeviceClass.MakeSignallingLog("LRM", "ERROR - Cannot find the SNPP with ID equals " + snpp_id_pair.first); SignallingNodeDeviceClass.MakeSignallingConsoleLog("LRM", "ERROR - Cannot find the SNPP with ID equals " + snpp_id_pair.first); } } if (first == null || second == null) { SignalMessage rejectedResponse = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.LinkConnectionDealocationResponse, General_DestinationIpAddress = _localPcIpAddress, General_SourceIpAddress = _localPcIpAddress, General_SourceModule = "LRM", General_DestinationModule = "CC", IsAccepted = false, }; SendMessageToPC(rejectedResponse); //zakończ działanie metody return; } #endregion #region Znajdź_SNP_związane_z_tym_connectionID SNP localSNP = null; for (int i = 0; i < first._allocatedSNP.Count; i++) { if (first._allocatedSNP[i]._connectionID == connectionID) { localSNP = first._allocatedSNP[i]; break; } } if (localSNP == null) { SignallingNodeDeviceClass.MakeSignallingLog("LRM", "ERROR - Cannot find the SNP with connectionID equals " + snpp_id_pair.first + " in SNPP with ID: " + first._localID); SignallingNodeDeviceClass.MakeSignallingConsoleLog("LRM", "ERROR - Cannot find the SNP with connectionID equals " + snpp_id_pair.first + " in SNPP with ID: " + first._localID); //wyślij wiadomość odmowną SignalMessage rejectedResponse = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.LinkConnectionDealocationResponse, General_DestinationIpAddress = _localPcIpAddress, General_SourceIpAddress = _localPcIpAddress, General_SourceModule = "LRM", General_DestinationModule = "CC", IsAccepted = false }; SendMessageToPC(rejectedResponse); //zakończ działanie metody return; } #endregion #region Wyslij_lokalne_i_zewnętrzne_snpRealise_i_czekaj_na_odp bool accept = false; List <int> dealocationIDList = new List <int>(); Random rnd = new Random(); while (!accept) { //losuje identyfikator negocjacji dealocationIDList.Add(rnd.Next()); while (_isSnpRealiseAnswerBack.ContainsKey(dealocationIDList[0])) { dealocationIDList[0] = rnd.Next(); } //utwórz wpis w słowniku z danym ID _isSnpRealiseAnswerBack.Add(dealocationIDList[0], false); //wysyłamy SNPRealise do lokalnego LRM SignalMessage snmInsideNegotiation = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.SNPRealise, General_DestinationIpAddress = _localPcIpAddress, General_SourceIpAddress = _localPcIpAddress, General_SourceModule = "LRM", General_DestinationModule = "LRM", Negotiation_ID = dealocationIDList[0], Negotiation_SnppID = second._localID, Negotiation_ConnectionID = connectionID }; SendMessageToPC(snmInsideNegotiation); //wysyłamy SNPRealise do pozostałych podsieci jeżeli jest taka konieczność if (first._areaName != _areaName) { dealocationIDList.Add(rnd.Next()); while (_isSnpRealiseAnswerBack.ContainsKey(dealocationIDList[dealocationIDList.Count - 1])) { dealocationIDList[dealocationIDList.Count - 1] = rnd.Next(); } //utwórz wpisy w słownikach _isSnpRealiseAnswerBack.Add(dealocationIDList[dealocationIDList.Count - 1], false); //znajdź adres PC odpowiedzialnego za dany LRM w sieci first._areaName string destinationIpAddr = _lrmToSubnetworksDictionary[first._areaName]; SignalMessage message = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.SNPRealise, General_SourceIpAddress = _localPcIpAddress, General_DestinationIpAddress = destinationIpAddr, General_SourceModule = "LRM", General_DestinationModule = "LRM", Negotiation_ID = dealocationIDList[dealocationIDList.Count - 1], Negotiation_SnppID = first._areaNameSnppID, Negotiation_ConnectionID = connectionID }; SendMessageToPC(message); } if (second._areaName != _areaName) { dealocationIDList.Add(rnd.Next()); while (_isSnpRealiseAnswerBack.ContainsKey(dealocationIDList[dealocationIDList.Count - 1])) { dealocationIDList[dealocationIDList.Count - 1] = rnd.Next(); } //utwórz wpisy w słownikach _isSnpRealiseAnswerBack.Add(dealocationIDList[dealocationIDList.Count - 1], false); //znajdź adres PC odpowiedzialnego za dany LRM w sieci first._areaName string destinationIpAddr = _lrmToSubnetworksDictionary[second._areaName]; SignalMessage message = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.SNPRealise, General_SourceIpAddress = _localPcIpAddress, General_DestinationIpAddress = destinationIpAddr, General_SourceModule = "LRM", General_DestinationModule = "LRM", Negotiation_ID = dealocationIDList[dealocationIDList.Count - 1], Negotiation_SnppID = second._areaNameSnppID, Negotiation_ConnectionID = connectionID }; SendMessageToPC(message); } //czekamy biernie na odpowiedzi wszystkie (min 1 max 3) int waitingAnswerstToGet = dealocationIDList.Count; while (waitingAnswerstToGet != 0) { for (int i = 0; i < dealocationIDList.Count; i++) { if (_isSnpRealiseAnswerBack[(dealocationIDList[i])] == true) { waitingAnswerstToGet--; } } } //sprawdzamy, czy wszystkie odpowiedzi były prawidłowe int numberOfAcceptAnswers = 0; for (int i = 0; i < dealocationIDList.Count; i++) { if (_snpRealiseAnswerBack[dealocationIDList[i]] == true) { numberOfAcceptAnswers++; } } if (numberOfAcceptAnswers == dealocationIDList.Count) { accept = true; } else { accept = false; //tutaj trzeba namierzyć tą która jest zła i wysłać Realise i ponownie spróbować losować jakąć czy coś } }//end while(!accept) #endregion #region Zwalnianie_etykiety_i_usuwanie_localSNP //zwalnianie etykiety int freeLabel = localSNP._allocatedLabel; first._availableLabels.Add(freeLabel); //usuwanie local SNP first._allocatedSNP.Remove(localSNP); #endregion #region Wysyłanie_wiadomości_wstecznej SignalMessage acceptedMessage = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.LinkConnectionDealocationResponse, General_DestinationIpAddress = _localPcIpAddress, General_SourceIpAddress = _localPcIpAddress, General_SourceModule = "LRM", General_DestinationModule = "CC", IsAccepted = true, }; SendMessageToPC(acceptedMessage); #endregion }
private void SNPRealise(int dealocationID, int snppID, int connectionID, string sourcePcIpAddress) { #region Odszukuje_obiekt_SNPP_o_zadanym_id SNPP requestedSnpp = null; for (int i = 0; i < _snppList.Count; i++) { if (_snppList[i]._localID == snppID) { requestedSnpp = _snppList[i]; break; } } //jeżeli nie ma takiego obiektu to zwróć błąd if (requestedSnpp == null) { //jest jakiś błąd i trzeba to zakomunikować SignallingNodeDeviceClass.MakeSignallingLog("LRM", "ERROR (SnppRealise)- Cannot find the SNPP with ID equals " + snppID); SignallingNodeDeviceClass.MakeSignallingConsoleLog("LRM", "ERROR (SnppRealise)- Cannot find the SNPP with ID equals " + snppID); //zwróć odpowiedź negatywną SignalMessage rejectedMessage = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.SNPRealiseResponse, General_DestinationIpAddress = sourcePcIpAddress, General_SourceIpAddress = _localPcIpAddress, General_SourceModule = "LRM", General_DestinationModule = "LRM", Negotiation_ID = dealocationID, IsAccepted = false }; //wyslij wiadomość i wyjdź z metody SendMessageToPC(rejectedMessage); return; } #endregion #region Znajduję_SNP_związane_z_connectionID SNP localSNP = null; for (int i = 0; i < requestedSnpp._allocatedSNP.Count; i++) { if (requestedSnpp._allocatedSNP[i]._connectionID == connectionID) { localSNP = requestedSnpp._allocatedSNP[i]; break; } } //jeżeli nie ma to zwróc negatywną odpowiedź if (localSNP == null) { SignallingNodeDeviceClass.MakeSignallingLog("LRM", "ERROR - Cannot find the SNP with connectionID equals " + connectionID + " in SNPP with ID: " + requestedSnpp._localID); SignallingNodeDeviceClass.MakeSignallingConsoleLog("LRM", "ERROR - Cannot find the SNP with connectionID equals " + connectionID + " in SNPP with ID: " + requestedSnpp._localID); //wyślij wiadomość odmowną SignalMessage message = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.SNPRealiseResponse, General_DestinationIpAddress = sourcePcIpAddress, General_SourceIpAddress = _localPcIpAddress, General_SourceModule = "LRM", General_DestinationModule = "LRM", Negotiation_ID = dealocationID, IsAccepted = false }; SendMessageToPC(message); //zakończ działanie metody return; } #endregion #region Zwolnij_etykiete_i_usun_localSNP int freeLabel = localSNP._allocatedLabel; requestedSnpp._availableLabels.Add(freeLabel); requestedSnpp._allocatedSNP.Remove(localSNP); #endregion #region Wyslij_odpowiedź SignalMessage acceptedMessage = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.SNPRealiseResponse, General_DestinationIpAddress = sourcePcIpAddress, General_SourceIpAddress = _localPcIpAddress, General_SourceModule = "LRM", General_DestinationModule = "LRM", Negotiation_ID = dealocationID, IsAccepted = true }; SendMessageToPC(acceptedMessage); #endregion }
private plotData GetPlotdata(SNP snp, string itemName, TaskSnp taskSnp, ConsumerParams cpParams, plotData offset) { plotData dataSeries = new plotData(); List <TdrParam> tdrParams = cpParams.TestConfigs[0].TdrParams; switch (taskSnp.ItemType) { case ItemType.Loss: if (itemName.StartsWith("S")) { itemName = GetReverseItem(itemName, !taskSnp.FirstHalf && taskSnp.Srevert); // cpParams.FormUi.AddStatus("analyze:"+itemName); string[] outPairs = new string[1]; var data = snp.EasyGetfreData(itemName, out outPairs); float[] x = SConvert.indexArray(data.dB, 0, false); dataSeries.xData = data.fre; dataSeries.yData = x; } else if (itemName.StartsWith("TDD")) { itemName = GetReverseItem(itemName, !taskSnp.FirstHalf && taskSnp.Trevert); // cpParams.FormUi.AddStatus("analyze:" + itemName); TdrParam tdrParam = tdrParams[int.Parse(itemName.Substring(3, 1)) - 1]; string[] outPairs = new string[1]; double timeStep = (tdrParam.EndTime - tdrParam.StartTime) / (tdrParam.Points - 1); var data = snp.EasyGetTimeData(itemName, out outPairs, tdrParam.RiseTime, timeStep, tdrParam.Points, tdrParam.Offset); float[] x = SConvert.indexArray(data.resistance, 0, false); dataSeries.xData = data.time; dataSeries.yData = x; } else if (itemName.Equals("ILD", StringComparison.OrdinalIgnoreCase)) { string[] outPairs = new string[1]; var data = snp.EasyGetILD(cpParams.TestConfigs[0].IldSpec, out outPairs); float[] x = SConvert.indexArray(data.dB, 0, false); dataSeries.xData = data.fre; dataSeries.yData = x; } break; case ItemType.Next: if (itemName.StartsWith("NEXT")) { // cpParams.FormUi.AddStatus("analyze:" + itemName); string[] outPairs = new string[1]; var data = snp.EasyGetfreData("SDD21", out outPairs); float[] x = SConvert.indexArray(data.dB, 0, false); dataSeries.xData = data.fre; dataSeries.yData = x; } break; case ItemType.Fext: if (itemName.StartsWith("FEXT")) { // cpParams.FormUi.AddStatus("analyze:" + itemName); string[] outPairs = new string[1]; var data = snp.EasyGetfreData("SDD21", out outPairs); float[] x = SConvert.indexArray(data.dB, 0, false); dataSeries.xData = data.fre; dataSeries.yData = x; } break; } if (offset.yData != null) { int length = dataSeries.yData.Length < offset.yData.Length ? dataSeries.yData.Length : offset.yData.Length; for (int i = 0; i < length; i++) { dataSeries.yData[i] = dataSeries.yData[i] + offset.yData[i]; } } return(dataSeries); }
// TODO: Fix the Calls to include Either FormValues Dictionary or DTO. public ActionResult Index(Guid?id, HttpPostedFileBase file) { if (file == null || file.ContentLength == 0 || file.ContentType == null || string.IsNullOrEmpty(file.FileName) || file.InputStream == null) { this.ModelState.AddModelError("PostedFile", "Must attach file."); return(View()); } if (file.ContentLength > 0) { string path = Path.Combine(ServerMapPath, id.ToString() + ".txt"); string fileName = Path.GetFileName(file.FileName); if (fileName.EndsWith(".zip")) { string tempPath = Path.Combine(ServerMapPath, id.ToString() + ".zip"); string extractPath = Path.Combine(ServerMapPath, id.ToString()); file.SaveAs(tempPath); System.IO.Compression.ZipFile.ExtractToDirectory(tempPath, extractPath); string[] names = Directory.GetFiles(extractPath); if (names.Length != 1) { throw new FileLoadException("Zip file must only contain one file."); } System.IO.File.Move(names[0], path); } List <SNP> snps = new List <SNP>(); int i = 0; using (StreamReader sr = new StreamReader(path)) { GeneXContext context = new GeneXContext(); while (sr.Peek() >= 0) { string line = sr.ReadLine(); if (line.StartsWith("#", true, CultureInfo.InvariantCulture)) { continue; } string[] parsed = line.Split("\t".ToCharArray()); string tmp = parsed[0]; SNP snp = context.SNP.Where(m => m.ClusterId == tmp && m.GenomeId == id.Value).FirstOrDefault(); int chromosome = 0; string chromosomeType; if (parsed[1].ToUpper().Equals("X") || parsed[1].ToUpper().Equals("Y")) { chromosome = 23; chromosomeType = parsed[1].ToUpper(); } else if (parsed[1].ToUpper().Equals("MT")) { chromosome = 0; chromosomeType = "MT"; } else { chromosome = int.Parse(parsed[1]); chromosomeType = "A"; } char?allele1 = null; char?allele2 = null; if (parsed[3].Length > 0) { allele1 = parsed[3][0]; } if (parsed[3].Length > 1) { allele2 = parsed[3][0]; } if (snp == null) { context.SNP.Add(new SNP { SNPId = Guid.NewGuid(), GenomeId = id.Value, ClusterId = parsed[0], Chromosome = chromosome, ChromosomeType = chromosomeType, Position = int.Parse(parsed[2]), Genotype = parsed[3], Allele1 = allele1.ToString(), Allele2 = allele2.ToString() }); } else { snp.ChromosomeType = chromosomeType; snp.Genotype = parsed[3]; } ++i; if (i % 1000 == 0) { context.SaveChanges(); context.Dispose(); context = new GeneXContext(); } } context.SaveChanges(); context.Dispose(); } } return(RedirectToAction("Index", "Home")); }