Exemplo n.º 1
0
        /// <summary>
        /// Loads the machine list
        /// </summary>
        public void Load(bool quietMode = false)
        {
            string fileName = SaveName;

            try
            {
                using (Stream stream = new FileStream(fileName, FileMode.OpenOrCreate))
                {
                    MachineList.Clear();
                    MachineList = (ObservableCollection <Machine>)formatter.Deserialize(stream);
                    _hasLoaded  = true;
                    RefreshConfigurations();
                }
            }
            catch (Exception exception)
            {
                // don't show the dialog if calling from the instance usage.
                if (quietMode)
                {
                    return;
                }

                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.DefaultExt  = "dat";
                openFileDialog.Filter      = "Data Files (.dat)|*.dat|All Files|*";
                openFileDialog.Multiselect = false;
                openFileDialog.Title       = "Open machine data file";

                bool?accept = openFileDialog.ShowDialog();
                if (accept == true)
                {
                    fileName = openFileDialog.FileName;
                    try
                    {
                        using (Stream stream = new FileStream(fileName, FileMode.OpenOrCreate))
                        {
                            MachineList.Clear();
                            MachineList = (ObservableCollection <Machine>)formatter.Deserialize(stream);
                            RefreshConfigurations();
                            _hasLoaded = true;
                        }
                    }
                    catch (Exception inException)
                    {
                        MessageBox.Show("Unable to load Machine configuration. Error: " + inException.Message, "ERROR", MessageBoxButton.OK);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <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();
                }
            }
        }