Search in sources :

Example 1 with DistributionStartSessionLog

use of com.microsoft.appcenter.distribute.ingestion.models.DistributionStartSessionLog in project AppCenter-SDK-Android by Microsoft.

the class DistributeSerializerTest method serialize.

@Test
public void serialize() throws JSONException {
    LogContainer expectedContainer = new LogContainer();
    List<Log> logs = new ArrayList<>();
    {
        DistributionStartSessionLog log = new DistributionStartSessionLog();
        log.setTimestamp(new Date());
        logs.add(log);
    }
    expectedContainer.setLogs(logs);
    UUID sid = UUIDUtils.randomUUID();
    for (Log log : logs) {
        log.setSid(sid);
    }
    /* Serialize and deserialize logs container. */
    LogSerializer serializer = new DefaultLogSerializer();
    serializer.addLogFactory(DistributionStartSessionLog.TYPE, new DistributionStartSessionLogFactory());
    String payload = serializer.serializeContainer(expectedContainer);
    LogContainer actualContainer = serializer.deserializeContainer(payload);
    /* Verify that logs container successfully deserialized. */
    Assert.assertEquals(expectedContainer, actualContainer);
}
Also used : DistributionStartSessionLogFactory(com.microsoft.appcenter.distribute.ingestion.models.json.DistributionStartSessionLogFactory) DistributionStartSessionLog(com.microsoft.appcenter.distribute.ingestion.models.DistributionStartSessionLog) Log(com.microsoft.appcenter.ingestion.models.Log) DistributionStartSessionLog(com.microsoft.appcenter.distribute.ingestion.models.DistributionStartSessionLog) ArrayList(java.util.ArrayList) LogContainer(com.microsoft.appcenter.ingestion.models.LogContainer) DefaultLogSerializer(com.microsoft.appcenter.ingestion.models.json.DefaultLogSerializer) LogSerializer(com.microsoft.appcenter.ingestion.models.json.LogSerializer) UUID(java.util.UUID) Date(java.util.Date) DefaultLogSerializer(com.microsoft.appcenter.ingestion.models.json.DefaultLogSerializer) Test(org.junit.Test)

Example 2 with DistributionStartSessionLog

use of com.microsoft.appcenter.distribute.ingestion.models.DistributionStartSessionLog in project AppCenter-SDK-Android by Microsoft.

the class Distribute method enqueueDistributionStartSessionLog.

/**
 * Send distribution start session log after enabling in-app updates (first app launch after installation).
 */
private synchronized void enqueueDistributionStartSessionLog() {
    /*
         * Session starts before in-app updates setup (using browser) so the first start session log
         * is sent without distributionGroupId value.
         *
         * Send the distribution start session log if start session log without distributionGroupId
         * value was sent before
         */
    SessionContext.SessionInfo lastSession = SessionContext.getInstance().getSessionAt(System.currentTimeMillis());
    if (lastSession == null || lastSession.getSessionId() == null) {
        AppCenterLog.debug(DistributeConstants.LOG_TAG, "No sessions were logged before, ignore sending of the distribution start session log.");
        return;
    }
    post(new Runnable() {

        @Override
        public void run() {
            DistributionStartSessionLog log = new DistributionStartSessionLog();
            mChannel.enqueue(log, DISTRIBUTE_GROUP);
        }
    });
}
Also used : DistributionStartSessionLog(com.microsoft.appcenter.distribute.ingestion.models.DistributionStartSessionLog) SessionContext(com.microsoft.appcenter.SessionContext)

Example 3 with DistributionStartSessionLog

use of com.microsoft.appcenter.distribute.ingestion.models.DistributionStartSessionLog in project mobile-center-sdk-android by Microsoft.

the class DistributeSerializerTest method serialize.

@Test
public void serialize() throws JSONException {
    LogContainer expectedContainer = new LogContainer();
    List<Log> logs = new ArrayList<>();
    {
        DistributionStartSessionLog log = new DistributionStartSessionLog();
        log.setTimestamp(new Date());
        logs.add(log);
    }
    expectedContainer.setLogs(logs);
    UUID sid = UUID.randomUUID();
    for (Log log : logs) {
        log.setSid(sid);
    }
    /* Serialize and deserialize logs container. */
    LogSerializer serializer = new DefaultLogSerializer();
    serializer.addLogFactory(DistributionStartSessionLog.TYPE, new DistributionStartSessionLogFactory());
    String payload = serializer.serializeContainer(expectedContainer);
    LogContainer actualContainer = serializer.deserializeContainer(payload, null);
    /* Verify that logs container successfully deserialized. */
    Assert.assertEquals(expectedContainer, actualContainer);
}
Also used : DistributionStartSessionLogFactory(com.microsoft.appcenter.distribute.ingestion.models.json.DistributionStartSessionLogFactory) DistributionStartSessionLog(com.microsoft.appcenter.distribute.ingestion.models.DistributionStartSessionLog) Log(com.microsoft.appcenter.ingestion.models.Log) DistributionStartSessionLog(com.microsoft.appcenter.distribute.ingestion.models.DistributionStartSessionLog) ArrayList(java.util.ArrayList) LogContainer(com.microsoft.appcenter.ingestion.models.LogContainer) DefaultLogSerializer(com.microsoft.appcenter.ingestion.models.json.DefaultLogSerializer) LogSerializer(com.microsoft.appcenter.ingestion.models.json.LogSerializer) UUID(java.util.UUID) Date(java.util.Date) DefaultLogSerializer(com.microsoft.appcenter.ingestion.models.json.DefaultLogSerializer) Test(org.junit.Test)

Example 4 with DistributionStartSessionLog

use of com.microsoft.appcenter.distribute.ingestion.models.DistributionStartSessionLog in project mobile-center-sdk-android by Microsoft.

the class Distribute method enqueueDistributionStartSessionLog.

/**
 * Send distribution start session log after enabling in-app updates (first app launch after installation).
 */
private synchronized void enqueueDistributionStartSessionLog() {
    /*
         * Session starts before in-app updates setup (using browser) so the first start session log
         * is sent without distributionGroupId value.
         *
         * Send the distribution start session log if start session log without distributionGroupId
         * value was sent before
         */
    SessionContext.SessionInfo lastSession = SessionContext.getInstance().getSessionAt(System.currentTimeMillis());
    if (lastSession == null || lastSession.getSessionId() == null) {
        AppCenterLog.debug(LOG_TAG, "No sessions were logged before, ignore sending of the distribution start session log.");
        return;
    }
    post(new Runnable() {

        @Override
        public void run() {
            DistributionStartSessionLog log = new DistributionStartSessionLog();
            mChannel.enqueue(log, DISTRIBUTE_GROUP, Flags.DEFAULTS);
        }
    });
}
Also used : DistributionStartSessionLog(com.microsoft.appcenter.distribute.ingestion.models.DistributionStartSessionLog) SessionContext(com.microsoft.appcenter.utils.context.SessionContext)

Aggregations

DistributionStartSessionLog (com.microsoft.appcenter.distribute.ingestion.models.DistributionStartSessionLog)4 DistributionStartSessionLogFactory (com.microsoft.appcenter.distribute.ingestion.models.json.DistributionStartSessionLogFactory)2 Log (com.microsoft.appcenter.ingestion.models.Log)2 LogContainer (com.microsoft.appcenter.ingestion.models.LogContainer)2 DefaultLogSerializer (com.microsoft.appcenter.ingestion.models.json.DefaultLogSerializer)2 LogSerializer (com.microsoft.appcenter.ingestion.models.json.LogSerializer)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 UUID (java.util.UUID)2 Test (org.junit.Test)2 SessionContext (com.microsoft.appcenter.SessionContext)1 SessionContext (com.microsoft.appcenter.utils.context.SessionContext)1