public virtual void Insert(IStructureSchema structureSchema, IStructure[] structures)
        {
            var groupedIndexInsertActions = new IndexInsertAction[0];

            Task task = null;
            try
            {
                task = Task.Factory.StartNew(
                    () => groupedIndexInsertActions = CreateGroupedIndexInsertActions(structureSchema, structures));

                InsertStructures(structureSchema, structures);
                InsertUniques(structureSchema, structures);

                Task.WaitAll(task);
            }
            finally
            {
                if (task != null && task.Status == TaskStatus.RanToCompletion)
                    task.Dispose();
            }

            if (!groupedIndexInsertActions.Any())
                return;

            InsertIndexes(groupedIndexInsertActions);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Getting a MD hash sequence for datastructure
        /// </summary>
        /// <param name="dta_struct">Data Structure</param>
        /// <returns></returns>
        public static string MD5Hash( IStructure dta_struct )
        {
            var str_hash = new StringBuilder( 32 );
            var str_elements = new StringBuilder( 32 );
            byte[] data_bytes = null;
            if (dta_struct != null) {
                if ( dta_struct is DataContainer ) {
                    foreach ( var clmn in  ((DataContainer)dta_struct).Columns ){
                        str_elements.Append( clmn.Name );
                        str_elements.Append( clmn.Type.ToString());
                    }
                    data_bytes = Encoding.UTF8.GetBytes(((DataContainer)dta_struct).Name +
                                                        str_elements.ToString());
                } else {
                    if ( dta_struct is Record ) {
                        // Let's assume, that Record Id is unique
                        str_elements.Append(((Record)dta_struct).Id.ToString());
                        data_bytes = Encoding.UTF8.GetBytes(((Record)dta_struct).Id.ToString() +
                                                            str_elements.ToString());
                    }
                }

                foreach (byte b in new MD5CryptoServiceProvider().ComputeHash(data_bytes))
                {
                    str_hash.Append(b.ToString("X2"));
                }
            } else
                throw new IOException( "Error in generating hash code: data structure is null" );
            return str_hash.ToString();
        }
        public virtual void InsertIndexesOnly(IStructureSchema structureSchema, IStructure[] structures)
        {
            var groupedIndexInsertActions = CreateGroupedIndexInsertActions(structureSchema, structures);
            if (!groupedIndexInsertActions.Any())
                return;

            InsertIndexes(groupedIndexInsertActions);
        }
Exemplo n.º 4
0
 public new void Add(IStructure dta_struct)
 {
     string new_index_hash = dta_struct.GetIndex().DwarfHashCode;
     if (dta_struct is Record)
     {
         items_dict.TryAdd(new_index_hash, dta_struct);
         Modified = true;
     }
 }
Exemplo n.º 5
0
 void IField.SetFieldData(byte[] field_data, IStructure caller)
 {
     offset0 = BitConverter.ToInt32(field_data, 0);
     offset1 = BitConverter.ToInt32(field_data, 4);
     offset2 = BitConverter.ToInt32(field_data, 8);
                                                         // <- the other 3 LODs which are never used.
     length0 = BitConverter.ToInt32(field_data, 24);
     length1 = BitConverter.ToInt32(field_data, 28);
     length2 = BitConverter.ToInt32(field_data, 32);
 }
        protected virtual void InsertStructures(IStructureSchema structureSchema, IStructure[] structures)
        {
            if (!structures.Any())
                return;

            if (structures.Length == 1)
                MainDbClient.SingleInsertStructure(structures[0], structureSchema);
            else
                MainDbClient.BulkInsertStructures(structureSchema, structures);
        }
        public virtual void Replace(IStructureSchema structureSchema, IStructure structure)
        {
            var structures = new[] { structure };
            MainDbClient.SingleUpdateOfStructure(structure, structureSchema);
            InsertUniques(structureSchema, structures);

            var groupedIndexInsertActions = CreateGroupedIndexInsertActions(structureSchema, new[] { structure });
            if (!groupedIndexInsertActions.Any())
                return;

            InsertIndexes(groupedIndexInsertActions);
        }
Exemplo n.º 8
0
        public ConfigurationController(IDocumentRepository documentRepository,
		                                IStructureRepository structureRepository)
            : base(true)
        {
            _documentRepository = documentRepository;
            _structureRepository = structureRepository;

            _document = new Document(_documentRepository);
            _structure = new Structure(_structureRepository);

            _user = new User();
        }
Exemplo n.º 9
0
 /// <summary>
 /// Creates a new index
 /// </summary>
 /// <param name="_index_object">Object for indexing</param>
 /// <returns></returns>
 public static Index CreateNew( IStructure _index_object )
 {
     if ( _index_object == null )
         throw new IndexException( "object for indexing is NULL" );
     return new Index( _index_object );
 }
 public void Add(IStructure structure)
 {
     _structures.Add(structure);
 }
Exemplo n.º 11
0
 /// <summary> Returns an array of Structure objects by name.  For example, if the Group contains
 /// an MSH segment and "MSH" is supplied then this call would return a 1-element array 
 /// containing the MSH segment.  Multiple elements are returned when the segment or 
 /// group repeats.  The array may be empty if no repetitions have been accessed
 /// yet using the get(...) methods. 
 /// </summary>
 /// <throws>  HL7Exception if the named Structure is not part of this Group.  </throws>
 public virtual IStructure[] GetAll(System.String name)
 {
     AbstractGroupItem item = GetGroupItem(name);
     if (item == null)
         throw new HL7Exception("The structure " + name + " does not exist in the group " + this.GetType().FullName, HL7Exception.APPLICATION_INTERNAL_ERROR);
     IStructure[] all = new IStructure[item.Structures.Count];
     for (int i = 0; i < item.Structures.Count; i++)
     {
         all[i] = item.Structures[i];
     }
     return all;
 }
Exemplo n.º 12
0
 /// <summary> Returns the index of the given structure as a child of the 
 /// given parent.  Returns null if the child isn't found. 
 /// </summary>
 public static Index getIndex(IGroup parent, IStructure child)
 {
     Index index = null;
     System.String[] names = parent.Names;
     for (int i = 0; i < names.Length; i++)
     {
         if (names[i].StartsWith(child.GetStructureName()))
         {
             try
             {
                 IStructure[] reps = parent.GetAll(names[i]);
                 for (int j = 0; j < reps.Length; j++)
                 {
                     if (child == reps[j])
                     {
                         index = new Index(names[i], j);
                         break;
                     }
                 }
             }
             catch (HL7Exception e)
             {
                 log.Error("", e);
                 throw new System.ApplicationException("Internal HL7Exception finding structure index: " + e.Message);
             }
         }
     }
     return index;
 }
Exemplo n.º 13
0
 /// <summary>
 /// Adding a new item to a chunk file in multithread mode
 /// </summary>
 /// <param name="filepath">path to a file</param>
 /// <param name="ds">datastructure</param>
 public static void AddItem( string filepath, IStructure ds )
 {
     if ( ds != null ) {
         var sw = new StreamWriter( File.Open( filepath, FileMode.Append ) );
         using (var json_writer = new JsonTextWriter(sw)) {
             var elem= new InnerChunkElement();
             if ( ds is Record ) {
                 elem.ElementType = InnerChunkElement.ElemType.RECORD;
                 elem.ElemParentName = ((Record)ds).OwnerDC.Name;
                 elem.ElemParentHash = ((Record)ds).OwnerDC.GetIndex().DwarfHashCode;
                 elem.Contents = JsonConvert.SerializeObject(ds, Formatting.Indented );
             } else if ( ds is DataContainer ) {
                 elem.ElementType = InnerChunkElement.ElemType.DATACONTAINER;
                 elem.ElemDB = ((DataContainer)ds).GetOwnerDB().Name;
                 elem.ElemParentName = null;
                 elem.ElemParentHash = null;
                 elem.ElementName = ((DataContainer)ds).Name;
                 var ds_sec = (DataContainer)ds;
                 elem.Contents = JsonConvert.SerializeObject(ds_sec, Formatting.Indented);
             }
             elem.ElementHash = ds.GetIndex().DwarfHashCode;
             sw.Write(JsonConvert.SerializeObject(elem, Formatting.Indented));
         }
     } else {
         Errors.Messages.DisplayError( "DataStructure object is null!", "", "", DateTime.Now);
     }
 }
Exemplo n.º 14
0
        /// <summary>
        /// Getting several elements from a chunk file in multithread mode
        /// </summary>
        /// <param name="filepath">path to file</param>
        /// <param name="idx_arr">indexes array</param>
        public static IStructure[] GetItemRange( string filepath, Index[] idx_arr )
        {
            var ret_arr = new IStructure[0];

            var tmp_path = CreateTemporaryFile( filepath );

            using (var json_reader = new JsonTextReader(new StreamReader(File.Open( tmp_path, FileMode.Open )))) {
                json_reader.SupportMultipleContent = true;
                foreach ( var index in idx_arr ) {
                    var elem = GetItemInfile( json_reader, index );
                    if ( elem != null ) {
                        Array.Resize( ref ret_arr, ret_arr.Length + 1 );
                        ret_arr[ret_arr.Length-1] = elem;
                    }
                }
            }

            DeleteTemporaryFile( tmp_path );

            return ret_arr;
        }
Exemplo n.º 15
0
        /// <summary>
        /// Saving an existant item to a chunk file in multithread mode
        /// </summary>
        /// <param name="filepath">path to a file</param>
        /// <param name="ds">datastructure</param>
        public static void SaveItemContents( string filepath, IStructure ds )
        {
            var elem= new InnerChunkElement();
            if ( ds != null ) {
                var sw_read = new StreamReader( File.Open( filepath, FileMode.Open ) );
                InnerChunkElement icm = null;

                using ( var json_reader = new JsonTextReader(sw_read) ) {
                    icm = FindItem( json_reader, ds.GetIndex().DwarfHashCode );
                }

                if ( icm == null )
                {
                    Errors.Messages.DisplayError("Can't find such item!", "Saving an item", "", DateTime.Now);
                    return;
                }

                var sw_write = new StreamWriter( File.Open( filepath, FileMode.Append ) );
                using (var json_writer = new JsonTextWriter(sw_write)) {
                    if ( ds is Record ) {
                        icm.Contents = JsonConvert.SerializeObject(ds, Formatting.Indented );
                    } else if ( ds is DataContainer ) {
                        icm.Contents = JsonConvert.SerializeObject(ds as DataContainer, Formatting.Indented);
                    }
                    elem.ElementHash = ds.GetIndex().DwarfHashCode;
                    sw_write.Write(JsonConvert.SerializeObject(elem, Formatting.Indented));
                }
            } else {
                Errors.Messages.DisplayError( "DataStructure object is null!", "", "", DateTime.Now);
            }
        }
Exemplo n.º 16
0
        public static IStructure FindItem( JsonReader json_reader, IStructure ds )
        {
            var item = new InnerChunkElement();
            while ( json_reader.Read() ) {
                item = json_serializer.Deserialize<InnerChunkElement>( json_reader );
                if ( item.ElementHash == ds.GetIndex().DwarfHashCode ) {
                    return ds;
                }
            }

            return null;
        }
Exemplo n.º 17
0
        /// <summary> Navigates to a specific location in the message</summary>
        private void drillHere(IStructure destination)
        {
            IStructure pathElem = destination;
            System.Collections.ArrayList pathStack = new System.Collections.ArrayList();
            System.Collections.ArrayList indexStack = new System.Collections.ArrayList();
            do
            {
                MessageIterator.Index index = MessageIterator.getIndex(pathElem.ParentStructure, pathElem);
                indexStack.Add(index);
                pathElem = pathElem.ParentStructure;
                pathStack.Add(pathElem);
            }
            while (!root.Equals(pathElem) && !typeof(IMessage).IsAssignableFrom(pathElem.GetType()));

            if (!root.Equals(pathElem))
            {
                throw new HL7Exception("The destination provided is not under the root of this navigator");
            }

            this.reset();
            while (!(pathStack.Count == 0))
            {
                IGroup parent = (IGroup)SupportClass.StackSupport.Pop(pathStack);
                MessageIterator.Index index = (MessageIterator.Index)SupportClass.StackSupport.Pop(indexStack);
                int child = search(parent.Names, index.name);
                if (!(pathStack.Count == 0))
                {
                    this.drillDown(child, 0);
                }
                else
                {
                    this.toChild(child);
                }
            }
        }
Exemplo n.º 18
0
 /// <summary>
 /// Processes the structure.
 /// A base structure can be either a segment, or segment group. This function
 /// determines which it is before passing it on.
 /// </summary>
 /// <param name="structure">The structure.</param>
 /// <param name="parentNode">The parent node, in the TreeListView.</param>
 private void ProcessStructure(IStructure structure, FieldGroup parentNode)
 {
     if (structure.GetType().IsSubclassOf(typeof(AbstractSegment)))
     {
         AbstractSegment seg = (AbstractSegment)structure;
         this.ProcessSegment(seg, parentNode);
     }
     else if (structure.GetType().IsSubclassOf(typeof(AbstractGroup)))
     {
         AbstractGroup structureGroup = (AbstractGroup)structure;
         this.ProcessStructureGroup(structureGroup, parentNode);
     }
     else
     {
         parentNode.FieldList.Add(new Field() { Name = "Something Else!!!" });
     }
 }
Exemplo n.º 19
0
        public bool TryRemove(IStructure data)
        {
            if (items_dict.ContainsKey(data.GetIndex().DwarfHashCode))
            {
                IStructure dummy = null;
                return items_dict.TryRemove(data.GetIndex().DwarfHashCode, out dummy);
            }

            return false;
        }
Exemplo n.º 20
0
 void IField.SetFieldData(byte[] field_data, IStructure caller)
 {
     tag_class = (TagClass)BitConverter.ToInt32(field_data, 0);
     tag_identifier = BitConverter.ToInt32(field_data, 4);
 }
Exemplo n.º 21
0
 private Index()
 {
     index_object = null;
 }
Exemplo n.º 22
0
 public virtual void NotifyUpdated(ISession session, IStructureSchema schema, IStructure structure, object item)
 {
     foreach (var handler in OnUpdatedHandlers)
         handler.Invoke(session, schema, structure, item);
 }
Exemplo n.º 23
0
 /// <summary> Determines whether the given structure matches the given name, or contains 
 /// a child that does.  
 /// </summary>
 /// <param name="s">the structure to check 
 /// </param>
 /// <param name="name">the name to look for 
 /// </param>
 /// <param name="firstDescendentsOnly">only checks first descendents (i.e. first 
 /// child, first child of first child, etc.)  In theory the first child 
 /// of a group should always be present, and we don't use this method with 
 /// subsequent children because finding the next position within a group is 
 /// straightforward.  
 /// </param>
 /// <param name="upToFirstRequired">only checks first descendents and of their siblings 
 /// up to the first required one.  This may be needed because in practice 
 /// some first children of groups are not required.  
 /// </param>
 public static bool contains(IStructure s, System.String name, bool firstDescendentsOnly, bool upToFirstRequired)
 {
     bool contains = false;
     if (typeof(ISegment).IsAssignableFrom(s.GetType()))
     {
         if (s.GetStructureName().Equals(name))
             contains = true;
     }
     else
     {
         IGroup g = (IGroup)s;
         System.String[] names = g.Names;
         for (int i = 0; i < names.Length && !contains; i++)
         {
             try
             {
                 contains = MessageIterator.contains(g.GetStructure(names[i], 0), name, firstDescendentsOnly, upToFirstRequired);
                 if (firstDescendentsOnly)
                     break;
                 if (upToFirstRequired && g.IsRequired(names[i]))
                     break;
             }
             catch (HL7Exception e)
             {
                 throw new System.ApplicationException("HL7Exception due to bad index: " + e.Message);
             }
         }
     }
     return contains;
 }
Exemplo n.º 24
0
 public Index( IStructure _index_object )
 {
     index_object = _index_object;
 }
Exemplo n.º 25
0
        /* may add configurability later ...
        private boolean findUpToFirstRequired;
        private boolean findFirstDescendentsOnly;

        public static final String WHOLE_GROUP;
        public static final String FIRST_DESCENDENTS_ONLY;
        public static final String UP_TO_FIRST_REQUIRED;
        */
        /// <summary>Creates a new instance of MessageIterator </summary>
        public MessageIterator(IStructure start, System.String direction, bool handleUnexpectedSegments)
        {
            this.currentStructure = start;
            this.direction = direction;
            this.handleUnexpectedSegments = handleUnexpectedSegments;
        }
Exemplo n.º 26
0
 private void ParseRep(System.Xml.XmlElement theElem, IStructure theObj)
 {
     if (theObj is IGroup)
     {
         Parse((IGroup)theObj, theElem);
     }
     else if (theObj is ISegment)
     {
         Parse((ISegment)theObj, theElem);
     }
     log.Debug("Parsed element: " + theElem.Name);
 }
Exemplo n.º 27
0
 void IField.Initialize(IStructure calling_structure)
 {
     parent = calling_structure;
 }
        protected virtual void InsertUniques(IStructureSchema structureSchema, IStructure[] structures)
        {
            if (!structures.Any())
                return;

            var uniques = structures.SelectMany(s => s.Uniques).ToArray();
            if (!uniques.Any())
                return;

            if (uniques.Length == 1)
                MainDbClient.SingleInsertOfUniqueIndex(uniques[0], structureSchema);
            else
                MainDbClient.BulkInsertUniques(structureSchema, uniques);
        }
Exemplo n.º 29
0
 public virtual void NotifyUpdated(ISession session, IStructureSchema schema, IStructure[] structures, object[] items)
 {
     for (var i = 0; i < structures.Length; i++)
         NotifyUpdated(session, schema, structures[i], items[i]);
 }
        protected virtual IndexInsertAction[] CreateGroupedIndexInsertActions(IStructureSchema structureSchema, IStructure[] structures)
        {
            var indexesTableNames = structureSchema.GetIndexesTableNames();
            var insertActions = new Dictionary<DataTypeCode, IndexInsertAction>(indexesTableNames.All.Length);
            foreach (var group in structures.SelectMany(s => s.Indexes).GroupBy(i => i.DataTypeCode))
            {
                var insertAction = CreateIndexInsertActionGroup(structureSchema, indexesTableNames, group.Key, group.ToArray());
                if (insertAction.HasData)
                    insertActions.Add(group.Key, insertAction);
            }

            var mergeStringsAndEnums = insertActions.ContainsKey(DataTypeCode.String) && insertActions.ContainsKey(DataTypeCode.Enum);
            if (mergeStringsAndEnums)
            {
                var strings = insertActions[DataTypeCode.String];
                var enums = insertActions[DataTypeCode.Enum];
                insertActions.Remove(DataTypeCode.Enum);

                insertActions[DataTypeCode.String] = CreateIndexInsertActionGroup(structureSchema, indexesTableNames, DataTypeCode.String, strings.Data.MergeWith(enums.Data).ToArray());
            }

            return insertActions.Values.ToArray();
        }