/// <summary> /// Translates the specified <paramref name="sdmxDate"/> to <see cref="SdmxQueryPeriod"/> /// </summary> /// <param name="sdmxDate">The SDMX date.</param> /// <param name="periodicity">The periodicity.</param> /// <returns> /// The <see cref="SdmxQueryPeriod" />. /// </returns> public static SdmxQueryPeriod ToQueryPeriod(this ISdmxDate sdmxDate, IPeriodicity periodicity) { if (sdmxDate == null) { return(null); } if (periodicity.TimeFormat.EnumType != sdmxDate.TimeFormatOfDate) { sdmxDate = new SdmxDateCore(sdmxDate.Date, periodicity.TimeFormat); } var time = new SdmxQueryPeriod(); string[] startTime = sdmxDate.DateInSdmxFormat.Split('-'); var startYear = Convert.ToInt32(startTime[0].Substring(0, 4), _invariantCulture); time.Year = startYear; if (startTime.Length >= 2) { int startPeriod; if (int.TryParse(startTime[1].Substring(periodicity.DigitStart), NumberStyles.None, _invariantCulture, out startPeriod)) { time.HasPeriod = true; time.Period = startPeriod; } } return(time); }
public ResourceServer(IModel model, string name, Guid guid, IPeriodicity periodicity, IResourceRequest[] requestTemplates) : base(model, name, guid, periodicity) { m_requestTemplates = requestTemplates; if (m_requestTemplates == null) { m_requestTemplates = new IResourceRequest[] {} } ; m_resourcesInUse = new Hashtable(); foreach (IResourceRequest irr in m_requestTemplates) { if (irr.DefaultResourceManager == null) { m_useBlockingCalls = true; } } if (!m_useBlockingCalls) { foreach (IResourceRequest irr in m_requestTemplates) { irr.DefaultResourceManager.ResourceReleased += new ResourceStatusEvent(DefaultResourceManager_ResourceReleased); } } else { throw new NotSupportedException("Resource Server Templates must specify (and use) default resource manager."); } }
/// <summary> /// Initializes a new instance of the <see cref="TimeTranscodingWhereBuilder"/> class. /// </summary> /// <param name="periodicity"> /// The periodicity. /// </param> /// <param name="expressionEntity"> /// The expression Entity. /// </param> /// <param name="whereFormat"> /// The where Format. /// </param> /// <param name="yearOnlyEnd"> /// The year Only End. /// </param> /// <param name="yearOnlyStart"> /// The year Only Start. /// </param> /// <param name="yearOnlyWhereFormat"> /// The year Only Where Format. /// </param> public TimeTranscodingWhereBuilder(IPeriodicity periodicity, TimeExpressionEntity expressionEntity, string whereFormat, string yearOnlyEnd, string yearOnlyStart, string yearOnlyWhereFormat) { this._periodicity = periodicity; this._expressionEntity = expressionEntity; this._whereFormat = whereFormat; this._yearOnlyEnd = yearOnlyEnd; this._yearOnlyStart = yearOnlyStart; this._yearOnlyWhereFormat = yearOnlyWhereFormat; }
public BufferedServer(IModel model, string name, Guid guid, IPeriodicity periodicity, bool usePreQueue, bool usePostQueue) : this(model, name, guid) { IServer server = new SimpleServer(model, name + ".InnerServer", Guid.NewGuid(), periodicity); IQueue preQueue = usePreQueue?new Queue(model, name + ".PreQueue", Guid.NewGuid()):null; IQueue postQueue = usePostQueue?new Queue(model, name + ".PreQueue", Guid.NewGuid()):null; Configure(server, preQueue, postQueue); }
/// <summary> /// Initializes a new instance of the <see cref="TimeDimensionMapping"/> class. /// Initialize an new instance of the TimeDimensionMapping based class /// </summary> /// <param name="mapping"> /// The time dimension mapping /// </param> /// <param name="expression"> /// The TRANSCODING.EXPRESSION contents /// </param> /// <param name="databaseType"> /// The dissemination database vendor from DB_CONNECTION.DB_TYPE at Mapping Store database. It is used to determine the substring command to use /// </param> /// <exception cref="TranscodingException"> /// Occurs when transcoding cannot performed due to incorrect mapping store data /// </exception> protected TimeDimensionMapping(MappingEntity mapping, TimeExpressionEntity expression, string databaseType) { this.Mapping = mapping; this.Component = mapping.Components[0]; this._expression = expression; this.SetDbType(databaseType); if (expression != null) { this._periodicity = PeriodicityFactory.Create(expression.Freq); } }
/// <summary> /// Creates a new instance of the <see cref="T:Ticker"/> class. /// </summary> /// <param name="model">The model in which this object runs.</param> /// <param name="periodicity">The periodicity of the ticker.</param> /// <param name="autoStart">if set to <c>true</c> the ticker will start automatically, immediately on model start, and cycle indefinitely.</param> /// <param name="nPulses">The number of pulses to be served.</param> public Ticker(IModel model, IPeriodicity periodicity, bool autoStart, long nPulses) { m_periodicity = periodicity; m_model = model; m_autoStart = autoStart; m_nPulses = nPulses; m_execEventReceiver = new ExecEventReceiver(OnExecEvent); if (autoStart) { m_model.Starting += new ModelEvent(OnModelStarting); } m_model.Stopping += new ModelEvent(OnModelStopping); }
public PulseSource(IModel model, IPeriodicity periodicity, bool initialPulse) { m_model = model; m_periodicity = periodicity; m_initialPulse = initialPulse; m_doPulse = new ExecEventReceiver(DoPulse); if (m_model.Executive.State.Equals(ExecState.Stopped) || m_model.Executive.State.Equals(ExecState.Finished)) { m_model.Executive.ExecutiveStarted += new ExecutiveEvent(StartPulsing); } else { StartPulsing(model.Executive); } }
public SimpleServer(IModel model, string name, Guid guid, IPeriodicity periodicity) { InitializeIdentity(model, name, null, guid); m_input = new SimpleInputPort(model, "Input", Guid.NewGuid(), this, new DataArrivalHandler(AcceptServiceObject)); m_output = new SimpleOutputPort(model, "Output", Guid.NewGuid(), this, null, null); // AddPort(m_input); <-- Done in port's ctor. // AddPort(m_output); <-- Done in port's ctor. m_periodicity = periodicity; m_input.DataAvailable += new PortEvent(OnServiceObjectAvailable); string sso = m_model.ModelConfig.GetSimpleParameter("SupportsServerObjects"); m_supportsServerObjects = (sso == null)?false:bool.Parse(sso); IMOHelper.RegisterWithModel(this); }
/// <summary> /// Creates a new instance of the <see cref="T:ServerPlus"/> class. /// </summary> /// <param name="model">The model in which this object runs.</param> /// <param name="name">The user-friendly name of this object. Typically not required to be unique in a pan-model context.</param> /// <param name="guid">The GUID of this object. Typically registered as this object's ModelObject key, and thus, required to be unique in a pan-model context.</param> /// <param name="periodicity">The periodicity.</param> public ServerPlus(IModel model, string name, Guid guid, IPeriodicity periodicity) { InitializeIdentity(model, name, null, guid); m_input = new SimpleInputPort(model, "Input", Guid.NewGuid(), this, new DataArrivalHandler(AcceptServiceObject)); m_output = new SimpleOutputPort(model, "Output", Guid.NewGuid(), this, null, null); m_periodicity = periodicity; string sso = m_model.ModelConfig.GetSimpleParameter("SupportsServerObjects"); m_supportsServerObjects = (sso == null)?false:bool.Parse(sso); OnCanWeProcessServiceObject = new ServiceRequestEvent(CanWeProcessServiceObjectHandler); OnPreCommencementSetup = new ServiceEvent(PreCommencementSetupHandler); OnPreCompletionTeardown = new ServiceEvent(PreCompletionTeardownHandler); IMOHelper.RegisterWithModel(this); }
/// <summary> /// Creates a new instance of the <see cref="T:Ticker"/> class. /// </summary> /// <param name="model">The model in which this object runs.</param> /// <param name="periodicity">The periodicity of the ticker.</param> /// <param name="autoStart">if set to <c>true</c> the ticker will start automatically, immediately on model start, and cycle indefinitely.</param> public Ticker(IModel model, IPeriodicity periodicity, bool autoStart) : this(model, periodicity, autoStart, long.MaxValue) { }
/// <summary> /// Writes an Observation value against the current series. /// <p/> /// The current series is determined by the latest writeKeyValue call, /// If this is a cross sectional dataset, then the observation Concept is expected to be the cross sectional concept value - for example if this is cross sectional on Country the id may be "FR" /// If this is a time series dataset then the observation Concept is expected to be the observation time - for example 2006-12-12 /// <p/> /// Validates the following: /// <ul> /// <li>The observation Time string format is one of an allowed SDMX time format</li> /// <li>The observation Time does not replicate a previously reported observation Time for the current series</li> /// </ul> /// </summary> /// <param name="observationConceptId">the concept id for the observation, for example 'COUNTRY'. If this is a Time Series, then the id will be DimensionBean.TIME_DIMENSION_FIXED_ID. </param> /// <param name="obsConceptValue">may be the observation time, or the cross section value </param> /// <param name="obsValue"> The observation value - can be numerical /// </param> /// <param name="annotations">Any additional annotations that are attached to the observation, can be null if no annotations exist </param> public void WriteObservation(string observationConceptId, string obsConceptValue, string obsValue, params IAnnotation[] annotations) { if (observationConceptId == null) { observationConceptId = DimensionObject.TimeDimensionFixedId; } if (!DimensionObject.TimeDimensionFixedId.Equals(observationConceptId)) { throw new ArgumentException("SDMX_EDI only supported time Series data, the observation conceptId is expected to be TIME_PERIOD, but got:" + observationConceptId, "observationConceptId"); } this.EndObservation(); this._startedObservation = true; if (string.IsNullOrEmpty(this._gesmesArrayCell.Frequency)) { throw new InvalidOperationException("Frequency value not set"); } if (this._periodicity == null) { TimeFormat timeFormatFromCodeId = TimeFormat.GetTimeFormatFromCodeId(this._gesmesArrayCell.Frequency); this._periodicity = PeriodicityFactory.Create(timeFormatFromCodeId.EnumType); } this._gesmesArrayCell.Observation.TimePeriod = GesmesHelper.GetPeriodValue(obsConceptValue); this._gesmesArrayCell.Observation.ObservationValue = GesmesHelper.GetObsValue( obsValue, this._defaultObs); }
/// <summary> /// Build where clauses in the form of : (year and (periodA or periodB or ... ) and write them /// to a specified StringBuilder /// </summary> /// <param name="ret">The StringBuilder to write the output</param> /// <param name="yearStr">The year string</param> /// <param name="firstPeriod">The first period</param> /// <param name="lastPeriod">The last period</param> /// <param name="periodicity">The periodicity.</param> /// <param name="timeExpressionEntity">The time expression entity.</param> /// <returns> /// The position of the last clause inside the StringBuilder /// </returns> private int BuildPeriodWhere(StringBuilder ret, string yearStr, int firstPeriod, int lastPeriod, IPeriodicity periodicity, TimeExpressionEntity timeExpressionEntity) { var queryCode = new CodeCollection(); ret.Append("( "); ret.AppendFormat(this._yearOnlyWhereFormat, yearStr); int lastClause = ret.Length; ret.Append(" and "); ret.Append("( "); for (int x = firstPeriod; x <= lastPeriod; x++) { string periodStr = x.ToString(periodicity.Format, _formatProvider); queryCode.Clear(); queryCode.Add(periodStr); string periodCode = timeExpressionEntity.TranscodingRules.GetLocalCodes(queryCode)[0][0]; ret.AppendFormat(CultureInfo.InvariantCulture, this._whereFormat, periodCode); lastClause = ret.Length; ret.Append(" or "); } ret.Length = lastClause; ret.Append(") "); ret.Append(") "); lastClause = ret.Length; ret.Append(" or "); return(lastClause); }
/// <summary> /// Conditionally end series /// </summary> private void EndSeries() { if (this._startedSeries) { this.EndObservation(); // in which case close it this._startedSeries = false; if (this._useTimeRange) { this._gesmesArrayCell.StreamToGesmesTimeRange(this._writer, this._periodicity.Gesmes); this._segmentCount++; } this._periodicity = null; this.BufferSeriesAttributes(); this._gesmesArrayCell.Clear(); this._totalSeriesWritten++; } }
/// <summary> /// Initializes a new instance of the <see cref="GesmesPeriod"/> class. /// </summary> /// <param name="periodicity">The periodicity.</param> public GesmesPeriod(IPeriodicity periodicity) { this._periodicity = periodicity; }
/// <summary> /// Build where clauses in the form of : (year and (periodA or periodB or ... ) and write them /// to a specified StringBuilder /// </summary> /// <param name="ret">The StringBuilder to write the output</param> /// <param name="yearStr">The year string</param> /// <param name="firstPeriod">The first period</param> /// <param name="lastPeriod">The last period</param> /// <param name="periodicity">The periodicity.</param> /// <param name="timeExpressionEntity">The time expression entity.</param> /// <returns> /// The position of the last clause inside the StringBuilder /// </returns> private int BuildPeriodWhere(StringBuilder ret, string yearStr, int firstPeriod, int lastPeriod, IPeriodicity periodicity, TimeExpressionEntity timeExpressionEntity) { var queryCode = new CodeCollection(); ret.Append("( "); ret.AppendFormat(this._yearOnlyWhereFormat, yearStr); int lastClause = ret.Length; ret.Append(" and "); ret.Append("( "); for (int x = firstPeriod; x <= lastPeriod; x++) { string periodStr = x.ToString(periodicity.Format, _formatProvider); queryCode.Clear(); queryCode.Add(periodStr); string periodCode = timeExpressionEntity.TranscodingRules.GetLocalCodes(queryCode)[0][0]; ret.AppendFormat(CultureInfo.InvariantCulture, this._whereFormat, periodCode); lastClause = ret.Length; ret.Append(" or "); } ret.Length = lastClause; ret.Append(") "); ret.Append(") "); lastClause = ret.Length; ret.Append(" or "); return lastClause; }
/// <summary> /// Translates the specified <paramref name="sdmxDate"/> to <see cref="SdmxQueryPeriod"/> /// </summary> /// <param name="sdmxDate">The SDMX date.</param> /// <param name="periodicity">The periodicity.</param> /// <returns> /// The <see cref="SdmxQueryPeriod" />. /// </returns> public static SdmxQueryPeriod ToQueryPeriod(this ISdmxDate sdmxDate, IPeriodicity periodicity) { if (sdmxDate == null) { return null; } if (periodicity.TimeFormat.EnumType != sdmxDate.TimeFormatOfDate) { sdmxDate = new SdmxDateCore(sdmxDate.Date, periodicity.TimeFormat); } var time = new SdmxQueryPeriod(); string[] startTime = sdmxDate.DateInSdmxFormat.Split('-'); var startYear = Convert.ToInt32(startTime[0].Substring(0, 4), _invariantCulture); time.Year = startYear; if (startTime.Length >= 2) { int startPeriod; if (int.TryParse(startTime[1].Substring(periodicity.DigitStart), NumberStyles.None, _invariantCulture, out startPeriod)) { time.HasPeriod = true; time.Period = startPeriod; } } return time; }
/// <summary> /// Writes an observation, the observation concept is assumed to be that which has been defined to be at the observation level (as declared in the start dataset method DatasetHeaderObject). /// </summary> /// <param name="obsConceptValue">May be the observation time, or the cross section value </param> /// <param name="obsValue">The observation value - can be numerical</param> /// <param name="annotations">Any additional annotations that are attached to the observation, can be null if no annotations exist</param> public void WriteObservation(string obsConceptValue, string obsValue, params IAnnotation[] annotations) { this.EndObservation(); this._startedObservation = true; if (string.IsNullOrEmpty(this._gesmesArrayCell.Frequency)) { throw new InvalidOperationException("Frequency value not set"); } if (this._periodicity == null) { TimeFormat timeFormatFromCodeId = TimeFormat.GetTimeFormatFromCodeId(this._gesmesArrayCell.Frequency); this._periodicity = PeriodicityFactory.Create(timeFormatFromCodeId.EnumType); } this._gesmesArrayCell.Observation.TimePeriod = GesmesHelper.GetPeriodValue(obsConceptValue); this._gesmesArrayCell.Observation.ObservationValue = GesmesHelper.GetObsValue( obsValue, this._defaultObs); }