/// <summary>
        /// Retrieves User info by email
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        private DTOs.User GetUser(string email)
        {
            DTOs.User user;

            Condition userQueryCondition = new TextCondition(UserFieldNames.EmailAddress, TextConditionEnum.EqualTo, email);

            Query <DTOs.User> userQuery = new Query <DTOs.User>(FieldValue.AllFields, userQueryCondition, new List <Sort>());

            QueryResultSet <DTOs.User> resultSet = null;

            using (IRSAPIClient rsapiClient = GetServiceFactory().CreateProxy <IRSAPIClient>())
            {
                rsapiClient.APIOptions = new APIOptions {
                    WorkspaceID = -1
                };

                resultSet = rsapiClient.Repositories.User.Query(userQuery);

                if (resultSet.Success && resultSet.TotalCount > 0)
                {
                    user = resultSet.Results.First().Artifact;
                }
                else
                {
                    throw new Exception($"Could not find user {email}");
                }
            }

            return(user);
        }
示例#2
0
        private DTOs.RelativityScript GetRelativityScriptByName()
        {
            DTOs.RelativityScript script = null;

            //Aseemble Relativity script query
            TextCondition nameCondition = new TextCondition(DTOs.RelativityScriptFieldNames.Name, TextConditionEnum.EqualTo, MainApp.Helper.Constant.SAVED_SEARCH_NAME);

            DTOs.Query <DTOs.RelativityScript> relScriptQuery =
                new DTOs.Query <DTOs.RelativityScript>
            {
                Condition = nameCondition,
                Fields    = DTOs.FieldValue.NoFields
            };

            try
            {
                // Execute query
                DTOs.QueryResultSet <DTOs.RelativityScript> relScriptQueryResults = null;

                relScriptQueryResults = Connection.Repositories.RelativityScript.Query(relScriptQuery);

                if (relScriptQueryResults.Success)
                {
                    script = relScriptQueryResults.Results[0].Artifact;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(script);
        }
示例#3
0
        private static int FindClientArtifactId(IRSAPIClient rsapiClient, string group)
        {
            int artifactId = 0;

            TextCondition clientCondition = new TextCondition(ClientFieldNames.Name, TextConditionEnum.EqualTo, group);

            Query <Client> queryClient = new Query <Client>
            {
                Condition = clientCondition,
                Fields    = FieldValue.AllFields
            };

            try
            {
                QueryResultSet <Client> resultSetClient = rsapiClient.Repositories.Client.Query(queryClient, 0);

                if (resultSetClient.Success && resultSetClient.Results.Count == 1)
                {
                    artifactId = resultSetClient.Results.FirstOrDefault().Artifact.ArtifactID;
                }
                else
                {
                    Console.WriteLine("The Query operation failed.{0}{1}", Environment.NewLine, resultSetClient.Message);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"An error occurred: {ex.Message}");
            }
            return(artifactId);
        }
        private int FindChoiceArtifactId(int choiceType, string value)
        {
            int artifactId = 0;

            WholeNumberCondition choiceTypeCondition      = new WholeNumberCondition(ChoiceFieldNames.ChoiceTypeID, NumericConditionEnum.EqualTo, (int)choiceType);
            TextCondition        choiceNameCondition      = new TextCondition(ChoiceFieldNames.Name, TextConditionEnum.EqualTo, value);
            CompositeCondition   choiceCompositeCondition = new CompositeCondition(choiceTypeCondition, CompositeConditionEnum.And, choiceNameCondition);

            Query <DTOs.Choice> choiceQuery = new Query <DTOs.Choice>(new List <FieldValue>
            {
                new
                FieldValue(ArtifactQueryFieldNames.ArtifactID)
            }, choiceCompositeCondition, new List <Sort>());
            QueryResultSet <DTOs.Choice> choiceQueryResult;

            using (var client = _helper.GetServicesManager().CreateProxy <IRSAPIClient>(API.ExecutionIdentity.System))
            {
                client.APIOptions.WorkspaceID = -1;
                choiceQueryResult             = client.Repositories.Choice.Query(choiceQuery);
            }
            if (choiceQueryResult.Success && choiceQueryResult.Results.Count == 1)
            {
                artifactId = choiceQueryResult.Results.FirstOrDefault().Artifact.ArtifactID;
            }

            return(artifactId);
        }
示例#5
0
        private static int FindChoiceArtifactId(IRSAPIClient rsapiClient, int choiceType, string value)
        {
            int artifactId = 0;

            WholeNumberCondition choiceTypeCondition                = new WholeNumberCondition(ChoiceFieldNames.ChoiceTypeID, NumericConditionEnum.EqualTo, (int)choiceType);
            TextCondition        choiceNameCondition                = new TextCondition(ChoiceFieldNames.Name, TextConditionEnum.EqualTo, value);
            CompositeCondition   choiceCompositeCondition           = new CompositeCondition(choiceTypeCondition, CompositeConditionEnum.And, choiceNameCondition);
            Query <kCura.Relativity.Client.DTOs.Choice> choiceQuery = new Query <kCura.Relativity.Client.DTOs.Choice>(
                new List <FieldValue>
            {
                new FieldValue(ArtifactQueryFieldNames.ArtifactID)
            },
                choiceCompositeCondition,
                new List <Sort>());

            try
            {
                QueryResultSet <kCura.Relativity.Client.DTOs.Choice> choiceQueryResult = rsapiClient.Repositories.Choice.Query(choiceQuery);

                if (choiceQueryResult.Success && choiceQueryResult.Results.Count == 1)
                {
                    artifactId = choiceQueryResult.Results.FirstOrDefault().Artifact.ArtifactID;
                }
                else
                {
                    Console.WriteLine("The choice could not be found.");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"An error occurred: {ex.Message}");
            }
            return(artifactId);
        }
示例#6
0
 void AddCondition(HideRowFilter drf)
 {
     if (_cbText.IsChecked == true)
     {
         TextCondition tc = TextCondition.FromString(TextCompareType.Contains, "*e*");
         drf.AddFilterItem(1, tc);
     }
     if (_cbStyle.IsChecked == true)
     {
         ColorCondition sc = ColorCondition.FromColor(ColorCompareType.BackgroundColor, Colors.Cyan);
         drf.AddFilterItem(1, sc);
     }
     if (_cbNum.IsChecked == true)
     {
         NumberCondition nc = NumberCondition.FromDouble(GeneralCompareType.LessThan, 20);
         drf.AddFilterItem(1, nc);
     }
     if (_cbDate.IsChecked == true)
     {
         DateExCondition dc = DateExCondition.FromWeek(DayOfWeek.Thursday);
         drf.AddFilterItem(1, dc);
     }
     if (_cbNull.IsChecked == true)
     {
         FormulaCondition cx = FormulaCondition.FromType(CustomValueType.Empty);
         drf.AddFilterItem(1, cx);
     }
 }
示例#7
0
        private static int FindGroupArtifactId(IRSAPIClient rsapiClient, string group)
        {
            int artifactId = 0;

            TextCondition groupCondition = new TextCondition(GroupFieldNames.Name, TextConditionEnum.EqualTo, group);

            Query <Group> queryGroup = new Query <Group>
            {
                Condition = groupCondition
            };

            queryGroup.Fields.Add(new FieldValue(ArtifactQueryFieldNames.ArtifactID));

            try
            {
                QueryResultSet <Group> resultSetGroup = rsapiClient.Repositories.Group.Query(queryGroup, 0);

                if (resultSetGroup.Success && resultSetGroup.Results.Count == 1)
                {
                    artifactId = resultSetGroup.Results.FirstOrDefault().Artifact.ArtifactID;
                }
                else
                {
                    Console.WriteLine("The Query operation failed.{0}{1}", Environment.NewLine, resultSetGroup.Message);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"An error occurred: {ex.Message}");
            }
            return(artifactId);
        }
        public async Task <List <int> > WorkspaceQueryAsync(string workspaceName)
        {
            Console2.WriteDisplayStartLine($"Querying for Workspaces [Name: {workspaceName}]");

            try
            {
                RsapiClient.APIOptions.WorkspaceID = -1;

                TextCondition     textCondition  = new TextCondition(WorkspaceFieldNames.Name, TextConditionEnum.EqualTo, workspaceName);
                Query <Workspace> workspaceQuery = new Query <Workspace>
                {
                    Fields    = FieldValue.AllFields,
                    Condition = textCondition
                };

                QueryResultSet <Workspace> workspaceQueryResultSet = await Task.Run(() => RsapiClient.Repositories.Workspace.Query(workspaceQuery));

                if (!workspaceQueryResultSet.Success || workspaceQueryResultSet.Results == null)
                {
                    throw new Exception("Failed to query Workspaces");
                }

                List <int> workspaceArtifactIds = workspaceQueryResultSet.Results.Select(x => x.Artifact.ArtifactID).ToList();

                Console2.WriteDisplayEndLine($"Queried for Workspaces! [Count: {workspaceArtifactIds.Count}]");

                return(workspaceArtifactIds);
            }
            catch (Exception ex)
            {
                throw new Exception("An error occured when querying Workspaces", ex);
            }
        }
示例#9
0
 public void Execute(object parameter)
 {
     if ((((_info != null) && (_info.RowFilter != null)) && ((_excel != null) && (_excel.ActiveSheet != null))) && ((_column >= 0) && (_column < _excel.ActiveSheet.ColumnCount)))
     {
         HideRowFilter rowFilter    = _info.RowFilter;
         object[]      filterValues = parameter as object[];
         _excel.ActiveSheet.Workbook.SuspendEvent();
         try
         {
             rowFilter.Unfilter(_column);
             rowFilter.RemoveFilterItems(_column);
             if (filterValues != null)
             {
                 for (int i = 0; i < filterValues.Length; i++)
                 {
                     object obj2 = filterValues[i];
                     if (obj2 is DateTime)
                     {
                         DateCondition filterItem = DateCondition.FromDateTime(DateCompareType.EqualsTo, (DateTime)obj2);
                         rowFilter.AddFilterItem(_column, filterItem);
                     }
                     else if (obj2 is TimeSpan)
                     {
                         TimeSpan      span       = (TimeSpan)obj2;
                         TimeCondition condition2 = TimeCondition.FromDateTime(DateCompareType.EqualsTo, Dt.Cells.Data.DateTimeExtension.FromOADate(span.TotalDays));
                         rowFilter.AddFilterItem(_column, condition2);
                     }
                     else
                     {
                         string expected = (string)(obj2 as string);
                         if ((obj2 == BlankFilterItem.Blank) || (expected == null))
                         {
                             expected = string.Empty;
                         }
                         TextCondition condition3 = TextCondition.FromString(TextCompareType.EqualsTo, expected);
                         rowFilter.AddFilterItem(_column, condition3);
                     }
                 }
             }
         }
         catch
         {
         }
         finally
         {
             _excel.ActiveSheet.Workbook.ResumeEvent();
         }
         if (!_excel.RaiseRangeFiltering(_column, filterValues))
         {
             rowFilter.Filter(_column);
             _excel.RaiseRangeFiltered(_column, filterValues);
         }
         _excel.RefreshRange(-1, -1, -1, -1, SheetArea.Cells | SheetArea.ColumnHeader | SheetArea.RowHeader);
         _excel.RefreshFloatingObjects();
     }
 }
        private static bool VerifyText(string text, TextCondition condition)
        {
            if (condition == null)
            {
                return(true);
            }

            if (condition.EqualTo != null && condition.EqualTo.Length > 0)
            {
                var verify = false;
                foreach (var equal in condition.EqualTo)
                {
                    if (text == equal)
                    {
                        verify = true;
                    }
                }

                if (!verify)
                {
                    return(false);
                }
            }

            if (condition.Contains != null && condition.Contains.Length > 0)
            {
                var verify = false;
                foreach (var contain in condition.Contains)
                {
                    if (text.Contains(contain))
                    {
                        verify = true;
                    }
                }
                if (!verify)
                {
                    return(false);
                }
            }

            if (condition.MinLength > 0)
            {
                if (!(text.Length >= condition.MinLength))
                {
                    return(false);
                }
            }

            if (condition.MaxLength <= 0)
            {
                return(true);
            }
            return(text.Length <= condition.MaxLength);
        }
        public static List <int> RetrieveJobsInWorkspaceWithStatus(IServicesMgr servicesMgr, int workspaceArtifactId, string status)
        {
            RsapiDao rsapiDao = new RsapiDao(servicesMgr, workspaceArtifactId, ExecutionIdentity.System);

            Guid fieldGuid = typeof(InstanceMetricsJobObj).GetProperty(nameof(InstanceMetricsJobObj.Status)).GetCustomAttribute <RelativityObjectFieldAttribute>().FieldGuid;

            Condition condition = new TextCondition(fieldGuid, TextConditionEnum.EqualTo, status);

            List <int> jobsList = rsapiDao.Query <InstanceMetricsJobObj>(condition, Gravity.Base.ObjectFieldsDepthLevel.FirstLevelOnly).Select(x => x.ArtifactId).ToList();

            return(jobsList);
        }
示例#12
0
        public static int GetScriptArtifactId(string scriptName, IRSAPIClient _client)
        {
            int ScriptArtifactId = 0;
            try
            {
                Query newQuery = new Query();
                TextCondition queryCondition = new TextCondition(RelativityScriptFieldNames.Name, TextConditionEnum.Like, scriptName);
                newQuery.Condition = queryCondition;
                newQuery.ArtifactTypeID = 28;
                _client.APIOptions.StrictMode = false;
                var results = _client.Query(_client.APIOptions, newQuery);
                ScriptArtifactId = results.QueryArtifacts[0].ArtifactID;
            }
            catch (Exception ex)
            {
                Console.WriteLine("An error occurred: {0}", ex.Message);
            }

            return ScriptArtifactId;
        }
示例#13
0
        public bool CanEdit(int workspaceId, int artifactTypeId)
        {
            var query = new Query();
            var objectTypeCondition         = new ObjectCondition(PermissionFieldNames.ArtifactType, ObjectConditionEnum.EqualTo, artifactTypeId);
            var editPermissionTypeCondition = new TextCondition(PermissionFieldNames.PermissionType, TextConditionEnum.EqualTo, PermissionType.Edit.Name);

            query.Condition = new CompositeCondition(objectTypeCondition, CompositeConditionEnum.And, editPermissionTypeCondition).ToQueryString();
            var permissions = this.permissionManager.QueryAsync(workspaceId, query, 1).Result;

            if (permissions.Success)
            {
                var permission = permissions.Results.FirstOrDefault().Artifact;
                var result     = this.permissionManager.GetPermissionSelectedAsync(workspaceId, new List <PermissionRef>()
                {
                    permission
                }).Result;
                return(result.FirstOrDefault()?.Selected ?? false);
            }

            return(false);
        }
        /// <summary>
        /// Creates/Gets DynamicAPI Group
        /// </summary>
        /// <returns></returns>
        private int CreateDynamicApiGroup()
        {
            int groupId = 0;

            Group newGroup = new Group();

            newGroup.Name = _dynamicApiGroup;

            TextCondition condition = new TextCondition(GroupFieldNames.Name, TextConditionEnum.EqualTo, newGroup.Name);

            Query <Group> query = new Query <Group> {
                Condition = condition
            };

            // STEP 2: Create a WriteResultSet. It provide details after the create operation completes.
            WriteResultSet <Group> resultSet = new WriteResultSet <Group>();

            using (IRSAPIClient rsapiClient = GetServiceFactory().CreateProxy <IRSAPIClient>())
            {
                rsapiClient.APIOptions = new APIOptions {
                    WorkspaceID = -1
                };

                QueryResultSet <Group> queryResultSet = rsapiClient.Repositories.Group.Query(query);

                if (queryResultSet.Success && queryResultSet.TotalCount == 0)
                {
                    resultSet = rsapiClient.Repositories.Group.Create(newGroup);
                    groupId   = resultSet.Results.First().Artifact.ArtifactID;
                    Console.WriteLine($"Group created ({newGroup.Name})");
                }
                else
                {
                    Console.WriteLine($"Group ({newGroup.Name}) already exists");
                    groupId = queryResultSet.Results.First().Artifact.ArtifactID;
                }
            }

            return(groupId);
        }
示例#15
0
        public static int FindChoiceArtifactId(IRSAPIClient proxy, int choiceType, string value)
        {
            int artifactId = 0;

            WholeNumberCondition choiceTypeCondition      = new WholeNumberCondition(ChoiceFieldNames.ChoiceTypeID, NumericConditionEnum.EqualTo, (int)choiceType);
            TextCondition        choiceNameCondition      = new TextCondition(ChoiceFieldNames.Name, TextConditionEnum.EqualTo, value);
            CompositeCondition   choiceCompositeCondition = new CompositeCondition(choiceTypeCondition, CompositeConditionEnum.And, choiceNameCondition);

            Query <Choice> choiceQuery = new Query <Choice>(new List <FieldValue>
            {
                new
                FieldValue(ArtifactQueryFieldNames.ArtifactID)
            }, choiceCompositeCondition, new List <Sort>());

            QueryResultSet <Choice> choiceQueryResult = proxy.Repositories.Choice.Query(choiceQuery);

            if (choiceQueryResult.Success && choiceQueryResult.Results.Count == 1)
            {
                artifactId = choiceQueryResult.Results.FirstOrDefault().Artifact.ArtifactID;
            }

            return(artifactId);
        }
        /// <summary>
        /// Deletes DynamicAPI Group
        /// </summary>
        /// <returns></returns>
        private void DeleteDynamicApiGroup(int groupId)
        {
            Group newGroup = new Group();

            newGroup.Name = _dynamicApiGroup;

            TextCondition condition = new TextCondition(GroupFieldNames.Name, TextConditionEnum.EqualTo, newGroup.Name);

            Query <Group> query = new Query <Group> {
                Condition = condition
            };

            // STEP 2: Create a WriteResultSet. It provide details after the create operation completes.
            WriteResultSet <Group> resultSet = new WriteResultSet <Group>();

            using (IRSAPIClient rsapiClient = GetServiceFactory().CreateProxy <IRSAPIClient>())
            {
                rsapiClient.APIOptions = new APIOptions {
                    WorkspaceID = -1
                };

                QueryResultSet <Group> queryResultSet = rsapiClient.Repositories.Group.Query(query);

                if (queryResultSet.Success && queryResultSet.TotalCount > 0)
                {
                    resultSet = rsapiClient.Repositories.Group.Delete(groupId);
                    if (resultSet.Success)
                    {
                        Console.WriteLine($"Group deleted ({newGroup.Name})");
                    }
                }
                else
                {
                    Console.WriteLine($"Group ({newGroup.Name}) does not exist");
                }
            }
        }
示例#17
0
        /// <summary>
        /// Returns all of the fields for a given object type.
        /// Does not include system fields.
        /// </summary>
        /// <param name="objMgr"></param>
        /// <param name="workspaceId"></param>
        /// <param name="objectTypeId"></param>
        /// <returns></returns>
        public static async Task <List <Field> > GetAllFieldsForObject(
            IObjectManager objMgr,
            int workspaceId,
            int objectTypeId)
        {
            var objectTypeCondition = new WholeNumberCondition(
                "Object Type Artifact Type ID",
                NumericConditionEnum.EqualTo,
                objectTypeId);

            // we want to exclude system types
            var          textCondition          = new TextCondition("Name", TextConditionEnum.Like, "System");
            NotCondition excludeSystemCondition = textCondition.Negate();

            var condition = new CompositeCondition(
                objectTypeCondition,
                CompositeConditionEnum.And,
                excludeSystemCondition);

            var queryRequest = new QueryRequest
            {
                ObjectType = new ObjectTypeRef {
                    ArtifactTypeID = FIELD_OBJ_TYPE_ID
                },
                Condition = condition.ToQueryString(),
                Fields    = new List <FieldRef>
                {
                    //new FieldRef() { Name = "Name" },
                    new FieldRef {
                        Name = "Field Type"
                    }
                },
                IncludeIDWindow          = false,
                IncludeNameInQueryResult = true
            };

            int start = 0;

            // a document shouldn't have more than 1000 fields, I would hope
            const int LENGTH = 1000;

            var retVal = new List <Field>();

            QueryResult result = await objMgr.QueryAsync(workspaceId, queryRequest, start, LENGTH);

            foreach (RelativityObject field in result.Objects)
            {
                if (!field.FieldValuePairExists("Field Type"))
                {
                    continue;  // skip
                }
                // determine the field type
                string    fieldTypeName = field.FieldValues.First().Value.ToString();
                FieldType type;
                switch (fieldTypeName)
                {
                case FieldTypes.CURRENCY:
                    type = FieldType.Currency;
                    break;

                case FieldTypes.DATE:
                    type = FieldType.Date;
                    break;

                case FieldTypes.DECIMAL:
                    type = FieldType.Decimal;
                    break;

                case FieldTypes.FILE:
                    type = FieldType.File;
                    break;

                case FieldTypes.FIXED_LENGTH_TXT:
                    type = FieldType.FixedLengthText;
                    break;

                case FieldTypes.LONG_TXT:
                    type = FieldType.LongText;
                    break;

                case FieldTypes.MULTI_CHOICE:
                    type = FieldType.MultipleChoice;
                    break;

                case FieldTypes.MULTI_OBJECT:
                    type = FieldType.MultipleObject;
                    break;

                case FieldTypes.SINGLE_CHOICE:
                    type = FieldType.SingleChoice;
                    break;

                case FieldTypes.SINGLE_OBJECT:
                    type = FieldType.SingleObject;
                    break;

                case FieldTypes.USER:
                    type = FieldType.User;
                    break;

                case FieldTypes.WHOLE_NUMBER:
                    type = FieldType.WholeNumber;
                    break;

                case FieldTypes.YES_NO:
                    type = FieldType.YesNo;
                    break;

                default:
                    type = FieldType.Empty;
                    break;
                }

                var fieldToAdd = new Field
                {
                    ArtifactID = field.ArtifactID,
                    FieldType  = type,
                    Name       = field.Name
                };
                retVal.Add(fieldToAdd);
            }

            return(retVal);
        }
示例#18
0
        public ICondition GetCondition(RuleItem item)
        {
            IEnumerable <Source.Model.Condition> srcConditions = item.Conditions;
            ICondition mainCondition = null;

            switch (item.Type)
            {
            case RuleItemType.Regex:
                mainCondition = new RegexCondition(item.Key);
                break;

            case RuleItemType.Terminal:
                mainCondition = new TextCondition(item.Key);
                break;

            case RuleItemType.Lemma:
                mainCondition = new LemmaCondition(item.Key);
                break;

            case RuleItemType.Morphology:
                // главный морфологический ключ объединяется
                // с второстепенными морфологичекими условиями
                var morphKeys = item.Key.Split(',');

                if (item.Conditions != null)
                {
                    morphKeys = morphKeys.Concat(item.Conditions
                                                 .Where(c => c.Key == "морф")
                                                 .SelectMany(c => c.Values))
                                .ToArray();
                }

                mainCondition = new MorphologyCondition(morphKeys);
                srcConditions = srcConditions?.Where(x => x.Key != "морф");
                break;

            case RuleItemType.Everything:
                mainCondition = new EverythingCondition();
                break;
            }

            if (item.HasConditions)
            {
                var adConds = _compileConditions(srcConditions).ToArray();

                if (adConds.Length == 1 && mainCondition == null)
                {
                    mainCondition = adConds[0];
                }
                else if (mainCondition == null)
                {
                    mainCondition = new AndCondition(adConds);
                }
                else
                {
                    mainCondition = new AndCondition(new[] { mainCondition }.Concat(adConds));
                }
            }

            return(mainCondition);
        }