Example #1
0
        public void CreateOfflineSymbolTable(List <string> sobjectList)
        {
            var nameSpace = ConnectionUtil.GetSession().VsProjectName + ".SObjects";

            Parallel.ForEach(sobjectList, (sobject) =>
            {
                HttpManager httpManager = new HttpManager();
                var objectDetailjson    = httpManager.Get($"sobjects/{sobject}/describe");

                SObjectDetail sObjectDetail = JsonConvert.DeserializeObject <SObjectDetail>(objectDetailjson);

                objectDetailjson  = JsonConvert.SerializeObject(sObjectDetail, Formatting.Indented);
                var cacheLocation = Path.Combine(ConnectionUtil.GetSession().VsProjectLocation, "Cache");
                var jsonFileName  = cacheLocation + "/" + sobject + ".json";
                File.WriteAllText(jsonFileName, objectDetailjson);

                var sObjectClass = CreateSalesForceClasses(nameSpace, sObjectDetail);

                var sobjectLocation = Path.Combine(ConnectionUtil.GetSession().VsProjectLocation, "SObjects");
                var saveFileName    = sobjectLocation + "\\" + sobject + ".cs";
                File.WriteAllText(saveFileName, sObjectClass);

                Log.ForContext <ModelGen>().Debug("Saved {sobject}", saveFileName);
            });
        }
Example #2
0
        internal List <string> GetReferencedSObjects(SObjectDetail sobject)
        {
            var refs =
                from field in sobject.fields
                where field.type == ReferenceType &&
                field.referenceTo != null &&
                field.referenceTo.Any() &&
                !string.IsNullOrWhiteSpace(field.relationshipName)
                select field.referenceTo[0];

            return(refs.Distinct().ToList());
        }
Example #3
0
        private string CreateSalesForceClasses(string nameSpace, SObjectDetail objectDetail)
        {
            var sb = new StringBuilder();

            sb.AppendLine("namespace " + nameSpace);
            sb.AppendLine("{");
            sb.AppendLine("\tusing Apex.System;");
            sb.AppendLine("\tusing ApexSharpApi.ApexApi;");
            sb.AppendLine();
            sb.AppendLine($"\tpublic class {objectDetail.name} : SObject");
            sb.AppendLine("\t{");

            var setGet = "{set;get;}";

            foreach (var objectField in objectDetail.fields)
            {
                if ((objectField.type == "reference") && (objectField.name == "OwnerId") && (objectField.referenceTo.Length > 1))
                {
                    sb.AppendLine($"\t\tpublic string {objectField.name} {setGet}");

                    sb.AppendLine($"\t\tpublic {objectField.referenceTo[1]} {objectField.relationshipName} {setGet}");
                }
                else if (objectField.type == "reference" && objectField.referenceTo.Length > 0)
                {
                    sb.AppendLine($"\t\tpublic string {objectField.name} {setGet}");

                    if (objectField.relationshipName != null)
                    {
                        sb.AppendLine($"\t\tpublic {objectField.referenceTo[0]} {objectField.relationshipName} {setGet}");
                    }
                }
                else if (objectField.type != "id")
                {
                    sb.AppendLine($"\t\tpublic {GetField(objectField)} {objectField.name} {setGet}");
                }
            }

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

            return(sb.ToString());
        }
Example #4
0
        internal string CreateSalesForceClass(string nameSpace, SObjectDetail objectDetail, bool orm = false)
        {
            var sb = new StringBuilder();

            sb.AppendLine("namespace " + nameSpace);
            sb.AppendLine("{");
            sb.AppendLine("\tusing Apex.System;");
            sb.AppendLine("\tusing ApexSharpApi.ApexApi;");
            sb.AppendLine("\tusing ApexSharpApi.Attributes;");
            if (orm)
            {
                sb.AppendLine("\tusing ServiceStack.DataAnnotations;");
            }

            sb.AppendLine("\tusing DateTime = global::System.DateTime;");
            sb.AppendLine();
            sb.AppendLine($"\tpublic class {objectDetail.name} : SObject");
            sb.AppendLine("\t{");

            var setGet = "{set;get;}";

            // Add a different name for ID if we are going to use SF Id as SF Id is different between systems
            if (orm)
            {
                sb.AppendLine($"\t\t[PrimaryKey]");
                sb.AppendLine($"\t\t[AutoIncrement]");
            }

            sb.AppendLine($"\t\tpublic int ExternalId {setGet}");

            foreach (var objectField in objectDetail.fields)
            {
                if ((objectField.type == ReferenceType) && (objectField.name == "OwnerId") && (objectField.referenceTo.Length > 1))
                {
                    AddApexIdAttribute(sb, objectField.relationshipName, orm);
                    AddStringLengthAttribute(sb, IdStringLength, orm);
                    AddIgnoreUpdateAttribute(sb, objectField.createable);
                    sb.AppendLine($"\t\tpublic string {objectField.name} {setGet}");

                    AddIgnoreAttribute(sb, orm);
                    sb.AppendLine($"\t\tpublic {objectField.referenceTo[1]} {objectField.relationshipName} {setGet}");
                }
                else if (objectField.type == ReferenceType && objectField.referenceTo.Length > 0)
                {
                    AddApexIdAttribute(sb, objectField.relationshipName, orm);
                    AddStringLengthAttribute(sb, IdStringLength, orm);
                    AddIgnoreUpdateAttribute(sb, objectField.createable);
                    sb.AppendLine($"\t\tpublic string {objectField.name} {setGet}");

                    if (objectField.relationshipName != null)
                    {
                        AddIgnoreAttribute(sb, orm);
                        sb.AppendLine($"\t\tpublic {objectField.referenceTo[0]} {objectField.relationshipName} {setGet}");
                    }
                }
                else if (objectField.type != "id")
                {
                    AddStringLengthAttribute(sb, objectField, orm);
                    AddIgnoreUpdateAttribute(sb, objectField.createable);
                    sb.AppendLine($"\t\tpublic {GetFieldType(objectField, objectDetail.name)} {objectField.name} {setGet}");
                }
            }

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

            return(sb.ToString());
        }