コード例 #1
0
ファイル: MessagePuller.cs プロジェクト: octogonz/yamster
 internal void WriteManualEnvelopeToDb(JsonMessageEnvelope envelopeJson, long groupId, DateTime lastFetchedUtc)
 {
     WriteReferencesToDb(envelopeJson.References, lastFetchedUtc);
     foreach (var message in envelopeJson.Messages)
     {
         WriteMessageToDb(message, lastFetchedUtc);
     }
 }
コード例 #2
0
ファイル: MessagePuller.cs プロジェクト: octogonz/yamster
        void WriteMetaPropertiesToDb(JsonMessageEnvelope envelope)
        {
            var originalProperties = yamsterCoreDb.Properties;

            if (envelope.Meta.CurrentUserId != originalProperties.CurrentUserId)
            {
                yamsterCoreDb.UpdateProperties(properties => {
                    properties.CurrentUserId = envelope.Meta.CurrentUserId;
                });
            }

            var anyMessage = envelope.Messages.FirstOrDefault();

            if (anyMessage != null)
            {
                if (anyMessage.NetworkId != originalProperties.CurrentNetworkId)
                {
                    yamsterCoreDb.UpdateProperties(properties => {
                        properties.CurrentNetworkId = anyMessage.NetworkId;
                    });
                }
            }
        }
コード例 #3
0
ファイル: YamsterApi.cs プロジェクト: octogonz/yamster
        static JsonMessageEnvelope ConvertArchiveMessageEnvelope(JsonMessageEnvelopeUntyped untypedEnvelope)
        {
            string reserializedString    = SQLiteJsonConverter.SaveToJson(untypedEnvelope);
            JsonMessageEnvelope envelope = SQLiteJsonConverter.LoadFromJson <JsonMessageEnvelope>(reserializedString);

            // Use untypedEnvelope to fill in the RawJson properties
            for (int i = 0; i < untypedEnvelope.Messages.Length; ++i)
            {
                JObject archiveMessage      = untypedEnvelope.Messages[i];
                string  reserializedMessage = SQLiteJsonConverter.SaveToJson(archiveMessage);
                envelope.Messages[i].RawJson = reserializedMessage;
            }

            foreach (var pair in untypedEnvelope.ThreadedExtended)
            {
                long      threadId           = pair.Key;
                JObject[] archiveMessageList = pair.Value;

                var messageList = envelope.ThreadedExtended[threadId];
                for (int i = 0; i < archiveMessageList.Length; ++i)
                {
                    JObject archiveMessage      = archiveMessageList[i];
                    string  reserializedMessage = SQLiteJsonConverter.SaveToJson(archiveMessage);
                    messageList[i].RawJson = reserializedMessage;
                }
            }

            // Two indexes are needed because YamsterReferenceJsonConverter discards unrecognized items
            // from envelope.References; we should probably fix that.
            for (int archiveIndex = 0, index = 0; ;)
            {
                if (archiveIndex >= untypedEnvelope.References.Length)
                {
                    break;
                }
                if (index >= envelope.References.Length)
                {
                    break;
                }

                var reference = envelope.References[index];

                JObject archiveReference   = untypedEnvelope.References[archiveIndex];
                long    archiveReferenceId = Convert.ToInt64(((JValue)archiveReference["id"]).Value);

                if (reference.Id == archiveReferenceId)
                {
                    string reserializedMessage = SQLiteJsonConverter.SaveToJson(archiveReference);
                    envelope.References[index].RawJson = reserializedMessage;
                    ++index;
                }
                ++archiveIndex;
            }
#if DEBUG
            foreach (var reference in envelope.References)
            {
                Debug.Assert(reference.RawJson != null);
            }
#endif
            return(envelope);
        }