private static bool IsSimpleValue(this Dictionary <string, AttributeValue> src) { // this is no any values when the actual value is undefined (null in .net terms) if (!src.HasValue()) { return(true); } if (src.Values.Count > 1) { return(false); } var val = src.Values.First(); if (!string.IsNullOrWhiteSpace(val.S) || !string.IsNullOrWhiteSpace(val.N) || val.NS.Any() || val.SS.Any() || val.IsBOOLSet || val.BS.Any() || val.B != null || val.NULL) { return(true); } return(false); }
/// <summary> /// 将集合 转成DataTable ,如集合没有值,返回null /// </summary> /// <typeparam name="T">必须是class</typeparam> /// <param name="value">待处理的value </param> /// <param name="defalueKeyValues">字段 需默认值</param> /// <returns></returns> public static DataTable ToDataTable <T>(this IEnumerable <T> value, Dictionary <string, object> defalueKeyValues = null) where T : class { if (!value.HasValue()) { return(null); } var properties = typeof(T).GetProperties(); var dataTable = new DataTable(); dataTable.Columns.AddRange(properties.Select(p => new DataColumn(p.Name, p.PropertyType)).ToArray()); bool hasDefault = defalueKeyValues.HasValue(); for (int i = 0; i < value.Count(); i++) { var tempList = new ArrayList(); foreach (PropertyInfo propertyInfo in properties) { if (hasDefault && defalueKeyValues.ContainsKey(propertyInfo.Name)) // 赋默认值 { tempList.Add(defalueKeyValues[propertyInfo.Name]); continue; } object objValue = propertyInfo.GetValue(value.ElementAt(i), null); tempList.Add(objValue); } var valueArray = tempList.ToArray(); dataTable.LoadDataRow(valueArray, true); } return(dataTable); }
private static (string, DataType, List <string>) GetValue(this Dictionary <string, AttributeValue> src) { // DynamoDB attribute types https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_streams_AttributeValue.html if (!src.HasValue()) { return("undefined", DataType.Unknown, null); } var val = src.Values.First(); return(val.GetValue()); }
/// <summary> /// Sets/Adds class type to mongo table connection mapping /// </summary> /// <param name="mappings">Entity mappings: class type to mongo table connection</param> public void Mappings(Dictionary <Type, string> mappings) { // If only mapping is present if (mappings.HasValue()) { // We do set/add each one foreach (var mapping in mappings) { // ... If mapping is not present yet if (!Entities.ContainsKey(mapping.Key)) { Entities.Add(mapping.Key, mapping.Value); } } } }
/// <summary> /// Parses the child DATA nodes out of the given config node, and returns the parsed values back in dataValues. /// </summary> /// <param name="configNode">The ConfigNode to load child DATA nodes from.</param> /// <param name="obj">The ContractConfigurator object to load from.</param> /// <param name="dataValues"></param> /// <param name="uniquenessChecks"></param> /// <returns></returns> public bool ParseDataNodes(ConfigNode configNode, IContractConfiguratorFactory obj, Dictionary <string, ContractType.DataValueInfo> dataValues, Dictionary <string, UniquenessCheck> uniquenessChecks) { bool valid = true; foreach (ConfigNode data in ConfigNodeUtil.GetChildNodes(configNode, "DATA")) { Type type = null; bool requiredValue = true; bool hidden = true; bool isLiteral = false; string title = ""; ConfigNodeUtil.SetCurrentDataNode(null); valid &= ConfigNodeUtil.ParseValue <Type>(data, "type", x => type = x, obj); valid &= ConfigNodeUtil.ParseValue <bool>(data, "requiredValue", x => requiredValue = x, obj, true); valid &= ConfigNodeUtil.ParseValue <string>(data, "title", x => title = x, obj, ""); valid &= ConfigNodeUtil.ParseValue <bool>(data, "hidden", x => hidden = x, obj, false); valid &= ConfigNodeUtil.ParseValue <bool>(data, "isLiteral", x => isLiteral = x, obj, false); bool doneTitleWarning = false; UniquenessCheck uniquenessCheck = UniquenessCheck.NONE; // Backwards compatibility for Contract Configurator 1.8.3 if (data.HasValue("uniqueValue") || data.HasValue("activeUniqueValue")) { LoggingUtil.LogWarning(this, "The use of uniqueValue and activeUniqueValue is obsolete since Contract Configurator 1.9.0, use uniquenessCheck instead."); bool uniqueValue = false; bool activeUniqueValue = false; valid &= ConfigNodeUtil.ParseValue <bool>(data, "uniqueValue", x => uniqueValue = x, obj, false); valid &= ConfigNodeUtil.ParseValue <bool>(data, "activeUniqueValue", x => activeUniqueValue = x, obj, false); uniquenessCheck = activeUniqueValue ? UniquenessCheck.CONTRACT_ACTIVE : uniqueValue ? UniquenessCheck.CONTRACT_ALL : UniquenessCheck.NONE; } else { valid &= ConfigNodeUtil.ParseValue <UniquenessCheck>(data, "uniquenessCheck", x => uniquenessCheck = x, obj, UniquenessCheck.NONE); } ConfigNodeUtil.SetCurrentDataNode(this); if (type != null) { foreach (ConfigNode.Value pair in data.values) { string name = pair.name; if (name != "type" && name != "title" && name != "hidden" && name != "requiredValue" && name != "uniqueValue" && name != "activeUniqueValue" && name != "uniquenessCheck" && name != "isLiteral") { if (uniquenessCheck != UniquenessCheck.NONE) { uniquenessChecks[name] = uniquenessCheck; } object value = null; // Create the setter function Type actionType = typeof(Action <>).MakeGenericType(type); Delegate del = Delegate.CreateDelegate(actionType, value, typeof(DataNode).GetMethod("NullAction")); // Set the ParseValue method generic MethodInfo method = (isLiteral ? methodParseValueLiteral : methodParseValue).MakeGenericMethod(new Type[] { type }); // Invoke the ParseValue method if (isLiteral) { this[name] = method.Invoke(null, new object[] { data, name, false }); } else { valid &= (bool)method.Invoke(null, new object[] { data, name, del, obj }); } dataValues[name] = new ContractType.DataValueInfo(title, requiredValue, hidden, type); // Recommend a title if (!data.HasValue("title") && requiredValue && !IsDeterministic(name) && !hidden && !doneTitleWarning && !dataValues[name].IsIgnoredType()) { doneTitleWarning = true; LoggingUtil.Log(obj.minVersion >= ContractConfigurator.ENHANCED_UI_VERSION ? LoggingUtil.LogLevel.ERROR : LoggingUtil.LogLevel.WARNING, this, obj.ErrorPrefix() + ": " + name + ": The field 'title' is required in for data node values where 'requiredValue' is true. Alternatively, the attribute 'hidden' can be set to true (but be careful - this can cause player confusion if all lines for the contract type show as 'Met' and the contract isn't generating)."); // Error on newer versions of contract packs if (obj.minVersion >= ContractConfigurator.ENHANCED_UI_VERSION) { valid = false; } } } } } } return(valid); }
static ClassReflector() { #region finding all types that are suppose to be to reflected Type[] allTypes = Assembly.GetExecutingAssembly().GetTypes(); //finding all 'Reflector' IEnumerable <Type> classReflectors = allTypes.Where( type => typeof(ClassReflector) != type && typeof(ClassReflector).IsAssignableFrom(type) && type.DeclaringType == null); foreach (var type in classReflectors) { //detecting if current 'Reflector' has custom className to reflect if not present its own name is used FieldInfo classNameConst = type.GetField("className", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly); if (classNameConst != null && (!classNameConst.IsLiteral || classNameConst.IsInitOnly)) { classNameConst = null; } //detecting if current 'Reflector' has custom nameSpace to reflect if not present no no namespace is used FieldInfo nameSpaceConst = type.GetField("nameSpace", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly); if (nameSpaceConst != null && (!nameSpaceConst.IsLiteral || nameSpaceConst.IsInitOnly)) { nameSpaceConst = null; } try { //finding 'Target' Type reflectedType = Methods.FindType( nameSpaceConst == null ? null : (string)nameSpaceConst.GetValue(null) + '.', classNameConst == null ? type.Name : (string)classNameConst.GetValue(null)); //detecting if this 'Reflector' reflects back to itself if (reflectedType == type) { throw new Exception(string.Format("Reflector \"{0}\" is reflecting itself", type)); } //members present inside 'Reflector' that have to be present on 'Target' side IEnumerable <MethodInfo> membersToReflect = type.GetMethods( BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.FlattenHierarchy) .Where(memb => memb.DeclaringType != typeof(ClassReflector)); //all members present in 'Target' Dictionary <string, MethodInfo> reflectedMembers = reflectedType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.FlattenHierarchy).ToDictionary(memb => memb.ToString()); //Dictionary to hold all 'Reflector' members that found their 'Target' counter part. Dictionary <MethodInfo, MethodInfo> membersDict = new Dictionary <MethodInfo, MethodInfo>(); #region finidng all members that are suppose to be present on 'Target' side foreach (var toReflect in membersToReflect) { MethodInfo fitinMember; if (reflectedMembers.TryGetValue(toReflect.ToString(), out fitinMember)) { reflectedMembers.Remove(toReflect.ToString()); membersDict.Add(toReflect, fitinMember); } else { throw new MissingMemberException(reflectedType.Name, toReflect.ToString()); } } #endregion s_reflectedTypeMembers.Add(type, membersDict); s_reflectedTypes.Add(type, reflectedType); } catch (Exception e) { s_notReflectedTypes.Add(type, e); } } #endregion // if error occured throwing them out if (s_notReflectedTypes.HasValue()) { throw new ReflectionTypeLoadException(s_notReflectedTypes.Keys.ToArray(), s_notReflectedTypes.Values.ToArray()); } }
public string RenderEvtAsHtml(ZonelessEvent evt, Calinfo calinfo, Dictionary<string,object> args) { if (evt.urls_and_sources == null) evt.urls_and_sources = new Dictionary<string, string>() { { evt.url, evt.source } }; string dtstart; if (evt.allday && evt.dtstart.Hour == 0) dtstart = " "; else dtstart = evt.dtstart.ToString("ddd hh:mm tt"); var month_day = evt.dtstart.ToString("M/d"); string categories = ""; List<string> catlist_links = new List<string>(); if (!String.IsNullOrEmpty(evt.categories)) { List<string> catlist = Utils.GetTagListFromTagString(evt.categories); if (args.ContainsKey("hub_tags") ) // exclude autogenerated hub names { var hub_tags = (List<string>)args["hub_tags"]; catlist = catlist.FindAll(c => hub_tags.Contains(c) == false); } // catlist = catlist.FindAll(c => c.Contains("{") == false); // don't show squiggly tags inline? // actually leave them in so client can show related images. curator can suppress display if desired using css foreach (var cat in catlist) { var category_url = string.Format("javascript:show_view('{0}')", cat); catlist_links.Add(string.Format(@"<a title=""open the {1} view"" href=""{0}"">{1}</a>", category_url, cat)); } categories = string.Format(@" <span class=""cat"">{0}</span>", string.Join(", ", catlist_links.ToArray())); } String description = ( String.IsNullOrEmpty(evt.description) || evt.description.Length < 10 ) ? "" : evt.description.UrlsToLinks(); string dom_id = "e" + evt.uid; string expander = ""; if ( ! String.IsNullOrEmpty(description) && args.HasValue("eventsonly",true) ) expander = String.Format(@"<span class=""sd""><a title=""show description"" href=""javascript:show_desc('{0}')"">...</a></span>", dom_id); string add_to_cal = String.Format(@"<span class=""atc""><a title=""add to calendar"" href=""javascript:add_to_cal('{0}')"">+</a></span>", dom_id); if ( args.HasValue("add_to_cal",false) ) // for view_calendar add_to_cal = ""; string visibility = ""; string more = ""; string source_key = ""; //string source_attr = ""; // not needed, int sequence_count = 1; int sequence_position = 1; string show_more_call; if (evt.urls_and_sources.Count == 1) { sequence_count = (int)args["sequence_count"]; source_key = (string)args["source_key"]; sequence_position = (int)args["sequence_position"]; } visibility = (sequence_count > 1 && sequence_position > 1) ? @" style=""display:none"" " : ""; if (sequence_count > 1 && sequence_position == 1) { show_more_call = "javascript:show_more('" + source_key + "')"; more = string.Format(@" <span class=""{0}""><a title=""show {2} more from {3}"" href=""{1}"">show {2} more</a></span>", source_key, show_more_call, sequence_count - 1, evt.source ); } else { more = ""; } var html = string.Format( @"<div id=""{0}"" class=""bl {12}"" {13} xmlns:v=""http://rdf.data-vocabulary.org/#"" typeof=""v:Event"" > <span style=""display:none"" class=""uid"">{15}</span> <span style=""display:none"" class=""hash"">{16}</span> <span class=""md"">{14}</span> <span class=""st"" property=""v:startDate"" content=""{1}"">{2}</span> <span href=""{3}"" rel=""v:url""></span> <span class=""ttl"">{4}</span> <span class=""src"" property=""v:description"">{5}</span> {6} {7} {8} {9} {11} </div>", dom_id, // 0 String.Format("{0:yyyy-MM-ddTHH:mm}", evt.dtstart), // 1 dtstart, // 2 evt.url, // 3 MakeTitleForRDFa(evt, dom_id, args), // 4 evt.urls_and_sources.Keys.Count == 1 ? evt.source : "", // 5 suppress source if multiple categories, // 6 MakeGeoForRDFa(evt), // 7 expander, // 8 add_to_cal, // 9 "", // 10 was source_attr, not needed more, // 11 source_key, // 12 visibility, // 13 month_day, // 14 evt.uid, // 15 evt.hash // 16 ); this.event_counter += 1; return html; }
// possibly filter an event list by view or count public List<ZonelessEvent> Filter(string view, int count, DateTime from, DateTime to, string source, ZonelessEventStore es, Dictionary<string,object> args) { var events = es.events.CloneObject(); var bare_events = args.HasValue("bare_events", true); var is_html_renderer = args.HasValue("html_renderer", true); if (!String.IsNullOrEmpty(source)) events = SourceFilter(source, events); if (!String.IsNullOrEmpty(view)) events = ViewFilter(view, events); if (from != DateTime.MinValue && to != DateTime.MinValue) events = TimeFilter(from, to, events); if (! bare_events) // bracket the available range before (maybe) reducing to count es.RememberFirstAndLastAvailableDays(events); // not required for non-html renderers but no reason to exclude them if (count != 0) // includes case where bare_events is true events = CountFilter(count, events); if ( ! is_html_renderer ) // do nothing else for non-html views return events; else // post-process result set to yield ~500 day-aligned events { var from_to = new Dictionary<string, DateTime>(); if (bare_events) from_to = HandleBareEvents(from); else from_to = HandleClothedEvents(events); if (from_to == null) return events; else return TimeFilter((DateTime)from_to["from_date"], (DateTime)from_to["to_date"], events); } }
public static string MakeTitleForRDFa(ZonelessEvent evt, string dom_id, Dictionary<string,object> args) { var is_eventsonly = args.HasValue("eventsonly", true); var coalesced_links = BuildCoalescedLinks(evt, dom_id); bool is_coalesced = !String.IsNullOrEmpty(coalesced_links); // case 1: eventsonly, coalesced // <span class="ttl"><a target="elmcity" property="v:summary" title="open event page on source site" href="http://www.harriscenter.org/calendar">Homeschool Program: Biographies of Famous Birds</a></span> // // case 2: eventsonly, not coalesced // <span class="ttl"><span property="v:summary">Crazy Quilters</span> [<a target="elmcity" title="gilsum church" href="http://gilsum.org/church.aspx"> 1 </a><a target="elmcity" title="town of gilsum" href="http://gilsum.org/"> 2 </a>]</span> // // case 3: not eventsonly, coalesced // <span class="ttl"><span property="v:summary"><a href="javascript:show_desc('e3')">Crazy Quilters</a></span> [<a title="gilsum church" href="http://gilsum.org/church.aspx"> 1 </a><a title="town of gilsum" href="http://gilsum.org/"> 2 </a>]</span> // // case 4: not eventsonly, not coalesced // <span class="ttl"><a property="v:summary" title="see details" href='javascript:show_desc("e2")'>Lunchtime Rallies at Central Square</a></span> // <span class="ttl"><span property="v:summary">Crazy Quilters</span> [<a target="elmcity" title="gilsum church" href="http://gilsum.org/church.aspx"> 1 </a><a target="elmcity" title="town of gilsum" href="http://gilsum.org/"> 2 </a>]</span> // otherwise this // <span class="ttl"><span property="v:summary"><a href="javascript:show_desc('e3')">Crazy Quilters</a></span> [<a title="gilsum church" href="http://gilsum.org/church.aspx"> 1 </a><a title="town of gilsum" href="http://gilsum.org/"> 2 </a>]</span> TitleType title_type; if (is_coalesced) title_type = is_eventsonly ? TitleType.EventsOnlyCoalesced : TitleType.NotEventsOnlyCoalesced; else title_type = is_eventsonly ? TitleType.EventsOnlyNotCoalesced : TitleType.NotEventsOnlyNotCoalesced; string title; if ( title_type == TitleType.EventsOnlyCoalesced ) title = string.Format("<span property=\"v:summary\">{0}</span>", evt.title); else title = string.Format("<a property=\"v:summary\" title=\"{0}\" href=\"{1}\">{2}</a>", is_eventsonly ? "open event page on source site": "see details", is_eventsonly ? evt.url : string.Format("javascript:show_desc('{0}')", dom_id), evt.title); if (is_coalesced) title += coalesced_links; return title; }