Example #1
0
        /// <summary>
        /// Parses an object.
        /// </summary>
        /// <returns></returns>
        SType ParseObject()
        {
            s_cachedObject = false;

            SType row;
            var   obj = new SObjectType();

            Parse(obj);

            if (obj.IsCachedMethodCallResult || obj.IsCachedObject || obj.IsKeyVal)
            {
                obj.AddMember(GetObject());
            }

            if (obj.IsObjectCachingCachedObject)
            {
                s_cachedObject = true;
                obj.AddMember(new SCachedObjectType(GetObject()));
            }

            if (obj.IsRowList || obj.IsCRowset)
            {
                do
                {
                    row = GetObject();
                    obj.AddMember(row);
                } while (row != null); // Null object is marker

                // Check for sequencial marker
                if (GetObject() != null)
                {
                    throw new ParserException("Marker was expected but not found");
                }
            }

            if (!obj.IsCFilterRowset && !obj.IsRowDict && !obj.IsCIndexedRowset)
            {
                return(obj);
            }

            // Check for single marker
            if (GetObject() != null)
            {
                return(obj);
            }
            do
            {
                row = GetObject();
                obj.AddMember(row);
            } while (row != null); // Null object is marker

            return(obj);
        }
Example #2
0
        /// <summary>
        /// Gets the children.
        /// </summary>
        /// <returns>The resulting children.</returns>
        public override INode[] GetChildren()
        {
            List<INode> nodes = new List<INode>();

            SObjectType fullObject = Project.Client.Data.DescribeObjectType(DataObject);
            foreach (SObjectFieldType field in fullObject.Fields.OrderBy(f => f.Name))
                nodes.Add(new DataObjectFieldNode(Project, field));

            Project.Language.UpdateSymbols(
                Project.ConvertToSymbolTable(fullObject),
                true,
                true,
                false);

            return nodes.ToArray();
        }
Example #3
0
        /// <summary>
        /// Checks to see if symbols have already been downloaded.  If they haven't, they are loaded from the server
        /// in the background.
        /// </summary>
        /// <param name="forceReload">If true the symbols will be loaded even if there are already symbols present.</param>
        public void LoadSymbolsAsync(bool forceReload)
        {
            if (_symbolsDownloading)
            {
                return;
            }

            _symbolsDownloading    = true;
            _symbolsDownloadCancel = false;

            ThreadPool.QueueUserWorkItem(
                (state) =>
            {
                try
                {
                    // download apex, parse it and then save to cache
                    if (forceReload || FileUtility.IsFolderEmpty(SymbolsFolder))
                    {
                        App.Instance.Dispatcher.Invoke(() => App.SetStatus("Downloading symbols and updating search index..."));

                        object[] parameters      = state as object[];
                        Project project          = parameters[0] as Project;
                        SalesForceClient client  = parameters[1] as SalesForceClient;
                        LanguageManager language = parameters[2] as LanguageManager;

                        SearchIndex searchIndex = new SearchIndex(project.SearchFolder, true);

                        try
                        {
                            project._symbolsDownloaded.Reset();

                            // get class ids
                            DataSelectResult data   = client.Data.Select("SELECT Id FROM ApexClass");
                            Queue <string> classIds = new Queue <string>();
                            foreach (DataRow row in data.Data.Rows)
                            {
                                classIds.Enqueue(row["Id"] as string);
                            }

                            // download classes in groups of 25
                            while (classIds.Count > 0)
                            {
                                if (project._symbolsDownloadCancel)
                                {
                                    break;
                                }

                                StringBuilder query = new StringBuilder("SELECT Id, Name, Body FROM ApexClass WHERE Id IN (");
                                for (int i = 0; i < 25 && classIds.Count > 0; i++)
                                {
                                    query.AppendFormat("'{0}',", classIds.Dequeue());
                                }

                                query.Length = query.Length - 1;
                                query.Append(")");

                                DataSelectResult classData = client.Data.Select(query.ToString());
                                foreach (DataRow row in classData.Data.Rows)
                                {
                                    string body      = row["Body"] as string;
                                    bool isGenerated = false;

                                    if (body == "(hidden)")
                                    {
                                        body        = Client.Meta.GetGeneratedContent(row["Id"] as string);
                                        isGenerated = true;
                                    }

                                    // parse symbols
                                    language.ParseApex(body, false, true, isGenerated);

                                    // add to search index
                                    searchIndex.Add(
                                        row["Id"] as string,
                                        String.Format("classes/{0}.cls", row["Name"]),
                                        "ApexClass",
                                        row["Name"] as string,
                                        body);
                                }
                            }

                            // download symbols for SObjects
                            if (!project._symbolsDownloadCancel)
                            {
                                SObjectTypePartial[] sObjects = client.Data.DescribeGlobal();
                                foreach (SObjectTypePartial sObject in sObjects)
                                {
                                    if (project._symbolsDownloadCancel)
                                    {
                                        break;
                                    }

                                    SObjectType sObjectDetail = client.Data.DescribeObjectType(sObject);

                                    language.UpdateSymbols(
                                        ConvertToSymbolTable(sObjectDetail),
                                        false,
                                        true,
                                        false);
                                }
                            }

                            // remove symbols and search index if the download was interupted
                            if (_symbolsDownloadCancel)
                            {
                                if (searchIndex != null)
                                {
                                    searchIndex.Clear();
                                }

                                FileUtility.DeleteFolderContents(project.SymbolsFolder);
                            }
                        }
                        finally
                        {
                            if (searchIndex != null)
                            {
                                searchIndex.Dispose();
                            }

                            project._symbolsDownloaded.Set();
                        }
                    }
                    // load cached symbols
                    else
                    {
                        App.Instance.Dispatcher.Invoke(() => App.SetStatus("Loading symbols..."));

                        XmlSerializer ser = new XmlSerializer(typeof(SymbolTable));

                        foreach (string file in Directory.GetFiles(SymbolsFolder))
                        {
                            using (FileStream fs = File.OpenRead(file))
                            {
                                SymbolTable st = ser.Deserialize(fs) as SymbolTable;
                                Language.UpdateSymbols(st, false, false, false);
                                fs.Close();
                            }
                        }
                    }
                }
                catch (Exception err)
                {
                    App.Instance.Dispatcher.Invoke(() => App.HandleException(err));
                }
                finally
                {
                    App.Instance.Dispatcher.Invoke(() => App.SetStatus(null));
                    _symbolsDownloading = false;
                }
            },
                new object[] { this, Client, Language });
        }
Example #4
0
        /// <summary>
        /// Convert an sObject type to a SymbolTable.
        /// </summary>
        /// <param name="objectType">The sObject type to convert.</param>
        /// <returns>The newly created symbol table.</returns>
        public static SymbolTable ConvertToSymbolTable(SObjectType objectType)
        {
            List <Field> fields = new List <Field>();

            foreach (SObjectFieldType sObjectField in objectType.Fields)
            {
                string fieldType = null;
                switch (sObjectField.FieldType)
                {
                case FieldType.String:
                case FieldType.Picklist:
                case FieldType.MultiPicklist:
                case FieldType.Combobox:
                case FieldType.TextArea:
                case FieldType.Phone:
                case FieldType.Url:
                case FieldType.Email:
                case FieldType.EncryptedString:
                    fieldType = "System.String";
                    break;

                case FieldType.Id:
                case FieldType.Reference:
                    fieldType = "System.Id";
                    break;

                case FieldType.Date:
                    fieldType = "System.Date";
                    break;

                case FieldType.DateTime:
                    fieldType = "System.DateTime";
                    break;

                case FieldType.Time:
                    fieldType = "System.Time";
                    break;

                case FieldType.Base64:
                    fieldType = "System.Long";
                    break;

                case FieldType.Double:
                case FieldType.Percent:
                    fieldType = "System.Double";
                    break;

                case FieldType.Boolean:
                    fieldType = "System.Boolean";
                    break;

                case FieldType.Int:
                case FieldType.Currency:
                    fieldType = "System.Integer";
                    break;

                default:
                    break;
                }

                // add the field
                fields.Add(new Field(
                               new TextPosition(0, 0),
                               sObjectField.Name,
                               null,
                               SymbolModifier.Public,
                               fieldType,
                               false));

                // add reference field if appropriate
                if (sObjectField.FieldType == FieldType.Reference &&
                    sObjectField.ReferenceTo != null &&
                    sObjectField.ReferenceTo.Length > 0)
                {
                    if (sObjectField.Name.EndsWith("__c", StringComparison.CurrentCultureIgnoreCase))
                    {
                        fields.Add(new Field(
                                       new TextPosition(0, 0),
                                       sObjectField.Name.Replace("__c", "__r"),
                                       null,
                                       SymbolModifier.Public,
                                       sObjectField.ReferenceTo[0],
                                       false));
                    }
                    else if (sObjectField.Name.EndsWith("Id", StringComparison.CurrentCultureIgnoreCase))
                    {
                        fields.Add(new Field(
                                       new TextPosition(0, 0),
                                       sObjectField.Name.Substring(0, sObjectField.Name.Length - 2),
                                       null,
                                       SymbolModifier.Public,
                                       sObjectField.ReferenceTo[0],
                                       false));
                    }
                }
            }

            // add child relationships as fields
            foreach (KeyValuePair <string, string> kvp in objectType.ChildRelationships)
            {
                fields.Add(new Field(
                               new TextPosition(0, 0),
                               kvp.Key,
                               null,
                               SymbolModifier.Public,
                               String.Format("{0}[]", kvp.Value),
                               false));
            }

            // return the symbol table
            return(new SymbolTable(new TextPosition(0, 0),
                                   objectType.Name,
                                   null,
                                   null,
                                   SymbolModifier.Public,
                                   SymbolTableType.SObject,
                                   null,
                                   fields.ToArray(),
                                   null,
                                   null,
                                   null,
                                   "System.sObject",
                                   null,
                                   null));
        }
Example #5
0
 public static List <SObject> loadData(SObjectType sObjectToken, string resourceName)
 {
     return(Implementation.loadData(sObjectToken, resourceName));
 }