Ejemplo n.º 1
0
 public FileStoreItem(string stateTag, long position, ItemPayload payload, int sizeInStore)
 {
     StateTag    = stateTag;
     Position    = position;
     Payload     = payload;
     SizeInStore = sizeInStore;
 }
Ejemplo n.º 2
0
        public IStoredItem Write(ref string stateTag, ItemPayload payload)
        {
            // We always write to the last store.
            var storeToWrite      = _innerStores[_innerStores.Length - 1];
            var storeToWriteState = (string)null;

            if (stateTag != null)
            {
                if (StateTag != stateTag)
                {
                    return(null);
                }
                storeToWriteState = storeToWrite.StateTag;
                if (StateTag != stateTag)
                {
                    return(null);
                }
            }

            // TODO: There is a slight chance that StateTag changes between the last verification above and the execution.

            var written = storeToWrite.Write(ref storeToWriteState, payload);

            if (written == null)
            {
                return(null);
            }

            return(GetPrevious(Eof));
        }
Ejemplo n.º 3
0
        public IStoredItem Write(ref string stateTag, ItemPayload payload)
        {
            if (stateTag != null)
            {
                throw new NotImplementedException();
            }

            // Before the first write, we read the last item in order to immediately create a link.
            // This way when the user iterate to the previous, it will always show the same item.
            if (_last == null)
            {
                GetPrevious(_eof);
                Debug.Assert(_last != null);
            }

            var inner = _inner.Write(ref stateTag, payload);

            Debug.Assert(inner != null);

            // If the last command is identical, do not create a new entry.
            if (SameCommand(inner, _last))
            {
                return(_last);
            }

            // The new last record is the one we just wrote.
            var newLast = new NewAtTailEntry(inner, _last, _eof);

            // Set the last and return the record we just wrote.
            SetLast(newLast);
            return(newLast);
        }
Ejemplo n.º 4
0
        public IStoredItem Write(ref string stateTag, ItemPayload payload)
        {
            if (stateTag != null)
            {
                throw new NotImplementedException();
            }

            if (_last != null)
            {
                stateTag = _last.StateTag;
            }

            var inner = _inner.Write(ref stateTag, payload);

            if (inner == null)
            {
                // If the conditional write failed, some records might have appeared after what knew for last record.
                // This means what we have for last record is not actually the last.
                SetLast(null);

                // Write again, this time unconditionally.
                stateTag = null;
                inner    = _inner.Write(ref stateTag, payload);
            }

            Debug.Assert(inner != null);

            // The new last record is the one we just wrote.
            var newLast = new CacheEntry(inner, _last, _eof);

            // Set the last and return the record we just wrote.
            SetLast(newLast);
            return(newLast);
        }
Ejemplo n.º 5
0
        public async Task <ActionResult <ItemResult> > PostAsync([FromBody] ItemPayload itemPayload)
        {
            Item item = _mapper.Map <Item>(itemPayload);

            await _cosmosDbRepo.AddItemAsync(item);

            return(Created(nameof(PostAsync), new { Id = item.Id, item.Created }));
        }
Ejemplo n.º 6
0
 private bool Accept(ItemPayload payload)
 {
     if (payload == null)
     {
         throw new InvalidOperationException();
     }
     return(_filter(payload));
 }
Ejemplo n.º 7
0
        public IStoredItem Write(ref string stateTag, ItemPayload payload)
        {
            if (!Accept(payload))
            {
                throw new NotImplementedException();
            }

            return(_inner.Write(ref stateTag, payload));
        }
Ejemplo n.º 8
0
        private static Payload ProcessChunk(BinaryReader reader)
        {
            Payload payload = null;

            reader.ReadByte();  // START_BYTE
            var chunkType = (SeStringChunkType)reader.ReadByte();
            var chunkLen  = GetInteger(reader);

            var packetStart = reader.BaseStream.Position;

            switch (chunkType)
            {
            case SeStringChunkType.Interactable:
            {
                var subType = (EmbeddedInfoType)reader.ReadByte();
                switch (subType)
                {
                case EmbeddedInfoType.PlayerName:
                    payload = new PlayerPayload();
                    break;

                case EmbeddedInfoType.ItemLink:
                    payload = new ItemPayload();
                    break;

                case EmbeddedInfoType.Status:
                    payload = new StatusPayload();
                    break;

                case EmbeddedInfoType.LinkTerminator:
                // this has no custom handling and so needs to fallthrough to ensure it is captured
                default:
                    Log.Verbose("Unhandled EmbeddedInfoType: {0}", subType);
                    // rewind so we capture the Interactable byte in the raw data
                    reader.BaseStream.Seek(-1, SeekOrigin.Current);
                    payload = new RawPayload((byte)chunkType);
                    break;
                }
            }
            break;

            default:
                Log.Verbose("Unhandled SeStringChunkType: {0}", chunkType);
                payload = new RawPayload((byte)chunkType);
                break;
            }

            payload?.ProcessChunkImpl(reader, reader.BaseStream.Position + chunkLen - 1);

            // read through the rest of the packet
            var readBytes = (int)(reader.BaseStream.Position - packetStart);

            reader.ReadBytes(chunkLen - readBytes + 1); // +1 for the END_BYTE marker

            return(payload);
        }
Ejemplo n.º 9
0
        public static IList <ItemPayload> GetItems()
        {
            // AllDevices has duplicates, so filtering this to be safe.
            var set = new HashSet <Item>();

            foreach (var item in Item.AllItems)
            {
                set.Add(item);
            }
            return(set.Select(x => ItemPayload.FromItem(x)).ToList());
        }
        private static async Task <ItemPayload> DeserializeAndValidatePayload(Stream content, string expectedId)
        {
            using (StreamReader reader = new StreamReader(content, utf8Encoding))
            {
                ItemPayload payload = JsonConvert.DeserializeObject <ItemPayload>(await reader.ReadToEndAsync());
                Assert.AreEqual(expectedId, payload.Id);
                Assert.AreEqual(expectedId, payload.PartitionKey);

                return(payload);
            }
        }
Ejemplo n.º 11
0
        public IStoredItem Write(ref string stateTag, ItemPayload payload)
        {
            var record     = ToRecord(payload);
            var binarySize = 0;
            var position   = WriteRecord(record, ref stateTag, ref binarySize);

            if (position == -1L)
            {
                return(null);
            }

            return(new FileStoreItem(stateTag, position, payload, binarySize));
        }
Ejemplo n.º 12
0
        private static DataFileRecord ToRecord(ItemPayload payload)
        {
            if (payload is CommandPayload commandPayload)
            {
                return(new DataFileRecord
                {
                    Type = DataFileRecord.CommandV2,
                    MachineName = commandPayload.MachineName,
                    Pid = commandPayload.Pid,
                    WhenExecuted = commandPayload.WhenExecuted,
                    Command = commandPayload.Command,
                    Output = commandPayload.Output
                });
            }

            throw new InvalidOperationException($"Unexpected payload type: {payload.GetType().FullName}");
        }
Ejemplo n.º 13
0
        private bool Match(ItemPayload a, ItemPayload b)
        {
            var aCmd = a as CommandPayload;
            var bCmd = b as CommandPayload;

            if (aCmd == null || bCmd == null)
            {
                return(false);
            }

            if (aCmd.WhenExecuted == bCmd.WhenExecuted && aCmd.Command == bCmd.Command)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 14
0
            public static IEnumerable <ColorString> FromItem(string str, ItemPayload item, TextTypes source)
            {
                var color1 = new Vector4(1, 1, 1, 1);
                var color2 = new Vector4(0, 0, 0, 1);

                switch (item.Item.Rarity)
                {
                case 2:
                    color1 = new Vector4(0.6549f, 0.92156f, 0.6549f, 1);
                    break;

                case 3:
                    color1 = new Vector4(0.21568f, 0.46274f, 0.92156f, 1);
                    break;

                case 4:
                    color1 = new Vector4(0.6f, 0.44705f, 0.92156f, 1);
                    break;

                default:
                    break;
                }

                yield return(MakeLinkChar(source));

                foreach (var s in FromStringSplitDelimiters(str, color1, color2, source))
                {
                    yield return(s);
                }
                if (item.Item.IsCollectable)
                {
                    yield return(MakeCollectibleChar(color1, color2, source));
                }
                if (item.IsHQ)
                {
                    yield return(MakeHqChar(color1, color2, source));
                }
            }
Ejemplo n.º 15
0
        private static Payload DecodeChunk(BinaryReader reader)
        {
            Payload payload = null;

            reader.ReadByte();  // START_BYTE
            var chunkType = (SeStringChunkType)reader.ReadByte();
            var chunkLen  = GetInteger(reader);

            var packetStart = reader.BaseStream.Position;

            // any unhandled payload types will be turned into a RawPayload with the exact same binary data
            switch (chunkType)
            {
            case SeStringChunkType.EmphasisItalic:
                payload = new EmphasisItalicPayload();
                break;

            case SeStringChunkType.SeHyphen:
                payload = SeHyphenPayload.Payload;
                break;

            case SeStringChunkType.Interactable:
            {
                var subType = (EmbeddedInfoType)reader.ReadByte();
                switch (subType)
                {
                case EmbeddedInfoType.PlayerName:
                    payload = new PlayerPayload();
                    break;

                case EmbeddedInfoType.ItemLink:
                    payload = new ItemPayload();
                    break;

                case EmbeddedInfoType.MapPositionLink:
                    payload = new MapLinkPayload();
                    break;

                case EmbeddedInfoType.Status:
                    payload = new StatusPayload();
                    break;

                case EmbeddedInfoType.QuestLink:
                    payload = new QuestPayload();
                    break;

                case EmbeddedInfoType.DalamudLink:
                    payload = new DalamudLinkPayload();
                    break;

                case EmbeddedInfoType.LinkTerminator:
                // this has no custom handling and so needs to fallthrough to ensure it is captured
                default:
                    // but I'm also tired of this log
                    if (subType != EmbeddedInfoType.LinkTerminator)
                    {
                        Log.Verbose("Unhandled EmbeddedInfoType: {0}", subType);
                    }

                    // rewind so we capture the Interactable byte in the raw data
                    reader.BaseStream.Seek(-1, SeekOrigin.Current);
                    break;
                }
            }

            break;

            case SeStringChunkType.AutoTranslateKey:
                payload = new AutoTranslatePayload();
                break;

            case SeStringChunkType.UIForeground:
                payload = new UIForegroundPayload();
                break;

            case SeStringChunkType.UIGlow:
                payload = new UIGlowPayload();
                break;

            case SeStringChunkType.Icon:
                payload = new IconPayload();
                break;

            default:
                Log.Verbose("Unhandled SeStringChunkType: {0}", chunkType);
                break;
            }

            payload ??= new RawPayload((byte)chunkType);
            payload.DecodeImpl(reader, reader.BaseStream.Position + chunkLen - 1);

            // read through the rest of the packet
            var readBytes = (uint)(reader.BaseStream.Position - packetStart);

            reader.ReadBytes((int)(chunkLen - readBytes + 1)); // +1 for the END_BYTE marker

            return(payload);
        }
Ejemplo n.º 16
0
 private static bool IsCommand(ItemPayload arg)
 {
     return(arg is CommandPayload);
 }