Пример #1
0
 private static IRecord CreateRecord(object item, System.Collections.Generic.IList <string> aliases)
 {
     System.Collections.ICollection collection = item as System.Collections.ICollection;
     if (collection != null)
     {
         System.Collections.Generic.List <object> list = collection.Cast <object>().ToList <object>();
         if (aliases != null && aliases.Count != list.Count)
         {
             aliases = null;
         }
         if (list.Count != 1)
         {
             int counter             = 0;
             DictionaryRecord record = new DictionaryRecord();
             list.ForEach(delegate(object obj)
             {
                 record.SetValue((aliases != null) ? aliases[counter++] : ("Value" + ++counter), obj);
             });
             return(record);
         }
         if (aliases != null)
         {
             aliases[0] = Pluralizer.ToSingular(aliases[0]);
         }
         item = list[0];
     }
     if (aliases == null || aliases.Count != 1)
     {
         return(RecordBase.CreateRecord(item));
     }
     return(RecordBase.CreateRecord(item, aliases[0]));
 }
Пример #2
0
        public static List <T> ToList <T>(this System.Collections.ICollection collection)
        {
            var list = new List <T>(collection.Count);

            list.AddRange(collection.Cast <T>());

            return(list);
        }
Пример #3
0
        /// <summary>
        /// 创建用来构建控件层次结构的列字段集。
        /// </summary>
        /// <param name="dataSource">数据源。</param>
        /// <param name="useDataSource">指示是否使用数据源。</param>
        /// <returns>列字段集。</returns>
        protected override System.Collections.ICollection CreateColumns(PagedDataSource dataSource, bool useDataSource)
        {
            System.Collections.ICollection cols =
                base.CreateColumns(dataSource, useDataSource);

            if (_colsOrders == null)
            {
                return(cols);
            }

            List <DataControlField> tmp =
                cols.Cast <DataControlField>().ToList();

            List <DataControlField> r = new List <DataControlField>();

            foreach (var entry in _colsOrders.OrderBy(p => p.Value))
            {
                if (entry.Value < 0)
                {
                    continue;
                }

                r.Add(
                    tmp.First(p => p.HeaderText.Equals(entry.Key)));
            }

            foreach (var f in tmp)
            {
                if (r.Exists(p => p.HeaderText.Equals(f.HeaderText)))
                {
                    continue;
                }

                r.Add(f);
            }

            return(r);
        }
Пример #4
0
 public static Java.Util.ICollection ToInteroperableCollection(this System.Collections.ICollection instance)
 {
     return(instance is Java.Util.ICollection ? (Java.Util.ICollection)instance : new ArrayList(instance.Cast <Java.Lang.Object>()));
 }
Пример #5
0
        private Paragraph PropParagraph(string name, System.Collections.ICollection props)
        {
            Paragraph p = new Paragraph();
            bool      appendSeparator = false;

            if (props != null)
            {
                foreach (dynamic value in props.Cast <object>().OrderBy(x => x.ToString()))
                {
                    if (appendSeparator)
                    {
                        p.Inlines.Add("\r\n");
                    }
                    else
                    {
                        appendSeparator = true;
                    }
                    string valueString = ((Object)value).ToString();
                    if (name == "userAccountControl:")
                    {
                        p.Inlines.Add(new Run(GetUserAccountControl(value)));
                    }
                    else if (valueString == "System.__ComObject")
                    {
                        try
                        {
                            // Try an ADSI Large Integer
                            Object o    = value;
                            Object low  = o.GetType().InvokeMember("LowPart", System.Reflection.BindingFlags.GetProperty, null, o, null);
                            Object high = o.GetType().InvokeMember("HighPart", System.Reflection.BindingFlags.GetProperty, null, o, null);

                            //long dateValue = (value.HighPart * &H100000000) + value.LowPart;
                            long     dateValue = ((long)((int)high) << 32) + (long)((int)low);
                            DateTime dt        = DateTime.FromFileTime(dateValue);
                            if (dt.ToString("dd-MMM-yyyy HH:mm") != "01-Jan-1601 11:00")
                            {
                                if (dt.Year == 1601)
                                {
                                    p.Inlines.Add(dt.ToString("HH:mm"));
                                }
                                else
                                {
                                    p.Inlines.Add(dt.ToString("dd-MMM-yyyy HH:mm"));
                                }
                            }
                        }
                        catch
                        {
                            p.Inlines.Add(valueString);
                        }
                    }
                    else if (valueString == "System.Byte[]")
                    {
                        byte[] bytes = value as byte[];
                        if (bytes.Length == 16)
                        {
                            Guid guid = new Guid(bytes);
                            p.Inlines.Add(guid.ToString("B"));
                        }
                        else if (bytes.Length == 28)
                        {
                            try
                            {
                                System.Security.Principal.SecurityIdentifier sid = new System.Security.Principal.SecurityIdentifier(bytes, 0);
                                p.Inlines.Add(sid.ToString());
                            }
                            catch
                            {
                                p.Inlines.Add(valueString);
                            }
                        }
                        else
                        {
                            System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes);
                            try
                            {
                                BitmapImage photoBitmap = new BitmapImage();
                                photoBitmap.BeginInit();
                                photoBitmap.StreamSource = ms;
                                photoBitmap.EndInit();
                                Image img = new Image();
                                img.Source  = photoBitmap;
                                img.Stretch = Stretch.None;
                                p.Inlines.Add(img);
                            }
                            catch
                            {
                                p.Inlines.Add(valueString);
                            }
                        }
                    }
                    else
                    {
                        if (valueString.StartsWith("CN=") || valueString.ToLower().StartsWith("http://"))
                        {
                            //string display = Regex.Match(valueString + ",", "CN=(.*?),").Groups[1].Captures[0].Value;
                            //Hyperlink h = new Hyperlink(new Run(display));
                            Hyperlink h = new Hyperlink(new Run(valueString));
                            h.NavigateUri = new Uri(valueString, valueString.ToLower().StartsWith("http://") ? UriKind.Absolute : UriKind.Relative);
                            h.Click      += new RoutedEventHandler(HyperlinkClicked);
                            //p.TextIndent = -20;
                            //p.Margin = new Thickness(20, p.Margin.Top, p.Margin.Right, p.Margin.Bottom);
                            p.Inlines.Add(h);
                        }
                        else
                        {
                            p.Inlines.Add(new Run(valueString));
                        }
                    }
                }
            }

            return(p);
        }