コード例 #1
0
    public Entry ParseEntry(JSONNode entry)
    {
        // Create entry
        Entry entryObject = new Entry();

        entryObject.setId(entry["id"]);

        // Create target
        Target targetObject;
        var    target     = entry["target"];
        string targetType = target["type"];

        switch (targetType)
        {
        case "IMAGE_TARGET":
            ImageTarget imageTargetObject = new ImageTarget();
            imageTargetObject.setFilename(target["filename"]);
            imageTargetObject.setStorageID(target["storageID"]);
            imageTargetObject.setId(target["id"]);
            imageTargetObject.setType(Target.targetType.IMAGE_TARGET);
            targetObject = imageTargetObject;
            break;

        case "GEOLOCATION_TARGET":
            GeolocationTarget geolocationTargetObject = new GeolocationTarget();
            geolocationTargetObject.setCity(target["city"]);
            geolocationTargetObject.setContinent(target["continent"]);
            geolocationTargetObject.setCountry(target["country"]);
            geolocationTargetObject.setId(target["id"]);
            geolocationTargetObject.setLatitude(target["latitude"]);
            geolocationTargetObject.setLongitude(target["longitude"]);
            geolocationTargetObject.setPlace(target["place"]);
            geolocationTargetObject.setType(Target.targetType.GEOLOCATION_TARGET);
            targetObject = geolocationTargetObject;
            break;

        case "BRICK_TARGET":
            BrickTarget brickTargetObject = new BrickTarget();
            brickTargetObject.setId(target["id"]);
            brickTargetObject.setType(Target.targetType.BRICK_TARGET);
            targetObject = brickTargetObject;
            break;

        default:
            targetObject = new Target();
            break;
        }
        List <string> hologramsListObject = new List <string>();
        int           j          = 0;
        var           hologramID = target["holograms"][j];

        while (hologramID != null)
        {
            hologramsListObject.Add(hologramID);
            hologramID = target["holograms"][++j];
        }
        targetObject.setHolograms(hologramsListObject);
        entryObject.setTarget(targetObject);

        // Create Hologram
        Hologram hologramObject;
        var      hologram     = entry["hologram"];
        string   hologramType = hologram["type"];

        switch (hologramType)
        {
        case "IMAGE_HOLOGRAM":
            ImageHologram imageHologramObject = new ImageHologram();
            imageHologramObject.setFilename(hologram["filename"]);
            imageHologramObject.setId(hologram["id"]);
            imageHologramObject.setStorageID(hologram["storageID"]);
            imageHologramObject.setTargetID(hologram["targetID"]);
            imageHologramObject.setType(Hologram.hologramType.IMAGE_HOLOGRAM);
            imageHologramObject.setTarget(targetObject);
            hologramObject = imageHologramObject;
            break;

        case "VIDEO_HOLOGRAM":
            VideoHologram videoHologramObject = new VideoHologram();
            videoHologramObject.setFilename(hologram["filename"]);
            videoHologramObject.setId(hologram["id"]);
            videoHologramObject.setStorageID(hologram["storageID"]);
            videoHologramObject.setTargetID(hologram["targetID"]);
            videoHologramObject.setType(Hologram.hologramType.VIDEO_HOLOGRAM);
            videoHologramObject.setTarget(targetObject);
            hologramObject = videoHologramObject;
            break;

        case "ECHO_HOLOGRAM":
            EchoHologram echoHologramObject = new EchoHologram();
            echoHologramObject.setFilename(hologram["filename"]);
            echoHologramObject.setId(hologram["id"]);
            echoHologramObject.setEncodedEcho(hologram["encodedEcho"]);
            echoHologramObject.setTextureFilename(hologram["textureFilename"]);
            echoHologramObject.setTargetID(hologram["targetID"]);
            echoHologramObject.setType(Hologram.hologramType.ECHO_HOLOGRAM);
            echoHologramObject.setTarget(targetObject);
            List <string> videosListObject = new List <string>();

            j = 0;
            var videoID = hologram["vidoes"][j];
            while (videoID != null)
            {
                videosListObject.Add(videoID);
                hologramID = hologram["vidoes"][++j];
            }
            echoHologramObject.setVidoes(videosListObject);

            hologramObject = echoHologramObject;
            break;

        case "MODEL_HOLOGRAM":
            ModelHologram modelHologramObject = new ModelHologram();
            modelHologramObject.setEncodedFile(hologram["encodedFile"]);
            modelHologramObject.setFilename(hologram["filename"]);
            modelHologramObject.setId(hologram["id"]);
            modelHologramObject.setMaterialFilename(hologram["materialFilename"]);
            modelHologramObject.setMaterialStorageID(hologram["materialStorageID"]);
            modelHologramObject.setStorageID(hologram["storageID"]);
            modelHologramObject.setTargetID(hologram["targetID"]);
            var textureFilenames  = hologram["textureFilenames"].AsArray;
            var textureStorageIDs = hologram["textureStorageIDs"].AsArray;
            for (j = 0; j < textureFilenames.Count; j++)
            {
                modelHologramObject.addTexture(textureFilenames[j], textureStorageIDs[j]);
            }
            modelHologramObject.setType(Hologram.hologramType.MODEL_HOLOGRAM);
            modelHologramObject.setTarget(targetObject);
            // If applicable, update model hologram with .glb version
            if (entry["additionalData"]["glbHologramStorageID"] != null)
            {
                modelHologramObject.setFilename(entry["additionalData"]["glbHologramStorageFilename"]);
                modelHologramObject.setStorageID(entry["additionalData"]["glbHologramStorageID"]);
            }
            hologramObject = modelHologramObject;
            break;

        default:
            hologramObject = new Hologram();
            break;
        }
        entryObject.setHologram(hologramObject);

        // Create SDKs array
        bool[] sdksObject = new bool[9];
        var    sdks       = entry["sdks"].AsArray;

        for (j = 0; j < 9; j++)
        {
            sdksObject[j] = sdks[j];
        }
        entryObject.setSupportedSDKs(sdksObject);

        // Create Additional Data
        var additionalData = entry["additionalData"];

        foreach (var data in additionalData)
        {
            entryObject.addAdditionalData(data.Key, data.Value);
        }

        // Add entry to database
        dbObject.addEntry(entryObject);

        // Return
        return(entryObject);
    }