private static void IfStructureChange()
    {
//		Profiler.BeginSample("IfStructureChange");
        //Logger.Log("PowerUpdateStructureChange", Category.Electrical);
        foreach (CableInheritance cabel in NUCableStructureChange)
        {
            cabel.PowerUpdateStructureChange();             //so Destruction of cables won't trigger the entire thing to refresh saving a bit of performance since they have a bit of code for jumping onto different supplies and  , adding them to NUStructureChangeReact
        }

        NUCableStructureChange.Clear();
        if (!StructureChange)
        {
//			Profiler.EndSample();
            return;
        }

        //Logger.Log("StructureChange bool PowerUpdateStructureChange!",Category.Electrical);
        StructureChange = false;
        foreach (var category in OrderList)
        {
            foreach (ElectricalNodeControl TheSupply in AliveSupplies[category])
            {
                TheSupply.PowerUpdateStructureChange();
            }
        }

        foreach (ElectricalNodeControl ToWork in PoweredDevices)
        {
            ToWork.PowerUpdateStructureChange();
        }

//		Profiler.EndSample();
    }
    private static void IfStructureChange()
    {
        Profiler.BeginSample("IfStructureChange");
        if (!StructureChange)
        {
            return;
        }
        //Logger.Log("PowerUpdateStructureChange");
        StructureChange = false;
        foreach (CableInheritance cabel in NUCableStructureChange)
        {
            cabel.PowerUpdateStructureChange();
        }
        NUCableStructureChange.Clear();
        foreach (var category in OrderList)
        {
            foreach (PowerSupplyControlInheritance TheSupply in AliveSupplies[category])
            {
                TheSupply.PowerUpdateStructureChange();
            }
        }

        foreach (PowerSupplyControlInheritance ToWork in PoweredDevices)
        {
            ToWork.PowerUpdateStructureChange();
        }
        Profiler.EndSample();
    }
示例#3
0
        public bool Execute(params object[] stuff)
        {
            RoomUser roomUser = (RoomUser)stuff[0];
            RoomItem roomItem = (RoomItem)stuff[1];

            if (!Items.Contains(roomItem) || roomUser.LastItem != roomItem.Id)
            {
                return(false);
            }

            if (
                roomItem.AffectedTiles.Values.Any(
                    current =>
                    (current.X == roomUser.X && current.Y == roomUser.Y) ||
                    (roomUser.X == roomItem.X && roomUser.Y == roomItem.Y)))
            {
                return(false);
            }

            ToWork.Enqueue(roomUser);

            if (Delay == 0)
            {
                OnCycle();
            }
            else
            {
                _mNext = Yupi.Now() + Delay;

                Room.GetWiredHandler().EnqueueCycle(this);
            }

            return(true);
        }
        /// <summary>
        /// Serialize this object's properties to XML.
        /// </summary>
        /// <param name="writer">Destination to write XML to.</param>
        public void WriteXml(XmlWriter writer)
        {
            if (writer is null)
            {
                throw new ArgumentNullException(nameof(writer));
            }
            writer.WriteAttributeString("Id", Id);
            if (Headcode != null)
            {
                writer.WriteElementString("Headcode", Headcode);
            }
            if (LocoDiagram != null)
            {
                writer.WriteElementString("LocoDiagram", LocoDiagram);
            }
            if (TrainClassId != null)
            {
                writer.WriteElementString("TrainClassId", TrainClassId);
            }

            if (GraphProperties != null)
            {
                writer.WriteStartElement("GraphProperties");
                GraphProperties.WriteXml(writer);
                writer.WriteEndElement();
            }

            writer.WriteStartElement("TrainTimes");
            foreach (TrainLocationTimeModel time in TrainTimes)
            {
                writer.WriteStartElement("Time");
                time.WriteXml(writer);
                writer.WriteEndElement();
            }
            writer.WriteEndElement();

            writer.WriteStartElement("FootnoteIds");
            foreach (string note in FootnoteIds)
            {
                writer.WriteElementString("Note", note);
            }
            writer.WriteEndElement();

            writer.WriteElementString("IncludeSeparatorAbove", IncludeSeparatorAbove ? "true" : "false");
            writer.WriteElementString("IncludeSeparatorBelow", IncludeSeparatorBelow ? "true" : "false");
            writer.WriteElementString("InlineNote", InlineNote);

            if (ToWork != null)
            {
                writer.WriteStartElement("ToWork");
                ToWork.WriteXml(writer);
                writer.WriteEndElement();
            }
            if (LocoToWork != null)
            {
                writer.WriteStartElement("LocoToWork");
                LocoToWork.WriteXml(writer);
                writer.WriteEndElement();
            }
        }
示例#5
0
        public bool Execute(params object[] stuff)
        {
            RoomUser roomUser = (RoomUser)stuff[0];
            RoomItem roomItem = (RoomItem)stuff[1];

            int userPosition     = roomUser.X;
            int lastUserPosition = roomUser.CopyX;

            if (!Items.Contains(roomItem) || (roomUser.LastItem != 0 && roomUser.LastItem == roomItem.Id && userPosition == lastUserPosition))
            {
                return(false);
            }

            if (roomItem.GetRoom() == null || roomItem.GetRoom().GetRoomItemHandler() == null || roomItem.GetRoom().GetRoomItemHandler().FloorItems.Values.Any(i => i.X == roomItem.X && i.Y == roomItem.Y && i.Z > roomItem.Z))
            {
                return(false);
            }

            ToWork.Enqueue(roomUser);

            if (Delay == 0)
            {
                OnCycle();
            }
            else
            {
                _mNext = Yupi.Now() + Delay;

                Room.GetWiredHandler().EnqueueCycle(this);
            }

            return(true);
        }
    /// <summary>
    /// Sends updates to things that might need it
    /// </summary>
    private static void PowerNetworkUpdate()
    {
//		Profiler.BeginSample("PowerNetworkUpdate");
        for (int i = 0; i < OrderList.Count; i++)
        {
            foreach (ElectricalNodeControl TheSupply in AliveSupplies[OrderList[i]])
            {
                TheSupply.PowerNetworkUpdate();
            }
        }

        foreach (ElectricalNodeControl ToWork in PoweredDevices)
        {
            ToWork.PowerNetworkUpdate();
        }

        WorkingCableUpdates = new HashSet <CableInheritance>(CableUpdates);
        CableUpdates.Clear();
        foreach (CableInheritance ToWork in WorkingCableUpdates)
        {
            ToWork.PowerNetworkUpdate();             //This is used to update the cables  if they have the current change to detect if there was an overcurrent
        }

        WorkingCableUpdates.Clear();
        if (CableToDestroy != null)
        {
            CableToDestroy.toDestroy();
            CableToDestroy = null;
        }

//		Profiler.EndSample();
    }
示例#7
0
 public Left(Folder mainFolder, Folder myComputer, ToWork toWork, int minimumDirectoryHeight, int maximumDirectoryHeight)
 {
     this.maximumDirectoryHeight = maximumDirectoryHeight;
     this.minimumDirectoryHeight = minimumDirectoryHeight;
     this.toWork     = toWork;
     this.mainFolder = mainFolder;
     this.myComputer = myComputer;
 }
        public void ToWorkClassUpdateModelMethodDoesNotThrowExceptionIfFirstParameterIsNull()
        {
            ToWork testObject = new ToWork {
                AtTime = _rnd.NextTimeOfDay(), Text = _rnd.NextString(_rnd.Next(64))
            };

            testObject.UpdateModel(null, null);
        }
示例#9
0
        public void ToWorkExtensionsClass_ToYamlToWorkModelMethod_ThrowsNullReferenceException_IfParameterIsNull()
        {
            ToWork testParam = null;

            _ = testParam.ToYamlToWorkModel();

            Assert.Fail();
        }
示例#10
0
        public void ToWorkExtensionsClass_ToYamlToWorkModelMethod_ReturnsObjectWithCorrectTextProperty_IfParameterHasTextPropertyThatIsNotNull()
        {
            ToWork testParam = GetTestObject();

            ToWorkModel testOutput = testParam.ToYamlToWorkModel();

            Assert.AreEqual(testParam.Text, testOutput.Text);
        }
        public void ToWorkModelExtensionsClass_ToToWorkMethod_ReturnsObjectWithCorrectTextProperty_IfTextPropertyOfParameterIsNotNull()
        {
            ToWorkModel testParam = GetModel();

            ToWork testOutput = testParam.ToToWork();

            Assert.AreEqual(testParam.Text, testOutput.Text);
        }
        public void ToWorkExtensionsClass_ToWorkModelMethod_ThrowsArgumentNullException_IfParameterIsNull()
        {
            ToWork testObject = null;

            _ = testObject.ToToWorkModel();

            Assert.Fail();
        }
        public void ToWorkClassCopyToMethodThrowsArgumentNullExceptionIfParameterIsNull()
        {
            ToWork testObject = new ToWork {
                AtTime = _rnd.NextTimeOfDay()
            };

            testObject.CopyTo(null);

            Assert.Fail();
        }
        public void ToWorkClassCopyMethodReturnsCorrectAtTimePropertyIfAtTimeIsNull()
        {
            ToWork testObject = new ToWork {
                AtTime = null
            };

            ToWork testResult = testObject.Copy();

            Assert.IsNull(testResult.AtTime);
        }
        public void ToWorkModelExtensionsClass_ToToWorkMethod_ReturnsObjectWithAtTimePropertyEqualToNull_IfAtPropertyOfParameterIsNull()
        {
            ToWorkModel testParam = GetModel();

            testParam.At = null;

            ToWork testOutput = testParam.ToToWork();

            Assert.IsNull(testOutput.AtTime);
        }
示例#16
0
        public void ToWorkExtensionsClass_ToYamlToWorkModelMethod_ReturnsObjectWithAtPropertyEqualToNull_IfParameterHasAtTimePropertyThatIsNotNull()
        {
            ToWork testParam = GetTestObject();

            testParam.AtTime = null;

            ToWorkModel testOutput = testParam.ToYamlToWorkModel();

            Assert.IsNull(testOutput.At);
        }
        public void ToWorkModelExtensionsClass_ToToWorkMethod_ReturnsObjectWithNullTextProperty_IfTextPropertyOfParameterIsNull()
        {
            ToWorkModel testParam = GetModel();

            testParam.Text = null;

            ToWork testOutput = testParam.ToToWork();

            Assert.IsNull(testOutput.Text);
        }
        public void ToWorkClassCopyMethodReturnsCorrectAtTimePropertyIfAtTimeIsNotNull()
        {
            TimeOfDay testTime   = _rnd.NextTimeOfDay();
            ToWork    testObject = new ToWork {
                AtTime = testTime
            };

            ToWork testResult = testObject.Copy();

            Assert.AreEqual(testTime, testResult.AtTime);
        }
        public void ToWorkClassCopyMethodReturnsCorrectTextProperty()
        {
            string testText   = _rnd.NextString(_rnd.Next(256));
            ToWork testObject = new ToWork {
                Text = testText
            };

            ToWork testResult = testObject.Copy();

            Assert.AreEqual(testText, testResult.Text);
        }
示例#20
0
        public void ToWorkExtensionsClass_ToYamlToWorkModelMethod_ReturnsObjectWithAtPropertyWithCorrectTimeProperty_IfParameterHasAtTimePropertyThatIsNotNull()
        {
            ToWork testParam = GetTestObject();

            ToWorkModel testOutput = testParam.ToYamlToWorkModel();

            string expectedValue = testParam.AtTime.Hours24.ToString("d2", CultureInfo.InvariantCulture) + ":" +
                                   testParam.AtTime.Minutes.ToString("d2", CultureInfo.InvariantCulture) + ":" +
                                   testParam.AtTime.Seconds.ToString("d2", CultureInfo.InvariantCulture);

            Assert.AreEqual(expectedValue, testOutput.At.Time);
        }
        public void ToWorkClassUpdateModelMethodSetsActualTimePropertyOfTargetIfTextPropertyIsEmptyString()
        {
            ToWork testObject = new ToWork {
                AtTime = _rnd.NextTimeOfDay(), Text = ""
            };
            GenericTimeModel testTarget = new GenericTimeModel {
                ActualTime = _rnd.NextTimeOfDay(), DisplayedText = _rnd.NextString(_rnd.Next(64))
            };

            testObject.UpdateModel(testTarget, null);

            Assert.AreEqual(testObject.AtTime, testTarget.ActualTime);
        }
示例#22
0
        /// <summary>
        /// Convert a <see cref="ToWork" /> instance to a <see cref="ToWorkModel" /> instance.
        /// </summary>
        /// <param name="toWork">The object to be converted.</param>
        /// <returns>A <see cref="ToWorkModel" /> instance containing the same data as the parameter.</returns>
        /// <exception cref="NullReferenceException">Thrown if the parameter is <c>null</c>.</exception>
        public static ToWorkModel ToYamlToWorkModel(this ToWork toWork)
        {
            if (toWork is null)
            {
                throw new NullReferenceException();
            }

            return(new ToWorkModel
            {
                Text = toWork.Text,
                At = toWork.AtTime?.ToYamlTimeOfDayModel(),
            });
        }
        public void ToWorkClassCopyToMethodSetsTextPropertyOfParameter()
        {
            ToWork testObject = new ToWork {
                AtTime = _rnd.NextTimeOfDay(), Text = _rnd.NextString(_rnd.Next(64))
            };
            ToWork testTarget = new ToWork {
                AtTime = _rnd.NextTimeOfDay(), Text = _rnd.NextString(_rnd.Next(64))
            };

            testObject.CopyTo(testTarget);

            Assert.AreEqual(testObject.Text, testTarget.Text);
        }
        public void ToWorkClassUpdateModelMethodSetsDisplayedTextPropertyOfTargetToEmptyStringIfAtTimePropertyIsNullAndTextPropertyIsNull()
        {
            ToWork testObject = new ToWork {
                AtTime = null, Text = null
            };
            GenericTimeModel testTarget = new GenericTimeModel {
                ActualTime = _rnd.NextTimeOfDay(), DisplayedText = _rnd.NextString(_rnd.Next(64))
            };

            testObject.UpdateModel(testTarget, null);

            Assert.AreEqual("", testTarget.DisplayedText);
        }
        public void ToWorkClassUpdateModelMethodSetsDisplayedTextPropertyOfTargetCorrectlyIfTextPropertyIsNullAndSecondParameterIsNull()
        {
            ToWork testObject = new ToWork {
                AtTime = _rnd.NextTimeOfDay(), Text = null
            };
            GenericTimeModel testTarget = new GenericTimeModel {
                ActualTime = _rnd.NextTimeOfDay(), DisplayedText = _rnd.NextString(_rnd.Next(64))
            };

            testObject.UpdateModel(testTarget, null);

            Assert.AreEqual(testObject.AtTime.ToString(), testTarget.DisplayedText);
        }
示例#26
0
 /// <summary>
 /// Sends updates to things that might need it
 /// </summary>
 private static void PowerNetworkUpdate()
 {
     for (int i = 0; i < OrderList.Count; i++)
     {
         foreach (PowerSupplyControlInheritance TheSupply in AliveSupplies[OrderList[i]])
         {
             TheSupply.PowerNetworkUpdate();
         }
     }
     foreach (PowerSupplyControlInheritance ToWork in PoweredDevices)
     {
         ToWork.PowerNetworkUpdate();
     }
 }
        public void ToWorkExtensionsClass_ToToWorkModelMethod_ThrowsArgumentNullExceptionWithCorrectParamNameProperty_IfParameterIsNull()
        {
            ToWork testObject = null;

            try
            {
                _ = testObject.ToToWorkModel();
                Assert.Fail();
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("data", ex.ParamName);
            }
        }
        public void ToWorkClassUpdateModelMethodSetsDisplayedTextPropertyOfTargetCorrectlyIfTextPropertyIsNullAndSecondParameterIsNotNull()
        {
            ToWork testObject = new ToWork {
                AtTime = _rnd.NextTimeOfDay(), Text = null
            };
            GenericTimeModel testTarget = new GenericTimeModel {
                ActualTime = _rnd.NextTimeOfDay(), DisplayedText = _rnd.NextString(_rnd.Next(64))
            };

            testObject.UpdateModel(testTarget, new TimeDisplayFormattingStrings {
                TimeWithoutFootnotes = "mmHH"
            });

            Assert.AreEqual(testObject.AtTime.ToString("mmHH", CultureInfo.CurrentCulture), testTarget.DisplayedText);
        }
示例#29
0
        public void Management()
        {
            ShowComposite.show(myComputer);
            ToWork toWork = new ToWork(true);

            //   folders[current.Index].Current = true;

            while (toWork.Working)
            {
                ConsoleKeyInfo key;
                if (folders.Count > 0)
                {
                    Down downArrow = new Down(fileSystemEntriesPaths, folders, current, myComputer);
                    Up   upArrow   = new Up(fileSystemEntriesPaths, folders, current, myComputer);

                    try
                    {
                        if (folders[current.Index] is Folder && Directory.GetFileSystemEntries(folders[current.Index].Way).Length > 0)
                        {
                            Right rightArrow = new Right(folders[current.Index] as Folder, indentationLength + 2, myComputer);
                            commands.Add(rightArrow);
                        }
                    }
                    catch (UnauthorizedAccessException)
                    {
                    }

                    commands.Add(downArrow);
                    commands.Add(upArrow);
                }

                Left leftArrow = new Left(mainFolder, myComputer, toWork, minimumDirectoryHeight, maximumDirectoryHeight);
                commands.Add(leftArrow);
                key = Console.ReadKey();

                folders[current.Index].Current = false;

                foreach (ICommand command in commands)
                {
                    command.Executive(key);
                }

                folders[current.Index].Current = true;

                ShowComposite.show(myComputer);
                commands.Clear();
            }
        }
        public void ToWorkModelExtensionsClass_ToToWorkMethod_ReturnsObjectWithCorrectAtTimeProperty_IfParameterHasAtPropertyWithTimePropertyThatConsistsOfNumberInRangeWithNoColons()
        {
            int         hoursValue = _rnd.Next(24);
            ToWorkModel testParam  = GetModel();

            testParam.At = new TimeOfDayModel {
                Time = hoursValue.ToString(CultureInfo.InvariantCulture)
            };

            ToWork testOutput = testParam.ToToWork();

            Assert.AreEqual(hoursValue * 3600, testOutput.AtTime.AbsoluteSeconds);
            Assert.AreEqual(hoursValue, testOutput.AtTime.Hours24);
            Assert.AreEqual(0, testOutput.AtTime.Minutes);
            Assert.AreEqual(0, testOutput.AtTime.Seconds);
        }