Exemple #1
0
        private void SendMessage(StandardMessage standardMessage, string agentName, bool isLeft)
        {
            int             middle         = (standardMessage.Left + standardMessage.Right) / 2;
            StandardMessage currentMessage = new StandardMessage
            {
                Action = Actions.Sort,
                Left   = isLeft ? standardMessage.Left : middle + 1,
                Right  = isLeft ? middle : standardMessage.Right,
                SourceToDestination = !standardMessage.SourceToDestination
            };

            if (
                isLeft ?
                (middle - standardMessage.Left) > Utils.Threshold :
                (standardMessage.Right - middle - 1) > Utils.Threshold
                )
            {
                _calls.Push(currentMessage);
            }
            else
            {
                _expectedMerge++;
            }

            Send(agentName, currentMessage.ToString());
        }
Exemple #2
0
        public void CreateNewModuleP16AndThenDeleteIt()
        {
            RestClient  restClient = new RestClient(new Uri(URI), USERNAME, PASSWORD, 6000);
            const House house      = House.P;
            const Unit  unit       = Unit.U16;
            // Create
            const ModuleType    expectedType    = ModuleType.Dimmer;
            const string        expectedName    = "Test";
            const bool          expectedOnState = true;
            NameValueCollection fields          = new NameValueCollection
            {
                { "on", expectedOnState ? "1" : "0" },
                { "type", Convert.ToString((byte)expectedType) },
                { "name", "\"Test\"" }
            };
            StandardMessage x10Message = (StandardMessage)restClient.PostModule(house, unit, fields);

            Assert.AreEqual(house, x10Message.House);
            Assert.AreEqual(unit, x10Message.Unit);
            Assert.AreEqual(expectedType, x10Message.ModuleType);
            Assert.AreEqual(expectedName, x10Message.Name);
            Assert.AreEqual(expectedOnState, x10Message.On);
            // Delete
            Assert.IsTrue(restClient.DeleteModule(house, unit));
        }
        public void AddVehicle()
        {
            Vehicle Vehicle = new Vehicle();

            CatchVehicleData(Vehicle);

            StandardMessage.ValidationSummary(Company.AddNewVehicle(Vehicle));
        }
        public void HireDriver()
        {
            Driver Driver = new Driver();

            CatchDriverData(Driver);

            StandardMessage.ValidationSummary(Company.AddNewDriver(Driver));
        }
Exemple #5
0
        /// <summary>
        /// Deletes state and info for specified module.
        /// </summary>
        /// <param name="house">House code.</param>
        /// <param name="unit">Unit code.</param>
        /// <exception cref="ProtocolViolationException"></exception>
        /// <exception cref="WebException"></exception>
        /// <returns>True if delete was successful</returns>
        public bool DeleteModule(House house, Unit unit)
        {
            HttpWebRequest  request  = GetRequest(house, unit, "DELETE");
            HttpWebResponse response = GetHttpResponse(request);
            StandardMessage module   = (StandardMessage)GetX10Message(response);

            return(module.ModuleType == ModuleType.Unknown && String.IsNullOrEmpty(module.Name) && !module.On.HasValue);
        }
Exemple #6
0
        public TelegramMessage GetStandardMessage(StandardMessage messageType)
        {
            if (!_standatdMessages.TryGetValue(messageType, out var message))
            {
                throw new NotSupportedException($"Message type {nameof(StandardMessage)}.{messageType} is not supported");
            }

            return(message);
        }
        public void AssignDriverToVehicle()
        {
            int driverId, vehicleId;

            driverId  = InputDriver.CatchDriverId();
            vehicleId = InputVehicle.CatchVehicleId();

            StandardMessage.ValidationSummary(Company.AssignDriverToVehicle(driverId, vehicleId));
        }
Exemple #8
0
        public void GetOneModule()
        {
            RestClient      restClient = new RestClient(new Uri(URI), USERNAME, PASSWORD, 6000);
            const House     house      = House.P;
            const Unit      unit       = Unit.U16;
            StandardMessage module     = (StandardMessage)restClient.GetModule(house, unit);

            Assert.AreEqual(house, module.House);
            Assert.AreEqual(unit, module.Unit);
        }
Exemple #9
0
        public static void Display(StandardMessage messageName)
        {
            if (messageName == StandardMessage.NoMessage)
            {
                return;
            }
            var msg = typeof(StandardMessages).GetProperty(messageName.ToString()).GetValue(null);

            Console.WriteLine(msg);
        }
Exemple #10
0
 static void GetPathToFile()
 {
     try
     {
         FileProcessor.TrySetPath(InputUser.CatchUserPathToFile());
     }
     catch (IndexOutOfRangeException)
     {
         StandardMessage.NoFileFound();
     }
 }
 private void TryFindVehicles(List <Vehicle> vehicles)
 {
     if (vehicles.Count > 0)
     {
         PrintVehicles(vehicles);
     }
     else
     {
         StandardMessage.NoVehicleFound();
     }
 }
 private void TryPrintDrivers(List <Driver> drivers)
 {
     if (Company.NumberOfHiredDrivers() > 0)
     {
         PrintDrivers(drivers);
     }
     else
     {
         StandardMessage.NoDriversHired();
     }
 }
 private void TryFindDrivers(List <Driver> drivers)
 {
     if (drivers.Count > 0)
     {
         PrintDrivers(drivers);
     }
     else
     {
         StandardMessage.NoDriverFound();
     }
 }
 private void TryPrintVehicles(List <Vehicle> vehicles)
 {
     if (Company.NumberOfOwnedVehicles() > 0)
     {
         PrintVehicles(vehicles);
     }
     else
     {
         StandardMessage.NoVehiclesOwned();
     }
 }
Exemple #15
0
        static void MainLoop()
        {
            bool programIsLooped;

            do
            {
                StandardMessage.Menu();

                int option = InputUser.CatchUserOption();
                programIsLooped = Controller.InvokeAction(option);
            }while (programIsLooped);
        }
 public void TryPrintAssignedDrivers(IEnumerable <Driver> drivers)
 {
     if (drivers.Count() > 0)
     {
         Console.WriteLine("Assigned drivers:");
         PrintDrivers(drivers);
     }
     else
     {
         StandardMessage.NoDriversAssigned();
     }
 }
        public void SearchForDrivers()
        {
            if (Company.NumberOfHiredDrivers() > 0)
            {
                string firstName = InputDriver.CatchDriverFirstName();
                string lastName  = InputDriver.CatchDriverLastName();

                TryFindDrivers(Company.SearchForDrivers(firstName, lastName));
            }
            else
            {
                StandardMessage.NoDriversHired();
            }
        }
        public void SearchForVehicles()
        {
            if (Company.NumberOfOwnedVehicles() > 0)
            {
                int minimumCapacity = InputVehicle.CatchVehicleCapacity();
                int minimumVolume   = InputVehicle.CatchVehicleVolume();

                TryFindVehicles(Company.SearchForVehicles(minimumCapacity, minimumVolume));
            }
            else
            {
                StandardMessage.NoVehiclesOwned();
            }
        }
Exemple #19
0
 static void LoadDataFromFile()
 {
     try
     {
         FileProcessor.LoadData();
     }
     catch (IOException)
     {
         if (!FileProcessor.HasDefaultPath())
         {
             StandardMessage.NoFileFound();
         }
     }
 }
Exemple #20
0
        public override void Setup()
        {
            _counter.Start();

            StandardMessage standardMessage = new StandardMessage
            {
                Action = Actions.Sort,
                Left   = 0,
                Right  = Utils.Length - 1,
                SourceToDestination = true
            };

            _calls.Push(standardMessage);

            SendMessage(standardMessage, Agents.WorkerAgentLeft, true);
            SendMessage(standardMessage, Agents.WorkerAgentRight, false);
        }
Exemple #21
0
        static void Main(string[] args)
        {
            StandardMessage.Welcome();
            StandardMessage.AddLine(1);

            string           data   = SortName.InputFile();
            IList <string>   names  = SortName.ReadData(data);
            List <NameModel> people = new List <NameModel>();

            StandardMessage.Enter();
            StandardMessage.Clear();

            SortName.Sort(names, people);

            StandardMessage.AddLine(1);

            ExportSortedNames.Export(people);
        }
Exemple #22
0
        static void Main(string[] args)
        {
            var firstNameInput = StandardMessage.CaptureData("first name");
            var surnameInput   = StandardMessage.CaptureData("surname");

            var annualSalaryInput = StandardMessage.CaptureData("annual salary");

            var superRateInput = StandardMessage.CaptureData("super rate");

            var startDate = StandardMessage.CaptureData("payment start date");
            var endDate   = StandardMessage.CaptureData("payment end date");

            var bracket1 = TaxBracket.Generate(0M, 18200M, 0M, 0M);
            var bracket2 = TaxBracket.Generate(18201M, 37000M, 0M, 0.325M);
            var bracket3 = TaxBracket.Generate(37001M, 87000M, 3572M, 0.325M);
            var bracket4 = TaxBracket.Generate(87001M, 180000M, 19822M, 0.37M);
            var bracket5 = TaxBracket.Generate(180000M, Int32.MaxValue, 54232M, 0.45M);

            var taxTable = TaxTable.Build(bracket1, bracket2, bracket3, bracket4, bracket5);

            EmployeeDetails employeeDetails = EmployeeDetails.ConstructFullName(firstNameInput, surnameInput);

            PayPeriod payPeriod = PayPeriod.Generate(startDate, endDate);

            GrossIncome grossIncome = GrossIncome.Generate(annualSalaryInput, payPeriod);
            IncomeTax   incomeTax   = IncomeTax.Generate(taxTable, grossIncome, payPeriod);
            NetIncome   netIncome   = NetIncome.Generate(grossIncome, incomeTax);

            Super super = Super.Generate(superRateInput, grossIncome);

            var paySlip = PaySlip.Create(
                employeeDetails,
                payPeriod,
                grossIncome,
                incomeTax,
                netIncome,
                super
                );

            var payslipOutput = PayslipBuilder.Print(paySlip);

            Console.WriteLine(payslipOutput);
//
        }
Exemple #23
0
 public void VerifyThatCorrectlyCreatedMessagesResultInValidToStringOutput()
 {
     for (var house = 'A'; house <= 'P'; house++)
     {
         for (byte unit = 0; unit <= 16; unit++)
         {
             for (byte command = 0; command <= 16; command++)
             {
                 string expected =
                     house + (unit == 0 ? "_" : (unit - 1).ToString("X")) +
                     (command == 0 ? "_" : (command - 1).ToString("X"));
                 string actualUsingBytes = new StandardMessage(house, unit, command).ToString();
                 string actualUsingEnums = new StandardMessage((House)house, (Unit)(unit - 1), (Command)(command - 1)).ToString();
                 Assert.AreEqual(expected, actualUsingBytes);
                 Assert.AreEqual(expected, actualUsingEnums);
             }
         }
     }
 }
        public static void Export(List <NameModel> people)
        {
            Console.Write("Specify export directory: ");
            string       path       = Console.ReadLine();
            FileStream   stream     = new FileStream(path + "/sorted-names-list.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
            StreamWriter writer     = new StreamWriter(stream);
            TextWriter   textWriter = Console.Out;

            Console.SetOut(writer);
            foreach (var sort in people.OrderBy(q => q.IndexName).ThenBy(q => q.FullName))
            {
                Console.WriteLine(sort.FullName);
            }
            Console.SetOut(textWriter);
            writer.Close();
            stream.Close();
            Console.WriteLine("File exported with name sorted-names-list.txt");
            StandardMessage.Enter();
        }
        public void OwnedVehiclesWithDriversAssigned()
        {
            List <Vehicle> vehicles = Company.ListOfOwnedVehicles();

            if (vehicles != null)
            {
                foreach (var vehicle in vehicles)
                {
                    Console.WriteLine($"{"ID",-10}{"NAME",-31}{"CAPACITY",-10}{"VOLUME",-10}{"ON THE ROAD",-13}{"NUMBER OF COURSES"}");
                    PrintVehicle(vehicle);

                    DriverController DriverController = new DriverController(Company);
                    DriverController.TryPrintAssignedDrivers(vehicle.AssignedDrivers);
                }
            }
            else
            {
                StandardMessage.NoVehiclesOwned();
            }
        }
Exemple #26
0
        static void Main(string[] args)
        {
            FillWater       fw = new FillWater();
            StandardMessage sm = new StandardMessage();

            sm.WelcomeMessage();
            sm.WaterMessage();
            int inputw = Convert.ToInt32(Console.ReadLine());

            fw.WaterToMachine(inputw);
            sm.FilterDiscard();
            Thread.Sleep(1000);
            sm.FilterNew();
            Thread.Sleep(500);
            int inputc = Convert.ToInt32(Console.ReadLine());

            fw.WaterToMachine(inputc);

            Console.ReadLine();
        }
Exemple #27
0
        public override void Act(ActressMas.Message message)
        {
            var standardMessage = new StandardMessage(message.Content);

            switch (standardMessage.Action)
            {
            case Actions.Sort:

                if (standardMessage.Right == standardMessage.Left)
                {
                    if (standardMessage.SourceToDestination)
                    {
                        Utils.Destination[standardMessage.Left] = Utils.Source[standardMessage.Left];
                    }

                    SendMergeMessage();
                }
                else if ((standardMessage.Right - standardMessage.Left) <= Utils.Threshold)
                {
                    Array.Sort(Utils.Source, standardMessage.Left,
                               standardMessage.Right - standardMessage.Left + 1);

                    if (standardMessage.SourceToDestination)
                    {
                        for (int i = standardMessage.Left; i <= standardMessage.Right; i++)
                        {
                            Utils.Destination[i] = Utils.Source[i];
                        }
                    }

                    SendMergeMessage();
                }
                else
                {
                    standardMessage.Action = Actions.Split;
                    Send(Agents.MasterAgent, standardMessage.ToString());
                }

                break;
            }
        }
Exemple #28
0
 /// <summary>
 /// Sends the specified direct message and waits for a response.
 /// </summary>
 /// <param name="packet">Packet to send</param>
 /// <param name="response">The response from the device</param>
 /// <returns>the result of the call</returns>
 public PowerLineModemMessage.MessageResponse SendDirectInsteonPacket(InsteonPacket packet, out InsteonPacket response)
 {
     // Only one packet at a time.
     lock (this)
     {
         if (packet.Flags.MessageType != InsteonPacket.InsteonFlags.MessageTypeEnum.Direct)
         {
             response = null;
             return(PowerLineModemMessage.MessageResponse.Invalid);
         }
         // Send only one direct packet at a time.
         PowerLineModemMessage.MessageResponse messageResponse;
         StandardMessage message = new StandardMessage(PowerLineModemMessage.Message.SendInsteonMessage, packet);
         this.sendingPacket = packet;
         messageResponse    = port.SendCommand(message);
         if (messageResponse == PowerLineModemMessage.MessageResponse.Ack)
         {
             // We should get an ack back for this message.
             if (this.linkingEvent.WaitOne(5000))
             {
                 // See if we got back an ack or nack.
                 if (this.receivedPacket.Flags.MessageType == InsteonPacket.InsteonFlags.MessageTypeEnum.NackDirect)
                 {
                     messageResponse = PowerLineModemMessage.MessageResponse.Nack;
                 }
                 response = this.receivedPacket;
             }
             else
             {
                 response = null;
                 return(PowerLineModemMessage.MessageResponse.Unknown);
             }
         }
         else
         {
             response = null;
         }
         return(messageResponse);
     }
 }
Exemple #29
0
        public override void Act(ActressMas.Message message)
        {
            var standardMessage = new StandardMessage(message.Content);

            switch (standardMessage.Action)
            {
            case Actions.Split:
                SendMessage(standardMessage, message.Sender, true);
                SendMessage(standardMessage, message.Sender, false);
                break;

            case Actions.Merge:
                _expectedMerge--;

                if (_expectedMerge == 0)
                {
                    while (_calls.Count > 0)
                    {
                        var currentCall = _calls.Pop();
                        int middle      = (currentCall.Left + currentCall.Right) / 2;
                        if (currentCall.SourceToDestination)
                        {
                            ParallelAlgorithm.MergeInnerPar(Utils.Source, currentCall.Left,
                                                            middle, middle + 1, currentCall.Right, Utils.Destination, currentCall.Left);
                        }
                        else
                        {
                            ParallelAlgorithm.MergeInnerPar(Utils.Destination, currentCall.Left,
                                                            middle, middle + 1, currentCall.Right, Utils.Source, currentCall.Left);
                        }
                    }

                    Environment.StopAll();
                }

                break;
            }
        }
Exemple #30
0
 private void UpdateUiOnStateChange(Message message)
 {
     if (message is StandardMessage)
     {
         cbxType.SelectedIndex = 0;
         StandardMessage stdMessage = message as StandardMessage;
         House = stdMessage.House;
         Unit  = stdMessage.Unit;
         cbxCommand.SelectionChanged -= cbxCommand_SelectionChanged;
         Command = stdMessage.Command;
         cbxCommand.SelectionChanged += cbxCommand_SelectionChanged;
         if (
             Command == Command.On ||
             Command == Command.Bright ||
             Command == Command.Dim ||
             Command == Command.StatusOn)
         {
             On = true;
         }
         else if (Command == Command.Off || Command == Command.StatusOff)
         {
             On = false;
         }
     }
     if (message is ExtendedMessage)
     {
         ExtendedMessage extMessage = message as ExtendedMessage;
         if (extMessage.ExtendedBrightness > 0)
         {
             if (extMessage.Command != Command.StatusOff)
             {
                 On = true;
             }
             Brightness = extMessage.ExtendedBrightness;
         }
     }
 }