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);
        }
        public async Task <int> CreateWorkspaceAsync(int templateArtifactId)
        {
            Console2.WriteDisplayStartLine("Creating new Workspace");

            try
            {
                const string workspaceCreationFailErrorMessage = "Failed to create new workspace";
                RsapiClient.APIOptions.WorkspaceID = -1;

                //Create the workspace object and apply any desired properties.
                Workspace newWorkspace = new Workspace
                {
                    Name             = Constants.Workspace.NAME,
                    Accessible       = Constants.Workspace.ACCESSIBLE,
                    DatabaseLocation = Constants.Workspace.DATABASE_LOCATION
                };

                ProcessOperationResult processOperationResult = await Task.Run(() => RsapiClient.Repositories.Workspace.CreateAsync(templateArtifactId, newWorkspace));

                if (!processOperationResult.Success)
                {
                    throw new Exception(workspaceCreationFailErrorMessage);
                }

                ProcessInformation processInformation = await Task.Run(() => RsapiClient.GetProcessState(RsapiClient.APIOptions, processOperationResult.ProcessID));

                const int maxTimeInMilliseconds         = (Constants.Waiting.MAX_WAIT_TIME_IN_MINUTES * 60 * 1000);
                const int sleepTimeInMilliSeconds       = Constants.Waiting.SLEEP_TIME_IN_SECONDS * 1000;
                int       currentWaitTimeInMilliseconds = 0;

                while ((currentWaitTimeInMilliseconds < maxTimeInMilliseconds) && (processInformation.State != ProcessStateValue.Completed))
                {
                    Thread.Sleep(sleepTimeInMilliSeconds);

                    processInformation = await Task.Run(() => RsapiClient.GetProcessState(RsapiClient.APIOptions, processOperationResult.ProcessID));

                    currentWaitTimeInMilliseconds += sleepTimeInMilliSeconds;
                }

                int?workspaceArtifactId = processInformation.OperationArtifactIDs.FirstOrDefault();
                if (workspaceArtifactId == null)
                {
                    throw new Exception(workspaceCreationFailErrorMessage);
                }

                Console2.WriteDebugLine($"Workspace ArtifactId: {workspaceArtifactId.Value}");
                Console2.WriteDisplayEndLine("Created new Workspace!");

                return(workspaceArtifactId.Value);
            }
            catch (Exception ex)
            {
                throw new Exception("An error occured when creating Workspace", ex);
            }
        }
        /// <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. 4
0
        public int Create(Workspace artifact)
        {
            int response           = 0;
            int?templateArtifactID = null;

            DTOs.Query <DTOs.Workspace> query = new DTOs.Query <DTOs.Workspace>();
            query.Condition = new TextCondition(DTOs.FieldFieldNames.Name, TextConditionEnum.EqualTo, "kCura Starter Template");
            query.Fields    = DTOs.FieldValue.AllFields;
            DTOs.QueryResultSet <DTOs.Workspace> results = client.Repositories.Workspace.Query(query, 0);

            if (results.Success)
            {
                templateArtifactID = results.Results.FirstOrDefault().Artifact.ArtifactID;
            }
            else
            {
                return(response);
            }
            DTOs.Workspace workspaceToCreate = new DTOs.Workspace();
            workspaceToCreate.Name     = artifact.Name;
            workspaceToCreate.Client   = client.Repositories.Client.ReadSingle(artifact.ClientId);
            workspaceToCreate.MatterID = artifact.MatterId;
            ProcessOperationResult result  = new ProcessOperationResult();
            ProcessInformation     process = new ProcessInformation();

            try
            {
                result   = client.Repositories.Workspace.CreateAsync(templateArtifactID.Value, workspaceToCreate);
                response = 1;
            }
            catch (Exception)
            {
                throw;
            }
            return(response);
        }