private void Update(long ticks, int interval) { lock (this) { // no update for inactive groups. if (!m_state.Active || !m_enabled /*|| m_dataChanged == null*/) { return; } //MZ: m_dataChanged == null means that we are updating only subscription that has OnDataChange handler, //but what if we reading synchronously and there is no OnDataChange handler // reset the tick offset after subscription is activated. this ensures that the next // cycle of the update thread will send an update instead of waiting until the // update period has expired. bool callbackRequired = true; //zgodnie z kodem dostarczonym z serwerem i NETApi2 if (m_tickOffset < 0) //zgodnie z kodem dostarczonym z serwerem i NETApi2 { callbackRequired = m_tickOffset == -1; //zgodnie z kodem dostarczonym z serwerem i NETApi2 m_tickOffset = ticks; } // do the next sample for each item. int changedItems = 0; foreach (SubscriptionItem item in m_items.Values) { changedItems += item.Update(ticks - m_tickOffset, interval, m_state.Locale, m_state.UpdateRate, m_state.Deadband); } if (m_dataChanged != null)//we are sending update only if we have handler { // create the values to return. if (callbackRequired && changedItems > 0)//zgodnie z kodem dostarczonym z serwerem i NETApi2 { ArrayList items = new ArrayList(changedItems); foreach (SubscriptionItem item in m_items.Values) { item.ReadSamples(items); } m_lastUpdate = DateTimeProvider.GetCurrentTime();//zgodnie z kodem dostarczonym z serwerem i NETApi2 m_updateQueue.Enqueue(items.ToArray(typeof(ItemValueResult))); ThreadPool.QueueUserWorkItem(new WaitCallback(OnUpdate)); } else if (m_state.KeepAlive > 0) { long delta = DateTimeProvider.GetCurrentTime().Ticks - m_lastUpdate.Ticks;//zgodnie z kodem dostarczonym z serwerem i NETApi2 if (delta > m_state.KeepAlive * TimeSpan.TicksPerMillisecond) { m_lastUpdate = DateTimeProvider.GetCurrentTime();//zgodnie z kodem dostarczonym z serwerem i NETApi2 m_updateQueue.Enqueue(new ItemValueResult[0]); ThreadPool.QueueUserWorkItem(new WaitCallback(OnUpdate)); } } } } }
/// <summary> /// Initializes the cache when the first server is created. /// </summary> public void Initialize() { lock (this) { if (m_disposed) { throw new ObjectDisposedException("Opc.Da.Cache"); } // create the resource manager. m_resourceManager = new ResourceManager("OpcDa.Resources.Strings", Assembly.GetExecutingAssembly()); // initialize status. m_status = new ServerStatus(); m_status.VendorInfo = ((AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyDescriptionAttribute))).Description; m_status.ProductVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); m_status.ServerState = serverState.running; m_status.StatusInfo = serverState.running.ToString(); m_status.StartTime = DateTimeProvider.GetCurrentTime(); m_status.LastUpdateTime = DateTime.MinValue; m_status.CurrentTime = DateTimeProvider.GetCurrentTime(); CommServerComponent _protocolHub = new CommServerComponent(); m_ServerShutdown += c => ToBeDisposedAfterShutdown.GetServerShutdownEventHandler(_protocolHub); _protocolHub.Initialize(CAS.Lib.RTLib.Management.AppConfigManagement.filename); Device _Device = new Device(); m_ServerShutdown += c => ToBeDisposedAfterShutdown.GetServerShutdownEventHandler(_Device); BuildAddressSpace(_Device, ((IDeviceIndexed)_Device).GetIndexedAddressSpace); } }
public void CorrectCurrentTimeReturned() { // Arrange var dateTimeProvider = new DateTimeProvider(); // Act var now = dateTimeProvider.GetCurrentTime(); // Assert Assert.That(now, Is.EqualTo(DateTime.Now).Within(TimeSpan.FromMilliseconds(5))); }
//====================================================================== // GetStatus /// <summary> /// Returns the current server status. /// </summary> /// <returns>The current server status.</returns> public ServerStatus GetStatus() { lock (this) { Opc.Da.ServerStatus status = m_cache.GetStatus(); status.StatusInfo = m_cache.GetString(status.StatusInfo, m_culture.Name); status.LastUpdateTime = DateTimeProvider.GetCurrentTime(); status.CurrentTime = DateTimeProvider.GetCurrentTime(); return(status); } }
/// <summary> /// Reads the value from the cache and converts it to the rqeuested type. /// </summary> internal ItemValueResult Read(string locale, System.Type reqType, int maxAge, bool supportsCOM) { // read value from device. DateTime target = DateTimeProvider.GetCurrentTime().AddMilliseconds((maxAge < 0) ? 0 : -maxAge); ItemValueResult result = m_settings.ReadNewValue(maxAge, target); if (result.ResultID.Succeeded()) { try { object currentvalue = result.Value; if (m_settings.EuType != euType.enumerated || reqType != typeof(string)) { result.Value = ChangeType(currentvalue, reqType, locale, supportsCOM); } else { result.Value = m_settings.EuInfo[System.Convert.ToInt32(currentvalue)]; } } catch (OverflowException e) { result.Quality = Quality.Bad; result.ResultID = ResultID.Da.E_RANGE; result.DiagnosticInfo = e.Message; } catch (InvalidCastException e) { result.Quality = Quality.Bad; result.ResultID = ResultID.Da.E_RANGE; result.DiagnosticInfo = e.Message; } catch (ResultIDException e) { result.Quality = Quality.Bad; result.ResultID = e.Result; result.DiagnosticInfo = e.Message; } catch (Exception e) { result.Quality = Quality.Bad; result.ResultID = ResultID.Da.E_BADTYPE; result.DiagnosticInfo = e.Message; } } return(result); }
internal ItemValueResult ReadNewValue(int maxAge, DateTime target) { lock (this) { if (maxAge == 0 || m_value == null || target > m_value.Timestamp) { m_value = m_device.Read(m_ItemIndex, Property.VALUE); m_value.Timestamp = DateTimeProvider.GetCurrentTime(); } ItemValueResult result = new ItemValueResult((ItemIdentifier)m_value); result.Value = m_value.Value; result.ResultID = m_value.ResultID; result.DiagnosticInfo = m_value.DiagnosticInfo; result.Quality = m_value.Quality; result.QualitySpecified = true; result.Timestamp = m_value.Timestamp; result.TimestampSpecified = true; return(result); } }
/// <summary> /// Copies the current status into object passed in. /// </summary> Opc.Da.ServerStatus ICacheServer.GetStatus() { lock (this) { if (m_disposed) { throw new ObjectDisposedException("Opc.Da.Cache"); } Opc.Da.ServerStatus status = new Opc.Da.ServerStatus(); status.VendorInfo = m_status.VendorInfo; status.ProductVersion = m_status.ProductVersion; status.ServerState = m_status.ServerState; status.StatusInfo = m_status.StatusInfo; status.StartTime = m_status.StartTime; status.LastUpdateTime = m_status.LastUpdateTime; status.CurrentTime = DateTimeProvider.GetCurrentTime(); return(status); } }
/// <summary> /// header for the report /// </summary> /// <returns></returns> protected virtual string getHeader() { System.Reflection.Assembly thisApp = Assembly.GetExecutingAssembly(); string[] inforesources = thisApp.GetManifestResourceNames(); Stream file = null; foreach (string resourcename in inforesources) { if (resourcename.LastIndexOf("cas_logo.gif") > 0) { file = thisApp.GetManifestResourceStream(resourcename); } } if (file != null) { Image img = Image.FromStream(file); img.Save(Path.GetTempPath() + "\\cas_logo.gif"); } //TODO: dopisac kopiowanie naszej ikony // //bierzemy obrazek z resourcow // System.Resources.ResourceManager rm = new System.Resources.ResourceManager("items", System.Reflection.Assembly.GetExecutingAssembly()); // Object o=rm.GetObject ("cas_logo.gif"); // string destgif = System.IO.Path.GetTempFileName()+".gif"; // //BinaryWriter w = new BinaryWriter(fs); // // using (BinaryWriter sw = new BinaryWriter(File.Create(DestFilename))) // { // sw.Write(o); // } // //System.Drawing.Image.Bitmap image = (Bitmap)rm.GetObject ("cas_logo.gif"); //wpisujemy nag³ówek return(@" <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'> <HTML> <HEAD> <title>" + reporttitle + " DateTime=" + m_DateTimeProvider.GetCurrentTime().ToString().Replace(":", "") + @"</title> <meta http-equiv=Content-Type content='text/html; charset=windows-1250'> <META NAME='Author' CONTENT='Maciej Zbrzezny'> <META NAME='Keywords' CONTENT='report'> <META NAME='Description' CONTENT='report'> <style> body{background:white;} h1{text-decoration: none; font-family: times new roman; font-size:40px; color: #000000; font-weight: bold;} h2{text-decoration: none; font-style: italic; font-family: times new roman; font-size:22px; color: #000000; font-weight: bold;} table.tt{padding-right: 0.5cm; padding-left: 0.5cm; border-style: inset; border-color: none; background-color: none;} table.t1{border-color: none; background-color: none;} table.t2{border-style: inset; border-color: none; background-color: none;} td.kk{padding-left: 1cm; font-family: times new roman, times; font-size:17px;} td.k1{background-color:none ; text-decoration: none; font-family: times new roman, times; font-size:16px; color: #000000; font-weight: bold;} td.k2{background-color:none ; text-decoration: none; font-family: times new roman, times; font-size:14px; color: #000000; font-weight: none;} td.k3{background-color:#eeeee0 ; text-decoration: none; font-family: times new roman, times; font-size:12px; color: #000000; font-weight: bold;} td.k4{background-color:none ; text-decoration: none; font-family: times new roman, times; font-size:12px; color: #000000; font-weight: none;} td.k41{background-color:#eeeeeb ; text-decoration: none; font-family: times new roman, times; font-size:12px; color: #000000; font-weight: none;} td.k5{background-color:#eeeee0 ; text-decoration: none; font-family: times new roman, times; font-size:16px; color: #000000; font-weight: bold; </style> </HEAD> <BODY > <table align='center' width='782' cellspacing='0' cellpadding='0' border='0' class='tt'> <tr><td bgcolor='#021376' width='782' height='1'></td></tr> "); }
/// <summary> /// Gets the string that represents the report. /// </summary> /// <returns>HTML report</returns> public override string GetReportString() { DateTimeProvider _DateTimeProvider = new DateTimeProvider(true); StringBuilder sb = new StringBuilder(); //wpisujemy nag³ówek sb.Append(this.getHeader()); //najpierw robimy nag³ówek sb.Append(@"<tr><td width='1200'><table border='0' align='center'><tr><td><h1>CAS - CommServer</h1></td></tr></table></td><tr>"); sb.Append(@"<tr><td bgcolor='#021376' width='1200' height='1'></td></tr>"); sb.Append(@"<tr><td width='1200'>"); try { // //Miejsce na wlasciwe dane sb.Append(@"<table border='0' align='center' width='1200' class='t1'>"); sb.Append(@"<tr><td class='k1'>Report time </td><td class='k2'>" + _DateTimeProvider.GetCurrentTime().ToString() + "</td></tr>"); sb.Append(@"<tr><td class='k1'>Run Time [s] </td><td class='k2'>" + CommServerComponent.RunTime.ToString() + "</td></tr>"); sb.Append(@"<tr><td class='k1'>Configuration file </td><td class='k2'>" + UAOOI.ProcessObserver.Configuration.Settings.AppConfigManagement.filename + "</td></tr>"); sb.Append(@"<tr><td class='k1'>Program Name </td><td class='k2'>" + System.Reflection.Assembly.GetExecutingAssembly().GetName().FullName + "</td></tr>"); sb.Append(@"</table>"); } catch (Exception ex) { SignalError(sb, ex); } sb.Append(@"<Table border='0' width='400'> <TBody> <TR> <TD class='kk'><t>.......................................................................................</TD> </TR></TBODY></Table> "); // // bool first = true; //stations: sb.Append(@"<h2>Stations</h2>"); sb.Append(@"<table border='1' class='t2'>"); try { foreach (IHtmlOutput obj in Statistics.stationList) { if (first) { sb.Append(obj.GetHtmlTableRowDescription()); first = false; } sb.Append(obj.ToHtmlTableRow()); } } catch (Exception ex) { SignalError(sb, ex); } sb.Append(@"</table>"); //segments: sb.Append(@"<h2>Segments</h2><table border='1'>"); first = true; try { if (Statistics.segmentList.Count > 0) { foreach (IHtmlOutput obj in Statistics.segmentList) { if (first) { sb.Append(obj.GetHtmlTableRowDescription()); first = false; } sb.Append(obj.ToHtmlTableRow()); } } else { sb.Append("No segments are defined"); } } catch (Exception ex) { SignalError(sb, ex); } sb.Append(@"</table>"); sb.Append(@"<h4> * Values might be equal 0 when number of samples is less than 10.</h4>"); sb.Append(@"<h4>** Values might be equal 0 when number of samples is less than 20.</h4>"); //interfaces: first = true; sb.Append(@"<h2>Interfaces</h2><table border='1'>"); try { if (Statistics.interfaceList.Count > 0) { foreach (IHtmlOutput obj in Statistics.interfaceList) { if (first) { sb.Append(obj.GetHtmlTableRowDescription()); first = false; } sb.Append(obj.ToHtmlTableRow()); } } else { sb.Append("No interfaces are defined"); } } catch (Exception ex) { SignalError(sb, ex); } sb.Append(@"</table>"); //Protocols: first = true; sb.Append(@"<h2>Protocols</h2><table border='1'>"); try { foreach (ProtocolDsc curr in Protocol.GetProtDescriptions) { IHtmlOutput obj = new Diagnostic.CommseverProtocol(curr); if (first) { sb.Append(obj.GetHtmlTableRowDescription()); first = false; } sb.Append(obj.ToHtmlTableRow()); } } catch (Exception ex) { SignalError(sb, ex); } sb.Append(@"</table>"); //footer: sb.Append(this.getFooter()); return(sb.ToString()); }