public void Initialize(Type t)
        {
            //cdt = new AConditionRuntime();
            cdt = Activator.CreateInstance(t) as AConditionRuntime;
            cdt.SetCurrentType(SelectedOutput.Split(' ')[0]);

            //<# foreach (var item in EnumNames)
            //{#>
            //	cdt.RegisterEnum(typeof(<#=ClassName#>.<#=item#>).AssemblyQualifiedName);
            //<# } #>
        }
Esempio n. 2
0
        public (bool success, string possibleError, object result) Generate(object parameter = null, Type wantedOutput = null)
        {
            SelectedOutput selectedOutput = SelectedOutput.StringWithDotSeparators;

            if (wantedOutput == null)
            {
                selectedOutput = SelectedOutput.StringWithDotSeparators;
            }
            else if (Array.IndexOf(supportedOutputTypes, wantedOutput) > -1)
            {
                if (wantedOutput == typeof(string))
                {
                    selectedOutput = SelectedOutput.StringWithDotSeparators;
                }
                else if (wantedOutput == typeof(uint))
                {
                    selectedOutput = SelectedOutput.Uint;
                }
            }
            else
            {
                return(success : false, possibleError : ErrorMessages.UnsupportedWantedOutputType(LongName, wantedOutput), result : null);
            }

            object returnValue = null;

            if (selectedOutput == SelectedOutput.StringWithDotSeparators)
            {
                returnValue = GetAsString(this.currentValue);
            }
            else if (selectedOutput == SelectedOutput.Uint)
            {
                returnValue = GetAsUint(this.currentValue);
            }

            return(success : true, possibleError : "", result : returnValue);
        }
        /// <summary>
        /// Selecteds the output changed.
        /// </summary>
        private void SelectedOutputChanged()
        {
            string[] outputParts = SelectedOutput.Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
            if (outputParts.Any(outputPart => outputPart.Trim().Length > 2) || outputParts.Any(outputPart => string.IsNullOrEmpty(outputPart) || outputPart == " "))
            {
                return;
            }

            List <byte> selectedBytes = outputParts.Select(outputPart => byte.Parse(outputPart, NumberStyles.HexNumber)).ToList();

            string byteValue   = string.Empty;
            string shortValue  = string.Empty;
            string uShortValue = string.Empty;
            string int24Value  = string.Empty;
            string uInt24Value = string.Empty;
            string intValue    = string.Empty;
            string uIntValue   = string.Empty;
            string floatValue  = string.Empty;
            string stringValue = string.Empty;

            if (selectedBytes.Count == 1)
            {
                byteValue = string.Format("Byte Value: '{0}' - ", selectedBytes[0]);
            }

            if (selectedBytes.Count == 2)
            {
                shortValue = string.Format("Short Value: '{0}' - ", (SwapBytes) ? BitConverter.ToInt16(selectedBytes.ToArray().Reverse().ToArray(), 0) : BitConverter.ToInt16(selectedBytes.ToArray(), 0));
            }

            if (selectedBytes.Count == 2)
            {
                uShortValue = string.Format("UShort Value: '{0}' - ", (SwapBytes) ? BitConverter.ToUInt16(selectedBytes.ToArray().Reverse().ToArray(), 0) : BitConverter.ToUInt16(selectedBytes.ToArray(), 0));
            }

            if (selectedBytes.Count == 3)
            {
                int24Value = string.Format("Int24 Value: '{0}' - ", (SwapBytes) ? new Int24(BitConverter.ToInt32(new byte[] { selectedBytes[2], selectedBytes[1], selectedBytes[0], 0 }, 0)).Value : new Int24(BitConverter.ToInt32(new byte[] { selectedBytes[0], selectedBytes[1], selectedBytes[2], 0 }, 0)).Value);
            }

            if (selectedBytes.Count == 3)
            {
                uInt24Value = string.Format("UInt24 Value: '{0}' - ", (SwapBytes) ? BitConverter.ToUInt32(new byte[] { selectedBytes[0], selectedBytes[1], selectedBytes[2], 0 }, 0) : BitConverter.ToUInt32(new byte[] { selectedBytes[2], selectedBytes[1], selectedBytes[0], 0 }, 0));
            }

            if (selectedBytes.Count == 4)
            {
                intValue = string.Format("Int32 Value: '{0}' - ", (SwapBytes) ? BitConverter.ToInt32(selectedBytes.ToArray().Reverse().ToArray(), 0) : BitConverter.ToInt32(selectedBytes.ToArray(), 0));
            }

            if (selectedBytes.Count == 4)
            {
                uIntValue = string.Format("UInt32 Value: '{0}' - ", (SwapBytes) ? BitConverter.ToUInt32(selectedBytes.ToArray().Reverse().ToArray(), 0) : BitConverter.ToUInt32(selectedBytes.ToArray(), 0));
            }

            if (selectedBytes.Count == 4)
            {
                floatValue = string.Format("Float Value: '{0}' - ", (SwapBytes) ? BitConverter.ToSingle(selectedBytes.ToArray().Reverse().ToArray(), 0) : BitConverter.ToSingle(selectedBytes.ToArray(), 0));
            }

            if (selectedBytes.Count > 0)
            {
                stringValue = string.Format("String Value: '{0}'", Encoding.ASCII.GetString(selectedBytes.ToArray()));
            }

            Value = string.Format("{0}{1}{2}{3}{4}{5}{6}{7}{8}", (!string.IsNullOrEmpty(byteValue)) ? byteValue : "",
                                  (!string.IsNullOrEmpty(shortValue)) ? shortValue : "",
                                  (!string.IsNullOrEmpty(uShortValue)) ? uShortValue : "",
                                  (!string.IsNullOrEmpty(int24Value)) ? int24Value : "",
                                  (!string.IsNullOrEmpty(uInt24Value)) ? uInt24Value : "",
                                  (!string.IsNullOrEmpty(intValue)) ? intValue : "",
                                  (!string.IsNullOrEmpty(uIntValue)) ? uIntValue : "",
                                  (!string.IsNullOrEmpty(floatValue)) ? floatValue : "",
                                  (!string.IsNullOrEmpty(stringValue)) ? stringValue : "");
        }