コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="jsonArray"></param>
        /// <returns></returns>
        protected internal List <NetmeraContent> convertJsonArrayToNetmeraContent(JArray jsonArray)
        {
            List <NetmeraContent> contentList = new List <NetmeraContent>();
            JArray entries = new JArray();

            //If the entry is type of JArray, it is already able to be casted to JArray.
            //Else it does not accept JArray cast. Instead, it is added to a JArray as a JObject
            if (jsonArray[0]["entry"].Type == JTokenType.Array)
            {
                entries = (JArray)jsonArray[0]["entry"];
            }
            else
            {
                entries.Add(jsonArray[0]["entry"]);
            }

            for (int i = 0; i < entries.Count; i++)
            {
                try
                {
                    JObject        json        = (JObject)entries[i];
                    String         contentName = (String)json[NetmeraConstants.Content_Params][NetmeraConstants.ContentData_Params][NetmeraConstants.ApiContentType];
                    NetmeraContent content     = new NetmeraContent(contentName);
                    content.setContent(json);
                    contentList.Add(content);
                }
                catch (JsonException e)
                {
                    throw new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_JSON, "Json contains content is invalid.", e.Message);
                }
            }

            return(contentList);
        }
コード例 #2
0
        public void bulkUpdate(Action <JObject, Exception> callback)
        {
            String tmpPath = path;

            NetmeraHttpUtils.updateBulkContent(data, (json, e) =>
            {
                NetmeraContent content = new NetmeraContent();
                content.setContent(json);
                if (mediaData != null && mediaData.Count != 0)
                {
                    createMedia(content, (j, exc) =>
                    {
                        if (callback != null)
                        {
                            callback(j, exc);
                        }
                    });
                }
                else
                {
                    if (callback != null)
                    {
                        if (callback != null)
                        {
                            callback(json, e);
                        }
                    }
                }
            });
        }
コード例 #3
0
        /// <summary>
        /// Updates the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="path">The path.</param>
        /// <param name="callback">method called when content update operation finishes</param>
        protected internal void update(JObject data, String path, Action <JObject, Exception> callback)
        {
            String tmpPath = path;

            NetmeraHttpUtils.updateContent(data, tmpPath, (json, e) =>
            {
                NetmeraContent content = new NetmeraContent();
                content.setContent(json);
                if (mediaData != null && mediaData.Count != 0)
                {
                    createMedia(content, (j, exc) =>
                    {
                        if (callback != null)
                        {
                            callback(j, exc);
                        }
                    });
                }
                else
                {
                    if (callback != null)
                    {
                        if (callback != null)
                        {
                            callback(json, e);
                        }
                    }
                }
            });
        }
コード例 #4
0
        /// <summary>
        /// Updates the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="path">The path.</param>
        protected internal JObject update(JObject data, String path)
        {
            JObject        json    = NetmeraHttpUtils.updateContent(data, path);
            NetmeraContent content = new NetmeraContent();

            content.setContent(json);
            if (mediaData != null && mediaData.Count != 0)
            {
                json = createMedia(content);
            }
            return(json);
        }
コード例 #5
0
        private JObject createMedia(NetmeraContent content)
        {
            JObject json = null;

            try
            {
                JObject mediaObject      = new JObject();
                bool    isMediaFileAdded = false;

                IEnumerable <JProperty> jlist = mediaData.Properties();

                foreach (JProperty token in jlist)
                {
                    String key = token.Name;
                    String tmpMediaDataJson = mediaData.Value <String>(key);

                    byte[] tmpMediaData = JsonConvert.DeserializeObject <byte[]>(tmpMediaDataJson);

                    NetmeraMedia file = new NetmeraMedia(tmpMediaData);

                    isMediaFileAdded = true;

                    String appId       = content.getContent().Value <string>(NetmeraConstants.Site);
                    String apiKey      = NetmeraClient.getSecurityToken();
                    String contentPath = content.getPath();
                    String viewerId    = content.getOwner().Value <String>(NetmeraConstants.Netmera_Owner_Node_Name);
                    String mediaUrl    = file.save(appId, apiKey, contentPath, viewerId);

                    mediaObject.Add(key, mediaUrl);
                }
                if (isMediaFileAdded)
                {
                    json = NetmeraHttpUtils.updateContent(mediaObject, content.getPath());
                }
            }
            catch (JsonException)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_JSON, "Json in the response of creating media file is invalid");
            }
            catch (WebException)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_REQUEST, "Request exception occurred while saving media data");
            }
            catch (IOException)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_IO_EXCEPTION, "IO Exception occurred while saving media data");
            }
            return(json);
        }
コード例 #6
0
        protected internal JObject createBulk(JObject data)
        {
            JObject        jArray  = NetmeraHttpUtils.createBulkContent(data);
            NetmeraContent content = new NetmeraContent();

            //foreach (JObject json in jArray)
            //{

            content.setContent(jArray);
            //if (mediaData != null && mediaData.Count != 0)
            //{
            //    jarray = createMedia(content);
            //}
            //}

            return((JObject)jArray);
        }