/// <summary> /// Retrieves list of Machine objects from SqlCommand, after database query /// number of rows retrieved and returned depends upon the rows field value /// </summary> /// <param name="cmd">The command object to use for query</param> /// <param name="rows">Number of rows to process</param> /// <returns>A list of Machine objects</returns> private MachineList GetList(SqlCommand cmd, long rows) { // Select multiple records SqlDataReader reader; long result = SelectRecords(cmd, out reader); //Machine list MachineList list = new MachineList(); using ( reader ) { // Read rows until end of result or number of rows specified is reached while (reader.Read() && rows-- != 0) { Machine machineObject = new Machine(); FillObject(machineObject, reader); list.Add(machineObject); } // Close the reader in order to receive output parameters // Output parameters are not available until reader is closed. reader.Close(); } return(list); }
public void GenerateMaps() { //Clear ClientToStoreMap this.ClientToStoreMap.Clear(); this.StoreToDatabaseServiceMap.Clear(); this.StoreToEsbServiceMap.Clear(); this.MachineList.Clear(); //Generate machine to store map if (ClientMachines.Count > 0 && Stores.Count > 0 && ClientStoreMapList.Count > 0) { foreach (var machine in ClientMachines) { if (machine == null) { continue; } ulong machineId = machine.Machine.ClientId; var mapEntry = ClientStoreMapList.Find( x => (x.ClientRegistryId == machineId && x.StoreNumber.Equals(this.StoreNumber))); if (mapEntry == null) { continue; } var pwnSecStore = this.Stores.Find( x => x.StoreSite.StoreNumber.Equals(mapEntry.StoreNumber)); if (pwnSecStore == null) { continue; } //Add client to store map entry ClientToStoreMap.Add(machine, pwnSecStore); MachineList.Add(new StoreMachineVO(machine.Machine.MachineName, machine.Machine.IsAllowed, machine.Machine.IsConnected)); //Create entry for database service and esb service if and only if the store //does not already exist as a key in the list if (StoreToDatabaseServiceMap.ContainsKey(pwnSecStore)) { continue; } var sConfig = pwnSecStore.StoreConfiguration; var sConfigDbServMapList = DatabaseServiceMapList.FindAll(x => x.StoreConfigId == sConfig.Id); if (CollectionUtilities.isNotEmpty(sConfigDbServMapList)) { var dbServList = from dbServ in DatabaseServiceList join dbServMap in sConfigDbServMapList on dbServ.Id equals dbServMap.DatabaseServiceId select dbServ; StoreToDatabaseServiceMap.Add(pwnSecStore, new List <DatabaseServiceVO>(dbServList)); } if (StoreToEsbServiceMap.ContainsKey(pwnSecStore)) { continue; } var sConfigEsbServMapList = ESBServiceMapList.FindAll(x => x.StoreConfigId == sConfig.Id); if (CollectionUtilities.isNotEmpty(sConfigEsbServMapList)) { var esbServList = from esbServ in ESBServiceList join esbServMap in sConfigEsbServMapList on esbServ.Id equals esbServMap.ESBServiceId select esbServ; StoreToEsbServiceMap.Add(pwnSecStore, new List <EsbServiceVO>(esbServList)); } } } //If these three conditions are true, the maps are valid if (CollectionUtilities.isNotEmpty(ClientToStoreMap) && CollectionUtilities.isNotEmpty(StoreToDatabaseServiceMap) && CollectionUtilities.isNotEmpty(StoreToEsbServiceMap) && CollectionUtilities.isNotEmpty(MachineList)) { this.MapsValid = true; } }
/// <summary> /// Parses the response received from the server. /// </summary> /// <param name="responseReader">The binary stream reader that should /// be used to read any response data necessary.</param> protected override void UnpackResponse() { base.UnpackResponse(); MemoryStream responseStream = new MemoryStream(m_responsePayload); BinaryReader responseReader = new BinaryReader(responseStream, Encoding.Unicode); if (responseStream.Length < MinResponseMessageLength) { throw new MessageWrongSizeException("Get Machine Status"); } try { responseReader.BaseStream.Seek(sizeof(int), SeekOrigin.Begin); UInt16 MachineCount = responseReader.ReadUInt16(); MachineList.Clear(); for (ushort x = 0; x < MachineCount; x++) { Machine machine = new Machine(); Staff staff = new Staff(); Operator operatordata = new Operator(); //MachineID machine.MachineID = responseReader.ReadInt32(); //MachineClientID machine.MachineClientID = ReadString(responseReader); //Machine Description machine.MachineDescription = ReadString(responseReader); //Machine LoginDate machine.MachineLoginDate = ReadDateTime(responseReader) ?? DateTime.MinValue; //StaffID staff.Id = responseReader.ReadInt32(); //Staff FirstName staff.FirstName = ReadString(responseReader); //Staff LastName staff.LastName = ReadString(responseReader); //Operator ID operatordata.Id = responseReader.ReadInt32(); //Operator Name operatordata.Name = ReadString(responseReader); machine.staffdata = staff; machine.operatorData = operatordata; MachineList.Add(machine); } } catch (EndOfStreamException e) { throw new MessageWrongSizeException("Get Machine status", e); } catch (Exception e) { throw new ServerException("Get Machine status", e); } finally { if (responseReader != null) { responseReader.Close(); } } }