예제 #1
0
        /// <summary>
        /// Gets the list.
        /// </summary>
        /// <param name="metaClass">The meta class.</param>
        /// <returns></returns>
        internal static MetaFieldCollection GetList(MetaClass metaClass)
        {
            #region ArgumentNullExceptions
            if (metaClass == null)
            {
                throw new ArgumentNullException("metaClass", AsyncResources.GetConstantValue("ARG_NULL_ERR_MSG"));
            }
            #endregion

            MetaFieldCollection retVal = new MetaFieldCollection();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_LoadMetaFieldListByMetaClassId"),
                                                                  new SqlParameter("@MetaClassId", metaClass.Id)))
            {
                while (reader.Read())
                {
                    MetaField newItem = MetaField.Load(metaClass, reader);
                    newItem.SetOwnerMetaClass(metaClass);

                    retVal.Add(newItem);
                }
                reader.Close();
            }

            return(retVal);
        }
예제 #2
0
        public HttpResponseMessage RemoveField(int metaClassId, int fieldId)
        {
            MetaDataContext context = MetaDataContext.Instance;

            Mediachase.MetaDataPlus.Configurator.MetaClass metaClass = Mediachase.MetaDataPlus.Configurator.MetaClass.Load(context, metaClassId);
            if (metaClass == null)
            {
                HttpResponseMessage errorResponse = Request.CreateResponse <string>(HttpStatusCode.NotFound, "Meta Class with id " + metaClassId + " could not be loaded.", "application/json");
                return(errorResponse);
            }

            MetaField field = MetaField.Load(MetaDataContext.Instance, fieldId);

            if (field == null)
            {
                HttpResponseMessage errorResponse = Request.CreateResponse <string>(HttpStatusCode.NotFound, "Meta Class with id " + metaClassId + " could not be loaded.", "application/json");
                return(errorResponse);
            }


            metaClass.DeleteField(field);

            string message = JsonConvert.SerializeObject(new
            {
                Message       = string.Format("Removed Meta Field '{0}' from Meta Class '{1}'", field.Name, metaClass.Name),
                MetaClassName = metaClass.Name,
                MetaFieldName = field.Name
            });

            HttpResponseMessage response = Request.CreateResponse <string>(HttpStatusCode.OK, "");

            response.Content = new StringContent(message);
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            return(response);
        }
예제 #3
0
        /// <summary>
        /// Gets the list.
        /// </summary>
        /// <param name="NamespaceItems">The namespace items.</param>
        /// <returns></returns>
        public static MetaFieldCollection GetList(params string[] namespaceItems)
        {
            #region ArgumentNullExceptions
            if (namespaceItems == null)
            {
                throw new ArgumentNullException("NamespaceItems", AsyncResources.GetConstantValue("ARG_NULL_ERR_MSG"));
            }
            #endregion

            MetaFieldCollection retVal = new MetaFieldCollection();

            foreach (string Namespace in namespaceItems)
            {
                using (SqlDataReader reader = SqlHelper.ExecuteReader(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_LoadMetaFieldByNamespace"),
                                                                      new SqlParameter("@Namespace", Namespace), new SqlParameter("@Deep", false)))
                {
                    while (reader.Read())
                    {
                        retVal.Add(MetaField.Load(reader));
                    }
                }
            }

            return(retVal);
        }
예제 #4
0
        /// <summary>
        /// Get or create card field
        /// </summary>
        /// <param name="mdContext"></param>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        private MetaField GetOrCreateCardField(MetaDataContext mdContext, string fieldName)
        {
            var f = MetaField.Load(mdContext, fieldName);

            if (f == null)
            {
                Logger.Debug(string.Format("Adding meta field '{0}' for Netaxept integration.", fieldName));
                f = MetaField.Create(mdContext, NetaxeptConstants.OrderNamespace, fieldName, fieldName, string.Empty, MetaDataType.LongString, Int32.MaxValue, true, false, false, false);
            }
            return(f);
        }
예제 #5
0
        public virtual MetaField GetOrCreateMetaField(MetaDataContext mdContext, string metaNamespace, string fieldName, string friendlyName, MetaDataType metadataType, bool allowNulls, bool multiLanguage)
        {
            var f = MetaField.Load(mdContext, fieldName);

            if (f == null)
            {
                f = MetaField.Create(mdContext, metaNamespace, fieldName, friendlyName, string.Empty, metadataType, 0, allowNulls, multiLanguage, false, false);
            }

            return(f);
        }
예제 #6
0
        /// <summary>
        /// Loads the specified reader.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        public static MetaField Load(SqlDataReader reader)
        {
            #region ArgumentNullExceptions
            if (reader == null)
            {
                throw new ArgumentNullException("reader", AsyncResources.GetConstantValue("ARG_NULL_ERR_MSG"));
            }
            #endregion

            return(MetaField.Load(null, reader));
        }
예제 #7
0
        protected MetaField GetOrCreateCardField(MetaDataContext mdContext, string fieldName, MetaDataType metaDataType = MetaDataType.LongString)
        {
            var f = MetaField.Load(mdContext, fieldName);

            if (f == null)
            {
                Logger.Debug($"Adding meta field '{fieldName}' for {IntegrationName} integration.");
                f = MetaField.Create(mdContext, Common.Constants.OrderNamespace, fieldName, fieldName, string.Empty, metaDataType, Int32.MaxValue, true, false, false, false);
            }
            return(f);
        }
예제 #8
0
        /// <summary>
        /// Loads the specified meta field id.
        /// </summary>
        /// <param name="MetaFieldId">The meta field id.</param>
        /// <returns></returns>
        public static MetaField Load(int metaFieldId)
        {
            MetaField retVal = null;

            using (SqlDataReader reader = SqlHelper.ExecuteReader(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_LoadMetaField"),
                                                                  new SqlParameter("@MetaFieldId", metaFieldId)))
            {
                if (reader.Read())
                {
                    retVal = MetaField.Load(reader);
                }
                reader.Close();
            }

            return(retVal);
        }
예제 #9
0
        /// <summary>
        /// Gets the list.
        /// </summary>
        /// <returns></returns>
        public static MetaFieldCollection GetList()
        {
            MetaFieldCollection retVal = new MetaFieldCollection();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_LoadMetaFieldList")))
            {
                while (reader.Read())
                {
                    MetaField newItem = MetaField.Load(reader);
                    retVal.Add(newItem);
                }
                reader.Close();
            }

            return(retVal);
        }
예제 #10
0
        /// <summary>
        /// Creates the specified namespace.
        /// </summary>
        /// <param name="metaNamespace">The namespace.</param>
        /// <param name="name">The name.</param>
        /// <param name="friendlyName">Name of the friendly.</param>
        /// <param name="description">The description.</param>
        /// <param name="dataType">Type of the data.</param>
        /// <param name="length">The length.</param>
        /// <param name="allowNulls">if set to <c>true</c> [allow nulls].</param>
        /// <param name="saveHistory">if set to <c>true</c> [save history].</param>
        /// <param name="multilanguageValue">if set to <c>true</c> [multilanguage value].</param>
        /// <param name="allowSearch">if set to <c>true</c> [allow search].</param>
        /// <returns></returns>
        public static MetaField Create(
            string metaNamespace,
            string name,
            string friendlyName,
            string description,
            MetaDataType dataType,
            int length,
            bool allowNulls,
            bool saveHistory,
            bool multilanguageValue,
            bool allowSearch)
        {
            #region ArgumentNullExceptions
            if (metaNamespace == null)
            {
                throw new ArgumentNullException("Namespace", AsyncResources.GetConstantValue("ARG_NULL_ERR_MSG"));
            }
            if (name == null)
            {
                throw new ArgumentNullException("Name", AsyncResources.GetConstantValue("ARG_NULL_ERR_MSG"));
            }
            if (friendlyName == null)
            {
                throw new ArgumentNullException("FriendlyName", AsyncResources.GetConstantValue("ARG_NULL_ERR_MSG"));
            }
            #endregion

            SqlParameter Retval = new SqlParameter("@Retval", SqlDbType.Int, 4);
            Retval.Direction = ParameterDirection.Output;

            SqlHelper.ExecuteNonQuery(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_AddMetaField"),
                                      new SqlParameter("@Namespace", metaNamespace),
                                      new SqlParameter("@Name", name),
                                      new SqlParameter("@FriendlyName", friendlyName),
                                      new SqlParameter("@Description", description),
                                      new SqlParameter("@DataTypeId", (int)dataType),
                                      new SqlParameter("@Length", length),
                                      new SqlParameter("@AllowNulls", allowNulls),
                                      new SqlParameter("@SaveHistory", saveHistory),
                                      //new SqlParameter("@MultiLanguageValue", multilanguageValue),
                                      new SqlParameter("@AllowSearch", allowSearch),
                                      Retval
                                      );

            return(MetaField.Load((int)Retval.Value));
        }
예제 #11
0
        /// <summary>
        /// Loads the specified name.
        /// </summary>
        /// <param name="Name">The name.</param>
        /// <returns></returns>
        public static MetaField Load(string name)
        {
            #region ArgumentNullExceptions
            if (name == null)
            {
                throw new ArgumentNullException("Name", AsyncResources.GetConstantValue("ARG_NULL_ERR_MSG"));
            }
            #endregion

            MetaField retVal = null;
            using (SqlDataReader reader = SqlHelper.ExecuteReader(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_LoadMetaFieldByName"),
                                                                  new SqlParameter("@Name", name)))
            {
                if (reader.Read())
                {
                    retVal = MetaField.Load(reader);
                }
                reader.Close();
            }

            return(retVal);
        }
예제 #12
0
        private static MetaField LoadMetaFieldVersion10(XmlNode xmlMetaField)
        {
            string Name = xmlMetaField.SelectSingleNode("Name").InnerXml;

            MetaField mf = MetaField.Load(Name);

            if (mf == null)
            {
                mf = MetaField.Create(xmlMetaField.SelectSingleNode("Namespace").InnerXml,
                                      Name,
                                      xmlMetaField.SelectSingleNode("FriendlyName").InnerXml,
                                      xmlMetaField.SelectSingleNode("Description").InnerXml,
                                      (MetaDataType)Enum.Parse(typeof(MetaDataType), xmlMetaField.SelectSingleNode("DataType").InnerXml),
                                      Int32.Parse(xmlMetaField.SelectSingleNode("Length").InnerXml, _culture),
                                      bool.Parse(xmlMetaField.SelectSingleNode("AllowNulls").InnerXml),
                                      bool.Parse(xmlMetaField.SelectSingleNode("SaveHistory").InnerXml),
                                      bool.Parse(xmlMetaField.SelectSingleNode("AllowSearch").InnerXml),
                                      xmlMetaField.SelectSingleNode("MultiLanguageValue") != null?
                                      bool.Parse(xmlMetaField.SelectSingleNode("MultiLanguageValue").InnerXml):
                                      false
                                      );
            }
            else
            {
                if (mf.FriendlyName != xmlMetaField.SelectSingleNode("FriendlyName").InnerXml)
                {
                    mf.FriendlyName = xmlMetaField.SelectSingleNode("FriendlyName").InnerXml;
                }

                if (mf.Description != xmlMetaField.SelectSingleNode("Description").InnerXml)
                {
                    mf.Description = xmlMetaField.SelectSingleNode("Description").InnerXml;
                }

                if (mf.SaveHistory != bool.Parse(xmlMetaField.SelectSingleNode("SaveHistory").InnerXml))
                {
                    mf.SaveHistory = bool.Parse(xmlMetaField.SelectSingleNode("SaveHistory").InnerXml);
                }

                if (mf.AllowSearch != bool.Parse(xmlMetaField.SelectSingleNode("AllowSearch").InnerXml))
                {
                    mf.AllowSearch = bool.Parse(xmlMetaField.SelectSingleNode("AllowSearch").InnerXml);
                }
            }

            string strTag = xmlMetaField.SelectSingleNode("Tag").InnerXml;

            if (!string.IsNullOrEmpty(strTag))
            {
                mf.Tag = Convert.FromBase64String(strTag);
            }
            else
            {
                mf.Tag = null;
            }

            // Dictionary
            if (mf.Dictionary != null)
            {
                foreach (XmlNode dicItem in xmlMetaField.SelectNodes("Dictionary"))
                {
                    if (!mf.Dictionary.Contains(dicItem.InnerXml))
                    {
                        mf.Dictionary.Add(dicItem.InnerXml);
                    }
                }
            }

            return(mf);
        }