public void Save()
        {
            var request = new ContentSaveRequestPacket(_bound as IContentTemplate, _contentType);

            // Send the request
            NetworkManager.Instance.SendPacket(request);
        }
        public static new Packet FromNetBuffer(NetIncomingMessage incomingMessage)
        {
            var length = incomingMessage.ReadInt32();
            var bytes = incomingMessage.ReadBytes(length);
            var type = (ContentType) incomingMessage.ReadByte();

            var o = SerializationHelper.ByteArrayToObject(bytes) as IContentTemplate;
            var packet = new ContentSaveRequestPacket(o, type);

            return packet;
        }
Пример #3
0
        private void buttonApplyChanges_Click(object sender, EventArgs e)
        {
            // Make the request
            var contentPage = GetActiveContentPage();
            var request = new ContentSaveRequestPacket(contentPage.BoundObject, contentPage.ContentType);

            // Send the request
            NetworkManager.Instance.SendPacket(request);

            // We need to ensure no double clicks are permitted / navigation away
            Enabled = false;
        }
Пример #4
0
        public void Save()
        {
            // Serialize the data
            _template.BinaryData = SerializationHelper.ObjectToByteArray(Map);

            var request = new ContentSaveRequestPacket(_template, ContentType.Map);

            // Send the request
            NetworkManager.Instance.SendPacket(request);
        }
Пример #5
0
        private void Handler(ContentSaveRequestPacket contentSaveRequestPacket)
        {
            var result = RequestResult.Succesful;

            var locked = !_contentLockManager.HasLock(contentSaveRequestPacket.Sender, contentSaveRequestPacket.ContentObject.Id,
                                                contentSaveRequestPacket.ContentType);
            if (!locked)
            {
                try
                {

                    // Create our context and use it
                    using (var context = new ServerContext())
                    {
                        switch (contentSaveRequestPacket.ContentType)
                        {
                            case ContentType.Item:
                                var item =
                                    context.ItemTemplates.Attach(contentSaveRequestPacket.ContentObject as ItemTemplate);
                                context.Entry(item).State = EntityState.Modified;
                                context.SaveChanges();
                                break;
                            case ContentType.Skill:
                                var skill =
                                    context.SkillTemplates.Attach(
                                        contentSaveRequestPacket.ContentObject as SkillTemplate);
                                context.Entry(skill).State = EntityState.Modified;
                                context.SaveChanges();
                                break;
                            case ContentType.Map:
                                var map = context.MapTemplates.Attach(contentSaveRequestPacket.ContentObject as MapTemplate);
                                context.Entry(map).State = EntityState.Modified;
                                context.SaveChanges();
                                break;

                            default:
                                result = RequestResult.Failed;
                                return;
                        }
                    }

                }
                catch (Exception exception)
                {
                    // Log the error and eat it
                    Logger.Instance.Log(Level.Error,
                                        "The content of type " + contentSaveRequestPacket.ContentType +
                                        " failed to save: " + exception);
                    result = RequestResult.Failed;
                }
            }
            else
            {
                // If it's locked, it's considered a failure
                result = RequestResult.Failed;
            }

            // Send the result either way back to the client
            var packet = new ContentSaveResultPacket(result);
            ClientNetworkManager.Instance.SendPacket(packet, contentSaveRequestPacket.Sender);
        }