private string GetDatatypeForContentType(Field field)
 {
     if (field.Fieldmetadata.RefMultipleContentType == false && !field.ReferenceTo.GetType().IsArray)
     {
         string      referenceTo = (string)(field.ReferenceTo);
         Contenttype contentType = _contentTypes.FirstOrDefault(c => c.Uid == referenceTo);
         if (contentType != null)
         {
             return(FormatClassName(contentType.Title));
         }
     }
     else if (field.ReferenceTo.GetType() == typeof(JArray))
     {
         JArray array = field.ReferenceTo as JArray;
         if (array.Count == 1)
         {
             string      referenceTo = (string)(array.First);
             Contenttype contentType = _contentTypes.FirstOrDefault(c => c.Uid == referenceTo);
             if (contentType != null)
             {
                 return(FormatClassName(contentType.Title));
             }
         }
     }
     return("object");
 }
Example #2
0
        public static ERPTopic_content Create(Contenttype contenttype, string content)

        {
            ERPTopic_content obj = new ERPTopic_content();

            obj.content_type = contenttype;
            obj.content      = content;
            return(obj);
        }
        private void CreateModularFile(string contentTypeName, string nameSpace, Contenttype contentType, DirectoryInfo directoryInfo, string extendsClass = null)
        {
            Console.WriteLine($"Extracting Modular Blocks in {contentTypeName}.");

            // Get modular Block within ContentType
            var    usingDirectiveList    = new List <string>();
            string modularUsingDirective = CreateModularBlocks(nameSpace, contentTypeName, contentType.Schema, directoryInfo);

            if (modularUsingDirective != null)
            {
                usingDirectiveList.Add(modularUsingDirective);
            }

            Console.WriteLine($"Extracting Groups in {contentTypeName}.");

            string groupUsingDirective = CreateGroup(nameSpace, contentTypeName, contentType.Schema, directoryInfo);

            usingDirectiveList.Add(groupUsingDirective);

            // Create File for ContentType
            var file = shouldCreateFile(contentTypeName, directoryInfo);

            if (file != null)
            {
                using (var sw = file.CreateText())
                {
                    var sb = new StringBuilder();
                    // Adding using at start of file
                    AddUsingDirectives(usingDirectiveList, sb);

                    // Creating namespace
                    AddNameSpace($"{nameSpace}.{directoryInfo.Name}", sb);

                    // Creating Class
                    AddClass(extendsClass != null ? $"{contentTypeName} : {extendsClass}" : contentTypeName, sb);

                    //Adding Params to contentType
                    AddParams(contentTypeName, contentType.Schema, sb);

                    // End of namespace and class
                    AddEnd(sb);

                    // write to file
                    sw.WriteLine(sb.ToString());
                }
            }
        }
Example #4
0
        public static ERPCourse_activity Create(string enrollment, string course, string student, Contenttype contenttype, string content, string activitydate)

        {
            ERPCourse_activity obj = new ERPCourse_activity();

            obj.enrollment    = enrollment;
            obj.course        = course;
            obj.student       = student;
            obj.content_type  = contenttype;
            obj.content       = content;
            obj.activity_date = activitydate;
            return(obj);
        }
        private void CreateFile(string contentTypeName, string nameSpace, Contenttype contentType, DirectoryInfo directoryInfo)
        {
            Console.WriteLine($"Extracting Modular Blocks in {contentTypeName}.");

            var fields = findRTEReference(contentType.Schema);

            // Get modular Block within ContentType
            var    usingDirectiveList    = new List <string>();
            string modularUsingDirective = CreateModularBlocks(nameSpace, contentTypeName, contentType.Schema, directoryInfo);

            if (modularUsingDirective != null)
            {
                usingDirectiveList.Add(modularUsingDirective);
            }

            Console.WriteLine($"Extracting Groups in {contentTypeName}.");

            string groupUsingDirective = CreateGroup(nameSpace, contentTypeName, contentType.Schema, directoryInfo);

            usingDirectiveList.Add(groupUsingDirective);

            // Create File for ContentType
            var file = shouldCreateFile(contentTypeName, directoryInfo);

            if (file != null)
            {
                using (var sw = file.CreateText())
                {
                    var sb = new StringBuilder();
                    // Adding using at start of file
                    AddUsingDirectives(usingDirectiveList, sb);

                    // Creating namespace
                    AddNameSpace($"{nameSpace}.{directoryInfo.Name}", sb);
                    sb.AppendLine("using Contentstack.Utils.Interfaces;");

                    var extendsClass = "IEmbeddedObject";

                    if (fields == true)
                    {
                        extendsClass = "IEntryEmbedable, IEmbeddedObject";
                    }

                    // Creating Class
                    AddClass(extendsClass != null ? $"{contentTypeName} : {extendsClass}" : contentTypeName, sb);

                    // Add Const
                    sb.AppendLine($"        public const string ContentType = \"{contentType.Uid}\";");
                    sb.AppendLine($"        public string Uid {{ get; set; }}");
                    sb.AppendLine($"        [JsonProperty(propertyName: \"_content_type_uid\")]");
                    sb.AppendLine($"        public string ContentTypeUid {{ get; set; }}");

                    //Adding Params to contentType
                    AddParams(contentTypeName, contentType.Schema, sb);

                    if (fields == true)
                    {
                        sb.AppendLine($"        [JsonProperty(propertyName: \"_embedded_items\")]");
                        sb.AppendLine("        public Dictionary<string, List<IEmbeddedObject>> embeddedItems { get; set; }");
                    }

                    // End of namespace and class
                    AddEnd(sb);

                    // write to file
                    sw.WriteLine(sb.ToString());
                }
            }
        }