public static bool DeleteTestWorkspace(Int32 workspaceID, IServicesMgr svcMgr, string userName, string password)
        {
            WriteResultSet <Workspace> resultSet = null;

            using (var proxy = svcMgr.GetProxy <IRSAPIClient>(userName, password))
            {
                proxy.APIOptions.WorkspaceID = -1;

                try
                {
                    //Create a Workspace Artifact and pass to the Delete method on the repository
                    var workspaceDTO = new kCura.Relativity.Client.DTOs.Workspace(workspaceID);
                    resultSet = proxy.Repositories.Workspace.Delete(workspaceDTO);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("An error occurred deleting the Workspace: {0}", ex.Message);
                    return(false);
                }


                if (!resultSet.Success)
                {
                    Console.WriteLine("An error occurred deleting the Workspace: {0}", resultSet.Message);
                    return(false);
                }

                return(true);
            }
        }
        public static bool Delete(IRSAPIClient proxy, int workspaceID)
        {
            var oldWorkspaceId = proxy.APIOptions.WorkspaceID;

            proxy.APIOptions.WorkspaceID = -1;
            try
            {
                //Create a Workspace Artifact and pass to the Delete method on the repository
                var workspaceDTO = new kCura.Relativity.Client.DTOs.Workspace(workspaceID);
                var resultSet    = proxy.Repositories.Workspace.Delete(workspaceDTO);
                if (!resultSet.Success)
                {
                    Console.WriteLine("An error occurred deleting the Workspace: {0}", resultSet.Message);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("An error occurred deleting the Workspace: {0}", ex.Message);
                return(false);
            }
            finally
            {
                proxy.APIOptions.WorkspaceID = oldWorkspaceId;
            }
            return(true);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Returns the name of a workspace by artifact ID.
 /// </summary>
 /// <param name="workspaceArtifactId"></param>
 /// <returns></returns>
 public string GetWorkspaceName(int workspaceArtifactId)
 {
     kCura.Relativity.Client.DTOs.Workspace workspace = new DTOs.Workspace();
     try
     {
         using (var client = _helper.GetServicesManager().CreateProxy <IRSAPIClient>(API.ExecutionIdentity.System))
         {
             client.APIOptions.WorkspaceID = -1;
             workspace = client.Repositories.Workspace.ReadSingle(workspaceArtifactId);
         }
     }
     catch (Exception ex)
     {
     }
     return(workspace.Name);
 }
Ejemplo n.º 4
0
 public static bool DeleteWorkspace(IRSAPIClient proxy, int workspaceID)
 {
     proxy.APIOptions.WorkspaceID = -1;
     try
     {
         //Create a Workspace Artifact and pass to the Delete method on the repository
         Workspace workspaceDTO = new kCura.Relativity.Client.DTOs.Workspace(workspaceID);
         proxy.Repositories.Workspace.DeleteSingle(workspaceID);
     }
     catch (Exception ex)
     {
         Console.WriteLine("An error occurred deleting the Workspace: {0}", ex.Message);
         return(false);
     }
     return(true);
 }
Ejemplo n.º 5
0
        public bool Update(int artifactId, Workspace artifact)
        {
            bool result = false;

            DTOs.Workspace workspace = new DTOs.Workspace(artifactId);
            workspace.Name     = artifact.Name;
            workspace.MatterID = artifact.MatterId;
            workspace.Client   = client.Repositories.Client.ReadSingle(artifact.ClientId);
            try
            {
                client.Repositories.Workspace.UpdateSingle(workspace);
                return(result);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 6
0
        static DTOs.Workspace FindWorkspace(string name, IRSAPIClient client)
        {
            client.APIOptions.WorkspaceID = -1;

            //build the query / condition
            DTOs.Query <DTOs.Workspace> query = new DTOs.Query <DTOs.Workspace>
            {
                Condition = new TextCondition(DTOs.WorkspaceFieldNames.Name, TextConditionEnum.EqualTo, name),
                Fields    = DTOs.FieldValue.AllFields
            };

            // query for the workspace
            DTOs.QueryResultSet <DTOs.Workspace> resultSet = new DTOs.QueryResultSet <DTOs.Workspace>();
            try
            {
                resultSet = client.Repositories.Workspace.Query(query, 0);
            }
            catch (Exception ex)
            {
                Console.WriteLine(String.Format("Exception:\r\n{0}\r\n{1}", ex.Message, ex.InnerException));
                return(null);
            }

            // check for success
            if (resultSet.Success)
            {
                if (resultSet.Results.Count > 0)
                {
                    DTOs.Workspace firstWorkspace = resultSet.Results.FirstOrDefault().Artifact;
                    Console.WriteLine(String.Format("Workspace found with artifactID {0}.", firstWorkspace.ArtifactID));
                    return(firstWorkspace);
                }
                else
                {
                    Console.WriteLine("Query was successful but workspace does not exist.");
                    return(null);
                }
            }
            else
            {
                Console.WriteLine("Query was not successful.");
                return(null);
            }
        }
Ejemplo n.º 7
0
        public Workspace Get(int artifactId)
        {
            Workspace workspace = new Workspace();

            try
            {
                DTOs.Workspace workspaceDTO = client.Repositories.Workspace.ReadSingle(artifactId);
                workspace.ArtifactId = workspaceDTO.ArtifactID;
                workspace.Name       = workspaceDTO.Name;
                workspace.MatterId   = workspaceDTO.MatterID.Value;
                workspace.ClientId   = workspaceDTO.Client.ArtifactID;
                Entities.Artifact user = new Entities.Artifact(workspaceDTO.SystemCreatedBy.ArtifactID);
                user.Name           = workspaceDTO.SystemCreatedBy.FullName;
                workspace.CreatedBy = user;
            }
            catch (Exception)
            {
                throw;
            }
            return(workspace);
        }
Ejemplo n.º 8
0
        static DTOs.Workspace FindWorkspaceArtifactID(int artifactID, IRSAPIClient client)
        {
            client.APIOptions.WorkspaceID = -1;

            //build the query / condition
            DTOs.Query <DTOs.Workspace> query = new DTOs.Query <DTOs.Workspace>
            {
                Condition = new WholeNumberCondition("Artifact ID", NumericConditionEnum.EqualTo, artifactID),
                Fields    = DTOs.FieldValue.AllFields
            };

            // query for the workspace
            DTOs.QueryResultSet <DTOs.Workspace> resultSet = new DTOs.QueryResultSet <DTOs.Workspace>();
            try
            {
                resultSet = client.Repositories.Workspace.Query(query, 0);
            }
            catch
            {
                return(null);
            }

            // check for success
            if (resultSet.Success)
            {
                if (resultSet.Results.Count > 0)
                {
                    DTOs.Workspace firstWorkspace = resultSet.Results.FirstOrDefault().Artifact;
                    return(firstWorkspace);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        static void DuplicateFolders(Relativity.Services.ServiceProxy.ServiceFactorySettings settings)
        {
            try
            {
                using (IRSAPIClient rsapiProxy = new Relativity.Services.ServiceProxy.ServiceFactory(settings).CreateProxy <IRSAPIClient>())
                {
                    // query for template workspace
                    DTOs.Workspace template = FindWorkspace(_templateCase, rsapiProxy);

                    if (template != null)
                    {
                        _templateArtifactId        = template.ArtifactID;
                        Folder._templateRootFolder = template.RootFolderID;
                    }
                    else
                    {
                        return;
                    }

                    // query for target workspace
                    DTOs.Workspace target = FindWorkspace(_targetCase, rsapiProxy);

                    if (target != null)
                    {
                        _targetArtifactId        = target.ArtifactID;
                        Folder._targetRootFolder = target.RootFolderID;
                    }
                    else
                    {
                        return;
                    }

                    rsapiProxy.APIOptions.WorkspaceID = _templateArtifactId;

                    // get folders from template workspace
                    List <DTOs.Result <DTOs.Folder> > source = GetSourceFolders(rsapiProxy);

                    if (source == null)
                    {
                        return;
                    }
                    else if (source.Count == 1)
                    {
                        Console.WriteLine("Template workspace has no folders; exiting.");
                        return;
                    }

                    rsapiProxy.APIOptions.WorkspaceID = _targetArtifactId;

                    // confirm target workspace has no folders
                    bool?targetIsEmpty = VerifyEmptyTarget(rsapiProxy);

                    if (targetIsEmpty == false)
                    {
                        Console.WriteLine("Target workspace already contains folders; exiting.");
                        return;
                    }
                    else if (targetIsEmpty == null)
                    {
                        return;
                    }

                    // create folders
                    Folder.CreateFolders(source, rsapiProxy);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(String.Format("Exception encountered:\r\n{0}\r\n{1}", ex.Message, ex.InnerException));
            }
        }
        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);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Creates a workspace and returns its artifact ID. No retry logic.
        /// </summary>
        /// <param name="workspaceName"></param>
        /// <param name="clientArtifactID"></param>
        /// <param name="matterArtifactID"></param>
        /// <param name="templateWorkspace"></param>
        /// <returns></returns>
        public int Create(string workspaceName, int clientArtifactID, int matterArtifactID, DTOs.Workspace templateWorkspace)
        {
            int workspaceID;

            using (var workspaceManager = _helper.GetServicesManager().CreateProxy <IWorkspaceManager>(ExecutionIdentity.System))
            {
                var settings = new WorkspaceSetttings
                {
                    Name                                  = workspaceName,
                    ClientArtifactId                      = clientArtifactID,
                    MatterArtifactId                      = matterArtifactID,
                    TemplateArtifactId                    = templateWorkspace.ArtifactID,
                    StatusCodeArtifactId                  = 675,
                    ResourceGroupArtifactId               = templateWorkspace.ResourcePoolID,
                    DefaultFileLocationCodeArtifactId     = templateWorkspace.DefaultFileLocation.ArtifactID,
                    DefaultDataGridLocationCodeArtifactId = templateWorkspace.DefaultDataGridLocation?.ArtifactID,
                    DefaultCacheLocationServerArtifactId  = templateWorkspace.DefaultCacheLocation,
                };
                WorkspaceRef result = workspaceManager.CreateWorkspaceAsync(settings).Result;
                workspaceID = result.ArtifactID;

                return(workspaceID);
            }
        }
Ejemplo n.º 13
0
        public override Response Execute()
        {
            //Get the logger from the helper and set the ForContext to this class.
            _logger = Helper.GetLoggerFactory().GetLogger().ForContext <WorkspaceCreate>();

            // construct a response object with default values
            retVal.Message = String.Empty;
            retVal.Success = true;

            try
            {
                // get the current workspace artifact ID
                int currentWorkspaceID = Helper.GetActiveCaseID();

                // get the current workspace database context
                IDBContext workspaceDBContext = Helper.GetDBContext(currentWorkspaceID);

                // query for template workspace artifactID
                int templateWorkspaceID = GetTemplateCase(workspaceDBContext);

                using (IRSAPIClient proxy = Helper.GetServicesManager().CreateProxy <IRSAPIClient>(ExecutionIdentity.System))
                {
                    // query for template workspace
                    DTOs.Workspace template = FindWorkspaceArtifactID(templateWorkspaceID, proxy);

                    if (template != null)
                    {
                        Folder._templateRootFolder = template.RootFolderID;
                    }
                    else
                    {
                        retVal.Success = false;
                        retVal.Message = "Template workspace not found; unable to replicate folder structure.";
                        return(retVal);
                    }

                    // query for target workspace
                    DTOs.Workspace target = FindWorkspaceArtifactID(currentWorkspaceID, proxy);

                    if (target != null)
                    {
                        Folder._targetRootFolder = target.RootFolderID;
                    }
                    else
                    {
                        retVal.Success = false;
                        retVal.Message = "Target workspace not found; unable to replicate folder structure.";
                        _logger.LogError("Target workspace not found; unable to replicate folder structure.");
                        return(retVal);
                    }

                    proxy.APIOptions.WorkspaceID = templateWorkspaceID;

                    // get folders from template workspace
                    List <DTOs.Result <DTOs.Folder> > source = Program.GetSourceFolders(proxy);

                    if (source == null)
                    {
                        retVal.Success = false;
                        retVal.Message = "Query for folders in template workspace was unsuccessful.";
                        _logger.LogError("Query for folders in template workspace was unsuccessful.");
                        return(retVal);
                    }
                    else if (source.Count == 1)
                    {
                        retVal.Success = false;
                        retVal.Message = "No folders found in template workspace.";
                        _logger.LogError("No folders found in template workspace.");
                        return(retVal);
                    }

                    proxy.APIOptions.WorkspaceID = currentWorkspaceID;

                    // create folders
                    Folder.CreateFolders(source, proxy);
                }
            }
            catch (Exception ex)
            {
                // catch an exception if it occurs, log it, and return a response with success = false.
                retVal.Success = false;
                retVal.Message = ex.ToString();
            }

            return(retVal);
        }