/// <summary> /// Updates the value of a document property with the new property value. /// /// Gets the property type id for the specified property type name. /// Gets the document contract for the specified document id. The contract /// contains an array of property contracts. Gets a list of property contracts. /// The method searches for the property contract with the property type id. /// If it finds the contract, it updates the property contract with the new /// value. Then it updates the document contract's properties field. /// Afterwards it calls the updateDocument method on an instance of the /// InfoShareService class and passes the connection id, the document contract, /// and the check in parameter contract as arguments. /// Releases the reservation of the document in order that other users can edit the document /// Returns a document contract, if the document is successfully updated. /// /// </summary> /// <param name="documentClient">the document client of the info share WCF service</param> /// <param name="commonClient">the common client of the info share WCF service</param> /// <param name="connectionID">the connection id</param> /// <param name="documentID">the document id</param> /// <param name="propertyTypeName">the property type name</param> /// <param name="newPropertyValue">the new property value</param> /// <param name="schemaCulture">the schema culture</param> /// <returns>the document contract</returns> public DocumentContract UpdateDocumentProperty(CommonService commonService, string connectionID, string documentID, string propertyTypeName, string newPropertyValue, string schemaCulture) { string propertyTypeID = commonService.GetPropertyTypeID(propertyTypeName, schemaCulture); DocumentContract documentContract = this.DocumentClient.GetDocument(connectionID, documentID); // Loops through all properties of property contract foreach (PropertyContract propertyContract in documentContract.Properties) { if (propertyContract.PropertyTypeId == propertyTypeID) { // If property contract found, set new value propertyContract.Values = new string[] { newPropertyValue }; break; } } CheckInParameterContract checkInParameterContract = new CheckInParameterContract { // Releases the reservation of the document in order that other users can edit the document ReleaseReservation = true }; documentContract = this.DocumentClient.UpdateDocument(connectionID, documentContract, null, checkInParameterContract); return(documentContract); }
public SearchResultContract SearchDocument(CommonService commonService, string connectionID, string[] searchProperties, string[] ResultProperties, string schemaCulture) { SearchResultContract searchResultContract = null; List <SearchConditionContract> lSearchConditionContract = new List <SearchConditionContract>(); log.Info("Preparing search- and resultproperties..."); log.Info("Searchproperties: "); foreach (string prop in searchProperties) { //SearchProperties = [index|value(s)|operator|relation] string[] split = prop.Split('|'); //Pepare comparison and relation enumerators Utility.SearchComparisonEnum comparisonEnum = 0; Utility.SearchRelationEnum relationEnum = 0; if (2 < split.Length) { comparisonEnum = (Utility.SearchComparisonEnum)Convert.ToInt16(split[2]); } if (3 < split.Length) { relationEnum = (Utility.SearchRelationEnum)Convert.ToInt16(split[3]); } string propertyTypeID = commonService.GetPropertyTypeID(split[0], schemaCulture); if (propertyTypeID != null) { // Sets values on SearchConditionContract SearchConditionContract searchConditionContract = new SearchConditionContract { PropertyTypeId = propertyTypeID }; string[] values = split[1].Split(';'); //Split multikey-search values by ";"-symbol. //Special variables for (int i = 0; i < values.Length; i++) { if (Regex.Matches(values[i], "%").Count == 2) { string val = values[i].Trim('%'); //Remove leading and ending % if (val.StartsWith("currentdate")) { DateTime now = DateTime.Now; val = val.Replace("currentdate", ""); if (val.Length > 2) { //string op = val.Substring(0, 1); string dmy = val.Substring(val.Length - 1, 1); double op = Convert.ToDouble(val.Replace(dmy, "")); if (dmy == "d") { now = now.AddDays(op); } if (dmy == "m") { now = now.AddMonths(Convert.ToInt16(op)); } if (dmy == "y") { now = now.AddYears(Convert.ToInt16(op)); } } values[i] = now.ToString("yyyy-MM-dd"); } if (val.StartsWith("endlastyear")) { DateTime now = DateTime.Now; } } } searchConditionContract.Values = values; if (values.Length > 1) //If it's multiple values, comparisonEnum must be "In". { comparisonEnum = Utility.SearchComparisonEnum.In; } searchConditionContract.Values = values; searchConditionContract.ComparisonEnum = ((int)comparisonEnum).ToString(); searchConditionContract.RelationEnum = ((int)relationEnum).ToString(); lSearchConditionContract.Add(searchConditionContract); //Write Property to Console log.Info(String.Format("[{0} {2} {1}] {3} ", split[0], String.Join(";", values), comparisonEnum.ToString(), relationEnum.ToString())); } } // Sets values on SearchDefinitionContract SearchDefinitionContract searchDefinitionContract = new SearchDefinitionContract { Conditions = lSearchConditionContract.ToArray(), PageSize = 100000 }; log.Info("Resultproperties:"); // Assembles an array of property type IDs to be returned from the document search //String[] resultPropertyIds = new String[ResultProperties.Length]; List <String> resultPropertyIds = new List <String>(); log.Info("[" + String.Join(",", ResultProperties) + "]"); //Get the propertyID's for (int i = 0; i < ResultProperties.Length; i++) { String propertyTypeId = commonService.GetPropertyTypeID(ResultProperties[i], schemaCulture); if (propertyTypeId != null) { resultPropertyIds.Add(propertyTypeId); } } log.Info("Searching for documents..."); // Searches for document searchResultContract = this.SearchClient.Search(connectionID, searchDefinitionContract, resultPropertyIds.ToArray() /* resultProperties */, null /* resume point */, customSecurityToken: null); return(searchResultContract); }