Esempio n. 1
0
        static void getSequence(int sequenceLength)
        {
            var   result = "\n";
            ulong x      = 0;
            ulong y      = 1;
            ulong z      = 0;

            if (sequenceLength < 2)
            {
                Console.WriteLine("\nYou need at least two numbers to create a sequence!");
            }

            else if (SequenceList.Count == 0)
            {
                SequenceList.Add(x);
                SequenceList.Add(y);
            }

            while (SequenceList.Count < sequenceLength)
            {
                z = x + y;
                SequenceList.Add(z);
                x = y;
                y = z;
            }
            ;

            foreach (var value in SequenceList)
            {
                result += (value + " ");
            }

            Console.WriteLine(result);
        }
Esempio n. 2
0
        internal protected override bool TryCreate(MetaElementType elementType, out ReadElement element)
        {
            switch (elementType)
            {
            case MetaElementType.Field:
                FieldReadElement fieldReadElement = new FieldReadElement();
                fieldList.Add(fieldReadElement);
                element = fieldReadElement;
                return(true);

            case MetaElementType.Sequence:
                SequenceReadElement sequenceReadElement = new SequenceReadElement();
                sequenceList.Add(sequenceReadElement);
                element = sequenceReadElement;
                return(true);

            case MetaElementType.Substitution:
                SubstitutionReadElement substitutionReadElement = new SubstitutionReadElement();
                substitutionList.Add(substitutionReadElement);
                element = substitutionReadElement;
                return(true);

            default:
                element = null;
                return(false);
            }
        }
Esempio n. 3
0
        private void fillList()
        {
            RoomsDetection roomsDetection = new RoomsDetection();

            if (_context.MovementSekv.Any())
            {
                var movSekvList = _context.MovementSekv.ToList();

                foreach (var movSekv in movSekvList)
                {
                    DateTime convertedDate = DateTime.Parse(movSekv.TimeStamp);

                    Izby   izba     = null;
                    String izbaName = "";
                    try {
                        izba     = _context.Rooms.Where(t => t.IzbaID == movSekv.IzbyFK).First();
                        izbaName = izba.Nazov;
                    }
                    catch (Exception e)
                    {
                        izbaName = "Vonku";
                    }
                    string alert = "NA";

                    if (movSekv.Upozornenie_Cas != 0)
                    {
                        alert = "Čas";
                    }
                    else if (movSekv.Upozornenie_Hranica != 0)
                    {
                        alert = "Hranica";
                    }


                    MovementObj movObj = new MovementObj
                    {
                        PohId    = movSekv.PohSekvId,
                        RoomName = izbaName,
                        Alert    = alert,
                        LongDate = convertedDate.ToLongDateString(),
                        Date     = convertedDate.ToShortDateString(),
                        Time     = convertedDate.ToLongTimeString(),
                        Duration = movSekv.Cas_Zotrvania,
                        xValue   = movSekv.Xhodnota,
                        yValue   = movSekv.Yhodnota
                    };

                    SequenceList.Add(movObj);
                }
                fillPageWithSequence(SequenceList.Last());
            }
            else
            {
                MovAlert = "Neexistuje žiadna sekvencia";
            }

            SequenceList = new ObservableCollection <MovementObj>(SequenceList.Reverse());
        }
 public void AddAllSequences(SequenceList newSequences)
 {
     if (newSequences != null)
     {
         foreach (Sequence sequence in newSequences.listSequence)
         {
             SequenceList.Add(sequence);
         }
     }
 }
Esempio n. 5
0
        public void Test()
        {
            SequenceList <int> list = new SequenceList <int>(5);

            // 1, 2, 3, 4
            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(4);
            Assert.Equal(4, list.Length);
            Assert.Equal(2, list[1]);

            // 1, 2, 3, 4
            // 1, 2, 3, 5
            list[3] = 5;
            Assert.Equal(4, list.Length);
            Assert.Equal(5, list[3]);

            // 1,    2, 3, 5
            // 1, 8, 2, 3, 5
            list.Insert(1, 8);
            Assert.Equal(5, list.Length);
            Assert.Equal(8, list[1]);
            Assert.Equal(2, list[2]);

            // 1, 8, 2, 3, 5
            // 1,    2, 3, 5
            int removedItem = list.RemoveAt(1);

            Assert.Equal(4, list.Length);
            Assert.Equal(8, removedItem);
            Assert.Equal(2, list[1]);

            list.Clear();
            Assert.Equal(0, list.Length);
        }
Esempio n. 6
0
        private void ParseDelegates(string methodName, MethodInfo method, CNMAttrSequence.options sequence)
        {
            CNMHomeComponent instance = modularRefs[methodTypes[method]];

    #if DEBUG
            Debug.LogFormat("CNMHome: Parsing {0} from {1} as {2}.", methodName, instance.GetType().Name, sequence);
    #endif

            try
            {
                switch (methodName)
                {
                case "CreateNode":
                    Sequence_CreateNode.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnNetworkInitialized":
                    Sequence_OnNetworkInitialized.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnNetworkPreUpdate":
                    Sequence_OnNetworkPreUpdate.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "Start":
                    Sequence_Start.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "Update":
                    Sequence_Update.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                default:
    #if DEBUG
                    log.warning("The method passed (" + methodName + ") was not a standard CommNet method.");
    #endif
                    return;
                }
                log.debug("Successfully parsed " + methodName + " from type " + instance.GetType().Name);
            }
            catch (Exception ex)
            {
                log.error("Encountered an error creating a delegate for " + methodName + " from type " + instance.GetType().Name);
                log.error(ex);
            }
        }
        private void ParseDelegates(string methodName, MethodInfo method, CNMAttrSequence.options sequence)
        {
            ModularCommNetVesselComponent instance = modularRefs[methodTypes[method]];

    #if DEBUG
            if (andOrList.ContainsKey(method))
            {
                Debug.LogFormat("ModularCommNetVessel: Parsing {0} from {1} as {2} with {3}.", methodName, instance.GetType().Name, sequence, andOrList[method]);
            }
            else
            {
                Debug.LogFormat("ModularCommNetVessel: Parsing {0} from {1} as {2}.", methodName, instance.GetType().Name, sequence);
            }
    #endif

            try
            {
                switch (methodName)
                {
                case "Awake":
                    Sequence_Awake.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnAwake":
                    Sequence_OnAwake.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnStart":
                    Sequence_OnStart.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnDestroy":
                    Sequence_OnDestroy.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnGoOffRails":
                    Sequence_OnGoOffRails.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnGoOnRails":
                    Sequence_OnGoOnRails.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnLoad":
                    Sequence_OnLoad.Add(sequence, Delegate.CreateDelegate(typeof(Action <ConfigNode>), instance, method) as Action <ConfigNode>, instance);
                    break;

                case "OnSave":
                    Sequence_OnSave.Add(sequence, Delegate.CreateDelegate(typeof(Action <ConfigNode>), instance, method) as Action <ConfigNode>, instance);
                    break;

                case "Update":
                    Sequence_Update.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action, instance);
                    break;

                case "OnNetworkInitialized":
                    Sequence_OnNetworkInitialized.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnNetworkPreUpdate":
                    Sequence_OnNetworkPreUpdate.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnNetworkPostUpdate":
                    Sequence_OnNetworkPostUpdate.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "CalculatePlasmaMult":
                    Sequence_CalculatePlasmaMult.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action, instance);
                    break;

                case "UpdateComm":
                    Sequence_UpdateComm.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action, instance);
                    break;

                case "CreateControlConnection":
                    Sequence_CreateControlConnection.Add(sequence, Delegate.CreateDelegate(typeof(Func <bool>), instance, method) as Func <bool>, new Pair <CNMAttrAndOr.options, ModularCommNetVesselComponent>(andOrList[method], instance));
                    break;

                case "GetBestTransmitter":
                    Sequence_GetBestTransmitter.Add(sequence, Delegate.CreateDelegate(typeof(Func <IScienceDataTransmitter>), instance, method) as Func <IScienceDataTransmitter>, instance);
                    break;

                case "GetControlLevel":
                    Sequence_GetControlLevel.Add(sequence, Delegate.CreateDelegate(typeof(Func <Vessel.ControlLevel>), instance, method) as Func <Vessel.ControlLevel>, instance);
                    break;

                case "OnMapFocusChange":
                    Sequence_OnMapFocusChange.Add(sequence, Delegate.CreateDelegate(typeof(Action <MapObject>), instance, method) as Action <MapObject>);
                    break;

                case "GetSignalStrengthModifier":
                    Sequence_GetSignalStrengthModifier.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, double>), instance, method) as Func <CommNode, double>, instance);
                    break;

                default:
    #if DEBUG
                    log.warning("The method passed (" + methodName + ") was not a standard CommNet method.");
    #endif
                    return;
                }
                log.debug("Successfully parsed " + methodName + " from type " + instance.GetType().Name);
            }
            catch (Exception ex)
            {
                log.error("Encountered an error creating a delegate for " + methodName + " from type " + instance.GetType().Name);
                log.error(ex);
            }
        }
        private void fillList()
        {
            int    low = 0; int height = 0; int middle = 0; int ok = 0;
            double lowMin = 0; double heightMin = 0; double middleMin = 0; double okMin = 0;
            double lowMinDay = 0; double heightMinDay = 0; double middleMinDay = 0; double okMinDay = 0;
            int    lowDay = 0; int heightDay = 0; int middleDay = 0; int okDay = 0;

            if (_context.TemperatureSekv.Any())
            {
                var listTemp = _context.TemperatureSekv.ToList();
                Helpers.SekvenceHelper.LimitCheck loader = new Helpers.SekvenceHelper.LimitCheck();
                //DateTime actualForSummary = DateTime.Parse("2017-01-01T12:04:19Z");
                DateTime actualForSummary = DateTime.Now;

                foreach (var t in listTemp)
                {
                    DateTime convertedDate = DateTime.Parse(t.TimeStart);
                    String   durationTime = null;
                    String   endTimeString = "NA"; String endDateString = "";
                    double   time = 0;
                    try
                    {
                        DateTime endtime = DateTime.Parse(t.TimeClose);
                        time = (endtime - convertedDate).TotalMinutes;
                        var x = time - Math.Truncate(time);
                        durationTime  = Math.Truncate(time).ToString() + " min " + Math.Round(x * 60).ToString() + " sec";
                        endDateString = endtime.ToLongDateString();
                        endTimeString = endtime.ToLongTimeString();
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine("Exception parse date " + e.ToString());
                        durationTime = "NA";
                    }

                    if (actualForSummary <= convertedDate.AddHours(12))
                    {
                        switch (t.Upozornenie)
                        {
                        case 0: ok++;
                            okMin += time;
                            break;

                        case 1: low++;
                            lowMin += time;

                            break;

                        case -1: low++;
                            lowMin += time;

                            break;

                        case 2: middle++;
                            middleMin += time;

                            break;

                        case 3: height++;
                            heightMin += time;

                            break;
                        }
                    }

                    if (actualForSummary <= convertedDate.AddHours(24))
                    {
                        switch (t.Upozornenie)
                        {
                        case 0:
                            okDay++;
                            okMinDay += time;

                            break;

                        case 1:
                            lowDay++;
                            lowMinDay += time;

                            break;

                        case -1:
                            lowDay++;
                            lowMinDay += time;

                            break;

                        case 2:
                            middleDay++;
                            middleMinDay += time;

                            break;

                        case 3:
                            heightDay++;
                            heightMinDay += time;

                            break;
                        }
                    }

                    TemperatureObj tem = new TemperatureObj()
                    {
                        TempId      = t.TeplSekvId,
                        Value       = "~" + t.Sekvencia.ToString("n2") + " °C",
                        LongDate    = convertedDate.ToLongDateString(),
                        Date        = convertedDate.ToShortDateString(),
                        Time        = convertedDate.ToLongTimeString(),
                        DateEnd     = endDateString,
                        TimeEnd     = endTimeString,
                        Duration    = durationTime,
                        Upozornenie = t.Upozornenie,
                        Alert       = loader.getStringValuePulseAndTempLimit(t.Upozornenie)
                    };

                    SequenceList.Add(tem);
                }
                fillPageWithSequence(SequenceList.Last());
            }
            else
            {
                TempAlert = "Neexistuje žiadna sekvencia";
            }

            HeightTwelve = "Vysoké: ~" + Math.Truncate(heightMin).ToString() + " min";
            MiddleTwelve = "Stredné: ~" + Math.Truncate(middleMin).ToString() + " min";
            LowTwelve    = "Slabé: ~" + Math.Truncate(lowMin).ToString() + " min";
            OkTwelve     = "OK: ~" + Math.Truncate(okMin).ToString() + " min";

            HeightDay = HeightTwelve = "Vysoké: ~" + Math.Truncate(heightMinDay).ToString() + " min";
            MiddleDay = "Stredné: ~" + Math.Truncate(middleMinDay).ToString() + " min";
            LowDay    = "Slabé: ~" + Math.Truncate(lowMinDay).ToString() + " min";
            OkDay     = "OK: ~" + Math.Truncate(okMinDay).ToString() + " min";

            // System.Diagnostics.Debug.WriteLine("/////CAS: " + okMin + " " + lowMin + " " + middleMin + " " + heightMin  + " " + Math.Truncate(okMin).ToString());


            SequenceList = new ObservableCollection <TemperatureObj>(SequenceList.Reverse());
        }
        private void ParseDelegates(string methodName, MethodInfo method, CNMAttrSequence.options sequence)
        {
            CommNetwork networkInstance = commNetworks[methodTypes[method]];

    #if DEBUG
            if (andOrList.ContainsKey(method))
            {
                Debug.LogFormat("CommNetManager: Parsing {0} from {1} as {2} with {3}.", methodName, networkInstance.GetType().Name, sequence, andOrList[method]);
            }
            else
            {
                Debug.LogFormat("CommNetManager: Parsing {0} from {1} as {2}.", methodName, networkInstance.GetType().Name, sequence);
            }
    #endif
            try
            {
                switch (methodName)
                {
                case "SetNodeConnection":
                    Sequence_SetNodeConnection.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommNode, bool>), networkInstance, method) as Func <CommNode, CommNode, bool>, andOrList[method]);
                    break;

                case "Add_CommNode":
                    Sequence_Add_CommNode.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommNode>), networkInstance, method) as Func <CommNode, CommNode>);
                    break;

                case "Add_Occluder":
                    Sequence_Add_Occluder.Add(sequence, Delegate.CreateDelegate(typeof(Func <Occluder, Occluder>), networkInstance, method) as Func <Occluder, Occluder>);
                    break;

                case "Connect":
                    Sequence_Connect.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommNode, double, CommLink>), networkInstance, method) as Func <CommNode, CommNode, double, CommLink>);
                    break;

                case "CreateShortestPathTree":
                    Sequence_CreateShortestPathTree.Add(sequence, Delegate.CreateDelegate(typeof(Action <CommNode, CommNode>), networkInstance, method) as Action <CommNode, CommNode>);
                    break;

                case "Disconnect":
                    Sequence_Disconnect.Add(sequence, Delegate.CreateDelegate(typeof(Action <CommNode, CommNode, bool>), networkInstance, method) as Action <CommNode, CommNode, bool>, andOrList[method]);
                    break;

                case "FindClosestControlSource":
                    Sequence_FindClosestControlSource.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommPath, bool>), networkInstance, method) as Func <CommNode, CommPath, bool>, andOrList[method]);
                    break;

                case "FindClosestWhere":
                    Sequence_FindClosestWhere.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommPath, Func <CommNode, CommNode, bool>, CommNode>), networkInstance, method) as Func <CommNode, CommPath, Func <CommNode, CommNode, bool>, CommNode>);
                    break;

                case "FindHome":
                    Sequence_FindHome.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommPath, bool>), networkInstance, method) as Func <CommNode, CommPath, bool>, andOrList[method]);
                    break;

                case "FindPath":
                    Sequence_FindPath.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommPath, CommNode, bool>), networkInstance, method) as Func <CommNode, CommPath, CommNode, bool>, andOrList[method]);
                    break;

                case "GetLinkPoints":
                    Sequence_GetLinkPoints.Add(sequence, Delegate.CreateDelegate(typeof(Action <List <Vector3> >), networkInstance, method) as Action <List <Vector3> >);
                    break;

                case "PostUpdateNodes":
                    Sequence_PostUpdateNodes.Add(sequence, Delegate.CreateDelegate(typeof(Action), networkInstance, method) as Action);
                    break;

                case "PreUpdateNodes":
                    Sequence_PreUpdateNodes.Add(sequence, Delegate.CreateDelegate(typeof(Action), networkInstance, method) as Action);
                    break;

                case "Rebuild":
                    Sequence_Rebuild.Add(sequence, Delegate.CreateDelegate(typeof(Action), networkInstance, method) as Action);
                    break;

                case "Remove_CommNode":
                    Sequence_Remove_CommNode.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, bool>), networkInstance, method) as Func <CommNode, bool>, andOrList[method]);
                    break;

                case "Remove_Occluder":
                    Sequence_Remove_Occluder.Add(sequence, Delegate.CreateDelegate(typeof(Func <Occluder, bool>), networkInstance, method) as Func <Occluder, bool>, andOrList[method]);
                    break;

                case "TestOcclusion":
                    Sequence_TestOcclusion.Add(sequence, Delegate.CreateDelegate(typeof(Func <Vector3d, Occluder, Vector3d, Occluder, double, bool>), networkInstance, method) as Func <Vector3d, Occluder, Vector3d, Occluder, double, bool>, andOrList[method]);
                    break;

                case "TryConnect":
                    Sequence_TryConnect.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommNode, double, bool, bool, bool, bool>), networkInstance, method) as Func <CommNode, CommNode, double, bool, bool, bool, bool>, andOrList[method]);
                    break;

                case "UpdateNetwork":
                    Sequence_UpdateNetwork.Add(sequence, Delegate.CreateDelegate(typeof(Action), networkInstance, method) as Action);
                    break;

                case "UpdateShortestPath":
                    Sequence_UpdateShortestPath.Add(sequence, Delegate.CreateDelegate(typeof(Action <CommNode, CommNode, CommLink, double, CommNode, CommNode>), networkInstance, method) as Action <CommNode, CommNode, CommLink, double, CommNode, CommNode>);
                    break;

                case "UpdateShortestWhere":
                    Sequence_UpdateShortestWhere.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, CommNode, CommLink, double, CommNode, Func <CommNode, CommNode, bool>, CommNode>), networkInstance, method) as Func <CommNode, CommNode, CommLink, double, CommNode, Func <CommNode, CommNode, bool>, CommNode>);
                    break;

                default:
    #if DEBUG
                    log.warning("The method passed (" + methodName + ") was not a standard CommNet method.");
    #endif
                    return;
                }
                log.debug("Successfully parsed " + methodName + " from type " + networkInstance.GetType().Name);
            }
            catch (Exception ex)
            {
                log.error("Encountered an error creating a delegate for " + methodName + " from type " + networkInstance.GetType().Name);
                log.error(ex);
            }
        }