Beispiel #1
0
        public DynamicObjectListSerialize GetDynamicObjectList(Guid objectId)
        {
            DynamicObjectListSerialize ret = null;
            Session session = null;

            try
            {
                session = XpoHelper.GetNewSession();
                NAS.DAL.CMS.ObjectDocument.Object cmsObject =
                    session.GetObjectByKey <NAS.DAL.CMS.ObjectDocument.Object>(objectId);

                if (cmsObject == null)
                {
                    throw new Exception("Could not found CMS Object");
                }

                if (cmsObject.DynamicObjectList != null)
                {
                    using (MemoryStream stream = new MemoryStream(cmsObject.DynamicObjectList))
                    {
                        ret = DynamicObjectListSerialize.Deserialize(stream);
                    }
                }

                return(ret);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
Beispiel #2
0
        public void SetDynamicObjectListItem(Session session, Guid objectId, DynamicObjectListSerializeDataItem data)
        {
            DynamicObjectListSerialize dynamicObjectList = null;

            NAS.DAL.CMS.ObjectDocument.Object CMSObject =
                session.GetObjectByKey <NAS.DAL.CMS.ObjectDocument.Object>(objectId);

            if (CMSObject == null)
            {
                return;
            }

            if (CMSObject.DynamicObjectList != null)
            {
                using (MemoryStream stream = new MemoryStream(CMSObject.DynamicObjectList))
                {
                    dynamicObjectList = DynamicObjectListSerialize.Deserialize(stream);
                    if (dynamicObjectList == null)
                    {
                        dynamicObjectList = new DynamicObjectListSerialize();
                    }
                }
            }
            else
            {
                dynamicObjectList = new DynamicObjectListSerialize();
            }

            using (MemoryStream stream = new MemoryStream())
            {
                dynamicObjectList[data.GetKey()] = data;
                DynamicObjectListSerialize.Serialize(dynamicObjectList, stream);
                CMSObject.DynamicObjectList = stream.ToArray();
                CMSObject.Save();
            }
        }
Beispiel #3
0
        public void RemoveDynamicObjectListItem(Session session, Guid objectId, Guid objectCustomFieldId)
        {
            DynamicObjectListSerialize dynamicObjectList = null;

            NAS.DAL.CMS.ObjectDocument.Object CMSObject =
                session.GetObjectByKey <NAS.DAL.CMS.ObjectDocument.Object>(objectId);

            if (CMSObject == null)
            {
                return;
            }

            if (CMSObject.DynamicObjectList != null)
            {
                using (MemoryStream stream = new MemoryStream(CMSObject.DynamicObjectList))
                {
                    dynamicObjectList = DynamicObjectListSerialize.Deserialize(stream);
                    if (dynamicObjectList == null)
                    {
                        dynamicObjectList = new DynamicObjectListSerialize();
                    }
                }

                using (MemoryStream stream = new MemoryStream())
                {
                    string key = objectCustomFieldId.ToString().Replace("-", "");
                    if (dynamicObjectList.ContainsKey(key))
                    {
                        dynamicObjectList.Remove(key);
                    }
                    DynamicObjectListSerialize.Serialize(dynamicObjectList, stream);
                    CMSObject.DynamicObjectList = stream.ToArray();
                    CMSObject.Save();
                }
            }
        }
        public static void Serialize(DynamicObjectListSerialize dictionary, Stream stream)
        {
            IFormatter formatter = new BinaryFormatter();

            formatter.Serialize(stream, dictionary);
        }