Пример #1
0
        /// <summary>
        /// Writes an FSUIPC offset using data supplied in a VoiceAttack variable
        /// </summary>
        /// <param name="offsetAddress">address of offset</param>
        /// <param name="dataType">the data type to write</param>
        /// <param name="sourceVariable">VoiceAttack variable containing the data</param>
        public void writeOffset(int offsetAddress, Type dataType, string sourceVariable)
        {
            lock (m_connectionLock)
            {
                if (!m_isConnected)
                {
                    writeErrorToLog("Not connected");
                    return;
                }
            }

            int numBytes = Utilities.numBytesFromType(dataType);

            if (numBytes < 1)
            {
                writeErrorToLog(dataType.Name + " is an unsupported type");
                return;
            }

            IOffset offset = m_offsetFactory.createOffset(offsetAddress, numBytes, true);

            object value = Utilities.getVariableValueForOffset(dataType, sourceVariable, m_vaProxy);

            if (value != null)
            {
                offset.SetValue(value);

                m_fsuipc.Process();
            }
            else
            {
                writeErrorToLog("Variable '" + sourceVariable + "' does not contain a value for type " + dataType.Name);
            }
        }
Пример #2
0
 internal RawBrokerMessage(byte[] rawContent, IEnumerable <MessageHeader> headers, IEndpoint endpoint, IOffset offset)
 {
     RawContent = rawContent ?? throw new ArgumentNullException(nameof(rawContent));
     Headers    = new MessageHeaderCollection(headers);
     Endpoint   = endpoint ?? throw new ArgumentNullException(nameof(endpoint));
     Offset     = offset;
 }
Пример #3
0
 public void Store(IOffset offset)
 {
     lock (_uncommittedOffsets)
     {
         _uncommittedOffsets[offset.Key] = offset;
     }
 }
Пример #4
0
        public int CompareTo(IOffset other)
        {
            var thisValue  = long.Parse(Value);
            var otherValue = long.Parse(other.Value);

            return(thisValue.CompareTo(otherValue));
        }
Пример #5
0
        /// <summary>
        /// Reads an FSUIPC offset and updates a VoiceAttack variable
        /// </summary>
        /// <param name="offsetAddress">address of offset</param>
        /// <param name="dataType">the data type to read</param>
        /// <param name="sourceVariable">VoiceAttack variable which will be written to</param>
        public void readOffset(int offsetAddress, Type dataType, string destinationVariable)
        {
            lock (m_connectionLock)
            {
                if (!m_isConnected)
                {
                    writeErrorToLog("Not connected");
                    return;
                }
            }

            int numBytes = Utilities.numBytesFromType(dataType);

            if (numBytes < 1)
            {
                writeErrorToLog(dataType.Name + " is an unsupported type");
                return;
            }

            IOffset offset = m_offsetFactory.createOffset(offsetAddress, numBytes);

            m_fsuipc.Process();

            if (!Utilities.setVariableValueFromOffset(dataType, offset, destinationVariable, m_vaProxy))
            {
                writeErrorToLog("Failed to set '" + destinationVariable + "' with type " + dataType.Name);
            }
        }
Пример #6
0
        /// <summary>
        /// Writes an offset which contains a string from a Text source variable
        /// </summary>
        /// <param name="offsetAddress">address of offset</param>
        /// <param name="length">the length of the string data</param>
        /// <param name="sourceVariable">the Text variable source in VoiceAttack</param>
        public void writeStringOffset(int offsetAddress, int length, string sourceVariable)
        {
            lock (m_connectionLock)
            {
                if (!m_isConnected)
                {
                    writeErrorToLog("Not connected");
                    return;
                }
            }

            string value = m_vaProxy.GetText(sourceVariable);

            if (value != null)
            {
                IOffset offset = m_offsetFactory.createOffset(offsetAddress, value.Length, true);
                offset.SetValue(value);

                m_fsuipc.Process();
            }
            else
            {
                writeErrorToLog("Variable '" + sourceVariable + "' does not contain a value for Text type");
            }
        }
Пример #7
0
        protected virtual async Task HandleMessageAsync(
            byte[]?message,
            IReadOnlyCollection <MessageHeader> headers,
            string sourceEndpointName,
            IOffset offset,
            IDictionary <string, string>?additionalLogData)
        {
            var envelope = new RawInboundEnvelope(
                message,
                headers,
                Endpoint,
                sourceEndpointName,
                offset,
                additionalLogData);

            _statusInfo.RecordConsumedMessage(offset);

            var consumerPipelineContext = new ConsumerPipelineContext(
                envelope,
                this,
                GetSequenceStore(offset),
                ServiceProvider);

            await ExecutePipelineAsync(consumerPipelineContext).ConfigureAwait(false);
        }
Пример #8
0
        public static bool setVariableValueFromOffset(Type dataType, IOffset offset, string destination, dynamic vaProxy)
        {
            object value = offset.GetValue(dataType);

            if (dataType == typeof(float) || dataType == typeof(double))
            {
                vaProxy.SetDecimal(destination, value);
            }
            else if (dataType == typeof(int) || dataType == typeof(uint) ||
                     dataType == typeof(short) || dataType == typeof(ushort) ||
                     dataType == typeof(char) || dataType == typeof(byte) ||
                     dataType == typeof(long) || dataType == typeof(ulong))
            {
                vaProxy.SetInt(destination, Convert.ToInt32(value));
            }
            else if (dataType == typeof(bool))
            {
                vaProxy.SetBoolean(destination, value);
            }
            else
            {
                return(false); // Unspported data type
            }

            return(true);
        }
 public MessageReceivedEventArgs(byte[] message, IEnumerable <MessageHeader> headers, IOffset offset,
                                 IEndpoint endpoint)
 {
     Message  = message;
     Headers  = headers;
     Offset   = offset;
     Endpoint = endpoint;
 }
Пример #10
0
        public void Not_Supported()
        {
            engine.Options.OffsetStyle = OffsetStyle.NotSupported;
            IOffset offset = sql.Offset(10);

            Exception ex = Assert.Throws <ClauseNotSupportedException>(() => engine.Compile(offset));

            Assert.Equal("Offset clause is not supported in this engine.", ex.Message);
        }
        public Task Store(IOffset offset)
        {
            lock (_uncommittedOffsets)
            {
                _uncommittedOffsets[offset.Key] = offset;
            }

            return(Task.CompletedTask);
        }
Пример #12
0
        private static bool Patch(string filepath, PatchType type, IOffset offsets)
        {
            switch (type)
            {
            case PatchType.Farclip:
                return(ApplyPatch(filepath, offsets.SetFarclipPattern.Clone()));

            default:
                return(false);
            }
        }
Пример #13
0
        public void Offset_Without_Parameters()
        {
            engine.Options.OffsetAsParameters = false;

            IOffset offset = sql.Offset(10).Fetch(20);

            QueryResult result = engine.Compile(offset);

            Assert.Equal("OFFSET 10 ROWS FETCH NEXT 20 ROWS ONLY", result.Sql);
            Assert.Equal(new Dictionary <string, object>(), result.Parameters);
        }
Пример #14
0
        /// <summary>
        ///     Returns the <see cref="ISequenceStore" /> to be used to store the pending sequences.
        /// </summary>
        /// <param name="offset">
        ///     The offset may determine which store is being used. For example a dedicated sequence store is used per
        ///     each Kafka partition, since they may be processed concurrently.
        /// </param>
        /// <returns>
        ///     The <see cref="ISequenceStore" />.
        /// </returns>
        protected virtual ISequenceStore GetSequenceStore(IOffset offset)
        {
            if (SequenceStores.Count == 0)
            {
                lock (SequenceStores)
                    SequenceStores.Add(ServiceProvider.GetRequiredService <ISequenceStore>());
            }

            return(SequenceStores.FirstOrDefault() ??
                   throw new InvalidOperationException("The sequence store is not initialized."));
        }
Пример #15
0
        public void Offset_Fetch_Overload()
        {
            IOffset offset = sql.Offset(10, 20);

            QueryResult result = engine.Compile(offset);

            Assert.Equal("OFFSET @p0 ROWS FETCH NEXT @p1 ROWS ONLY", result.Sql);
            Assert.Equal(new Dictionary <string, object>()
            {
                ["@p0"] = 10, ["@p1"] = 20
            }, result.Parameters);
        }
Пример #16
0
 public int CompareTo(IOffset obj)
 {
     if (ReferenceEquals(this, obj))
     {
         return(0);
     }
     if (obj is null)
     {
         return(1);
     }
     return(obj is InMemoryOffset other?CompareTo(other) : throw new ArgumentException($"Object must be of type {nameof(InMemoryOffset)}"));
 }
Пример #17
0
        public async Task TestPush(object message, MessageHeaderCollection headers, IOffset offset = null,
                                   IMessageSerializer serializer = null)
        {
            if (serializer == null)
            {
                serializer = new JsonMessageSerializer();
            }

            var buffer = serializer.Serialize(message, headers);

            await TestPush(buffer, headers, offset);
        }
Пример #18
0
        public static void SetOffset(IOffset offset, string value, ref string lineToParse, ref int lengthToSum)
        {
            int index = lineToParse.IndexOf(value);

            if (index != VALUE_NOT_FOUND)
            {
                offset.Offset    = index + lengthToSum;
                offset.EndOffset = offset.Offset + value.Length;
                lineToParse      = lineToParse.Remove(offset.Offset - lengthToSum, value.Length);
                lengthToSum     += value.Length;
            }
        }
Пример #19
0
        public InboundMessage(byte[] rawContent, IEnumerable <MessageHeader> headers, IOffset offset, IEndpoint endpoint, bool mustUnwrap)
        {
            if (headers != null)
            {
                Headers.AddRange(headers);
            }

            Offset     = offset;
            Endpoint   = endpoint;
            RawContent = rawContent;
            MustUnwrap = mustUnwrap;
        }
Пример #20
0
        public void Limit_Without_Parameters()
        {
            engine.Options.OffsetStyle        = OffsetStyle.Limit;
            engine.Options.OffsetAsParameters = false;

            IOffset offset = sql.Offset(10).Fetch(20);

            QueryResult result = engine.Compile(offset);

            Assert.Equal("LIMIT 20 OFFSET 10", result.Sql);
            Assert.Equal(new Dictionary <string, object>(), result.Parameters);
        }
Пример #21
0
        public void Offset()
        {
            IOffset offset = sql.Offset(10);

            QueryResult result = engine.Compile(offset);

            Assert.Equal("OFFSET @p0 ROWS", result.Sql);
            Assert.Equal(new Dictionary <string, object>
            {
                ["@p0"] = 10
            }, result.Parameters);
        }
Пример #22
0
 public RawInboundEnvelope(
     Stream?rawMessage,
     IEnumerable <MessageHeader>?headers,
     IConsumerEndpoint endpoint,
     string actualEndpointName,
     IOffset offset,
     IDictionary <string, string>?additionalLogData = null)
     : base(rawMessage, headers, endpoint, additionalLogData)
 {
     ActualEndpointName = actualEndpointName;
     Offset             = offset;
 }
Пример #23
0
        private Dictionary <string, object> getMonitorContext()
        {
            Dictionary <string, object> context = new Dictionary <string, object>();

            // Get the altimeter setting (feet/meters)
            IOffset <short> altimeterSetting = m_offsetFactory.createOffset <short>(OffsetValues.AltimeterSetting);

            m_fsuipc.Process();

            context.Add("altimeterSetting", altimeterSetting.Value);

            return(context);
        }
Пример #24
0
        public void Store(IOffset offset)
        {
            lock (_lock)
            {
                var entity = DbSet.Find(offset.Key) ??
                             DbSet.Add(new StoredOffset
                {
                    Key = offset.Key
                }).Entity;

                entity.Offset = JsonConvert.SerializeObject(offset, typeof(IOffset), SerializerSettings);
            }
        }
Пример #25
0
 internal static void RemoveOffset(IOffset Offset)
 {
     lock (FSUIPCConnection.dataGroups)
     {
         if (!FSUIPCConnection.dataGroups.ContainsKey(Offset.Group))
         {
             return;
         }
         FSUIPCConnection.dataGroups[Offset.Group].Remove(Offset.ID);
         Offset.Connected = false;
         FSUIPCConnection.offsetGroupDictionary.Remove(Offset.ID);
     }
 }
Пример #26
0
        public void Offset_Limit()
        {
            engine.Options.OffsetStyle = OffsetStyle.Limit;

            IOffset offset = sql.Offset(10);

            QueryResult result = engine.Compile(offset);

            Assert.Equal("LIMIT @p0 OFFSET @p1", result.Sql);
            Assert.Equal(new Dictionary <string, object>()
            {
                ["@p0"] = long.MaxValue, ["@p1"] = 10
            }, result.Parameters);
        }
Пример #27
0
        public void Fetch_Limit()
        {
            engine.Options.OffsetStyle = OffsetStyle.Limit;

            IOffset offset = sql.Fetch(20);

            QueryResult result = engine.Compile(offset);

            Assert.Equal("LIMIT @p0", result.Sql);
            Assert.Equal(new Dictionary <string, object>
            {
                ["@p0"] = 20
            }, result.Parameters);
        }
Пример #28
0
 public RawInboundEnvelope(
     byte[]?rawMessage,
     IEnumerable <MessageHeader>?headers,
     IConsumerEndpoint endpoint,
     string actualEndpointName,
     IOffset offset,
     IDictionary <string, string>?additionalLogData = null)
     : this(
         rawMessage != null ? new MemoryStream(rawMessage) : null,
         headers,
         endpoint,
         actualEndpointName,
         offset,
         additionalLogData)
 {
 }
Пример #29
0
        /// <summary>
        /// Reads an offset which contains a string and updates a Text destination variable
        /// </summary>
        /// <param name="offsetAddress">address of offset</param>
        /// <param name="length">length the length of the string data</param>
        /// <param name="destinationVariable">the Text variable destination in VoiceAttack</param>
        public void readStringOffset(int offsetAddress, int length, string destinationVariable)
        {
            lock (m_connectionLock)
            {
                if (!m_isConnected)
                {
                    writeErrorToLog("Not connected");
                    return;
                }
            }

            IOffset offset = m_offsetFactory.createOffset(offsetAddress, length);

            m_fsuipc.Process();

            m_vaProxy.SetText(destinationVariable, offset.GetValue(typeof(string)));
        }
Пример #30
0
        private void Log(ILogger logger, LogLevel logLevel, Exception exception, string logMessage, object message,
                         IEndpoint endpoint, IOffset offset, int?failedAttempts, Guid?batchId, int?batchSize)
        {
            var properties = new List <(string, string, object)>();

            if (offset != null)
            {
                properties.Add(("offset", "offset", $"{offset.Key}@{offset.Value}"));
            }

            if (endpoint != null)
            {
                properties.Add(("endpoint", "endpointName", endpoint.Name));
            }

            if (message != null && !(message is byte[]))
            {
                properties.Add(("type", "messageType", message.GetType().Name));

                var key = _messageKeyProvider.GetKey(message, false);
                if (key != null)
                {
                    properties.Add(("id", "messageId", key));
                }
            }

            if (failedAttempts != null && failedAttempts > 0)
            {
                properties.Add(("failedAttempts", "failedAttempts", failedAttempts));
            }

            if (batchId != null)
            {
                properties.Add(("batchId", "batchId", batchId));
            }

            if (batchSize != null)
            {
                properties.Add(("batchSize", "batchSize", batchSize));
            }

            logger.Log(
                logLevel, exception,
                logMessage + " {{" + string.Join(", ", properties.Select(p => $"{p.Item1}={{{p.Item2}}}")) + "}}",
                properties.Select(p => p.Item3).ToArray());
        }