示例#1
0
        /// <summary>
        /// Starts the server.
        /// </summary>
        public void Start()
        {
            if (channel != null)// channel is null when there was exception(catched) in the constructor
            {
                //rejestracja kana³u
                ChannelServices.RegisterChannel(channel, false);
                //rejestracja OPCRealtimeDataAccess
                WellKnownServiceTypeEntry remObj = new WellKnownServiceTypeEntry
                                                   (
                    typeof(CAS.DataPorter.Lib.BaseStation.RemoteAccess.OPCDataAccess),
                    "OPCDataAccess",
                    WellKnownObjectMode.Singleton
                                                   );
                RemotingConfiguration.RegisterWellKnownServiceType(remObj);
#if !COMMSERVER
                //rejestracja OPCBufferedDataAccess
                WellKnownServiceTypeEntry remObj2 = new WellKnownServiceTypeEntry
                                                    (
                    typeof(CAS.DataPorter.Lib.BaseStation.RemoteAccess.OPCAdvancedDataAccess),
                    "OPCAdvancedDataAccess",
                    WellKnownObjectMode.Singleton
                                                    );
                RemotingConfiguration.RegisterWellKnownServiceType(remObj2);
#endif
                EventLogMonitor.WriteToEventLogInfo("TcpServerChannel" + "..started", (int)Error.DataPorter_Servers);
            }
        }
示例#2
0
        /// <summary>
        /// This function gets message from the remote unit.
        /// </summary>
        /// <param name="Rxmsg">Received message</param>
        /// <param name="Txmsg">Transmited message, information about this frmae could be necessary to properly init received frame.
        /// </param>
        /// <returns>
        ///   ALRes_Success: Operation accomplished successfully
        ///   ALRes_DatTransferErrr: Data transfer is imposible because of a communication error – loss of
        ///      communication with a station
        ///   ALRes_DisInd: Disconnect indication – connection has been shut down remotely or lost because of
        ///      communication error. Data is unavailable
        /// </returns>
        protected override AL_ReadData_Result GetMessage(out Message Rxmsg, Message Txmsg)
        {
            Rxmsg = m_Pool.GetEmptyISesDBuffer();
            Rxmsg.ResetContent();
            Rxmsg.userDataLength = Rxmsg.userBuffLength;
            ushort received  = 0;
            bool   receiving = true;
            byte   lastChar;

            while (receiving)
            {
                switch (GetICommunicationLayer.GetChar(out lastChar, 0))
                {
                case TGetCharRes.Success:
                    if (!Rxmsg.WriteByte(lastChar))
                    {
                        EventLogMonitor.WriteToEventLogError("Response frame is too long. The data cannot be longer than " + Rxmsg.userBuffLength + " characters", 92);
                        return(AL_ReadData_Result.ALRes_DatTransferErrr);
                    }
                    received++;
                    break;

                default:
                    receiving = false;
                    break;
                }
            }
            if (Rxmsg.offset == 0)
            {
                return(AL_ReadData_Result.ALRes_DatTransferErrr);
            }
            Rxmsg.userDataLength = received;
            return(AL_ReadData_Result.ALRes_Success);
        } //GetMessage
示例#3
0
        /// <summary>
        /// Read Data
        /// </summary>
        /// <param name="block">Block description to be read</param>
        /// <param name="station">Address of the remote station connected to the common field bus. –1 if not applicable.
        /// </param>
        /// <param name="data">The frame with the requested data.</param>
        /// <param name="retries">Number of retries to get data.</param>
        /// <returns>
        ///   ALRes_Success: Operation accomplished successfully
        ///   ALRes_DatTransferErrr: Data transfer is imposible because of a communication error – loss of
        ///      communication with a station
        ///   ALRes_DisInd: Disconnect indication – connection has been shut down remotely or lost because of
        ///      communication error. Data is unavailable
        /// </returns>
        AL_ReadData_Result IApplicationLayerMaster.ReadData
            (IBlockDescription block, int station, out IReadValue data, byte retries)
        {
            data = null;
            if (!m_protocol.GetICommunicationLayer.Connected)
            {
                return(AL_ReadData_Result.ALRes_DisInd);
            }
            T_ALMessage request = m_Pool.GetEmptyISesDBuffer();
            T_ALMessage response;

            request.PrepareRequest(station, block);
            AL_ReadData_Result res = TxGetResponse(request, out response, retries);

            if (res == AL_ReadData_Result.ALRes_Success)
            {
                response.SetBlockDescription(station, block);
                data = (IReadValue)response;
            }
            else
            if (response != null && !((IEnvelope)response).InPool)
            {
                EventLogMonitor.WriteToEventLogInfo("TxGetResponse has failed and  response != null  && !( (IEnvelope)response ).InPool", 195);
                response.ReturnEmptyEnvelope();
            }
            request.ReturnEmptyEnvelope();
            m_protocol.GetIProtocolParent.RxDataBlock(res == AL_ReadData_Result.ALRes_Success);
            return(res);
        }
示例#4
0
        /// <summary>
        /// Starts the server.
        /// </summary>
        public void Start()
        {
            if (m_Channel == null) // channel is null when there was exception caught in the constructor
            {
                return;
            }
            ChannelServices.RegisterChannel(m_Channel, false);
            WellKnownServiceTypeEntry remObj = new WellKnownServiceTypeEntry
                                               (
                typeof(OPCDataAccess),
                "OPCDataAccess",
                WellKnownObjectMode.Singleton
                                               );

            RemotingConfiguration.RegisterWellKnownServiceType(remObj);
#if !COMMSERVER
            //register OPCBufferedDataAccess
            WellKnownServiceTypeEntry remObj3 = new WellKnownServiceTypeEntry
                                                (
                typeof(OPCAdvancedDataAccess),
                "OPCAdvancedDataAccess",
                WellKnownObjectMode.Singleton
                                                );
            RemotingConfiguration.RegisterWellKnownServiceType(remObj3);
#endif
            EventLogMonitor.WriteToEventLogInfo("HTTPServerChannel" + "..started", (int)Error.DataPorter_Servers);
        }
示例#5
0
        private void CountSymulator()
        {
            while (true)
            {
                try
                {
                    //sprawdzanie czy zainstnialy powody do resetu lub inicjalizacji
                    if (valuesCMD[(int)commandsIdx.ResetAll])
                    {
                        Initialisation();
                        valuesCMD[(int)commandsIdx.ResetAll] = false;
                    }
                    if (valuesCMD[(int)commandsIdx.ResetToCurrent])
                    {
                        ResetSoft();
                        valuesCMD[(int)commandsIdx.ResetToCurrent] = false;
                    }

                    values[(int)signalsIdx.Rkpz_act] = valve2(values[(int)signalsIdx.Akpz], values[(int)signalsIdx.Akpzo], values[(int)signalsIdx.Rkpc]);
                    values[(int)signalsIdx.Rkpp_act] = valve2(values[(int)signalsIdx.Akpp], values[(int)signalsIdx.Akppo], values[(int)signalsIdx.Rkpc]);
                    values[(int)signalsIdx.Rkrz_act] = valve(values[(int)signalsIdx.Akrz], values[(int)signalsIdx.Rkrc], true);
                    values[(int)signalsIdx.Rkrp_act] = valve(values[(int)signalsIdx.Akrp], values[(int)signalsIdx.Rkrc], true);
                    //          double R2u    = valve(values[(int)signalsIdx.A2u  ],values[(int)signalsIdx.Rkrc ],true);
                    double Pu2_temp = values[(int)signalsIdx.Pu2];
                    values[(int)signalsIdx.Ru2]     = R2u_calculate(values[(int)signalsIdx.P2u], ref Pu2_temp, values[(int)signalsIdx.Puwys]);
                    values[(int)signalsIdx.Pu2_act] = Pu2_temp;
                    double mian  = values[(int)signalsIdx.Rkpp_act] + values[(int)signalsIdx.Rkpz_act] + values[(int)signalsIdx.R2o] + values[(int)signalsIdx.R3o];
                    double F2o   = ((F2i.OVal * (values[(int)signalsIdx.R3o] + values[(int)signalsIdx.Rkpp_act] + values[(int)signalsIdx.Rkpz_act]) + F3i.OVal * values[(int)signalsIdx.R3o] - Fui.OVal * values[(int)signalsIdx.Rkpp_act]) / mian);
                    double F3o   = ((F3i.OVal * (values[(int)signalsIdx.R2o] + values[(int)signalsIdx.Rkpp_act] + values[(int)signalsIdx.Rkpz_act]) + F2i.OVal * values[(int)signalsIdx.R2o] + Fui.OVal * values[(int)signalsIdx.Rkpp_act]) / mian);
                    double Fkpp  = (F2i.OVal * values[(int)signalsIdx.R2o] - F3i.OVal * values[(int)signalsIdx.R3o] - Fui.OVal * (values[(int)signalsIdx.R2o] + values[(int)signalsIdx.R3o] + values[(int)signalsIdx.Rkpz_act])) / mian;
                    double F2p   = F2o + Fkpp;
                    double F3p   = F3o - Fkpp;
                    double P2p   = F2p * (values[(int)signalsIdx.Rkrp_act] + values[(int)signalsIdx.R2p]);
                    double P3p   = F3p * values[(int)signalsIdx.R3p];
                    double dPkpp = Fkpp * values[(int)signalsIdx.Rkpp_act];
                    double dP23u = -P2p + P3p - dPkpp;
                    double P3u   = Fui.OVal * values[(int)signalsIdx.R3u] + values[(int)signalsIdx.Pu3] + values[(int)signalsIdx.P3Stat];
                    CountP(values[(int)signalsIdx.Rkrz_act], values[(int)signalsIdx.Rkrp_act], F2p, F3p, dP23u, P3u);
                    double dP2 = F2o * values[(int)signalsIdx.R2o] + P2p + F2i.OVal * (values[(int)signalsIdx.Rkrz_act] + values[(int)signalsIdx.R2z]) - values[(int)signalsIdx.P2];
                    F2i.count(-dP2);
                    double dP3 = F3o * values[(int)signalsIdx.R3o] + P3p + F3i.OVal * values[(int)signalsIdx.R3z] - values[(int)signalsIdx.P3];
                    F3i.count(-dP3);
                    double dPu = dP23u + Fui.OVal * values[(int)signalsIdx.Ru2] + P3u - Pu2_temp;
                    Fui.count(-dPu);
                    System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(values[(int)signalsIdx.cycle]));
                }
                catch (Exception)
                {
                    EventLogMonitor.WriteToEventLogInfo("Ec2Ec3Symulator has done wrong operation and it was restarted",
                                                        (int)CAS.Lib.RTLib.Processes.Error.CommServer_EC2EC3_symulator);
                    Initialisation();
                }
            }
        }
示例#6
0
        void RunAndTestLog(RunTriggersParams p, Action <EventLogMonitor> action)
        {
            var handler = new RunTriggersHandler();

            using (var eventLogMonitor = new EventLogMonitor())
            {
                var bgTask = handler.ToBackgroundTask(p);
                handler.HandleTask(bgTask);

                action(eventLogMonitor);
            }
        }
        static ApplicationConfiguration()
        {
            ConfigValues = ConfigurationManager.AppSettings;
            System.Configuration.Configuration CurrConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            ConfigFilePath = Path.GetDirectoryName(CurrConfig.FilePath) + Path.DirectorySeparatorChar;
            string AppInfo = "Base directory:" + AppDomain.CurrentDomain.BaseDirectory
                             + "| AppDomain.CurrentDomain.ToString():" + AppDomain.CurrentDomain.ToString()
                             + "| AppDomain.CurrentDomain.SetupInformation.ConfigurationFile:" + AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
                             + "| ConfigFilePath" + ConfigFilePath;

            EventLogMonitor.WriteToEventLogInfo("Configuration for: " + AppInfo, (int)Error.DataPorter_ApplicationConfiguration);
        }
示例#8
0
        public void Test_TraceCacheInvalidations(bool traceCacheInvalidations)
        {
            CacheInvalidator <long, long> cacheInvalidator;
            ICache <long, long>           cache;
            IList <IEntity> testEntities;
            IEntity         testEntity1;
            IEntity         testEntity2;
            const string    cacheInvalidatorName = "Test";

            testEntity1 = Entity.Create <Folder>();
            testEntity1.Save();

            testEntity2 = Entity.Create <Folder>();
            testEntity2.Save();

            testEntities = new[] { testEntity1, testEntity2 };

            cache = new DictionaryCache <long, long>();
            cache.Add(testEntity1.Id, testEntity1.Id);

            cacheInvalidator = new TestCacheInvalidator <long, long>(cache, cacheInvalidatorName,
                                                                     () => traceCacheInvalidations);

            using (CacheContext cacheContext = new CacheContext())
            {
                cacheContext.Entities.Add(testEntities.Select(e => e.Id));

                cacheInvalidator.AddInvalidations(cacheContext, testEntity1.Id);
                using (EventLogMonitor monitor = new EventLogMonitor())
                {
                    cacheInvalidator.OnEntityChange(testEntities, InvalidationCause.Save, null);

                    if (traceCacheInvalidations)
                    {
                        // Note: even only one of the entities has changed, both will appear in the message as it is processed in bulk.
                        Assert.That(monitor.Entries,
                                    Has.Exactly(1)
                                    .Property("Level").EqualTo(EventLogLevel.Trace).And
                                    .Property("ThreadId").EqualTo(Thread.CurrentThread.ManagedThreadId).And
                                    .Property("Message").EqualTo(
                                        string.Format(
                                            "Change to 'entity {0},{1}' caused cache invalidator '{2}' to remove entries '{3}'",
                                            testEntity1.Id, testEntity2.Id, cacheInvalidatorName, testEntity1.Id)));
                    }
                }
            }
        }
 /// <summary>
 /// Gets the data type from configuration row.
 /// </summary>
 /// <param name="myDSC">Tag description as row from configuration.</param>
 /// <returns></returns>
 internal static System.Type GetDataTypeFromConfig(ComunicationNet.TagsRow myDSC)
 {
   System.Type typetobereturned = null;
   if (!myDSC.IsDataTypeConversionNull())
   {
     try
     {
       typetobereturned = System.Type.GetType(myDSC.DataTypeConversion);
     }
     catch (Exception ex)
     {
       EventLogMonitor.WriteToEventLogInfo("Unknown type:" + myDSC.DataTypeConversion + "; conversion exception info:" + ex.Message, 128);
     }
     if (typetobereturned == null)
       EventLogMonitor.WriteToEventLogInfo("Unknown type:" + myDSC.DataTypeConversion, 166);
   }
   if (typetobereturned != null)
     return typetobereturned;
   else
     return typeof(object);
 }
示例#10
0
        /// <summary>
        /// Constructor for the HTTP on Soap Formatter server
        /// </summary>
        /// <param name="portNumber">TCP port number that this server is listening on</param>
        public HTTPSoapServer(int portNumber)
        {
            try
            {
                IDictionary formatterProps = new Hashtable();
                formatterProps["includeVersions"] = false;
                formatterProps["strictBinding"]   = false;

                SoapServerFormatterSinkProvider ftProvider = new SoapServerFormatterSinkProvider(formatterProps, null);
                //SoapServerFormatterSinkProvider ftProvider = new SoapServerFormatterSinkProvider();
                ftProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

                ftProvider.Next = new System.Runtime.Remoting.MetadataServices.SdlChannelSinkProvider();
                m_Channel       = new HttpServerChannel(null, portNumber, ftProvider);
                EventLogMonitor.WriteToEventLogInfo("HTTPServerChannel, port:" + portNumber.ToString() + "..created", (int)Error.DataPorter_Servers);
            }
            catch (Exception ex)
            {
                EventLogMonitor.WriteToEventLogError("HTTPServerChannel not started, exception:" + ex.Message, (int)Error.DataPorter_Servers);
            }
        }
示例#11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProtocolHubConfiguration"/> class.
 /// </summary>
 /// <param name="ConfigurationFilename">The configuration filename.</param>
 /// <param name="open_readonly">if set to <c>true</c> file is opened as read only.</param>
 public ProtocolHubConfiguration(string ConfigurationFilename, bool open_readonly)
 {
     filename = ConfigurationFilename;
     try
     {
         configuration = new ComunicationNet();
         this.configuration.BeginInit();
         this.configuration.DataSetName = "ComunicationNet";
         this.configuration.Locale      = new System.Globalization.CultureInfo("en-US");
         this.configuration.EndInit();
         XML2DataSetIO.readXMLFile(configuration, filename, open_readonly);
     }
     catch (System.IO.IOException ioex)
     {
         EventLogMonitor.WriteToEventLogError("Problem with CommServer configuration file:" + ioex.Message, (int)Error.CommServer_Configuration);
     }
     catch (Exception ex)
     {
         string _path = Environment.CurrentDirectory;
         EventLogMonitor.WriteToEventLogError($"Problem with CommServer XML configuration file : {filename} - in directory: {_path } error: {ex.ToString()}", (int)Error.CommServer_Configuration);
     }
 }
示例#12
0
 /// <summary>
 /// reading of configuration XML file
 /// </summary>
 /// <param name="myData">target data set</param>
 /// <param name="filename">filename</param>
 public void readXMLFile(DataSet myData, string filename)
 {
     if (string.IsNullOrEmpty(filename))
     {
         EventLogMonitor.WriteToEventLogInfo(itemdscHasNotBeenSet, 39);
         return;
     }
     else if (filename == "item_dsc.xml")
     {
         FileInfo fi          = RelativeFilePathsCalculator.GetAbsolutePathToFileInApplicationDataFolder(filename);
         string   itemdscPath = fi.FullName;
         if (!new FileInfo(itemdscPath).Exists)
         {
             EventLogMonitor.WriteToEventLog(itemdscDoesNotExists, EventLogEntryType.Warning);
             return;
         }
         else
         {
             filename = itemdscPath;
         }
     }
     else if (!new FileInfo(filename).Exists)
     {
         EventLogMonitor.WriteToEventLog(string.Format(itemdscDoesNotExists, filename), EventLogEntryType.Warning);
         return;
     }
     myData.Clear();
     try
     {
         myData.ReadXml(filename, XmlReadMode.IgnoreSchema);
     }
     catch (Exception)
     {
         EventLogMonitor.WriteToEventLog(itemdscCannotBeOpened, EventLogEntryType.Warning);
     }
 }
        public void Purge(int numEventLogEntries, int maxEventLogEntries)
        {
            IList <WorkflowRunLogEntry> entries;
            EventLogSettings            eventLogSettings;
            int numberEntitiesDeleted;

            var workflowRunLogEntries = Entity.GetInstancesOfType <WorkflowRunLogEntry>( ).ToList( );

            var longs = workflowRunLogEntries.Select(e => e.Id).ToList( );

            // Remove any existing log entries
            Entity.Delete(longs);

            // Create the test entries
            entries = Enumerable.Range(0, numEventLogEntries)
                      .Select(i =>
            {
                WorkflowRunLogEntry entry;

                entry = new WorkflowRunLogEntry
                {
                    Name = string.Format("Test Entry {0}", i + 1),
                    LogEntrySeverity_Enum = LogSeverityEnum_Enumeration.InformationSeverity
                };
                entry.Save();

                // Wait to ensure creation times are different. The resolution of
                // CreatedDate is a second, unfortunately.
                Thread.Sleep(1000);

                return(entry);
            })
                      .ToList();

            // Reload the entities to get the correct created date and other fields
            entries = Entity.Get <WorkflowRunLogEntry>(entries.Select(e => e.Id), new IEntityRef[] { Resource.CreatedDate_Field })
                      .OrderBy(e => e.CreatedDate)
                      .ToList();

            // Set the maximum number of event log entries
            eventLogSettings = Entity.Get <EventLogSettings>(ActivityLogPurger.EventLogSettingsAlias, true);
            eventLogSettings.MaxEventLogEntries = maxEventLogEntries;
            eventLogSettings.Save();

            using (EventLogMonitor eventLogMonitor = new EventLogMonitor())
            {
                new ActivityLogPurger().Purge();

                numberEntitiesDeleted = Math.Max(numEventLogEntries - maxEventLogEntries, 0);
                if (numberEntitiesDeleted > 0)
                {
                    Assert.That(
                        eventLogMonitor.Entries,
                        Has.Exactly(1)
                        .Property("Message").Matches("Deleting \\d+ excess event log entry entities.")
                        .And.Property("Level").EqualTo(EventLogLevel.Information));
                }

                workflowRunLogEntries = Entity.GetInstancesOfType <WorkflowRunLogEntry>( ).ToList( );

                longs = workflowRunLogEntries.Select(e => e.Id).ToList( );

                Assert.That(longs,
                            Is.EquivalentTo(
                                entries.Reverse()
                                .Take(Math.Min(maxEventLogEntries, numEventLogEntries))
                                .Select(e => e.Id)));
            }
        }
示例#14
0
        private void CountSymulator()
        {
            while (true)
            {
                try
                {
                    #region resetowanie
                    //sprawdzanie czy zainstnialy powody do resetu lub inicjalizacji
                    if (valuesCMD[(int)commandsIdx.ResetAll])
                    {
                        Initialisation();
                        valuesCMD[(int)commandsIdx.ResetAll] = false;
                    }
                    if (valuesCMD[(int)commandsIdx.ResetToCurrent])
                    {
                        InitialisationMasterValues();
                        valuesCMD[(int)commandsIdx.ResetToCurrent] = false;
                    }
                    #endregion resetowanie
                    #region rownania symulatora
                    //  h3 = -(a3 * cycle) / (A3 * 1000) * Math.Sqrt(2 * g * h3) + ((1 - r2) * k2 * V2/100 * cycle)
                    //  / (A3 * 1000) + poprz_h3;
                    values[(int)signalsIdx.h3] = -(values[(int)signalsIdx.a3] * values[(int)signalsIdx.cycle])
                                                 / (values[(int)signalsIdx.A3] * 1000) * Math.Sqrt(2 * values[(int)signalsIdx.g] *
                                                                                                   values[(int)signalsIdx.h3]) + ((1 - values[(int)signalsIdx.r2]) *
                                                                                                                                  values[(int)signalsIdx.k2] * values[(int)signalsIdx.V2] / 100 * values[(int)signalsIdx.cycle])
                                                 / (values[(int)signalsIdx.A3] * 1000) + values[(int)signalsIdx.poprz_h3];
                    if (values[(int)signalsIdx.h3] < 0 || values[(int)signalsIdx.h3].CompareTo(double.NaN) == 0)
                    {
                        values[(int)signalsIdx.h3] = 0;
                    }
                    //h1 = -(a1 * cycle) / (A1 * 1000) * Math.Sqrt(2 * g * h1) + (a3 * cycle *Math.Sqrt(2 * g * h3))
                    //  / (A1*1000) + (r1 * k1 * V1/100 * cycle) / (A1 * 1000) + poprz_h1;
                    values[(int)signalsIdx.h1] = -(values[(int)signalsIdx.a1] * values[(int)signalsIdx.cycle])
                                                 / (values[(int)signalsIdx.A1] * 1000) * Math.Sqrt(2 * values[(int)signalsIdx.g] *
                                                                                                   values[(int)signalsIdx.h1]) + (values[(int)signalsIdx.a3] * values[(int)signalsIdx.cycle]
                                                                                                                                  * Math.Sqrt(2 * values[(int)signalsIdx.g] * values[(int)signalsIdx.h3]))
                                                 / (values[(int)signalsIdx.A1] * 1000) + (values[(int)signalsIdx.r1] * values[(int)signalsIdx.k1]
                                                                                          * values[(int)signalsIdx.V1] / 100 * values[(int)signalsIdx.cycle]) / (values[(int)signalsIdx.A1]
                                                                                                                                                                 * 1000) + values[(int)signalsIdx.poprz_h1];
                    if (values[(int)signalsIdx.h1] < 0 || values[(int)signalsIdx.h1].CompareTo(double.NaN) == 0)
                    {
                        values[(int)signalsIdx.h1] = 0;
                    }
                    // h4 = -(a4 * cycle) / (A4 * 1000) * Math.Sqrt(2 * g * h4) + ((1 - r1) * k1 * V1/100 * cycle)
                    //  / (A4 * 1000) + poprz_h4;
                    values[(int)signalsIdx.h4] = -(values[(int)signalsIdx.a4] * values[(int)signalsIdx.cycle])
                                                 / (values[(int)signalsIdx.A4] * 1000) * Math.Sqrt(2 * values[(int)signalsIdx.g]
                                                                                                   * values[(int)signalsIdx.h4]) + ((1 - values[(int)signalsIdx.r1]) * values[(int)signalsIdx.k1]
                                                                                                                                    * values[(int)signalsIdx.V1] / 100 * values[(int)signalsIdx.cycle]) / (values[(int)signalsIdx.A4]
                                                                                                                                                                                                           * 1000) + values[(int)signalsIdx.poprz_h4];
                    if (values[(int)signalsIdx.h4] < 0 || values[(int)signalsIdx.h4].CompareTo(double.NaN) == 0)
                    {
                        values[(int)signalsIdx.h4] = 0;
                    }
                    // h2 = -(a2 * cycle) / (A2 * 1000) * Math.Sqrt(2 * g * h2) + (a4 * cycle * Math.Sqrt(2 * g * h4))
                    //  / (A2 * 1000) + (r2 * k2 * V2/100 * cycle) / (A2 * 1000) + poprz_h2;
                    values[(int)signalsIdx.h2] = -(values[(int)signalsIdx.a2] * values[(int)signalsIdx.cycle])
                                                 / (values[(int)signalsIdx.A2] * 1000) * Math.Sqrt(2 * values[(int)signalsIdx.g]
                                                                                                   * values[(int)signalsIdx.h2]) + (values[(int)signalsIdx.a4] * values[(int)signalsIdx.cycle] * Math.Sqrt(2 *
                                                                                                                                                                                                           values[(int)signalsIdx.g] * values[(int)signalsIdx.h4])) / (values[(int)signalsIdx.A2] * 1000)
                                                 + (values[(int)signalsIdx.r2] * values[(int)signalsIdx.k2] * values[(int)signalsIdx.V2] / 100
                                                    * values[(int)signalsIdx.cycle]) / (values[(int)signalsIdx.A2] * 1000) +
                                                 values[(int)signalsIdx.poprz_h2];
                    if (values[(int)signalsIdx.h2] < 0 || values[(int)signalsIdx.h2].CompareTo(double.NaN) == 0)
                    {
                        values[(int)signalsIdx.h2] = 0;
                    }
                    #endregion rownania symulatora
                    #region  po oibliczeniach glownych:

                    //wyznaczenie rozniczek
                    values[(int)signalsIdx.dh1] = values[(int)signalsIdx.h1] - values[(int)signalsIdx.poprz_h1];
                    values[(int)signalsIdx.dh2] = values[(int)signalsIdx.h2] - values[(int)signalsIdx.poprz_h2];
                    values[(int)signalsIdx.dh3] = values[(int)signalsIdx.h3] - values[(int)signalsIdx.poprz_h3];
                    values[(int)signalsIdx.dh4] = values[(int)signalsIdx.h4] - values[(int)signalsIdx.poprz_h4];

                    //ustawianie alarmu
                    if (values[(int)signalsIdx.dh1] < values[(int)signalsIdx.alarm_delta] &&
                        values[(int)signalsIdx.dh2] < values[(int)signalsIdx.alarm_delta] &&
                        values[(int)signalsIdx.dh3] < values[(int)signalsIdx.alarm_delta] &&
                        values[(int)signalsIdx.dh4] < values[(int)signalsIdx.alarm_delta]
                        )
                    {
                        valuesCMD[(int)commandsIdx.Alarm_switchON]  = false;
                        valuesCMD[(int)commandsIdx.Alarm_switchOFF] = true;
                    }
                    else
                    {
                        valuesCMD[(int)commandsIdx.Alarm_switchON]  = true;
                        valuesCMD[(int)commandsIdx.Alarm_switchOFF] = false;
                    }

                    //poprz_h1=h1
                    values[(int)signalsIdx.poprz_h1] = values[(int)signalsIdx.h1];
                    //poprz_h2=h2
                    values[(int)signalsIdx.poprz_h2] = values[(int)signalsIdx.h2];
                    //poprz_h3=h3
                    values[(int)signalsIdx.poprz_h3] = values[(int)signalsIdx.h3];
                    //poprz_h4=h4
                    values[(int)signalsIdx.poprz_h4] = values[(int)signalsIdx.h4];
                    #endregion  po oibliczeniach glownych:
                    #region Generator
                    //generatory
                    values[(int)signalsIdx.y_sin] = Generator_sinus(values[(int)signalsIdx.t]);
                    values[(int)signalsIdx.y_pil] = Generator_pila(values[(int)signalsIdx.t]);
                    if (values[(int)signalsIdx.y_pil] >= (values[(int)signalsIdx.A_pil]) * values[(int)signalsIdx.b])
                    {
                        values[(int)signalsIdx.mn]++;
                    }
                    //ustalanie aktualnego czasu lub resetowanie go
                    if (valuesCMD[(int)commandsIdx.reset_t] == true)
                    {
                        values[(int)signalsIdx.t]           = 0;
                        valuesCMD[(int)commandsIdx.reset_t] = false;
                    }
                    else
                    {
                        values[(int)signalsIdx.t] = values[(int)signalsIdx.t] + values[(int)signalsIdx.cycle] / 1000;
                    }
                    #endregion Generator
                    #region toberemoved
                    ////jesli nie ma alarmu to zwiekszamy czas probkowania

                    //if ( valuesCMD[ (int)commandsIdx.Alarm_switchON ] == false )
                    //{
                    //  if ( zmiana )
                    //  {
                    //    values[ (int)signalsIdx.cycle ] = 2 * values[ (int)signalsIdx.cycle ];
                    //    zmiana = false;
                    //  }

                    //}
                    //if ( valuesCMD[ (int)commandsIdx.Alarm_switchON ] == true )
                    //{
                    //  if ( !zmiana )
                    //  {
                    //    values[ (int)signalsIdx.cycle ] = values[ (int)signalsIdx.cycle ] / 2;
                    //    zmiana = true;
                    //  }

                    //}
                    #endregion toberemoved
                    #region time
                    values[(int)signalsIdx.year]   = System.DateTime.Now.Year;
                    values[(int)signalsIdx.month]  = System.DateTime.Now.Month;
                    values[(int)signalsIdx.day]    = System.DateTime.Now.Day;
                    values[(int)signalsIdx.hour]   = System.DateTime.Now.Hour;
                    values[(int)signalsIdx.minute] = System.DateTime.Now.Minute;
                    values[(int)signalsIdx.second] = System.DateTime.Now.Second;
                    #endregion time
                    //odczekanie
                    System.Threading.Thread.Sleep((int)values[(int)signalsIdx.cycle]);
                }
                catch (Exception ex)
                {
                    EventLogMonitor.WriteToEventLogInfo("Demo simulator has done wrong operation and it was restarted; " + ex.Message,
                                                        (int)CAS.Lib.RTLib.Processes.Error.CommServer_EC2EC3_symulator);
                    Initialisation();
                }
            }
        }
示例#15
0
 /// <summary>
 /// Starts the server with specified product name and version.
 /// </summary>
 /// <param name="cProductName">Name of the c product.</param>
 /// <param name="cProductVersion">The c product version.</param>
 public static void Start(string cProductName, string cProductVersion)
 {
     if (!started)
     {
         ProductName    = cProductName;
         ProductVersion = cProductVersion;
         //inicjalizacja kanalu
         started = true;
         try
         {
             TcpServerChannel channel;
             //        SoapServerFormatterSinkProvider ftProvider = new SoapServerFormatterSinkProvider();
             //        ftProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
             //        ftProvider.Next=new  System.Runtime.Remoting.MetadataServices.SdlChannelSinkProvider();
             BinaryServerFormatterSinkProvider ftProvider = new BinaryServerFormatterSinkProvider();
             ftProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
             channel = new TcpServerChannel(null, AppConfigManagement.ConsoleRemotingHTTPport, ftProvider);
             //rejestracja kana³u
             ChannelServices.RegisterChannel(channel, false);
         }
         catch (Exception ex)
         {
             EventLogMonitor.WriteToEventLog
             (
                 String.Format(Resources.ConsoleInterface_ChannelRegistrationError, ex.Message),
                 EventLogEntryType.Error, (int)Error.CommServer_CommServerComponent, 267
             );
         }
         //rejestracja OPCRealtimeDataAccess
         WellKnownServiceTypeEntry remObj = new WellKnownServiceTypeEntry
                                            (
             typeof(BaseStation.ConsoleIterface),
             "CommServerConsole",
             WellKnownObjectMode.Singleton
                                            );
         RemotingConfiguration.RegisterWellKnownServiceType(remObj);
         //inicjalizacja listy protokolow :
         //inicjalizacja listy stacji :
         stationlist = new SortedList <long, Statistics.StationStatistics.StationStatisticsInternal>(Statistics.stationList.Count);
         foreach (Statistics.StationStatistics obj in Statistics.stationList)
         {
             stationlist.Add(((Statistics.StationStatistics)obj).myStat.myID, ((Statistics.StationStatistics)obj).myStat);
         }
         //inicjalizacja listy segmentow :
         segmentlistpairs = new SortedList <long, StatisticAndIUpdatePair <Statistics.SegmentStatistics.SegmentStatisticsInternal> >(Statistics.segmentList.Count);
         segmentlist      = new SortedList <long, Statistics.SegmentStatistics.SegmentStatisticsInternal>(Statistics.segmentList.Count);
         foreach (Statistics.SegmentStatistics obj in Statistics.segmentList)
         {
             segmentlist.Add(obj.myStat.MyID, obj.myStat);
             segmentlistpairs.Add(
                 obj.myStat.MyID, new StatisticAndIUpdatePair <Statistics.SegmentStatistics.SegmentStatisticsInternal>
                     (obj.myStat, obj));
         }
         //inicjalizacja listy interfejsow :
         interfacelistpairs = new SortedList <ulong, StatisticAndIUpdatePair <Statistics.InterfaceStatistics.InterfaceStatisticsInternal> >(Statistics.interfaceList.Count);
         interfacelist      = new SortedList <ulong, Statistics.InterfaceStatistics.InterfaceStatisticsInternal>(Statistics.interfaceList.Count);
         foreach (Statistics.InterfaceStatistics obj in Statistics.interfaceList)
         {
             interfacelist.Add(obj.myStat.myID_Internal, obj.myStat);
             interfacelistpairs.Add(
                 obj.myStat.myID_Internal, new StatisticAndIUpdatePair <Statistics.InterfaceStatistics.InterfaceStatisticsInternal>
                     (obj.myStat, obj));
         }
         listSegmentStates   = new SortedList <long, Statistics.SegmentStatistics.States>(segmentlistpairs.Count);
         listStationStates   = new SortedList <long, int>(stationlist.Count);
         listInterfaceStates = new SortedList <ulong, Statistics.InterfaceStatistics.InterfaceState>(interfacelistpairs.Count);
     }
 }
示例#16
0
        /// <summary>
        /// Initializes the Main CommServer Component using specified configuration file name.
        /// </summary>
        /// <param name="configurationFileName">The configuration file name.</param>
        public void Initialize(string configurationFileName, ISettingsBase settings)
        {
            if (m_isInitialized)
            {
                throw new ApplicationException("Only one initialization of CommServerComponent is allowed.");
            }
            m_isInitialized = true;
            int  cEventID     = (int)Error.CommServer_CommServerComponent;
            bool m_DemoVer    = true;
            int  cRTConstrain = 2;
            int  cVConstrain  = 15;

            LicenseManager.IsValid(this.GetType(), this, out License lic);
            LicenseFile m_license = lic as LicenseFile;

            if (m_license == null)
            {
                EventLogMonitor.WriteToEventLog(Resources.Tx_LicNoFileErr, EventLogEntryType.Error, cEventID, 93);
            }
            else
            {
                using (lic)
                {
                    MaintenanceControlComponent mcc = new MaintenanceControlComponent();
                    if (mcc.Warning != null)
                    {
                        Tracer.TraceWarning(143, this.GetType().Name, "The following warning(s) appeared during loading the license: " + mcc.Warning);
                    }
                    if (m_license.FailureReason != string.Empty)
                    {
                        EventLogMonitor.WriteToEventLog(m_license.FailureReason, EventLogEntryType.Error, cEventID, 95);
                    }
                    else
                    {
                        m_DemoVer = false;
                        EventLogMonitor.WriteToEventLog("Opened the license: " + m_license.ToString(), EventLogEntryType.Information, cEventID, 98);
                        cRTConstrain = m_license.RunTimeConstrain;
                        if (m_license.VolumeConstrain < 0)
                        {
                            cVConstrain = int.MaxValue;
                        }
                        else
                        {
                            cVConstrain = m_license.VolumeConstrain;
                        }
                    }
                }
            }
            if (m_DemoVer)
            {
                EventLogMonitor.WriteToEventLog(Resources.Tx_LicDemoModeInfo, EventLogEntryType.Information, cEventID, 98);
            }
            string cProductName;
            string cProductVersion;
            string cFullName;

            cProductName    = Assembly.GetExecutingAssembly().GetName().Name;
            cProductVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
            cFullName       = Assembly.GetExecutingAssembly().GetName().FullName;
            ulong vd        = m_RuntimeStopWatch.Start;
            int   cVcounter = cVConstrain;

            EventLogMonitor.WriteToEventLog("Communication server started - product name:" + cFullName, EventLogEntryType.Information, (int)Error.CommServer_CommServerComponent, 130);
            Initialization.InitializeServer(this, m_DemoVer, ref cVcounter, configurationFileName, settings);
            ConsoleIterface.Start(cProductName, cProductVersion);
            if (cVcounter <= 0)
            {
                EventLogMonitor.WriteToEventLog("Some tags have not been added due to license limitation – the volume constrain have been reached", EventLogEntryType.Warning, (int)Error.CommServer_CommServerComponent, 134);
            }
            else
            {
                string msg = string.Format("Initiated {0} tags, The license allows you to add {1} more tags. ", cVConstrain - cVcounter, cVcounter);
                EventLogMonitor.WriteToEventLog(msg, EventLogEntryType.Information, (int)Error.CommServer_CommServerComponent, 139);
            }
            if (cRTConstrain > 0)
            {
                string msg = string.Format("Runtime of the product is constrained up to {0} hours.", cRTConstrain);
                EventLogMonitor.WriteToEventLog(msg, EventLogEntryType.Warning, (int)Error.CommServer_CommServerComponent, 145);
                m_RunTimeout = new System.Timers.Timer(cRTConstrain * 60 * 60 * 1000);
                m_RunTimeout.Start();
                m_RunTimeout.Elapsed += new System.Timers.ElapsedEventHandler(m_RunTimeout_Elapsed);
            }
        }
示例#17
0
 private void m_RunTimeout_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     EventLogMonitor.WriteToEventLog("Runtime expired – server entered demo mode – no data will be read. ", EventLogEntryType.Warning, (int)Error.CommServer_CommServerComponent, 72);
     Segment.DemoMode = true;
 }