public static Int32 ImportApplication(IRSAPIClient client, Int32 workspaceId, bool forceFlag, string filePath, string applicationName, int appArtifactID = -1)
        {
            Console.WriteLine("Starting Import Application.....");
            int artifactID = 0;

            client.APIOptions.WorkspaceID = workspaceId;             //set the target workspace of application to be imported.

            // Create an application install request.
            // This list contains the ArtifactID for each Relativity Application that you want to install.
            List <int> appsToOverride = new List <int>();

            // Set the forceFlag to true. The forceFlag unlocks any applications in the workspace
            // that conflict with the application that you are loading. The applications must be unlocked
            // for the install operation to succeed.

            AppInstallRequest appInstallRequest = new AppInstallRequest();

            appInstallRequest.FullFilePath = filePath;
            appInstallRequest.ForceFlag    = forceFlag;
            appInstallRequest.AppsToOverride.Add(appArtifactID);

            try
            {
                ProcessOperationResult por = null;
                por = client.InstallApplication(client.APIOptions, appInstallRequest);

                if (por.Success)
                {
                    while (client.GetProcessState(client.APIOptions, por.ProcessID).State == ProcessStateValue.Running)
                    {
                        Thread.Sleep(10);
                    }

                    client.GetProcessState(client.APIOptions, por.ProcessID);
                    Console.WriteLine("Import Application Application complete.....");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed to import Application" + ex.Message);
            }

            Console.WriteLine("Querying for Application artifact id....");
            kCura.Relativity.Client.DTOs.Query <kCura.Relativity.Client.DTOs.RelativityApplication> query = new kCura.Relativity.Client.DTOs.Query <kCura.Relativity.Client.DTOs.RelativityApplication>();
            query.Fields.Add(new FieldValue(RelativityApplicationFieldNames.Name));
            query.Condition = new kCura.Relativity.Client.TextCondition(RelativityApplicationFieldNames.Name, kCura.Relativity.Client.TextConditionEnum.EqualTo, applicationName);
            kCura.Relativity.Client.DTOs.QueryResultSet <kCura.Relativity.Client.DTOs.RelativityApplication> queryResultSet = client.Repositories.RelativityApplication.Query(query);

            if (queryResultSet != null)
            {
                artifactID = queryResultSet.Results.FirstOrDefault().Artifact.ArtifactID;
                Console.WriteLine("Application artifactid is " + artifactID);
            }

            Console.WriteLine("Exiting Import Application method.....");
            return(artifactID);
        }
        /// <summary>
        /// Creates a testing workspace and installs the DynamicAPI application
        /// </summary>
        private void SetupWorkspaceAndRapFile()
        {
            using (IRSAPIClient rsapiClient = GetServiceFactory().CreateProxy <IRSAPIClient>())
            {
                try
                {
                    Console.WriteLine("Starting Import Application.....");
                    rsapiClient.APIOptions.WorkspaceID = _dynamicApiWorkspaceId;

                    AppInstallRequest appInstallRequest = new AppInstallRequest();
                    int appArtifactID = -1;

                    appInstallRequest.FullFilePath = _dapiRapFullFilePath;
                    appInstallRequest.ForceFlag    = true;
                    appInstallRequest.AppsToOverride.Add(appArtifactID);

                    ProcessOperationResult por = rsapiClient.InstallApplication(rsapiClient.APIOptions, appInstallRequest);

                    if (por.Success)
                    {
                        ProcessInformation state;
                        do
                        {
                            Thread.Sleep(10);
                            state = rsapiClient.GetProcessState(rsapiClient.APIOptions, por.ProcessID);
                        } while (state.State == ProcessStateValue.Running);

                        if (state.State == ProcessStateValue.CompletedWithError)
                        {
                            throw new Exception(state.Message ?? state.Status ?? "The install completed an unknown error");
                        }
                        else if (state.State == ProcessStateValue.HandledException || state.State == ProcessStateValue.UnhandledException)
                        {
                            throw new Exception(state.Message ?? state.Status ?? "The install failed with a unknown error");
                        }
                    }
                    else
                    {
                        throw new Exception($"There was an error installing the application {por.Message}");
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception($"{nameof(SetupWorkspaceAndRapFile)} - Could not create or find Workspace and Application: {ex.Message}");
                }
            }
        }
Esempio n. 3
0
        public static void ImportApplication(IRSAPIClient client, Int32 workspaceId, bool forceFlag, string filePath, int appArtifactID = -1)
        {
            Console.WriteLine("Starting Import Application.....");
            client.APIOptions.WorkspaceID = workspaceId; //set the target workspace of application to be imported.

            // Set the forceFlag to true. The forceFlag unlocks any applications in the workspace
            // that conflict with the application that you are loading. The applications must be unlocked
            // for the install operation to succeed.

            var appInstallRequest = new AppInstallRequest();

            appInstallRequest.FullFilePath = filePath;
            appInstallRequest.ForceFlag    = forceFlag;
            appInstallRequest.AppsToOverride.Add(appArtifactID);

            var por = client.InstallApplication(client.APIOptions, appInstallRequest);

            if (por.Success)
            {
                ProcessInformation state;
                do
                {
                    Thread.Sleep(10);
                    state = client.GetProcessState(client.APIOptions, por.ProcessID);
                } while (state.State == ProcessStateValue.Running);

                if (state.State == ProcessStateValue.CompletedWithError)
                {
                    throw new ApplicationInstallException(state.Message ?? state.Status ?? "The install completed an unknown error");
                }
                else if (state.State == ProcessStateValue.HandledException || state.State == ProcessStateValue.UnhandledException)
                {
                    throw new ApplicationInstallException(state.Message ?? state.Status ?? "The install failed with a unknown error");
                }
            }
            else
            {
                throw new ApplicationInstallException($"There was an error installing the application {por.Message}");
            }
        }
        private static int CreateInternal(IRSAPIClient proxy, string workspaceName, string templateName, int?serverId)
        {
            var oldWorkspaceId = proxy.APIOptions.WorkspaceID;

            try
            {
                proxy.APIOptions.WorkspaceID = -1;

                if (string.IsNullOrWhiteSpace(templateName))
                {
                    throw new SystemException("Template name is blank in your configuration setting. Please add a template name to create a workspace");
                }
                var resultSet = GetArtifactIdOfTemplate(proxy, templateName);

                if (!resultSet.Success)
                {
                    throw new ApplicationException($"Error creating workspace {workspaceName} with error {resultSet.Message}");
                }

                if (!resultSet.Results.Any())
                {
                    throw new ApplicationException($"No template with name {templateName} found in this environment");
                }

                var workspace          = resultSet.Results.FirstOrDefault().Artifact;
                int templateArtifactID = workspace.ArtifactID;

                var workspaceDTO = new Workspace();
                workspaceDTO.Name = workspaceName;

                if (serverId.HasValue)
                {
                    workspaceDTO.ServerID = serverId.Value;
                }

                var result = proxy.Repositories.Workspace.CreateAsync(templateArtifactID, workspaceDTO);

                if (!result.Success)
                {
                    throw new System.Exception($"Workspace creation failed: {result.Message}");
                }

                ProcessInformation info = proxy.GetProcessState(proxy.APIOptions, result.ProcessID);

                int iteration = 0;

                //I have a feeling this will bite us in the future, but it hasn't yet
                while (info.State != ProcessStateValue.Completed)
                {
                    //Workspace creation takes some time sleep until the workspaces is created and then get the artifact id of the new workspace
                    System.Threading.Thread.Sleep(10000);
                    info = proxy.GetProcessState(proxy.APIOptions, result.ProcessID);

                    if (iteration > 6)
                    {
                        Console.WriteLine("Workspace creation timed out");
                    }
                    iteration++;
                }
                var testId = info?.OperationArtifactIDs?.FirstOrDefault();
                if (!testId.HasValue)
                {
                    throw new Exception("There was an error getting the created workspaceId");
                }
                return(testId.Value);
            }
            finally
            {
                proxy.APIOptions.WorkspaceID = oldWorkspaceId;
            }
        }
        public static Int32 Create(IRSAPIClient proxy, string workspaceName, string templateName)
        {
            try
            {
                int workspaceID = 0;

                //Set the workspace ID
                proxy.APIOptions.WorkspaceID = -1;

                if (templateName == "")
                {
                    throw new SystemException("Template name is blank in your configuration setting. Please add a template name to create a workspace");
                }
                var resultSet = GetArtifactIdOfTemplate(proxy, templateName);

                if (resultSet.Success)
                {
                    //Save the artifact ID of the template workspace
                    int templateArtifactID = resultSet.Results.FirstOrDefault().Artifact.ArtifactID;

                    //Create the workspace DTO
                    var workspaceDTO = new kCura.Relativity.Client.DTOs.Workspace();

                    //Set primary fields
                    //The name of the sample data is being set to a random string so that sample data can be debugged
                    //and never causes collisions. You can set this to any string that you want
                    workspaceDTO.Name = workspaceName;

                    //Get the server id or use the configuration value
                    //NOTE: We're using the server ID from the template workspace. This may not be correct and may need to be updatedServerID is hard-coded since we don't have a way to get the server ID
                    int?serverID = resultSet.Results.FirstOrDefault().Artifact.ServerID;
                    if (ConfigurationManager.AppSettings.AllKeys.Contains("ServerID"))
                    {
                        int serverIDConfigValue = Convert.ToInt32(ConfigurationManager.AppSettings["ServerID"]);
                        if (serverIDConfigValue != serverID)
                        {
                            serverID = serverIDConfigValue;
                        }
                    }
                    workspaceDTO.ServerID = serverID.Value;

                    kCura.Relativity.Client.ProcessOperationResult result = new kCura.Relativity.Client.ProcessOperationResult();
                    try
                    {
                        //Create the workspace
                        result = proxy.Repositories.Workspace.CreateAsync(templateArtifactID, workspaceDTO);
                        if (result.Success)
                        {
                            //Manually check the results and return the workspace ID synchronously
                            kCura.Relativity.Client.ProcessInformation info = proxy.GetProcessState(proxy.APIOptions, result.ProcessID);
                            int iteration = 0;
                            while (info.State != ProcessStateValue.Completed)
                            {
                                System.Threading.Thread.Sleep(10000);
                                info = proxy.GetProcessState(proxy.APIOptions, result.ProcessID);

                                if (iteration > 6)
                                {
                                    Console.WriteLine("Workspace creation timed out");
                                }
                                iteration++;
                            }

                            workspaceID = (int)info.OperationArtifactIDs.FirstOrDefault();

                            Console.WriteLine("Workspace Created with Artiafact ID :" + workspaceID);

                            //DataHelper.DeleteData[Constants.WORKSPACE_ID_LIST].Add(workspaceID);

                            return(workspaceID);
                        }
                        else
                        {
                            throw new System.Exception(String.Format("workspace creation failed: {0}", result.Message));
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new System.Exception(String.Format("Unhandled Exception : {0}", ex));
                    }
                }
                else
                {
                    return(workspaceID);
                }
            }
            catch (Exception ex)
            {
                throw new System.Exception("Create Workspace failed", ex);
            }
        }