예제 #1
0
        /// <summary>
        /// Create a new checkpoint.
        /// </summary>
        /// <param name="file">The file to create a checkpoint in.</param>
        /// <param name="lineNumber">The line number in the file to create the checkpoint for.</param>
        /// <param name="iteration">The number of iterations before the checkpoint is processed.</param>
        /// <param name="isHeapDump">If true a heap dump will be collected with the checkpoint.</param>
        /// <param name="script">An optional script to run with the checkpoint.</param>
        /// <param name="scriptType">The type of script specified.</param>
        /// <returns>The newly created checkpoint.</returns>
        public Checkpoint CreateCheckpoint(
            SourceFile file,
            int lineNumber,
            int iteration,
            bool isHeapDump,
            string script,
            CheckpointScriptType scriptType)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            // get record id
            string entityId = null;

            switch (file.FileType.Name)
            {
            case "ApexClass":
            case "ApexTrigger":
                DataSelectResult objectQueryResult = _client.Data.Select(String.Format("SELECT id FROM {0} WHERE Name = '{1}'", file.FileType.Name, file.Name));
                if (objectQueryResult.Data.Rows.Count > 0)
                {
                    entityId = objectQueryResult.Data.Rows[0]["id"] as string;
                }
                break;

            default:
                throw new Exception("Unsupported type: " + file.FileType.Name);
            }

            if (entityId == null)
            {
                throw new Exception("Couldn't get id for: " + file.Name);
            }

            return(CreateCheckpoint(
                       entityId,
                       file.Name,
                       lineNumber,
                       iteration,
                       isHeapDump,
                       script,
                       scriptType));
        }
예제 #2
0
        /// <summary>
        /// Create a new checkpoint.
        /// </summary>
        /// <param name="entityId">The id of the file to create a checkpoint in.</param>
        /// <param name="fileName">The name of the file to create a checkpoint in.</param>
        /// <param name="lineNumber">The line number in the file to create the checkpoint for.</param>
        /// <param name="iteration">The number of iterations before the checkpoint is processed.</param>
        /// <param name="isHeapDump">If true a heap dump will be collected with the checkpoint.</param>
        /// <param name="script">An optional script to run with the checkpoint.</param>
        /// <param name="scriptType">The type of script specified.</param>
        /// <returns>The newly created checkpoint.</returns>
        private Checkpoint CreateCheckpoint(
            string entityId,
            string fileName,
            int lineNumber,
            int iteration,
            bool isHeapDump,
            string script,
            CheckpointScriptType scriptType)
        {
            if (entityId == null)
            {
                throw new ArgumentNullException("entityId");
            }

            SalesForceAPI.Tooling.ApexExecutionOverlayAction action = new SalesForceAPI.Tooling.ApexExecutionOverlayAction();
            action.ActionScript            = script;
            action.ActionScriptType        = scriptType.ToString();
            action.ExecutableEntityId      = entityId;
            action.ExpirationDate          = DateTime.Now.AddDays(1);
            action.ExpirationDateSpecified = true;
            action.IsDumpingHeap           = isHeapDump;
            action.IsDumpingHeapSpecified  = true;
            action.Iteration          = iteration;
            action.IterationSpecified = true;
            action.Line          = lineNumber;
            action.LineSpecified = true;
            action.ScopeId       = _client.User.Id;

            SalesForceAPI.Tooling.createResponse response = _client.ToolingClient.create(new SalesForceAPI.Tooling.createRequest(
                                                                                             new SalesForceAPI.Tooling.SessionHeader()
            {
                sessionId = _client.SessionId
            },
                                                                                             new SalesForceAPI.Tooling.sObject[]
            {
                action
            }));

            if (response != null && response.result != null && response.result.Length == 1)
            {
                if (!response.result[0].success)
                {
                    StringBuilder sb = new StringBuilder();
                    if (response.result[0].errors != null)
                    {
                        foreach (SalesForceAPI.Tooling.Error err in response.result[0].errors)
                        {
                            sb.AppendLine(err.message);
                        }
                    }

                    throw new Exception("Couldn't create checkpoint: \r\n" + sb.ToString());
                }
            }
            else
            {
                throw new Exception("Couldn't create checkpoint: Invalid response received.");
            }

            action.Id = response.result[0].id;

            return(new Checkpoint(action, fileName));
        }