public void DataFunctionCall_SetDataDate()
        {
            // Get the search builder.
            var mfSearchBuilder = this.GetSearchBuilder();

            // Create the data function call.
            var dataFunctionCall = new DataFunctionCall();

            dataFunctionCall.SetDataDate();

            // Add a search condition for the SetDataDate data function call.
            mfSearchBuilder.Property
            (
                PropertyValueSearchConditionTestBase.TestTimestampPropertyId,
                new DateTime(2018, 10, 29),
                dataFunctionCall: dataFunctionCall
            );

            // Retrieve the search condition.
            var condition = mfSearchBuilder.Conditions[1];

            // Ensure that the data type is correct.
            Assert.AreEqual
            (
                MFDataType.MFDatatypeDate,
                condition.TypedValue.DataType
            );

            // Ensure that the search condition has the correct data function call setting.
            Assert.AreEqual
            (
                MFDataFunction.MFDataFunctionDate,
                condition.Expression.DataPropertyValueDataFunction
            );
        }
Beispiel #2
0
        private static void ProcessData(string vaultName, Vault vault, IView view, DateTime startDate,
                                        IProcessor processor)
        {
            Thread.CurrentThread.Name = $"Thread-{vaultName}";


            var conditions = view.SearchConditions;
            var dfDate     = new DataFunctionCall();

            dfDate.SetDataDate();

            var search     = new SearchCondition();
            var expression = new Expression();
            var value      = new TypedValue();

            expression.SetPropertyValueExpression((int)MFBuiltInPropertyDef.MFBuiltInPropertyDefLastModified,
                                                  MFParentChildBehavior.MFParentChildBehaviorNone, dfDate);
            search.Set(expression, MFConditionType.MFConditionTypeGreaterThanOrEqual, value);

            conditions.Add(-1, search);

            search     = new SearchCondition();
            expression = new Expression();
            value      = new TypedValue();
            expression.SetPropertyValueExpression((int)MFBuiltInPropertyDef.MFBuiltInPropertyDefLastModified,
                                                  MFParentChildBehavior.MFParentChildBehaviorNone, dfDate);
            search.Set(expression, MFConditionType.MFConditionTypeLessThan, value);

            conditions.Add(-1, search);


            var currentDateTime = startDate;

            var processorContext = processor.CreateContext();

            while (currentDateTime < DateTime.Now)
            {
                conditions[conditions.Count - 1].TypedValue.SetValue(MFDataType.MFDatatypeDate, currentDateTime);
                currentDateTime = currentDateTime.AddMonths(1);
                conditions[conditions.Count].TypedValue.SetValue(MFDataType.MFDatatypeDate, currentDateTime);


                ObjectSearchResults objects = vault.ObjectSearchOperations.SearchForObjectsByConditionsEx(conditions,
                                                                                                          MFSearchFlags.MFSearchFlagReturnLatestVisibleVersion, false, 0);

                foreach (ObjectVersion objVer in objects)
                {
                    processorContext.ProcessObject(new ObjectVersionWrapper(objVer, vault, vaultName));
                }
                //internalDocuments.AddRange(from ObjectVersion obj in objects
                //                            select new MFilesInternalDocument(internalVault, obj));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Adds a <see cref="SearchCondition"/> to the collection for a <see cref="MFDataType.MFDatatypeDate"/>
        /// or <see cref="MFDataType.MFDatatypeTimestamp"/> property definition.
        /// This method ignores any time component in the property value or in <paramref name="value"/>, equivalent to using
        /// a <see cref="DataFunctionCall" /> set to <see cref="DataFunctionCall.SetDataDate"/>.
        /// </summary>
        /// <param name="searchBuilder">The <see cref="MFSearchBuilder"/> to add the condition to.</param>
        /// <param name="propertyDef">The ID of the property to search by.</param>
        /// <param name="value">The value to search for.</param>
        /// <param name="conditionType">What type of search to execute (defaults to <see cref="MFConditionType.MFConditionTypeEqual"/>).</param>
        /// <param name="parentChildBehavior">Whether to accept matches to parent/child values as well (defaults to <see cref="MFParentChildBehavior.MFParentChildBehaviorNone"/>).</param>
        /// <param name="indirectionLevels">The indirection levels (from the search object) to access the property to match.</param>
        /// <returns>The <paramref name="searchBuilder"/> provided, for chaining.</returns>
        public static MFSearchBuilder Date
        (
            this MFSearchBuilder searchBuilder,
            int propertyDef,
            DateTime value,
            MFConditionType conditionType              = MFConditionType.MFConditionTypeEqual,
            MFParentChildBehavior parentChildBehavior  = MFParentChildBehavior.MFParentChildBehaviorNone,
            PropertyDefOrObjectTypes indirectionLevels = null
        )
        {
            // Sanity.
            if (null == searchBuilder)
            {
                throw new ArgumentNullException(nameof(searchBuilder));
            }
            if (0 > propertyDef)
            {
                throw new ArgumentOutOfRangeException(nameof(propertyDef), "Property Ids must be greater than -1; ensure that your property alias was resolved.");
            }

            // What is the type of this property?
            var dataType = searchBuilder.Vault.PropertyDefOperations.GetPropertyDef(propertyDef).DataType;

            // What is the data type of the property?
            DataFunctionCall dataFunctionCall;

            switch (dataType)
            {
            case MFDataType.MFDatatypeTimestamp:
            case MFDataType.MFDatatypeDate:

                // Timestamps should be converted to dates using a data function call.
                dataFunctionCall = new DataFunctionCall();
                dataFunctionCall.SetDataDate();

                break;

            default:
                throw new ArgumentException($"Property {propertyDef} is not a date or timestamp property.", nameof(propertyDef));
            }

            // Use the property method.
            return(searchBuilder.Property
                   (
                       propertyDef,
                       value.Date,
                       conditionType,
                       parentChildBehavior,
                       indirectionLevels,
                       dataFunctionCall
                   ));
        }