Beispiel #1
0
 public static string ExtractRootFromPatientId(string patientId, string rootExtSeparator, string idTrail)
 {
     if (patientId.EndsWith("'") && string.IsNullOrEmpty(idTrail))
     {
         idTrail = "'";
     }
     if (string.IsNullOrEmpty(idTrail))
     {
         return(patientId.Substring(patientId.IndexOf(rootExtSeparator) + rootExtSeparator.Length));
     }
     return(StringUtility.ExtractFromDelimiters(patientId, rootExtSeparator, idTrail));
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="escapeMarkerStart"></param>
 /// <param name="escapeMarkerEnd"></param>
 /// <param name="indexedRefStart"></param>
 /// <param name="indexedRefEnd"></param>
 /// <param name="nullString"></param>
 /// <param name="foreachKeyStart"></param>
 /// <param name="foreachKeyEnd"></param>
 /// <param name="foreachItemKey"></param>
 /// <param name="objects"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public static string ParseObjectsIntoString(
     string escapeMarkerStart,
     string escapeMarkerEnd,
     string indexedRefStart,
     string indexedRefEnd,
     string nullString,
     string foreachKeyStart,
     string foreachKeyEnd,
     string foreachItemKey,
     Dictionary <string, object> objects,
     string value)
 {
     if (string.IsNullOrEmpty(value))
     {
         return(value);
     }
     if (objects != null)
     {
         value = ResolveLists(escapeMarkerStart,
                              escapeMarkerEnd,
                              indexedRefStart,
                              indexedRefEnd,
                              nullString,
                              foreachKeyStart,
                              foreachKeyEnd,
                              foreachItemKey,
                              objects,
                              value);
         while (StringUtility.ContainsDelimiters(value, escapeMarkerStart, escapeMarkerEnd))
         {
             string refName  = StringUtility.ExtractFromDelimiters(value, escapeMarkerStart, escapeMarkerEnd);
             object refValue = GetObjectFromReference(
                 indexedRefStart,
                 indexedRefEnd,
                 objects,
                 refName);
             string refValString = refValue == null ? nullString : refValue.ToString();
             value = StringUtility.ReplaceIgnoreCase(value, escapeMarkerStart + refName + escapeMarkerEnd, refValString);
         }
     }
     return(value);
 }
Beispiel #3
0
 public static string ExtractRootFromPatientIdWithUrnOid(string patientId)
 {
     return(StringUtility.ExtractFromDelimiters(patientId, "^^^&urn:oid:", "&ISO"));
 }
        /// <summary>
        /// resolves a value from a set of objects base on a reference that contains the key to the object in the dictionary
        /// and optionally a dot notation reference to properties of the object.
        /// </summary>
        /// <param name="indexedRefStart">an indexed reference start string such as [ in some.reference[index]</param>
        /// <param name="indexedRefEnd">an indexed reference start string such as ] in some.reference[index]</param>
        /// <param name="objects"></param>
        /// <param name="refName"></param>
        /// <returns></returns>
        public static object GetObjectFromReference(
            string indexedRefStart,
            string indexedRefEnd,
            Dictionary <string, object> objects,
            string refName
            )
        {
            object refValue                  = null;
            int    firstIndexOfDot           = refName.IndexOf(".");
            int    firstIndexOfSquareBracket = refName.IndexOf(indexedRefStart);

            if (StringUtility.Contains(refName, ".") &&
                (firstIndexOfSquareBracket < 0 || firstIndexOfDot < firstIndexOfSquareBracket))
            {
                StringTokenizer tokenizer = new StringTokenizer(refName, ".");
                string          envName   = tokenizer.NextToken();
                object          obj       = null;
                if (StringUtility.NotEmpty(envName))
                {
                    obj = objects[envName];
                    if (obj != null)
                    {
                        while (tokenizer.HasMoreTokens())
                        {
                            if (obj == null)
                            {
                                break;
                            }
                            string token    = tokenizer.NextToken();
                            string propName = token;
                            if (StringUtility.NotEmpty(token))
                            {
                                bool hasIndex = false;
                                if (StringUtility.Contains(token, indexedRefStart))
                                {
                                    hasIndex = true;
                                    propName = token.Substring(0, token.IndexOf(indexedRefStart));
                                }
                                PropertyInfo prop = obj.GetType().GetProperty(propName);
                                if (prop != null && prop.CanRead)
                                {
                                    if (typeof(IDictionary).IsAssignableFrom(prop.PropertyType))
                                    {
                                        IDictionary dictObj = (IDictionary)prop.GetValue(obj, null);
                                        if (hasIndex)
                                        {
                                            obj = dictObj[StringUtility.ExtractFromDelimiters(token, indexedRefStart, indexedRefEnd)];
                                        }
                                        else
                                        {
                                            obj = dictObj;
                                        }
                                    }
                                    else if (typeof(IList).IsAssignableFrom(prop.PropertyType))
                                    {
                                        IList listObj = (IList)prop.GetValue(obj, null);
                                        if (hasIndex)
                                        {
                                            try
                                            {
                                                int indx = Convert.ToInt32(StringUtility.ExtractFromDelimiters(token, indexedRefStart, indexedRefEnd));
                                                obj = listObj[indx];
                                            }
                                            catch
                                            {
                                                obj = listObj;
                                            }
                                        }
                                        else
                                        {
                                            obj = listObj;
                                        }
                                    }
                                    else
                                    {
                                        obj = prop.GetValue(obj, null);
                                    }
                                }
                                else
                                {
                                    obj = null;
                                    break;
                                }
                            }
                        }
                    }
                }
                refValue = obj;
            }
            else
            {
                bool   hasIndex = false;
                string propName = refName;
                if (StringUtility.Contains(refName, indexedRefStart))
                {
                    hasIndex = true;
                    propName = refName.Substring(0, refName.IndexOf(indexedRefStart));
                }
                object obj = objects[propName];
                if (obj == null)
                {
                    refValue = null;
                }
                else
                {
                    if (hasIndex)
                    {
                        if (typeof(IDictionary).IsAssignableFrom(obj.GetType()))
                        {
                            IDictionary dictObj = (IDictionary)obj;
                            obj = dictObj[StringUtility.ExtractFromDelimiters(refName, indexedRefStart, indexedRefEnd)];
                        }
                        else if (typeof(IList).IsAssignableFrom(obj.GetType()))
                        {
                            IList listObj = (IList)obj;
                            int   indx    = Convert.ToInt32(StringUtility.ExtractFromDelimiters(refName, indexedRefStart, indexedRefEnd));
                            obj = listObj[indx];
                        }
                    }
                    refValue = obj;
                }
            }
            return(refValue);
        }