private void removeSharingWithProtocolIndex(SharingProtocol sharer, int protocolIndex) { string logMSG; if (sharer == null) { logMSG = "removeSharingWithProtocolIndex called. Invalid input parameter 'sharer' is null."; LogFile.AddMessage(System.Diagnostics.TraceLevel.Verbose, logMSG); return; } int initQuad = 0; //make sure this protocol index doesn't map to anything if (sharedSectorsProtocolIndex != null) { for (int i = 0; i < 4; ++i) { if (i < sharedSectorsProtocolIndex.Length && sharedSectorsProtocolIndex[i] == protocolIndex) { sharedSectorsTranslation[i] = 0; initQuad = (initQuad == 0) ? i + 1 : initQuad; } } //remove from sharer if (initQuad != 0) { sharer.removeSharingWith(initQuad); } } }
//print debug info private void printAllQuadrants() { for (int i = 0; i < myAllProtocols.Length; i++) { SharingProtocol p = myAllProtocols[i]; if (p == null) { continue; } for (int j = 0; j < p.Quadrants; j++) { if (j == 0) { System.Diagnostics.Debug.WriteLine("............................." + p.Name + " " + sharedSectorsTranslation[p.InitQuadrant + j] + " " + sharedSectorsProtocolIndex[p.InitQuadrant + j]); } else { System.Diagnostics.Debug.WriteLine(" " + sharedSectorsTranslation[p.InitQuadrant + j] + " " + sharedSectorsProtocolIndex[p.InitQuadrant + j]); } } } }
private void removeSharingWith(SharingProtocol sharer) { string logMSG; if (sharer == null) { logMSG = "removeSharingWith called. Invalid input parameter 'sharer' is null."; LogFile.AddMessage(System.Diagnostics.TraceLevel.Verbose, logMSG); return; } int quadrantID = sharer.InitQuadrant + 1; //go through sharer's quadrants for (int i = 0; i < sharer.Quadrants; ++i) { //make sure no quadrant maps to it for (int j = 0; j < 4; ++j) { if (j < sharedSectorsTranslation.Length && sharedSectorsTranslation[j] == quadrantID + i) { sharedSectorsTranslation[j] = 0; } } } //clear sharer sharer.clear(); }
private DialogResult confirmSpecificProtocol(SharingProtocol sharingProtocol) { string logMSG; if (sharingProtocol == null) { logMSG = "confirmSpecificProtocol called. Invalid input parameter 'sharingProtocol' is null."; LogFile.AddMessage(System.Diagnostics.TraceLevel.Verbose, logMSG); return(DialogResult.Cancel); } ArrayList sharingWith = sharingProtocol.SharingWith; if (sharingWith == null) { logMSG = "confirmSpecificProtocol called. Invalid input parameter 'sharingProtocol.SharingWith' is null."; LogFile.AddMessage(System.Diagnostics.TraceLevel.Verbose, logMSG); return(DialogResult.Cancel); } int initQuadrantIndex = sharingProtocol.InitQuadrant; //build message string quadrantsLabel = "Q" + (initQuadrantIndex + 1); for (int i = 0; i < sharingWith.Count; i++) { if (i >= sharingWith.Count - 1) { quadrantsLabel += " and Q" + sharingWith[i]; } else { quadrantsLabel += ", Q" + sharingWith[i]; } } //ask the user string sMSG = LanguageINI.GetString("QS1") + " " + quadrantsLabel + " " + LanguageINI.GetString("QS2") + " " + sharingProtocol.Name + " " + LanguageINI.GetString("QS3"); RoboMessagePanel messageDialog = new RoboMessagePanel(RoboSep_UserConsole.getInstance(), MessageIcon.MBICON_QUESTION, sMSG, LanguageINI.GetString("headerQS"), LanguageINI.GetString("Yes"), LanguageINI.GetString("No")); RoboSep_UserConsole.showOverlay(); DialogResult result = messageDialog.ShowDialog(); RoboSep_UserConsole.hideOverlay(); messageDialog.Dispose(); return(result);//messageDialog.DialogResult; }
public void SetupInputDistribution() { int myPosition = Quorum.GetPositionOf(PartyIds, Me.Id); GateAddress myInputGateAddr = SortNetwork.FirstGateForWire[myPosition]; Quorum myInputQuorum = GateQuorumMapping[myInputGateAddr.Gate]; Protocol sortValueDistribution = new SharingProtocol(Me, Me.Id, myInputQuorum, SortValue, Prime, ProtocolIdGenerator.GateInputSharingIdentifier(myInputGateAddr.Gate.TopologicalRank, 2 * myInputGateAddr.Port)); Protocol secretDistribution = new SharingProtocol(Me, Me.Id, myInputQuorum, Secret, Prime, ProtocolIdGenerator.GateInputSharingIdentifier(myInputGateAddr.Gate.TopologicalRank, 2 * myInputGateAddr.Port + 1)); List <Protocol> inputProtocols = new List <Protocol>(); inputProtocols.Add(sortValueDistribution); inputProtocols.Add(secretDistribution); InputProtocolMapping = new Dictionary <InputGateAddress, Tuple <ulong, ulong> >(); for (int i = 0; i < PartyIds.Count; i++) { var gateAddr = SortNetwork.FirstGateForWire[i]; foreach (Quorum q in MyQuorums) { if (GateQuorumMapping[gateAddr.Gate] == q) { if (i == myPosition) { InputProtocolMapping[gateAddr] = new Tuple <ulong, ulong>(sortValueDistribution.ProtocolId, secretDistribution.ProtocolId); } else { ulong sortRecvId = ProtocolIdGenerator.GateInputSharingIdentifier(gateAddr.Gate.TopologicalRank, 2 * gateAddr.Port); ulong shareRecvId = ProtocolIdGenerator.GateInputSharingIdentifier(gateAddr.Gate.TopologicalRank, 2 * gateAddr.Port + 1); InputProtocolMapping[gateAddr] = new Tuple <ulong, ulong>(sortRecvId, shareRecvId); // I need to receive for this gate inputProtocols.Add(new SharingProtocol(Me, PartyIds.ElementAt(i), q, null, Prime, sortRecvId)); inputProtocols.Add(new SharingProtocol(Me, PartyIds.ElementAt(i), q, null, Prime, shareRecvId)); } } } } ExecuteSubProtocols(inputProtocols); }
public void queryAllProtocols() { if (myAllProtocols == null) { System.Diagnostics.Debug.WriteLine("queryAllProtocols: myAllProtocols = null"); // bdr return; } //query user and adjust info DialogResult result = DialogResult.Cancel; for (int i = 0; i < myAllProtocols.Length; i++) { SharingProtocol sharingProtocol = myAllProtocols[i]; if (sharingProtocol == null) { continue; } //Init Quadrant Selection state result = DialogResult.Cancel; QuadrantSelectionDialog.QuadrantSelectionState[] QStates = new QuadrantSelectionDialog.QuadrantSelectionState[4]; for (int j = 0; j < 4; j++) { QStates[j] = QuadrantSelectionDialog.QuadrantSelectionState.DISABLED; } if (0 <= sharingProtocol.InitQuadrant && sharingProtocol.InitQuadrant < QStates.Length) { QStates[sharingProtocol.InitQuadrant] = QuadrantSelectionDialog.QuadrantSelectionState.SELECTED_ALWAYS; } ArrayList sharingWith = sharingProtocol.SharingWith; //if sharing if (sharingWith != null && sharingWith.Count > 0) { // ASK USER ABOUT THIS PROTOCOL result = confirmSpecificProtocol(sharingProtocol); //go into quadrant selection if Yes if (result == DialogResult.OK) { int nIndex = 0; //enable relevent quadrants for (int j = 0; j < sharingWith.Count; j++) { nIndex = (int)sharingWith[j] - 1; if (0 <= nIndex && nIndex < QStates.Length) { QStates[nIndex] = QuadrantSelectionDialog.QuadrantSelectionState.ENABLED; } } // ASK USER ABOUT SPECIFIC QUADRANT SELECTION if (!querySpecificProtocol(QStates, sharingProtocol)) { //false means not successful (i.e. Cancel) so redo loop --i; continue; } } else { //need to remove translation if selected No removeSharingWith(sharingProtocol); } } } printAllQuadrants(); }
private bool checkValidCombo(QuadrantSelectionDialog.QuadrantSelectionState[] QStates, bool[] QuadrantStatus) { string logMSG; if (QStates == null || QuadrantStatus == null) { logMSG = "checkValidCombo called. Invalid input parameter 'QStates' or 'QuadrantStatus' is null."; LogFile.AddMessage(System.Diagnostics.TraceLevel.Verbose, logMSG); return(false); } if (sharedSectorsProtocolIndex == null) { logMSG = "checkValidCombo called. Simply returns because 'sharedSectorsProtocolIndex' is null."; LogFile.AddMessage(System.Diagnostics.TraceLevel.Verbose, logMSG); return(false); } double[] VialAVolume = { 0, 0, 0, 0 }; double[] VialBVolume = { 0, 0, 0, 0 }; double[] VialCVolume = { 0, 0, 0, 0 }; int nIndex; for (int quad = 0; quad < 4; ++quad) { //this check makes sure k is initial quadrant of protocol if (quad < QuadrantStatus.Length && QuadrantStatus[quad] && quad < sharedSectorsProtocolIndex.Length) { nIndex = sharedSectorsProtocolIndex[quad]; if (nIndex < 0 || myAllProtocols.Length <= nIndex) { continue; } SharingProtocol p = myAllProtocols[nIndex]; if (p != null && p.Consumables != null) { for (int i = 0; i < p.Quadrants; i++) { if (i < p.Consumables.GetLength(0)) { double A = p.Consumables[i, (int)RelativeQuadrantLocation.VialA].Volume.Amount; double B = p.Consumables[i, (int)RelativeQuadrantLocation.VialB].Volume.Amount; double C = p.Consumables[i, (int)RelativeQuadrantLocation.VialC].Volume.Amount; if (i < VialAVolume.Length) { VialAVolume[i] += (A > 0) ? (A - 100) : 0; } if (i < VialBVolume.Length) { VialBVolume[i] += (B > 0) ? (B - 100) : 0; } if (i < VialCVolume.Length) { VialCVolume[i] += (C > 0) ? (C - 100) : 0; } } } } } } for (int quad = 0; quad < 4; ++quad) { //ignore dead volume if ((VialAVolume != null && quad < VialAVolume.Length) && (VialBVolume != null && quad < VialBVolume.Length) && (VialCVolume != null && quad < VialCVolume.Length)) { if (VialAVolume[quad] > 1000 || VialBVolume[quad] > 1000 || VialCVolume[quad] > 1000) { return(false); } } } return(true); }
public QuadrantSharing(SharingProtocol[] allProtocols) { if (allProtocols == null) { System.Diagnostics.Debug.WriteLine("QuadrantSharing constructor: allProtocols = null"); // bdr return; } myAllProtocols = allProtocols; //cycles through each protocol for (int i = 0; i < myAllProtocols.Length; i++) { SharingProtocol leechProtocol = myAllProtocols[i]; if (leechProtocol == null) { continue; } //cycles through each protocol to find translation int translate = 0, current = 0; for (int j = 0; j < myAllProtocols.Length; j++) { SharingProtocol sharingProtocol = myAllProtocols[j]; if (sharingProtocol == null) { continue; } //find the first quadrant that matches to leech if (sharingProtocol.Name.Equals(leechProtocol.Name)) { //Can't share with itself if (i == j) { break; } translate = sharingProtocol.InitQuadrant + 1; current = leechProtocol.InitQuadrant + 1; sharingProtocol.addSharingWith(current); break; } } //Now Fill in current protocol's leeching info int quadrants = leechProtocol.Quadrants; int nIndex = 0; for (int k = 0; k < quadrants; k++) { nIndex = leechProtocol.InitQuadrant + k; if (0 <= nIndex && nIndex < sharedSectorsTranslation.Length) { sharedSectorsTranslation[nIndex] = translate > 0 ? translate + k : 0; } if (0 <= nIndex && nIndex < sharedSectorsProtocolIndex.Length) { sharedSectorsProtocolIndex[nIndex] = i; } } } }
private bool querySpecificProtocol(QuadrantSelectionDialog.QuadrantSelectionState[] QStates, SharingProtocol sharer) { string logMSG; if (QStates == null) { logMSG = "querySpecificProtocol called. Invalid input parameter 'QStates' is null."; LogFile.AddMessage(System.Diagnostics.TraceLevel.Verbose, logMSG); return(false); } DialogResult result = DialogResult.Retry; bool[] QuadrantStatus = null; //error checking case while (result == DialogResult.Retry) { QuadrantSelectionDialog dlg = new QuadrantSelectionDialog(QStates[0], QStates[1], QStates[2], QStates[3]); dlg.Location = RoboSep_UserConsole.getInstance().Location; RoboSep_UserConsole.showOverlay(); result = dlg.ShowDialog(); RoboSep_UserConsole.hideOverlay(); if (result == DialogResult.OK) { QuadrantStatus = dlg.getQuadrantSelectionStatus(); //error check here /* * if (!checkValidCombo(QStates, QuadrantStatus)) * { * //error message * RoboMessagePanel errorPrompt = new RoboMessagePanel(RoboSep_UserConsole.getInstance(), MessageIcon.MBICON_ERROR, * LanguageINI.GetString("msgOverload"), LanguageINI.GetString("Error"), LanguageINI.GetString("Ok")); * RoboSep_UserConsole.showOverlay(); * errorPrompt.ShowDialog(); * RoboSep_UserConsole.hideOverlay(); * errorPrompt.Dispose(); * result = DialogResult.Retry; * } */ } dlg.Dispose(); } //redo loop if cancel if (result == DialogResult.Cancel) { return(false); } else { //Done was pressed //don't set isSharing if nothing is selected //remove translation (include 2nd Q...) if not selected bool selected = false; //for special case all 4 the same SharingProtocol nextSharer = null; for (int quad = 0; quad < 4; ++quad) { //this check makes sure k is initial quadrant of protocol if (quad < QStates.Length && QStates[quad] == QuadrantSelectionDialog.QuadrantSelectionState.ENABLED) { System.Diagnostics.Debug.WriteLine("+++++++++++++++++++++++" + quad + " " + QuadrantStatus[quad] + " " + nextSharer + " "); if (quad < QuadrantStatus.Length && QuadrantStatus[quad]) { selected = true; } else { //if a quadrant is not selected //do not translate quadrants with the same protocol index if (sharedSectorsProtocolIndex != null && quad < sharedSectorsProtocolIndex.Length) { removeSharingWithProtocolIndex(sharer, sharedSectorsProtocolIndex[quad]); } int nIndex = 0; if (nextSharer == null) { if (quad < sharedSectorsProtocolIndex.Length) { nIndex = sharedSectorsProtocolIndex[quad]; if (0 <= nIndex && nIndex < myAllProtocols.Length) { nextSharer = myAllProtocols[nIndex]; } } } else { nextSharer.SharingWith.Add((quad + 1)); nIndex = sharedSectorsProtocolIndex[quad]; SharingProtocol leechProtocol = null; if (0 <= nIndex && nIndex < myAllProtocols.Length) { leechProtocol = myAllProtocols[nIndex]; } //Now Fill in current protocol's leeching info if (leechProtocol != null) { int quadrants = leechProtocol.Quadrants; int translate = nextSharer.InitQuadrant + 1; for (int k = 0; k < quadrants; k++) { if (0 <= (leechProtocol.InitQuadrant + k) && (leechProtocol.InitQuadrant + k) < sharedSectorsTranslation.Length) { sharedSectorsTranslation[leechProtocol.InitQuadrant + k] = translate + k; } } } } } } } //isSharing only if something is selected if (selected) { isSharing = true; } } return(true); }