Ejemplo n.º 1
0
        public override IsoValue ParseBinary(int field,
                                             sbyte[] buf,
                                             int pos,
                                             ICustomField custom)
        {
            if (pos < 0)
            {
                throw new ParseException($"Invalid DATE_EXP field {field} position {pos}");
            }
            if (pos + 2 > buf.Length)
            {
                throw new ParseException($"Insufficient data for DATE_EXP field {field} pos {pos}");
            }

            var tens  = new int[2];
            var start = 0;

            for (var i = pos; i < pos + tens.Length; i++)
            {
                tens[start++] = ((buf[i] & 0xf0) >> 4) * 10 + (buf[i] & 0x0f);
            }

            var calendar = new DateTime(DateTime.Now.Year - DateTime.Now.Year % 100 + tens[0],
                                        tens[1],
                                        1,
                                        0,
                                        0,
                                        0);

            if (TimeZoneInfo != null)
            {
                calendar = TimeZoneInfo.ConvertTime(calendar,
                                                    TimeZoneInfo);
            }

            return(new IsoValue(IsoType,
                                calendar));
        }
Ejemplo n.º 2
0
        public override IsoValue ParseBinary(int field,
                                             sbyte[] buf,
                                             int pos,
                                             ICustomField custom)
        {
            if (pos < 0)
            {
                throw new ParseException($"Invalid bin NUMERIC field {field} pos {pos}");
            }
            if (pos + Length / 2 > buf.Length)
            {
                throw new ParseException(
                          $"Insufficient data for bin {IsoType} field {field} of length {Length}, pos {pos}");
            }

            //A long covers up to 18 digits
            if (Length < 19)
            {
                return(new IsoValue(IsoType.NUMERIC,
                                    Bcd.DecodeToLong(buf,
                                                     pos,
                                                     Length),
                                    Length));
            }
            try
            {
                return(new IsoValue(IsoType.NUMERIC,
                                    Bcd.DecodeToBigInteger(buf,
                                                           pos,
                                                           Length),
                                    Length));
            }
            catch (Exception)
            {
                throw new ParseException(
                          $"Insufficient data for bin {IsoType} field {field} of length {Length}, pos {pos}");
            }
        }
        protected void btnSave_ServerClick(object sender, System.EventArgs e)
        {
            Page.Validate();
            if (!Page.IsValid)
            {
                return;
            }


            MetaObject obj = null;

            if (ObjectId > 0)
            {
                obj = MetaDataWrapper.LoadMetaObject(ObjectId, MetaClassName, Security.CurrentUser.UserID, DateTime.UtcNow);
            }
            if (obj == null)
            {
                obj = MetaDataWrapper.NewMetaObject(ObjectId, MetaClassName);
            }

            foreach (HtmlTableRow row in tblCustomFields.Rows)
            {
                HtmlTableCell cell       = row.Cells[1];
                ICustomField  ctrl       = (ICustomField)cell.Controls[0];
                object        FieldValue = ctrl.Value;
                string        FieldName  = ctrl.FieldName;

                obj[FieldName] = FieldValue;
            }

            ObjectId = MetaDataWrapper.AcceptChanges(obj);

            Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(),
                                                    "<script language=javascript>" +
                                                    "try {var str=window.opener.location.href;" +
                                                    "window.opener.location.href=str;}" +
                                                    "catch (e){} window.close();</script>");
        }
Ejemplo n.º 4
0
        public void RegisterCustomFields(Assembly assembly)
        {
            foreach (var t in assembly.GetTypes())
            {
                if (t.IsClass && typeof(ICustomField).IsAssignableFrom(t))
                {
                    try
                    {
                        ICustomField instance = (ICustomField)Activator.CreateInstance(t);
                        if (instance == null)
                        {
                            continue;
                        }

                        RegisterCustomField(instance);
                    }
                    catch (Exception ex)
                    {
                        Rocket.Core.Logging.Logger.LogException(ex, $"Coult not register custom field '{t.FullName}'");
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public override IsoValue ParseBinary(int field,
                                             sbyte[] buf,
                                             int pos,
                                             ICustomField custom)
        {
            if (pos < 0)
            {
                throw new ParseException($"Invalid DATE14 field {field} position {pos}");
            }
            if (pos + 7 > buf.Length)
            {
                throw new ParseException($"Insufficient data for DATE14 field {field}, pos {pos}");
            }
            var tens  = new int[7];
            var start = 0;

            for (var i = pos; i < pos + tens.Length; i++)
            {
                tens[start++] = ((buf[i] & 0xf0) >> 4) * 10 + (buf[i] & 0x0f);
            }

            var calendar = new DateTime(tens[0] * 100 + tens[1],
                                        tens[2],
                                        tens[3],
                                        tens[4],
                                        tens[5],
                                        tens[6]).AddMilliseconds(0);

            if (TimeZoneInfo != null)
            {
                calendar = TimeZoneInfo.ConvertTime(calendar,
                                                    TimeZoneInfo);
            }

            return(new IsoValue(IsoType,
                                AdjustWithFutureTolerance(new DateTimeOffset(calendar)).DateTime));
        }
Ejemplo n.º 6
0
        public override IsoValue ParseBinary(int field,
                                             sbyte[] buf,
                                             int pos,
                                             ICustomField custom)
        {
            if (pos < 0)
            {
                throw new ParseException($"Invalid bin TIME field {field} pos {pos}");
            }
            if (pos + 3 > buf.Length)
            {
                throw new ParseException($"Insufficient data for bin TIME field {field}, pos {pos}");
            }
            var sbytes = buf;
            var tens   = new int[3];
            var start  = 0;

            for (var i = pos; i < pos + 3; i++)
            {
                tens[start++] = ((sbytes[i] & 0xf0) >> 4) * 10 + (sbytes[i] & 0x0f);
            }

            var calendar = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day,
                                        tens[0],
                                        tens[1],
                                        tens[2]);

            if (TimeZoneInfo != null)
            {
                calendar = TimeZoneInfo.ConvertTime(calendar,
                                                    TimeZoneInfo);
            }

            return(new IsoValue(IsoType,
                                calendar));
        }
Ejemplo n.º 7
0
        public IsoValue(IsoType t,
                        object val,
                        int len,
                        ICustomField custom = null)
        {
            Type    = t;
            Value   = val;
            Length  = len;
            Encoder = custom;
            if (Length == 0 && t.NeedsLength())
            {
                throw new ArgumentException($"Length must be greater than zero for type {t} (value '{val}')");
            }
            switch (t)
            {
            case IsoType.LLVAR:
            case IsoType.LLLVAR:
            case IsoType.LLLLVAR:
                if (len == 0)
                {
                    Length = Encoder?.EncodeField(val).Length ?? val.ToString().Length;
                }
                if (t == IsoType.LLVAR && Length > 99)
                {
                    throw new ArgumentException("LLVAR can only hold values up to 99 chars");
                }
                if (t == IsoType.LLLVAR && Length > 999)
                {
                    throw new ArgumentException("LLLVAR can only hold values up to 999 chars");
                }
                if (t == IsoType.LLLLVAR && Length > 9999)
                {
                    throw new ArgumentException("LLLLVAR can only hold values up to 9999 chars");
                }
                break;

            case IsoType.LLBIN:
            case IsoType.LLLBIN:
            case IsoType.LLLLBIN:
                if (len == 0)
                {
                    if (Encoder == null)
                    {
                        var obj = val;
                        Length = ((byte[])obj).Length;
                    }
                    else if (Encoder is ICustomBinaryField)
                    {
                        var customBinaryField = (ICustomBinaryField)custom;
                        if (customBinaryField != null)
                        {
                            Length = customBinaryField.EncodeBinaryField(Value).Length;
                        }
                    }
                    else
                    {
                        Length = Encoder.EncodeField(Value).Length;
                    }
                    Length = Encoder?.EncodeField(Value).Length ?? ((sbyte[])val).Length;
                }
                if (t == IsoType.LLBIN && Length > 99)
                {
                    throw new ArgumentException("LLBIN can only hold values up to 99 chars");
                }
                if (t == IsoType.LLLBIN && Length > 999)
                {
                    throw new ArgumentException("LLLBIN can only hold values up to 999 chars");
                }
                if (t == IsoType.LLLLBIN && Length > 9999)
                {
                    throw new ArgumentException("LLLLBIN can only hold values up to 9999 chars");
                }
                break;
            }
        }
Ejemplo n.º 8
0
        public IsoValue(IsoType t,
                        object value,
                        ICustomField custom = null)
        {
            if (t.NeedsLength())
            {
                throw new ArgumentException("Fixed-value types must use constructor that specifies length");
            }

            Encoder = custom;
            Type    = t;
            Value   = value;

            switch (Type)
            {
            case IsoType.LLVAR:
            case IsoType.LLLVAR:
            case IsoType.LLLLVAR:
                if (Encoder == null)
                {
                    Length = value.ToString().Length;
                }
                else
                {
                    var enc = Encoder.EncodeField(value) ?? (value?.ToString() ?? string.Empty);
                    Length = enc.Length;
                }
                if (t == IsoType.LLVAR && Length > 99)
                {
                    throw new ArgumentException("LLVAR can only hold values up to 99 chars");
                }
                if (t == IsoType.LLLVAR && Length > 999)
                {
                    throw new ArgumentException("LLLVAR can only hold values up to 999 chars");
                }
                if (t == IsoType.LLLLVAR && Length > 9999)
                {
                    throw new ArgumentException("LLLLVAR can only hold values up to 9999 chars");
                }
                break;

            case IsoType.LLBIN:
            case IsoType.LLLBIN:
            case IsoType.LLLLBIN:
                if (Encoder == null)
                {
                    if (value.GetType() == typeof(sbyte[]))
                    {
                        var obj = value;
                        Length = ((sbyte[])obj).Length;
                    }
                    else
                    {
                        Length = value.ToString().Length / 2 + value.ToString().Length % 2;
                    }
                }
                else if (Encoder is ICustomBinaryField)
                {
                    Length = ((ICustomBinaryField)Encoder).EncodeBinaryField(value).Length;
                }
                else
                {
                    var enc = Encoder.EncodeField(value) ?? (value?.ToString() ?? string.Empty);
                    Length = enc.Length;
                }
                if (t == IsoType.LLBIN && Length > 99)
                {
                    throw new ArgumentException("LLBIN can only hold values up to 99 chars");
                }
                if (t == IsoType.LLLBIN && Length > 999)
                {
                    throw new ArgumentException("LLLBIN can only hold values up to 999 chars");
                }
                if (t == IsoType.LLLLBIN && Length > 9999)
                {
                    throw new ArgumentException("LLLLBIN can only hold values up to 9999 chars");
                }
                break;

            default:
                Length = Type.Length();
                break;
            }
        }
Ejemplo n.º 9
0
 public bool TryRemoveCustomField(ICustomField customField)
 {
     return(CustomFields.Remove(customField));
 }
Ejemplo n.º 10
0
        public override IsoValue ParseBinary(int field,
                                             sbyte[] buf,
                                             int pos,
                                             ICustomField custom)
        {
            if (pos < 0)
            {
                throw new ParseException($"Invalid bin LLBIN field {field} position {pos}");
            }
            if (pos + 1 > buf.Length)
            {
                throw new ParseException($"Insufficient bin LLBIN header field {field}");
            }

            var sbytes = buf;

            var l = ((sbytes[pos] & 0xf0) >> 4) * 10 + (sbytes[pos] & 0x0f);

            if (l < 0)
            {
                throw new ParseException($"Invalid bin LLBIN length {l} pos {pos}");
            }
            if (l + pos + 1 > buf.Length)
            {
                throw new ParseException(
                          $"Insufficient data for bin LLBIN field {field}, pos {pos}: need {l}, only {buf.Length} available");
            }
            var v = new sbyte[l];

            Array.Copy(sbytes,
                       pos + 1,
                       v,
                       0,
                       l);
            if (custom == null)
            {
                return(new IsoValue(IsoType,
                                    v));
            }
            if (custom is ICustomBinaryField)
            {
                try
                {
                    var dec = ((ICustomBinaryField)custom).DecodeBinaryField(sbytes,
                                                                             pos + 1,
                                                                             l);
                    return(dec == null
                        ? new IsoValue(IsoType,
                                       v,
                                       v.Length)
                        : new IsoValue(IsoType,
                                       dec,
                                       l,
                                       custom));
                }
                catch (Exception)
                {
                    throw new ParseException($"Insufficient data for LLBIN field {field}, pos {pos} length {l}");
                }
            }
            {
                var dec = custom.DecodeField(HexCodec.HexEncode(v,
                                                                0,
                                                                v.Length));
                return(dec == null
                    ? new IsoValue(IsoType,
                                   v)
                    : new IsoValue(IsoType,
                                   dec,
                                   custom));
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 ///     Parses binary data from the buffer, creating and returning an IsoValue of the configured
 ///     type and length.
 /// </summary>
 /// <param name="field">he field index, useful for error reporting.</param>
 /// <param name="buf">The full ISO message buffer.</param>
 /// <param name="pos">The starting position for the field data.</param>
 /// <param name="custom">A CustomField to decode the field.</param>
 /// <returns></returns>
 public abstract IsoValue ParseBinary(int field,
                                      sbyte[] buf,
                                      int pos,
                                      ICustomField custom);
Ejemplo n.º 12
0
 public bool TryRemoveCustomField(ICustomField customField)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 13
0
        public override IsoValue ParseBinary(int field,
                                             sbyte[] buf,
                                             int pos,
                                             ICustomField custom)
        {
            if (pos < 0)
            {
                throw new ParseException($"Invalid bin LLLLBIN field {field} pos {pos}");
            }
            if (pos + 2 > buf.Length)
            {
                throw new ParseException($"Insufficient LLLLBIN header field {field}");
            }

            int l = ((buf[pos] & 0xf0) * 1000) + ((buf[pos] & 0x0f) * 100)
                    + (((buf[pos + 1] & 0xf0) >> 4) * 10) + (buf[pos + 1] & 0x0f);

            if (l < 0)
            {
                throw new ParseException($"Invalid LLLLBIN length {l} field {field} pos {pos}");
            }
            if (l + pos + 2 > buf.Length)
            {
                throw new ParseException(
                          $"Insufficient data for bin LLLLBIN field {field}, pos {pos} requires {l}, only {buf.Length - pos + 1} available");
            }

            var v = new sbyte[l];

            Array.Copy(buf,
                       pos + 2,
                       v,
                       0,
                       l);
            if (custom == null)
            {
                return(new IsoValue(IsoType,
                                    v));
            }
            var customBinaryField = custom as ICustomBinaryField;

            if (customBinaryField != null)
            {
                try
                {
                    var dec = customBinaryField.DecodeBinaryField(buf,
                                                                  pos + 2,
                                                                  l);
                    return(dec == null
                        ? new IsoValue(IsoType,
                                       v,
                                       v.Length)
                        : new IsoValue(IsoType,
                                       dec,
                                       l,
                                       custom));
                }
                catch (Exception)
                {
                    throw new ParseException($"Insufficient data for LLLLBIN field {field}, pos {pos}");
                }
            }
            {
                var dec = custom.DecodeField(HexCodec.HexEncode(v,
                                                                0,
                                                                v.Length));
                return(dec == null
                    ? new IsoValue(IsoType,
                                   v)
                    : new IsoValue(IsoType,
                                   dec,
                                   custom));
            }
        }
        private void LoadBlocksToCell(TableCell cell, ControlData[] blocks, string prefix, bool needToBind)
        {
            for (int i = 0; i < blocks.Length; i++)
            {
                if (!String.IsNullOrEmpty(blocks[i].Settings))
                {
                    XmlDocument settings = new XmlDocument();
                    settings.LoadXml(blocks[i].Settings);
                    XmlNode     nameNode   = settings.SelectSingleNode("MetaDataBlockViewControl/Name");
                    XmlNodeList mfNodeList = settings.SelectNodes("MetaDataBlockViewControl/MetaField");

                    // BlockHeader
                    BlockHeaderLightWithMenu blockHeader = (BlockHeaderLightWithMenu)LoadControl("~/Modules/BlockHeaderLightWithMenu.ascx");
                    blockHeader.ID = String.Concat(prefix, i.ToString());
                    cell.Controls.Add(blockHeader);

                    // Collapsible Table
                    Table collapsibleTable = new Table();
                    collapsibleTable.CssClass    = "ibn-stylebox-light text";
                    collapsibleTable.CellSpacing = 0;
                    collapsibleTable.CellPadding = 5;
                    collapsibleTable.Width       = Unit.Percentage(100);
                    collapsibleTable.ID          = String.Concat("tbl", prefix, i.ToString());
                    cell.Controls.Add(collapsibleTable);

                    blockHeader.CollapsibleControlId = collapsibleTable.ID;
                    blockHeader.AddText(nameNode.InnerText);

                    foreach (XmlNode mfNode in mfNodeList)
                    {
                        foreach (MetaField field in mc.UserMetaFields)
                        {
                            if (field.Name == mfNode.InnerText)
                            {
                                TableRow row = new TableRow();
                                collapsibleTable.Rows.Add(row);

                                TableCell cellTitle = new TableCell();
                                cellTitle.VerticalAlign = VerticalAlign.Middle;
                                cellTitle.CssClass      = "ibn-label";
                                cellTitle.Width         = Unit.Pixel(220);
                                cellTitle.Text          = String.Concat(field.FriendlyName, ":");
                                row.Cells.Add(cellTitle);

                                TableCell cellValue = new TableCell();
                                row.Cells.Add(cellValue);

                                object fieldValue = obj[field.Name];
                                System.Web.UI.UserControl control = null;

                                switch (field.DataType)
                                {
                                case MetaDataType.Binary:
                                    cellValue.Text = "[BinaryData]";
                                    break;

                                case MetaDataType.File:
                                    cellTitle.VerticalAlign = VerticalAlign.Top;
                                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/FileValue.ascx");
                                    break;

                                case MetaDataType.ImageFile:
                                    cellTitle.VerticalAlign = VerticalAlign.Top;
                                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/ImageFileValue.ascx");
                                    break;

                                case MetaDataType.DateTime:
                                    Mediachase.UI.Web.Modules.EditControls.DateTimeValue control_datetime = (Mediachase.UI.Web.Modules.EditControls.DateTimeValue)Page.LoadControl("~/Modules/EditControls/DateTimeValue.ascx");
                                    control_datetime.Path_JS = "../../Scripts/";
                                    control = (System.Web.UI.UserControl)control_datetime;
                                    break;

                                case MetaDataType.Money:
                                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/MoneyValue.ascx");
                                    break;

                                case MetaDataType.Float:
                                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/FloatValue.ascx");
                                    break;

                                case MetaDataType.Integer:
                                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/IntValue.ascx");
                                    break;

                                case MetaDataType.Boolean:
                                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/BooleanValue.ascx");
                                    break;

                                case MetaDataType.Date:
                                    Mediachase.UI.Web.Modules.EditControls.DateValue control_date = (Mediachase.UI.Web.Modules.EditControls.DateValue)Page.LoadControl("~/Modules/EditControls/DateValue.ascx");
                                    control_date.Path_JS = "../../Scripts/";
                                    control = (System.Web.UI.UserControl)control_date;
                                    break;

                                case MetaDataType.Email:
                                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/EmailValue.ascx");
                                    break;

                                case MetaDataType.Url:
                                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/URLValue.ascx");
                                    break;

                                case MetaDataType.ShortString:
                                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/ShortStringValue.ascx");
                                    break;

                                case MetaDataType.LongString:
                                    cellTitle.VerticalAlign = VerticalAlign.Top;
                                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/LongStringValue.ascx");
                                    break;

                                case MetaDataType.LongHtmlString:
                                    cellTitle.VerticalAlign = VerticalAlign.Top;
                                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/LongHTMLStringValue.ascx");
                                    break;

                                case MetaDataType.DictionarySingleValue:
                                case MetaDataType.EnumSingleValue:
                                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/DictionarySingleValue.ascx");
                                    ((DictionarySingleValue)control).InitControl(field.Id, (field.AllowNulls ? !field.IsRequired : field.AllowNulls));
                                    break;

                                case MetaDataType.DictionaryMultivalue:
                                case MetaDataType.EnumMultivalue:
                                    cellTitle.VerticalAlign = VerticalAlign.Top;
                                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/DictionaryMultivalue.ascx");
                                    ((DictionaryMultivalue)control).InitControl(field.Id);
                                    break;

                                default:
                                    if (fieldValue != null)
                                    {
                                        cellValue.Text = fieldValue.ToString();
                                    }
                                    break;
                                }

                                if (control != null)
                                {
                                    cellValue.Controls.Add(control);

                                    if (field.DataType == MetaDataType.File)
                                    {
                                        ((FileValue)control).MetaClassName = MetaClassName;
                                        ((FileValue)control).ObjectId      = ObjectId;
                                    }
                                    else if (field.DataType == MetaDataType.ImageFile)
                                    {
                                        ((ImageFileValue)control).MetaClassName = MetaClassName;
                                        ((ImageFileValue)control).ObjectId      = ObjectId;
                                    }

                                    ICustomField iCustomField = ((ICustomField)control);
                                    iCustomField.FieldName = field.Name;
                                    if (fieldValue != null && needToBind)
                                    {
                                        iCustomField.Value = fieldValue;
                                    }
                                    iCustomField.AllowEmptyValues = !mc.GetFieldIsRequired(field);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Is this Steam game Installed?
        /// </summary>
        /// <param name="GameID">Steam GameID</param>
        /// <returns>Nullable Boolean</returns>
        public static bool?IsInstalled(UInt64 GameID, IGame game)
        {
            lock (contextLock)
            {
                if (!context.SteamIsRunning)
                {
                    if (game == null)
                    {
                        return(null);
                    }
                    if (!LaunchBoxPremiumLicenceFound)
                    {
                        return(null);
                    }

                    ICustomField installedFieldX = game.GetAllCustomFields().Where(field => field.Name == "Steam Game Installed").FirstOrDefault();
                    if (installedFieldX == null)
                    {
                        return(null);
                    }
                    bool retVal;
                    if (bool.TryParse(installedFieldX.Value, out retVal))
                    {
                        return(retVal);
                    }
                    return(null);
                }

                bool _isInstalled = context.IsInstalled(GameID);
                if (game == null)
                {
                    return(context.IsInstalled(GameID));
                }

                //if(SteamGameAutoHideShow)
                //{
                //    //show or hide game
                //}

                bool dataDirty = false;
                if (LaunchBoxPremiumLicenceFound)
                {
                    ICustomField installedField = game.GetAllCustomFields().Where(field => field.Name == "Steam Game Installed").FirstOrDefault();
                    if (installedField == null)
                    {
                        installedField       = game.AddNewCustomField();
                        installedField.Name  = "Steam Game Installed";
                        installedField.Value = _isInstalled.ToString();
                        dataDirty           |= true; // PluginHelper.DataManager.Save(false);
                    }
                    else if (installedField.Value != _isInstalled.ToString())
                    {
                        installedField.Value = _isInstalled.ToString();
                        dataDirty           |= true; // PluginHelper.DataManager.Save(false);
                    }
                }
                if (SteamToolsOptions.HideUninstalled)
                {
                    if (!game.Hide && !_isInstalled)
                    {
                        game.Hide  = true;
                        dataDirty |= true;
                    }
                }
                if (SteamToolsOptions.ShowInstalled)
                {
                    if (game.Hide && _isInstalled)
                    {
                        game.Hide  = false;
                        dataDirty |= true;
                    }
                }

                if (dataDirty)
                {
                    PluginHelper.DataManager.Save(false);
                }

                return(_isInstalled);
            }
        }
Ejemplo n.º 16
0
 private static void CheckSteamGames()
 {
     for (int i = 0; i < 60; i++)
     {
         if (SteamUpdateSentinalToken.IsCancellationRequested)
         {
             return;
         }
         Thread.Sleep(1000);
     }
     if (SteamUpdateSentinalToken.IsCancellationRequested)
     {
         return;
     }
     for (;;)
     {
         if (SteamUpdateSentinalToken.IsCancellationRequested)
         {
             return;
         }
         bool steamRunning = false;
         lock (contextLock)
         {
             steamRunning = context?.SteamIsRunning ?? false;
         }
         if (steamRunning)
         {
             if (LaunchBoxPremiumLicenceFound)// || SteamGameAutoHideShow)
             {
                 IGame[] games = PluginHelper.DataManager.GetAllGames();
                 if (SteamUpdateSentinalToken.IsCancellationRequested)
                 {
                     return;
                 }
                 bool dataDirty = false;
                 foreach (IGame game in games)
                 {
                     if (SteamUpdateSentinalToken.IsCancellationRequested)
                     {
                         break;
                     }
                     if (IsSteamGame(game))
                     {
                         if (SteamUpdateSentinalToken.IsCancellationRequested)
                         {
                             break;
                         }
                         UInt64?GameID = GetSteamGameID(game);
                         if (SteamUpdateSentinalToken.IsCancellationRequested)
                         {
                             break;
                         }
                         if (GameID.HasValue)
                         {
                             bool?_isInstalled = null;
                             //Thread.Sleep(1000);
                             lock (contextLock)
                             {
                                 _isInstalled = context?.IsInstalled(GameID.Value);
                             }
                             if (_isInstalled.HasValue)
                             {
                                 if (LaunchBoxPremiumLicenceFound)
                                 {
                                     ICustomField installedField = game.GetAllCustomFields().Where(field => field.Name == "Steam Game Installed").FirstOrDefault();
                                     if (installedField == null)
                                     {
                                         installedField       = game.AddNewCustomField();
                                         installedField.Name  = "Steam Game Installed";
                                         installedField.Value = _isInstalled.ToString();
                                         dataDirty           |= dataDirty; // PluginHelper.DataManager.Save(true);
                                     }
                                     else if (installedField.Value != _isInstalled.ToString())
                                     {
                                         installedField.Value = _isInstalled.ToString();
                                         dataDirty           |= dataDirty; // PluginHelper.DataManager.Save(true);
                                     }
                                 }
                                 if (SteamToolsOptions.HideUninstalled)
                                 {
                                     if (!game.Hide && !_isInstalled.Value)
                                     {
                                         game.Hide  = true;
                                         dataDirty |= true;
                                     }
                                 }
                                 if (SteamToolsOptions.ShowInstalled)
                                 {
                                     if (game.Hide && _isInstalled.Value)
                                     {
                                         game.Hide  = false;
                                         dataDirty |= true;
                                     }
                                 }
                             }
                             if (SteamUpdateSentinalToken.IsCancellationRequested)
                             {
                                 break;
                             }
                         }
                     }
                 }
                 if (dataDirty)
                 {
                     PluginHelper.DataManager.Save(false);
                 }
             }
             if (SteamUpdateSentinalToken.IsCancellationRequested)
             {
                 return;
             }
             for (int i = 0; i < SteamToolsOptions.PollingSteamRate; i++)
             {
                 if (SteamUpdateSentinalToken.IsCancellationRequested)
                 {
                     return;
                 }
                 Thread.Sleep(1000);
             }
         }
         else
         {
             for (int i = 0; i < 60; i++)
             {
                 if (SteamUpdateSentinalToken.IsCancellationRequested)
                 {
                     return;
                 }
                 Thread.Sleep(1000);
             }
         }
     }
 }
Ejemplo n.º 17
0
        public override IsoValue Parse(int field,
                                       sbyte[] buf,
                                       int pos,
                                       ICustomField custom)
        {
            if (pos < 0)
            {
                throw new ParseException($"Invalid DATE12 field {field} position {pos}");
            }

            if (pos + 12 > buf.Length)
            {
                throw new ParseException($"Insufficient data for DATE12 field {field}, pos {pos}");
            }

            DateTime calendar;
            int      year;

            if (ForceStringDecoding)
            {
                year = Convert.ToInt32(buf.ToString(pos,
                                                    2,
                                                    Encoding),
                                       10);

                if (year > 50)
                {
                    year = 1900 + year;
                }
                else
                {
                    year = 2000 + year;
                }
                var month = Convert.ToInt32(buf.ToString(pos,
                                                         2,
                                                         Encoding),
                                            10);
                var day = Convert.ToInt32(buf.ToString(pos + 2,
                                                       2,
                                                       Encoding),
                                          10);
                var hour = Convert.ToInt32(buf.ToString(pos + 4,
                                                        2,
                                                        Encoding),
                                           10);
                var min = Convert.ToInt32(buf.ToString(pos + 6,
                                                       2,
                                                       Encoding),
                                          10);
                var sec = Convert.ToInt32(buf.ToString(pos + 8,
                                                       2,
                                                       Encoding),
                                          10);

                calendar = new DateTime(year,
                                        month,
                                        day,
                                        hour,
                                        min,
                                        sec);
            }
            else
            {
                year = (buf[pos] - 48) * 10 + buf[pos + 1] - 48;

                if (year > 50)
                {
                    year = 1900 + year;
                }
                else
                {
                    year = 2000 + year;
                }

                calendar = new DateTime(year,
                                        (buf[pos + 2] - 48) * 10 + buf[pos + 3] - 48,
                                        (buf[pos + 4] - 48) * 10 + buf[pos + 5] - 48,
                                        (buf[pos + 6] - 48) * 10 + buf[pos + 7] - 48,
                                        (buf[pos + 8] - 48) * 10 + buf[pos + 9] - 48,
                                        (buf[pos + 10] - 48) * 10 + buf[pos + 11] - 48);
            }

            calendar = calendar.AddMilliseconds(0);

            if (TimeZoneInfo != null)
            {
                calendar = TimeZoneInfo.ConvertTime(calendar,
                                                    TimeZoneInfo);
            }

            return(new IsoValue(IsoType,
                                AdjustWithFutureTolerance(new DateTimeOffset(calendar)).DateTime));
        }
Ejemplo n.º 18
0
        private void BindCustomFields()
        {
            MetaObject obj = null;

            if (ObjectId > 0)
            {
                obj = MetaDataWrapper.LoadMetaObject(ObjectId, MetaClassName);
            }
            if (obj == null)
            {
                obj = MetaDataWrapper.NewMetaObject(ObjectId, MetaClassName);
            }

            MetaClass mc = obj.MetaClass;

            SortedList <int, MetaField> userMetaFields = new SortedList <int, MetaField>();

            foreach (MetaField field in mc.UserMetaFields)
            {
                if (ContainsMetaField(field.Name))
                {
                    int cur_weight = _mflist.IndexOf(field.Name);
                    userMetaFields.Add(cur_weight, field);
                }
            }

            foreach (MetaField field in userMetaFields.Values)
            {
                HtmlTableRow  row       = new HtmlTableRow();
                HtmlTableCell cellTitle = new HtmlTableCell();
                HtmlTableCell cellValue = new HtmlTableCell();

                cellTitle.VAlign    = "middle";
                cellTitle.InnerHtml = String.Format("<b>{0}</b>:", field.FriendlyName);
                object fieldValue = obj[field.Name];
                System.Web.UI.UserControl control = null;

                switch (field.DataType)
                {
                case MetaDataType.Binary:
                    cellValue.InnerText = "[BinaryData]";
                    break;

                case MetaDataType.File:
                    cellTitle.VAlign = "top";
                    control          = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/FileValue.ascx");
                    break;

                case MetaDataType.ImageFile:
                    cellTitle.VAlign = "top";
                    control          = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/ImageFileValue.ascx");
                    break;

                case MetaDataType.DateTime:
                    //control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/DateTimeValue.ascx");
                    Mediachase.UI.Web.Modules.EditControls.DateTimeValue control_datetime = (Mediachase.UI.Web.Modules.EditControls.DateTimeValue)Page.LoadControl("~/Modules/EditControls/DateTimeValue.ascx");
                    control_datetime.Path_JS = "../../Scripts/";
                    control = (System.Web.UI.UserControl)control_datetime;
                    break;

                case MetaDataType.Money:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/MoneyValue.ascx");
                    break;

                case MetaDataType.Float:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/FloatValue.ascx");
                    break;

                case MetaDataType.Integer:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/IntValue.ascx");
                    break;

                case MetaDataType.Boolean:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/BooleanValue.ascx");
                    break;

                case MetaDataType.Date:
                    //control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/DateValue.ascx");
                    Mediachase.UI.Web.Modules.EditControls.DateValue control_date = (Mediachase.UI.Web.Modules.EditControls.DateValue)Page.LoadControl("~/Modules/EditControls/DateValue.ascx");
                    control_date.Path_JS = "../../Scripts/";
                    control = (System.Web.UI.UserControl)control_date;
                    break;

                case MetaDataType.Email:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/EmailValue.ascx");
                    break;

                case MetaDataType.Url:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/URLValue.ascx");
                    break;

                case MetaDataType.ShortString:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/ShortStringValue.ascx");
                    break;

                case MetaDataType.LongString:
                    cellTitle.VAlign = "top";
                    control          = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/LongStringValue.ascx");
                    break;

                case MetaDataType.LongHtmlString:
                    cellTitle.VAlign = "top";
                    control          = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/LongHTMLStringValue.ascx");
                    break;

                case MetaDataType.DictionarySingleValue:
                case MetaDataType.EnumSingleValue:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/DictionarySingleValue.ascx");
                    ((DictionarySingleValue)control).InitControl(field.Id, (field.AllowNulls ? !field.IsRequired : field.AllowNulls));
                    break;

                case MetaDataType.DictionaryMultivalue:
                case MetaDataType.EnumMultivalue:
                    cellTitle.VAlign = "top";
                    control          = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/DictionaryMultivalue.ascx");
                    ((DictionaryMultivalue)control).InitControl(field.Id);
                    break;

                default:
                    if (fieldValue != null)
                    {
                        cellValue.InnerText = fieldValue.ToString();
                    }
                    break;
                }

                if (control != null)
                {
                    cellValue.Controls.Add(control);
                }

                row.Cells.Add(cellTitle);
                row.Cells.Add(cellValue);

                tblCustomFields.Rows.Add(row);

                if (control != null)
                {
                    ICustomField iCustomField = ((ICustomField)control);
                    iCustomField.FieldName = field.Name;
                    if (fieldValue != null)
                    {
                        iCustomField.Value = fieldValue;
                    }
                    iCustomField.AllowEmptyValues = !mc.GetFieldIsRequired(field);
                }
            }
        }
Ejemplo n.º 19
0
        public override IsoValue Parse(int field,
                                       sbyte[] buf,
                                       int pos,
                                       ICustomField custom)
        {
            if (pos < 0)
            {
                throw new ParseException($"Invalid LLVAR field {field} {pos}");
            }
            if (pos + 2 > buf.Length)
            {
                throw new ParseException($"Insufficient data for LLVAR header, pos {pos}");
            }
            var len = DecodeLength(buf,
                                   pos,
                                   2);

            if (len < 0)
            {
                throw new ParseException($"Invalid LLVAR length {len}, field {field} pos {pos}");
            }
            if (len + pos + 2 > buf.Length)
            {
                throw new ParseException($"Insufficient data for LLVAR field {field}, pos {pos}");
            }

            string v;

            try
            {
                v = len == 0
                    ? ""
                    : buf.SignedBytesToString(pos + 2,
                                              len,
                                              Encoding);
            }
            catch (Exception)
            {
                throw new ParseException($"Insufficient data for LLVAR header, field {field} pos {pos}");
            }

            //This is new: if the String's length is different from the specified length in the
            //buffer, there are probably some extended characters. So we create a String from
            //the rest of the buffer, and then cut it to the specified length.
            if (v.Length != len)
            {
                v = buf.SignedBytesToString(pos + 2,
                                            buf.Length - pos - 2,
                                            Encoding).Substring(0,
                                                                len);
            }

            if (custom == null)
            {
                return(new IsoValue(IsoType,
                                    v,
                                    len));
            }

            var decoded = custom.DecodeField(v);

            //If decode fails, return string; otherwise use the decoded object and its codec
            return(decoded == null
                ? new IsoValue(IsoType,
                               v,
                               len)
                : new IsoValue(IsoType,
                               decoded,
                               len,
                               custom));
        }
Ejemplo n.º 20
0
        public override IsoValue Parse(int field,
                                       sbyte[] buf,
                                       int pos,
                                       ICustomField custom)
        {
            if (pos < 0)
            {
                throw new ParseException($"Invalid LLLBIN field {field} pos {pos}");
            }
            if (pos + 3 > buf.Length)
            {
                throw new ParseException($"Insufficient LLLBIN header field {field}");
            }

            var l = DecodeLength(buf,
                                 pos,
                                 3);

            if (l < 0)
            {
                throw new ParseException($"Invalid LLLBIN length {l} field {field} pos {pos}");
            }
            if (l + pos + 3 > buf.Length)
            {
                throw new ParseException($"Insufficient data for LLLBIN field {field}, pos {pos}");
            }

            var binval = l == 0
                ? new sbyte[0]
                : HexCodec.HexDecode(buf.SignedBytesToString(pos + 3,
                                                             l,
                                                             Encoding.Default));

            if (custom == null)
            {
                return(new IsoValue(IsoType,
                                    binval,
                                    binval.Length));
            }
            var customBinaryField = custom as ICustomBinaryField;

            if (customBinaryField != null)
            {
                try
                {
                    var dec = customBinaryField.DecodeBinaryField(buf,
                                                                  pos + 3,
                                                                  l);
                    return(dec == null
                        ? new IsoValue(IsoType,
                                       binval,
                                       binval.Length)
                        : new IsoValue(IsoType,
                                       dec,
                                       0,
                                       custom));
                }
                catch (Exception)
                {
                    throw new ParseException($"Insufficient data for LLLBIN field {field}, pos {pos}");
                }
            }
            try
            {
                var dec = custom.DecodeField(l == 0
                    ? ""
                    : buf.SignedBytesToString(pos + 3,
                                              l,
                                              Encoding.Default));
                return(dec == null
                    ? new IsoValue(IsoType,
                                   binval,
                                   binval.Length)
                    : new IsoValue(IsoType,
                                   dec,
                                   l,
                                   custom));
            }
            catch (Exception)
            {
                throw new Exception($"Insufficient data for LLLBIN field {field}, pos {pos}");
            }
        }
Ejemplo n.º 21
0
        public override IsoValue Parse(int field, sbyte[] buf, int pos, ICustomField custom)
        {
            if (pos < 0)
            {
                throw new ParseException($"Invalid DATE6 field {field} position {pos}");
            }
            if (pos + 6 > buf.Length)
            {
                throw new ParseException($"Insufficient data for DATE6 field {field}, pos {pos}");
            }

            int year, month, day, minute, seconds, milliseconds;

            //Set the month and the day in the date
            if (ForceStringDecoding)
            {
                year = Convert.ToInt32(buf.BytesToString(pos,
                                                         2,
                                                         Encoding), 10);
                month = Convert.ToInt32(buf.BytesToString(pos + 2,
                                                          2,
                                                          Encoding), 10) - 1;
                day = Convert.ToInt32(buf.BytesToString(pos + 4,
                                                        2,
                                                        Encoding), 10);
            }
            else
            {
                year  = (buf[pos] - 48) * 10 + buf[pos + 1] - 48;
                month = (buf[pos + 2] - 48) * 10 + buf[pos + 3] - 48;
                day   = (buf[pos + 4] - 48) * 10 + buf[pos + 5] - 48;
            }

            var hour = minute = seconds = milliseconds = 0;

            if (year > 50)
            {
                year = 1900 + year;
            }
            else
            {
                year = 2000 + year;
            }

            var dt = new DateTime(year,
                                  month,
                                  day,
                                  hour,
                                  minute,
                                  seconds,
                                  milliseconds);

            if (TimeZoneInfo != null)
            {
                dt = TimeZoneInfo.ConvertTime(dt,
                                              TimeZoneInfo);
            }

            return(new IsoValue(IsoType,
                                dt));
        }
Ejemplo n.º 22
0
        private void BindCustomFields()
        {
            MetaObject obj = null;

            if (ObjectId > 0)
            {
                obj = MetaDataWrapper.LoadMetaObject(ObjectId, MetaClassName);
            }
            if (obj == null)
            {
                obj = MetaDataWrapper.NewMetaObject(ObjectId, MetaClassName);
            }

            foreach (MetaField field in obj.MetaClass.UserMetaFields)
            {
                HtmlTableRow  row       = new HtmlTableRow();
                HtmlTableCell cellTitle = new HtmlTableCell();
                HtmlTableCell cellValue = new HtmlTableCell();

                cellTitle.Attributes.Add("class", "ibn-label");
                cellTitle.Width     = "110px";
                cellTitle.VAlign    = "middle";
                cellTitle.InnerHtml = String.Format("{0}:", field.FriendlyName);
                object fieldValue = obj[field.Name];
                System.Web.UI.UserControl control = null;

                switch (field.DataType)
                {
                case MetaDataType.Binary:
                    cellValue.InnerText = "[BinaryData]";
                    break;

                case MetaDataType.File:
                    cellTitle.VAlign = "top";
                    control          = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/FileValue.ascx");
                    break;

                case MetaDataType.ImageFile:
                    cellTitle.VAlign = "top";
                    control          = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/ImageFileValue.ascx");
                    break;

                case MetaDataType.DateTime:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/DateTimeValue.ascx");
                    break;

                case MetaDataType.Money:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/MoneyValue.ascx");
                    break;

                case MetaDataType.Float:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/FloatValue.ascx");
                    break;

                case MetaDataType.Integer:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/IntValue.ascx");
                    break;

                case MetaDataType.Boolean:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/BooleanValue.ascx");
                    break;

                case MetaDataType.Date:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/DateValue.ascx");
                    break;

                case MetaDataType.Email:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/EmailValue.ascx");
                    break;

                case MetaDataType.Url:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/URLValue.ascx");
                    break;

                case MetaDataType.ShortString:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/ShortStringValue.ascx");
                    break;

                case MetaDataType.LongString:
                    cellTitle.VAlign = "top";
                    control          = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/LongStringValue.ascx");
                    break;

                case MetaDataType.LongHtmlString:
                    cellTitle.VAlign = "top";
                    control          = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/LongHTMLStringValue.ascx");
                    break;

                case MetaDataType.DictionarySingleValue:
                case MetaDataType.EnumSingleValue:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/DictionarySingleValue.ascx");
                    ((DictionarySingleValue)control).InitControl(field.Id, (field.AllowNulls ? !field.IsRequired : field.AllowNulls));
                    break;

                case MetaDataType.DictionaryMultivalue:
                case MetaDataType.EnumMultivalue:
                    cellTitle.VAlign = "top";
                    control          = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/DictionaryMultivalue.ascx");
                    ((DictionaryMultivalue)control).InitControl(field.Id);
                    break;

                default:
                    if (fieldValue != null)
                    {
                        cellValue.InnerText = fieldValue.ToString();
                    }
                    break;
                }

                if (control != null)
                {
                    cellValue.Controls.Add(control);
                }

                row.Cells.Add(cellTitle);
                row.Cells.Add(cellValue);

                tblCustomFields.Rows.Add(row);

                if (control != null)
                {
                    ICustomField iCustomField = ((ICustomField)control);
                    iCustomField.FieldName = field.Name;
                    if (fieldValue != null)
                    {
                        iCustomField.Value = fieldValue;
                    }
                    if (field.AllowNulls)
                    {
                        iCustomField.AllowEmptyValues = !field.IsRequired;
                    }
                    else
                    {
                        iCustomField.AllowEmptyValues = false;
                    }
                }
            }
        }
Ejemplo n.º 23
0
        public override IsoValue Parse(int field,
                                       sbyte[] buf,
                                       int pos,
                                       ICustomField custom)
        {
            if (pos < 0)
            {
                throw new ParseException($"Invalid LLBIN field {field} position {pos}");
            }
            if (pos + 2 > buf.Length)
            {
                throw new ParseException($"Invalid LLBIN field {field} position {pos}");
            }
            var len = DecodeLength(buf,
                                   pos,
                                   2);

            if (len < 0)
            {
                throw new ParseException($"Invalid LLBIN field {field} length {len} pos {pos}");
            }

            if (len + pos + 2 > buf.Length)
            {
                throw new ParseException(
                          $"Insufficient data for LLBIN field {field}, pos {pos} (LEN states '{buf.SignedBytesToString(pos, 2, Encoding.Default)}')");
            }

            var binval = len == 0
                ? new sbyte[0]
                : HexCodec.HexDecode(buf.SignedBytesToString(pos + 2,
                                                             len,
                                                             Encoding.Default));

            if (custom == null)
            {
                return(new IsoValue(IsoType,
                                    binval,
                                    binval.Length));
            }
            var binaryField = custom as ICustomBinaryField;

            if (binaryField != null)
            {
                try
                {
                    var dec = binaryField.DecodeBinaryField(buf,
                                                            pos + 2,
                                                            len);
                    if (dec == null)
                    {
                        return(new IsoValue(IsoType,
                                            binval,
                                            binval.Length));
                    }
                    return(new IsoValue(IsoType,
                                        dec,
                                        0,
                                        custom));
                }
                catch (Exception)
                {
                    throw new ParseException(
                              $"Insufficient data for LLBIN field {field}, pos {pos} (LEN states '{buf.SignedBytesToString(pos, 2, Encoding.Default)}')");
                }
            }
            try
            {
                var dec = custom.DecodeField(buf.SignedBytesToString(pos + 2,
                                                                     len,
                                                                     Encoding.Default));
                return(dec == null
                    ? new IsoValue(IsoType,
                                   binval,
                                   binval.Length)
                    : new IsoValue(IsoType,
                                   dec,
                                   binval.Length,
                                   custom));
            }
            catch (Exception)
            {
                throw new ParseException(
                          $"Insufficient data for LLBIN field {field}, pos {pos} (LEN states '{buf.SignedBytesToString(pos, 2, Encoding.Default)}')");
            }
        }
Ejemplo n.º 24
0
        public override IsoValue Parse(int field,
                                       sbyte[] buf,
                                       int pos,
                                       ICustomField custom)
        {
            if (pos < 0)
            {
                throw new ParseException($"Invalid LLLLVAR field {field} {pos}");
            }
            if (pos + 4 > buf.Length)
            {
                throw new ParseException($"Insufficient data for LLLLVAR header, pos {pos}");
            }
            var len = DecodeLength(buf,
                                   pos,
                                   4);

            if (len < 0)
            {
                throw new ParseException($"Invalid LLLLVAR length {len}, field {field} pos {pos}");
            }
            if (len + pos + 4 > buf.Length)
            {
                throw new ParseException($"Insufficient data for LLLLVAR field {field}, pos {pos}");
            }

            string v;

            try
            {
                v = len == 0
                    ? ""
                    : buf.SbyteString(pos + 4,
                                      len,
                                      Encoding);
            }
            catch (Exception)
            {
                throw new ParseException($"Insufficient data for LLLLVAR header, field {field} pos {pos}");
            }

            //This is new: if the String's length is different from the specified
            // length in the buffer, there are probably some extended characters.
            // So we create a String from the rest of the buffer, and then cut it to
            // the specified length.
            if (v.Length != len)
            {
                v = buf.SbyteString(pos + 4,
                                    buf.Length - pos - 4,
                                    Encoding).Substring(0,
                                                        len);
            }
            if (custom == null)
            {
                return(new IsoValue(IsoType,
                                    v,
                                    len));
            }
            var dec = custom.DecodeField(v);

            return(dec == null
                ? new IsoValue(IsoType,
                               v,
                               len)
                : new IsoValue(IsoType,
                               dec,
                               len,
                               custom));
        }