コード例 #1
0
        public void ControlActiveSettings(List <CAS> signals)
        {
            foreach (CAS signal in signals)
            {
                CAS temp = SimulatorModel.Instance.ControlActiveSignals.FirstOrDefault(o => o.Gid.Equals(signal.Gid));

                if (temp == null)
                {
                    SimulatorModel.Instance.ControlActiveSignals.Add(signal);
                    continue;
                }

                temp.ControlledBy = signal.ControlledBy;
            }
        }
コード例 #2
0
ファイル: ListCommand.cs プロジェクト: Nauja/SoGModLoader
        private static void Print <T>(IMonitor monitor, ICollection <T> values, string singular, string plural, Func <T, string> getId, Func <T, string> getName, Func <T, string, string> getAttr, string[] what)
        {
            int    total   = values.Count;
            string message = $"{total} {(total == 1 ? singular : plural)}";

            CAS.AddChatMessage(message);
            monitor.Log($"{message}{(total == 0 ? "." : ":")}", LogLevel.Info);
            if (total != 0)
            {
                // Display column names
                string columns = String.Join(" ", what.Select(_ => _.ToUpper()));
                monitor.Log($"- ID: NAME {columns}", LogLevel.Info);
                // Display entries
                foreach (var value in values)
                {
                    string attributes = String.Join(" ", what.Select(_ => getAttr(value, _.ToLower())).Where(_ => _.Length != 0));
                    monitor.Log($"- {getId(value)}: {getName(value)} {attributes}", LogLevel.Info);
                }
            }
        }
コード例 #3
0
ファイル: Callbacks.cs プロジェクト: Boboo99/SoG-Modding
        private static bool OnChatParseCommandPrefix(string sMessage, int iConnection)
        {
            // Maybe a transpiler could do the job better, but I'm not familliar enough with the technique
            // Consider this a TODO
            try
            {
                // Original code
                int  iIndex        = sMessage.IndexOf(' ');
                bool bNoSecondPart = iIndex == -1;
                if (iIndex == -1)
                {
                    iIndex = sMessage.Length;
                }
                string sFirst = sMessage.Substring(0, iIndex);
                sMessage = sMessage.Substring(sMessage.IndexOf(' ') + 1);
                if (bNoSecondPart)
                {
                    sMessage = "";
                }
                sFirst.ToLowerInvariant();
                // End

                bool vanillaExecution = true;
                foreach (var onChatParseCommandCallback in _onChatParseCommandCallbacks)
                {
                    // If a mod callback returns false, the original function will not run
                    // This means that vanilla commands won't run in tandem with mod commands for "false" return
                    // Multiple mod commands with the same name will still run though...
                    vanillaExecution &= onChatParseCommandCallback(sFirst, sMessage, iConnection);
                }
                return(vanillaExecution);
            }
            catch (Exception e)
            {
                CAS.AddChatMessage("GrindScript: " + e.Message);
            }
            return(true);
        }
コード例 #4
0
        /// <summary>
        /// Simulation of analog points changes
        /// </summary>
        private void SimulatorForAnalogPoints()
        {
            while (true)
            {
                lock (SimulatorModel.Instance.Lock2PC)
                {
                    foreach (AnalogValue value in model.AnalogPoints)
                    {
                        SynchronousMachine der = model.Ders[value.SynchronousMachine];

                        if (!SimulatorModel.Instance.CurrentWeathers.ContainsKey(der.GlobalId))
                        {
                            Console.WriteLine(DateTime.Now + ": Weather forecast is not available for GlobalId: " + der.GlobalId);
                            continue;
                        }

                        CAS signal = SimulatorModel.Instance.ControlActiveSignals.Where(o => o.Gid.Equals(value.GlobalId)).FirstOrDefault();

                        if (signal != null)
                        {
                            if (signal.ControlledBy.Equals(CASEnum.Normal))
                            {
                                Console.WriteLine(DateTime.Now + ": Signal gid: {0}, Status: {1}", signal.Gid, signal.ControlledBy);
                                continue;
                            }
                        }

                        WeatherInfo wInfo = SimulatorModel.Instance.CurrentWeathers[der.GlobalId];

                        switch (der.FuelType)
                        {
                        case FuelType.Sun:
                        {
                            if (value.PowerType == PowerType.Reactive)
                            {
                                float currentQ = 0;
                                currentQ = RawValuesConverter.ConvertRange(currentQ, EGU_MIN, EGU_MAX, RAW_MIN, RAW_MAX);
                                WriteSingleHoldingRegister(value.Address, currentQ);
                            }
                            else
                            {
                                long sunriseTime = wInfo.Daily.Data.FirstOrDefault().SunriseTime;
                                long sunsetTime  = wInfo.Daily.Data.FirstOrDefault().SunsetTime;

                                float currentP = pCalculator.GetActivePowerForSolarGenerator((float)wInfo.Currently.Temperature, (float)wInfo.Currently.CloudCover, der.NominalP, sunriseTime, sunsetTime);

                                currentP = RawValuesConverter.ConvertRange(currentP, EGU_MIN, EGU_MAX, RAW_MIN, RAW_MAX);
                                WriteSingleHoldingRegister(value.Address, currentP);
                            }
                        }

                        break;

                        case FuelType.Wind:
                        {
                            float currentP = pCalculator.GetActivePowerForWindGenerator(der.NominalP, (float)(wInfo.Currently.WindSpeed));

                            if (value.PowerType == PowerType.Reactive)
                            {
                                // 5% of active power
                                float currentQ = currentP * 0.05f;

                                currentQ = RawValuesConverter.ConvertRange(currentQ, EGU_MIN, EGU_MAX, RAW_MIN, RAW_MAX);
                                WriteSingleHoldingRegister(value.Address, currentQ);
                            }
                            else
                            {
                                currentP = RawValuesConverter.ConvertRange(currentP, EGU_MIN, EGU_MAX, RAW_MIN, RAW_MAX);
                                WriteSingleHoldingRegister(value.Address, currentP);
                            }
                        }

                        break;
                        }
                    }
                }

                Thread.Sleep(5000);
            }
        }
コード例 #5
0
        public EDI835SchemaModel ParseEDI835(string fileText)
        {
            bool   payerSeg     = false;
            bool   payeeSeg     = false;
            string claimSegment = string.Empty;
            string segmentValue = string.Empty;

            string[] ediTextArray         = fileText.Split("~");
            CLP      clp                  = null;
            SVC      svc                  = null;
            bool     findNextCLP          = false;
            bool     isServiceLineVisited = false;

            foreach (string stringSegment in ediTextArray)
            {
                string[] segmentArray = stringSegment.Split("*");
                if (segmentArray != null)
                {
                    IEnumerable <string> values = Enum.GetValues(typeof(EDI835Segments))
                                                  .OfType <EDI835Segments>()
                                                  .Select(s => Convert.ToString(s));

                    if (values.Contains(segmentArray[0].TrimStart()))
                    {
                        if (segmentArray[0].TrimStart() != "CLP" && findNextCLP == true)
                        {
                            continue;
                        }
                        //else continue;
                        segmentValue = segmentArray[0].TrimStart();
                        if (claimSegment == "CLP")
                        {
                            segmentValue = "CLP";
                        }
                        switch (segmentValue)
                        {
                        case "ISA":
                        {
                            ISA ISA = GetSegmentInfo <ISA>(new ISA(), segmentArray);
                            ediSchemaModel.ISA = ISA;
                            break;
                        }

                        case "GS":
                        {
                            GS GS = GetSegmentInfo <GS>(new GS(), segmentArray);
                            ediSchemaModel.GS = GS;
                            break;
                        }

                        case "ST":
                        {
                            ST ST = GetSegmentInfo <ST>(new ST(), segmentArray);
                            ediSchemaModel.ST = ST;
                            break;
                        }

                        case "BPR":
                        {
                            BPR BPR = GetSegmentInfo <BPR>(new BPR(), segmentArray);
                            ediSchemaModel.BPR = BPR;
                            break;
                        }

                        case "TRN":
                        {
                            TRN TRN = GetSegmentInfo <TRN>(new TRN(), segmentArray);
                            ediSchemaModel.TRN = TRN;
                            break;
                        }

                        case "DTM":
                        {
                            DTM DTM = GetSegmentInfo <DTM>(new DTM(), segmentArray);
                            ediSchemaModel.DTM = DTM;
                            break;
                        }

                        case "N1":
                        {
                            if (segmentArray[1] == "PR")
                            {
                                N1 N1 = GetSegmentInfo <N1>(new N1(), segmentArray);
                                ediSchemaModel.PayerInfo = N1;
                                payerSeg = true;
                            }
                            else if (segmentArray[1] == "PE")
                            {
                                N1 N1 = GetSegmentInfo <N1>(new N1(), segmentArray);
                                ediSchemaModel.PayeeInfo = N1;
                                payeeSeg = true;
                            }
                            break;
                        }

                        case "N3":
                        {
                            if (payerSeg)
                            {
                                N3 N3 = GetSegmentInfo <N3>(new N3(), segmentArray);
                                ediSchemaModel.PayerAddress = N3;
                            }
                            else if (payeeSeg)
                            {
                                N3 N3 = GetSegmentInfo <N3>(new N3(), segmentArray);
                                ediSchemaModel.PayeeAddress = N3;
                            }

                            break;
                        }

                        case "N4":
                        {
                            if (payerSeg)
                            {
                                N4 N4 = GetSegmentInfo <N4>(new N4(), segmentArray);
                                ediSchemaModel.PayerCityStateZip = N4;
                                payerSeg = false;
                            }
                            else if (payeeSeg)
                            {
                                N4 N4 = GetSegmentInfo <N4>(new N4(), segmentArray);
                                ediSchemaModel.PayeeCityStateZip = N4;
                                payeeSeg = false;
                            }
                            break;
                        }

                        case "CLP":
                        {
                            claimSegment = "CLP";
                            switch (segmentArray[0].TrimStart())
                            {
                            case "CLP":
                            {
                                findNextCLP = false;
                                if (clp != null)
                                {
                                    ediSchemaModel.CLPList.Add(clp);
                                    isServiceLineVisited = false;
                                    clp = null;
                                }
                                clp = GetSegmentInfo <CLP>(new CLP(), segmentArray);
                                break;
                            }

                            case "SVC":
                            {
                                //if (svc != null)
                                //{
                                //    if (clp.SVCList == null) clp.SVCList = new List<SVC>();
                                //    clp.SVCList.Add(svc);
                                //    svc = null;
                                //}
                                svc = GetSegmentInfo <SVC>(new SVC(), segmentArray);
                                if (clp != null && clp.SVCList == null)
                                {
                                    clp.SVCList = new List <SVC>();
                                }

                                clp.SVCList.Add(svc);
                                isServiceLineVisited = true;
                                break;
                            }

                            case "CAS":
                            {
                                if (isServiceLineVisited)
                                {
                                    CAS CAS = GetSegmentInfo <CAS>(new CAS(), segmentArray);
                                    if (svc.SVCAdjList == null)
                                    {
                                        svc.SVCAdjList = new List <CAS>();
                                    }
                                    svc.SVCAdjList.Add(CAS);
                                    CAS = null;
                                }
                                break;
                            }

                            case "REF":
                            {
                                if (segmentArray[1].Trim() == "6R" && svc != null && svc.REF == null)
                                {
                                    svc.REF = new REF();
                                    svc.REF = GetSegmentInfo <REF>(new REF(), segmentArray);
                                }
                                break;
                            }

                            case "GE":
                            {
                                if (clp != null)
                                {
                                    ediSchemaModel.CLPList.Add(clp);
                                    isServiceLineVisited = false;
                                    clp         = null;
                                    findNextCLP = true;
                                }
                                break;
                            }

                            default:
                            {
                                break;
                            }
                            }
                            break;
                        }
                        }
                    }
                }
            }
            return(ediSchemaModel);
        }
コード例 #6
0
 public void SetItem(T item)
 {
     CAS.Set(ref _item, item);
 }
コード例 #7
0
 public bool CasItem(T comparand, T item)
 {
     return(CAS.TryCompareSet(ref _item, item, comparand));
 }
コード例 #8
0
 public bool CasNext(Node <T> comparand, Node <T> node)
 {
     return(CAS.TryCompareSet(ref _next, node, comparand));
 }
コード例 #9
0
 public void SetNext(Node <T> node)
 {
     CAS.Set(ref _next, node);
 }
コード例 #10
0
 private void CasTail(Node <T> comparand, Node <T> node)
 {
     CAS.TryCompareSet(ref _tail, node, comparand);
 }
コード例 #11
0
 private bool CasHead(Node <T> comparand, Node <T> node)
 {
     return(CAS.TryCompareSet(ref _head, node, comparand));
 }