Exemplo n.º 1
0
        internal void GenerateCSharp(SharePointContents spContents)
        {
            try
            {
                LogWarning($"Generate C# to {CSharpFile} disk");

                StringBuilder sb = new StringBuilder();

                sb.AppendLine("namespace " + spContents.ApplicationName + "Entities");
                sb.AppendLine("{");
                sb.AppendLine("\t//Autogen'ed from Data on: " + DateTime.Now.ToString());
                sb.AppendLine();

                foreach (SharePointList spList in spContents.SharePointLists)
                {
                    sb.AppendLine("\tpublic class " + spContents.ApplicationName + "Entities_" + spList.Name);
                    sb.AppendLine("\t{");

                    sb.AppendLine("\t\tpublic const string ListName = \"" + spList.Name + "\";");
                    sb.AppendLine();

                    foreach (SharePointColumn spColumn in spList.SharePointColumns)
                    {
                        sb.AppendLine("\t\tpublic const string " + spColumn.Name + " = \"" + spColumn.Name + "\";");
                    }

                    sb.AppendLine("\t\tpublic const string " + spList.TitleName + " = \"Title\";");

                    sb.AppendLine("\t}");
                }
                sb.AppendLine("}");

                using (StreamWriter swFile = new StreamWriter($"{CSharpFile}_Entities.cs", false))
                {
                    swFile.Write(sb.ToString());
                }

                LogVerbose("Completed generate C#");
            }
            catch (Exception ex)
            {
                LogError(ex, ex.Message);
            }
        }
Exemplo n.º 2
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            var siteUrl = ClientContext.Url;
            var dtStart = DateTime.Now;
            var strJSON = string.Empty;

            // Read file
            using (StreamReader sr = new StreamReader(JSONFile))
            {
                strJSON = sr.ReadToEnd();
            }

            // Process the JSON
            var jsSerializer = new JavaScriptSerializer();
            SharePointContents spContents = (SharePointContents)jsSerializer.Deserialize(strJSON, typeof(SharePointContents));


            foreach (SharePointList spList in spContents.SharePointLists)
            {
                if (!spList.Ignore)
                {
                    // delete list, using new context
                    using (var cContext = this.ClientContext.Clone(siteUrl))
                    {
                        DeleteList(cContext, spList.Name);
                    }

                    // add list, using new context
                    using (var cContext = this.ClientContext.Clone(siteUrl))
                    {
                        CreateList(cContext, spList.Name, spList.Type);
                    }

                    // modify list and data, using new context
                    using (var cContext = this.ClientContext.Clone(siteUrl))
                    {
                        if (spList.TitleName != null && spList.TitleName != string.Empty)
                        {
                            if (spList.TitleName != "DELETE")
                            {
                                RenameTitle(cContext, spList);
                            }
                            else
                            {
                                DeleteTitle(cContext, spList);
                            }
                        }
                        else
                        {
                            spList.TitleName = "Title";
                        }

                        foreach (SharePointColumn spColumn in spList.SharePointColumns)
                        {
                            AddColumn(cContext, spColumn.Name, spColumn.Type, spList.Name, spColumn.Parent, spColumn.Data);
                        }

                        AddReferenceData(cContext, spList);
                    }
                }
            }

            //Optional, creates c# class
            if (!string.IsNullOrEmpty(CSharpFile))
            {
                GenerateCSharp(spContents);
            }

            LogVerbose($"DONE! {(DateTime.Now - dtStart).TotalSeconds.ToString()} seconds");
        }