public static bool ValueListContains(ValueListItems vlitems, string item, int owner = -1) { HashSet <string> VListItems = new HashSet <string>(StringComparer.OrdinalIgnoreCase); if (owner != -1) { foreach (ValueListItem vl in vlitems) { if (vl.OwnerID != owner) { continue; } VListItems.Add($"{owner}{vl.Name}"); } if (VListItems.Contains($"{owner}{item}")) { return(true); } } else { foreach (ValueListItem vl in vlitems) { VListItems.Add(vl.Name); } if (VListItems.Contains(item)) { return(true); } } return(false); }
public static int GetVautlValueListItem(this IObjVerEx obj, VL_ValueLists vlId, string item) { ValueListItems vlItems = obj.objVerEx.Vault.ValueListItemOperations.GetValueListItems((int)vlId); foreach (ValueListItem vlItem in vlItems) { if (item.Equals(vlItem.Name.Trim(), StringComparison.InvariantCultureIgnoreCase)) { return(vlItem.ID); } } return(-1); }
public static void DeleteValueListItem(this IObjVerEx obj, VL_ValueLists vlId, string vlItemNameToDelete) { if (string.IsNullOrWhiteSpace(vlItemNameToDelete)) { return; } ValueListItems vlItems = obj.objVerEx.Vault.ValueListItemOperations.GetValueListItems((int)vlId); foreach (ValueListItem vlItem in vlItems) { if (vlItemNameToDelete.Equals(vlItem.Name, StringComparison.InvariantCultureIgnoreCase)) { obj.objVerEx.Vault.ValueListItemOperations.RemoveValueListItem((int)vlId, vlItem.ID); break; } } }
public static bool HasValueListItem(this IObjVerEx obj, VL_ValueLists vlId, string vlItemName) { bool vlItemExists = false; if (string.IsNullOrWhiteSpace(vlItemName)) { return(vlItemExists); } ValueListItems vlItems = obj.objVerEx.Vault.ValueListItemOperations.GetValueListItems((int)vlId); foreach (ValueListItem vlItem in vlItems) { if (vlItemName.Equals(vlItem.Name, StringComparison.InvariantCultureIgnoreCase)) { vlItemExists = true; break; } } return(vlItemExists); }
public static ValueListItem CreateValueListItemAdmin(this IObjVerEx obj, VL_ValueLists vlId, string vlItemNameToAdd) { if (string.IsNullOrWhiteSpace(vlItemNameToAdd)) { return(null); } ValueListItems vlItems = obj.objVerEx.Vault.ValueListItemOperations.GetValueListItems((int)vlId); foreach (ValueListItem vlItem in vlItems) { if (vlItemNameToAdd.Equals(vlItem.Name, StringComparison.InvariantCultureIgnoreCase)) { return(null); } } ValueListItem vlItemToAdd = new ValueListItem() { Name = vlItemNameToAdd }; return(obj.objVerEx.Vault.ValueListItemOperations.AddValueListItem((int)vlId, vlItemToAdd, true)); }
public static void Run(string serverName, string userName, string password, string[] vaultNames, string viewName, DateTime startDate, IDictionary <string, IEnumerable <PropertyListType> > listProperties, IProcessor processor) { _mfilesServer = new MFilesServerApplication(); MFServerConnection result; try { result = _mfilesServer.Connect(MFAuthType.MFAuthTypeSpecificMFilesUser, userName, password, NetworkAddress: serverName); } catch (COMException ex) { ClassLogger.Error(ex, $"Could not connect to M-Files server"); return; } if (result != MFServerConnection.MFServerConnectionAuthenticated) { ClassLogger.Error("Could not connect to M-Files server"); return; } var topContext = processor.CreateContext(); var vaultsOnServer = _mfilesServer.GetVaults(); IList <Tuple <string, Vault, IView> > data = new List <Tuple <string, Vault, IView> >(); foreach (var vaultName in vaultNames) { IVaultOnServer vaultOnServer; try { vaultOnServer = vaultsOnServer.GetVaultByName(vaultName); } catch (COMException) { ClassLogger.Error($"Could not find vault '{vaultName}'"); continue; } Vault vault = vaultOnServer.LogIn(); if (!vault.LoggedIn) { ClassLogger.Error($"Could not logging to vault '{vaultName}'"); continue; } if (listProperties.ContainsKey(vaultName)) { foreach (var listProperty in listProperties[vaultName]) { var def = vault.PropertyDefOperations.GetPropertyDefs() .Cast <PropertyDef>() .SingleOrDefault(x => x.Name == listProperty.PropertyName); if (def == null || !def.BasedOnValueList) { ClassLogger.Error($"Property {listProperty.PropertyName} in {vaultName} is not a list"); continue; } ValueListItems items = vault.ValueListItemOperations.GetValueListItems(def.ValueList, true, MFExternalDBRefreshType.MFExternalDBRefreshTypeQuick); foreach (ValueListItem item in items) { Guid guid; if (!Guid.TryParse(item.DisplayID, out guid)) { guid = Guid.NewGuid(); } listProperty.Items.Add(new PropertyListItem(guid, item.Name)); } topContext.ProcessListProperty(listProperty); } } IView view = vault.ViewOperations.GetViews().Cast <IView>().FirstOrDefault(v => v.Name == viewName); if (view == null) { ClassLogger.Warn($"Could not find view '{viewName}' in vault '{vaultName}'"); continue; } data.Add(Tuple.Create(vaultName, vault, view)); } IList <Task> tasks = new List <Task>(); foreach (var taskData in data) { var task = new Task(() => ProcessData(taskData.Item1, taskData.Item2, taskData.Item3, startDate, processor)); tasks.Add(task); task.Start(); } foreach (var task in tasks) { task.Wait(); } processor.AfterProcessing(); }