private static void ParseXMLFile() { Console.WriteLine("Введите путь xml файла:"); string xmlFilePath = Console.ReadLine(); //string xmlFilePath = @"C:\Users\workstation1\Desktop\sors\UZI\ее\1.xml"; string str; using (StreamReader sr = new StreamReader(File.Open(xmlFilePath, FileMode.Open))) { str = sr.ReadToEnd(); } // ! Обязательно удалить строчку в xml файле: xmlns="http://tempuri.org/FormalDocumentFieldDefinitions" // FormalDocumentFieldDefinitionsCollection collection = EntityDataHelper.Deserialize <FormalDocumentFieldDefinitionsCollection>(str); List <string> list = new List <string>(); Regex regex = new Regex(@"[А-я]"); foreach (var field in collection.Fields) { if (regex.IsMatch(field.DisplayedName)) { CheckIfNotExist(list, field.DisplayedName); } foreach (var value in field.FormalDocumentFieldValueDefinitions) { if (regex.IsMatch(value.DisplayedValue)) { CheckIfNotExist(list, value.DisplayedValue); } } } foreach (var field in collection.Groups) { bool isMatch = regex.IsMatch(field.DisplayedName); if (isMatch) { CheckIfNotExist(list, field.DisplayedName); } } SaveToExcel(list); }
/// <summary> /// Creates a new entity returning the map of old to new entity ids. /// </summary> /// <param name="entityData">The entity data.</param> /// <returns>A map of old to new entity ids.</returns> /// <exception cref="System.ArgumentNullException">entityData</exception> /// <exception cref="System.ArgumentException">entityData.TypeId must be set.</exception> public IDictionary <long, IEntity> CreateEntityGetMap(EntityData entityData) { try { // Validate arguments if (entityData == null) { throw new ArgumentNullException("entityData"); } if (entityData.TypeIds == null || entityData.TypeIds.Count < 0) { throw new ArgumentException("entityData.TypeId must be set."); } // Process create entityData.DataState = DataState.Create; return(CreateUpdateDeleteImpl(entityData, true)); } catch (Exception ex) { EventLog.Application.WriteError("CreateEntity failed:\n{0}\n\nException:\n{1}", EntityDataHelper.GetDebug(entityData), ex); throw; } }
/// <summary> /// Creates a new entity. /// </summary> public EntityRef CreateEntity(EntityData entityData) { try { var entityMap = CreateEntityGetMap(entityData); IEntity entity = entityMap[entityData.Id.Id]; long id = entity == null ? -1 : entity.Id; return(new EntityRef(id)); } catch (CardinalityViolationException cvEx) { EventLog.Application.WriteWarning("Create Entity failed:\n{0}\n\nException:\n{1}", EntityDataHelper.GetDebug(entityData), cvEx.InnerException); throw; } catch (Exception ex) { EventLog.Application.WriteError("CreateEntity failed:\n{0}\n\nException:\n{1}", EntityDataHelper.GetDebug(entityData), ex); throw; } }
/// <summary> /// Decodes entity data. /// </summary> /// <param name="entityData">The data</param> /// <param name="persistChanges">If true, the nugget is intended to be persisted.</param> public IEntity DecodeEntity(EntityData entityData, bool persistChanges = false) { try { if (entityData == null) { return(null); } var entity = CreateUpdateDeleteImpl(entityData, persistChanges); return(entity[entityData.Id.Id]); } catch (CardinalityViolationException cvEx) { EventLog.Application.WriteWarning("Decode Entity failed:\n{0}\n\nException:\n{1}", EntityDataHelper.GetDebug(entityData), cvEx.InnerException); throw; } catch (Exception ex) { EventLog.Application.WriteError("DecodeEntity failed:\n{0}\n\nException:\n{1}", EntityDataHelper.GetDebug(entityData), ex); throw; } }
/// <summary> /// Updates an entity. /// </summary> public void UpdateEntity(EntityData entityData) { try { // Validate arguments if (entityData == null) { throw new ArgumentNullException("entityData"); } // Process update entityData.DataState = DataState.Update; CreateUpdateDeleteImpl(entityData, true); NotifyRootModification(entityData.Id); } catch (CardinalityViolationException cvEx) { EventLog.Application.WriteWarning("Update Entity failed:\n{0}\n\nException:\n{1}", EntityDataHelper.GetDebug(entityData), cvEx.InnerException); throw; } catch (Exception ex) { EventLog.Application.WriteError("UpdateEntity failed:\n{0}\n\nException:\n{1}", EntityDataHelper.GetDebug(entityData), ex); throw; } }
/// <summary> /// Clones the entity at the root of the request then updates it or any cloned or original related entities as needed. /// </summary> /// <param name="entityData">The entity data.</param> /// <returns></returns> public IDictionary <long, long> CloneAndUpdateEntity(EntityData entityData) { try { // Validate arguments if (entityData == null) { throw new ArgumentNullException(nameof(entityData)); } // Get the entity to clone IEntity entity = Entity.Get(entityData.Id); if (entity.IsTemporaryId) { throw new InvalidOperationException("Cannot clone a temporary entity."); } // Clone it IEntity clone = entity.Clone(CloneOption.Deep); // Do a save and store the mapping of old to new ids var clonedIdsMap = clone.Save(); // Update the cloned ids in the entity graph UpdateEntityDataClonedIds(entityData, clonedIdsMap); UpdateEntity(entityData); if (!string.IsNullOrWhiteSpace(entity.Alias)) { // Clear alias to prevent duplicates clone.SetField("core:alias", null); clone.Save(); } return(clonedIdsMap); } catch (CardinalityViolationException cvEx) { EventLog.Application.WriteWarning("Clone Entity failed:\n{0}\n\nException:\n{1}", EntityDataHelper.GetDebug(entityData), cvEx.InnerException); throw; } catch (Exception ex) { EventLog.Application.WriteError("CloneEntity failed:\n{0}\n\nException:\n{1}", EntityDataHelper.GetDebug(entityData), ex); throw; } }