Example #1
0
        public int Get()
        {
            var SFclient      = new SalesForceClient(_configuration);
            var queryResponse = SFclient.ConnectandGet();

            return(queryResponse.Result.Length);
        }
    private EntityModel GetEntityModel(string name)
    {
        ISessionProvider sessionProvider = CreateSessionProvider();
        Session          session         = sessionProvider.CreateSession();
        SalesForceClient client          = new SalesForceClient(session);

        return(client.DescribeEntity(name));
    }
Example #3
0
        /// <summary>
        /// Create a new local project.
        /// </summary>
        public override void Execute()
        {
            SalesForceCredential credential = null;

            // get credentials for new project.
            EditSalesForceCredentialWindow dlg = new EditSalesForceCredentialWindow();

            dlg.Title = "New Project";
            while (App.ShowDialog(dlg))
            {
                try
                {
                    using (App.Wait("Verifying credentials..."))
                    {
                        credential = dlg.Credential;
                        SalesForceClient.TestLogin(credential);
                    }
                    break;
                }
                catch (Exception err)
                {
                    App.MessageUser(err.Message, "Login Failed", MessageBoxImage.Error, new string[] { "OK" });

                    dlg            = new EditSalesForceCredentialWindow();
                    dlg.Title      = "New Project";
                    dlg.Credential = credential;
                }
            }

            // create the new project or open an existing project that has the same credentials
            if (credential != null)
            {
                Project project = null;
                if (Project.ProjectExists(credential.Username))
                {
                    project            = Project.OpenProject(credential.Username);
                    project.Credential = credential;
                }
                else
                {
                    project = new Project(credential);
                }

                project.Save();

                App.Instance.SalesForceApp.OpenProject(project);
            }
        }
Example #4
0
    private string GetOrganizationName(OrganizationCredentials credentials, string organizationId)
    {
        RefreshTokenSessionProvider provider = new RefreshTokenSessionProvider
        {
            ClientId     = credentials.ClientId,
            ClientSecret = credentials.ClientSecret,
            RefreshToken = credentials.RefreshToken
        };
        Session              session           = provider.CreateSession();
        SalesForceClient     client            = new SalesForceClient(session);
        EntityModel          organizationModel = client.DescribeEntity("Organization");
        SelectEntitiesResult result            = client.SelectEntities(String.Format("select Name, Division from Organization where Id = '{0}'", organizationId), organizationModel);

        if (result.TotalEntityCount == 0)
        {
            return(String.Empty);
        }
        Entity        organization = result.Entities[0];
        string        name         = organization.GetAttributeValue <string>("Name");
        string        division     = organization.GetAttributeValue <string>("Division");
        StringBuilder builder      = new StringBuilder();

        if (!String.IsNullOrEmpty(name))
        {
            builder.Append(name);
        }
        if (!String.IsNullOrEmpty(division))
        {
            if (builder.Length > 0)
            {
                builder.AppendFormat("({0})", division);
            }
            else
            {
                builder.Append(division);
            }
        }

        return(builder.ToString());
    }
Example #5
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 });
        }
 public SIFInterface(AuthModel auth)
 {
     _auth   = auth;
     _client = new SalesForceClient(auth);
 }
    private string GetOrganizationName(OrganizationCredentials credentials, string organizationId)
    {
        RefreshTokenSessionProvider provider = new RefreshTokenSessionProvider
        {
            ClientId = credentials.ClientId,
            ClientSecret = credentials.ClientSecret,
            RefreshToken = credentials.RefreshToken
        };
        Session session = provider.CreateSession();
        SalesForceClient client = new SalesForceClient(session);
        EntityModel organizationModel = client.DescribeEntity("Organization");
        SelectEntitiesResult result = client.SelectEntities(String.Format("select Name, Division from Organization where Id = '{0}'", organizationId), organizationModel);
        if (result.TotalEntityCount == 0)
        {
            return String.Empty;
        }
        Entity organization = result.Entities[0];
        string name = organization.GetAttributeValue<string>("Name");
        string division = organization.GetAttributeValue<string>("Division");
        StringBuilder builder = new StringBuilder();
        if (!String.IsNullOrEmpty(name))
        {
            builder.Append(name);
        }
        if (!String.IsNullOrEmpty(division))
        {
            if (builder.Length > 0)
            {
                builder.AppendFormat("({0})", division);
            }
            else
            {
                builder.Append(division);
            }
        }

        return builder.ToString();
    }
        /// <summary>
        /// Open a new project.
        /// </summary>
        /// <param name="project">The project to open.</param>
        public void OpenProject(Project project)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }

            // check for existing project
            if (CurrentProject != null)
            {
                if (App.MessageUser("The current project must be closed before opening a new one.  Do you want to close the current project?",
                                    "Close Project",
                                    MessageBoxImage.Warning,
                                    new string[] { "Yes", "No" }) != "Yes")
                {
                    return;
                }

                CloseProject();
            }

            // test the credential
            SalesForceCredential credential = project.Credential;

            while (true)
            {
                try
                {
                    using (App.Wait("Verifying credentials..."))
                        SalesForceClient.TestLogin(credential);

                    using (App.Wait("Initializing project..."))
                    {
                        project.Repository.AuthorName  = project.Client.User.Name;
                        project.Repository.AuthorEmail = project.Client.UserEmail;
                        project.LoadSymbolsAsync(false);
                    }

                    break;
                }
                catch (Exception err)
                {
                    App.MessageUser(err.Message, "Login Failed", MessageBoxImage.Error, new string[] { "OK" });

                    EditSalesForceCredentialWindow dlg = new EditSalesForceCredentialWindow();
                    dlg.Credential = credential;
                    dlg.Title      = "Enter credentials";

                    if (!App.ShowDialog(dlg))
                    {
                        return;
                    }

                    credential         = dlg.Credential;
                    project.Credential = credential;
                    project.Save();
                }
            }

            // open the project
            using (App.Wait("Opening project..."))
            {
                CurrentProject            = project;
                App.Instance.SessionTitle = project.Credential.Username;

                App.Instance.Navigation.Nodes.Add(new SourceFolderNode(project));
                App.Instance.Navigation.Nodes.Add(new DataFolderNode(project));
                App.Instance.Navigation.Nodes.Add(new LocalFolderNode(project));

                App.Instance.Menu.UpdateFunctions();
                App.Instance.ToolBar.UpdateFunctions();

                App.Instance.GetFunction <InsertSnippetContainerFunction>().Refresh(App.Instance.Menu);
            }
        }
    private EntityModel GetEntityModel(string name)
    {
        ISessionProvider sessionProvider = CreateSessionProvider();
        Session session = sessionProvider.CreateSession();
        SalesForceClient client = new SalesForceClient(session);

        return client.DescribeEntity(name);
    }