Exemplo n.º 1
0
        public static List <string> ToStringList(List <T> list)
        {
            var items = new List <string>();

            if (list != null)
            {
                items.AddRange(Enumerable.Select(list, item => Enum.Format(typeof(T), item, "g")));
            }
            return(items);
        }
Exemplo n.º 2
0
        public void SelectTest()
        {
            int[] enumerable = new int[] { 0, 1, 2 };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Select(enumerable, x => x.ToString()),
                IteratorPattern.Select(enumerable, x => x.ToString()));

            enumerable = new int[] { };
            EnumerableAssert.AreSequentialEqual(
                Enumerable.Select(enumerable, x => x.ToString()),
                IteratorPattern.Select(enumerable, x => x.ToString()));
        }
Exemplo n.º 3
0
        private void NotifySource(CollectionChangedNotificationResult <TSource> sourceChange, List <TResult> added, List <TResult> removed)
        {
            if (sourceChange.RemovedItems != null)
            {
                foreach (var item in sourceChange.RemovedItems)
                {
                    SubSourcePair wrapper;
                    if (sourceItems.TryGetValue(item, out wrapper))
                    {
                        removed.AddRange(wrapper);
                        wrapper.Successors.Unset(this);
                        sourceItems.Remove(item);
                    }
                }
            }

            if (sourceChange.AddedItems != null)
            {
                foreach (var item in sourceChange.AddedItems)
                {
                    var subSource = func.Observe(item);
                    var wrapper   = new SubSourcePair(subSource, item, this);
                    wrapper.Successors.Set(this);
                    sourceItems.Add(item, wrapper);
                    added.AddRange(wrapper);
                }
            }

            if (sourceChange.ReplaceAddedItems != null)
            {
                for (int i = 0; i < sourceChange.ReplaceAddedItems.Count; i++)
                {
                    var oldItem = sourceChange.ReplaceRemovedItems[i];
                    var newItem = sourceChange.ReplaceAddedItems[i];

                    var newSubSource = func.Observe(newItem);

                    SubSourcePair wrapper;
                    if (sourceItems.TryGetValue(oldItem, out wrapper))
                    {
                        removed.AddRange(SL.Select(wrapper.Results.Values, res => res.Value));
                        wrapper.Successors.Unset(this);
                        sourceItems.Remove(oldItem);
                    }

                    wrapper = new SubSourcePair(newSubSource, newItem, this);
                    sourceItems.Add(newItem, wrapper);
                    wrapper.Successors.Set(this);
                    added.AddRange(SL.Select(wrapper.Results.Values, res => res.Value));
                }
            }
        }
Exemplo n.º 4
0
            public void OnSourceChanged(object sender, ValueChangedEventArgs e)
            {
                DetachSubsource();
                var notifier = e.OldValue as INotifyCollectionChanged;

                if (notifier != null)
                {
                    notifier.CollectionChanged -= OnCollectionChanged;
                }

                AttachSubSource(this);
                Parent.OnAddItems(SL.Select(Values.Values, res => res.Value));
            }
Exemplo n.º 5
0
        public void LoadFromExcelXLSX()
        {
            var filename = IsotopeTestCommon.Helper.GetTestMethodOutputFilename("Customers.xlsx");
            var data     = IsotopeTests.Properties.Resources.Customers;
            var fp       = System.IO.File.Create(filename);

            fp.Write(data, 0, data.Length);
            fp.Close();

            var dt = Isotope.Data.DataTableBuilder.FromExcelWorksheet(filename, "Sheet1", true);

            var colnames = Enumerable.Select <System.Data.DataColumn, string>(dt.Columns.AsEnumerable(), col => col.ColumnName);

            Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(Enumerable.Contains(colnames, "Telephone"));
        }
Exemplo n.º 6
0
            public override INotificationResult Notify(IList <INotificationResult> sources)
            {
                var added          = new List <TResult>();
                var removed        = new List <TResult>();
                var replaceAdded   = new List <TResult>();
                var replaceRemoved = new List <TResult>();

                foreach (var change in sources)
                {
                    if (change.Source == SubSource)
                    {
                        var subSourceChange = (IValueChangedNotificationResult)change;
                        DetachSubSourceValue((IEnumerable <TIntermediate>)subSourceChange.OldValue, removed);
                        OnAttach();
                        added.AddRange(SL.Select(Results.Values, res => res.Value));
                    }
                    else if (change.Source is TaggedObservableValue <TResult, int> )
                    {
                        var resultChange = (ValueChangedNotificationResult <TResult>)change;
                        replaceRemoved.Add(resultChange.OldValue);
                        replaceAdded.Add(resultChange.NewValue);
                    }
                    else
                    {
                        var subSourceValueChange = (CollectionChangedNotificationResult <TIntermediate>)change;
                        if (subSourceValueChange.IsReset)
                        {
                            DetachSubSourceValue(SubSource.Value, removed);
                            AttachSubSourceValue();
                            added.AddRange(SL.Select(Results.Values, res => res.Value));
                        }
                        else
                        {
                            NotifySubSourceValue(added, removed, subSourceValueChange);
                        }
                    }
                }

                if (added.Count == 0 && removed.Count == 0 && replaceAdded.Count == 0)
                {
                    return(UnchangedNotificationResult.Instance);
                }

                OnRemoveItems(removed);
                OnAddItems(added);
                OnReplaceItems(replaceRemoved, replaceAdded);
                return(new CollectionChangedNotificationResult <TResult>(this, added, removed, replaceAdded, replaceRemoved));
            }
Exemplo n.º 7
0
            public override INotificationResult Notify(IList <INotificationResult> sources)
            {
                var notification = CollectionChangedNotificationResult <TResult> .Create(this);

                var added   = notification.AddedItems;
                var removed = notification.RemovedItems;

                foreach (var change in sources)
                {
                    if (change.Source == SubSource)
                    {
                        var subSourceChange = (IValueChangedNotificationResult)change;
                        DetachSubSourceValue((IEnumerable <TIntermediate>)subSourceChange.OldValue, removed);
                        OnAttach();
                        added.AddRange(SL.Select(Results.Values, res => res.Value));
                    }
                    else if (change.Source is TaggedObservableValue <TResult, int> )
                    {
                        var resultChange = (IValueChangedNotificationResult <TResult>)change;
                        removed.Add(resultChange.OldValue);
                        added.Add(resultChange.NewValue);
                    }
                    else
                    {
                        var subSourceValueChange = (ICollectionChangedNotificationResult <TIntermediate>)change;
                        if (subSourceValueChange.IsReset)
                        {
                            DetachSubSourceValue(SubSource.Value, removed);
                            AttachSubSourceValue();
                            added.AddRange(SL.Select(Results.Values, res => res.Value));
                        }
                        else
                        {
                            NotifySubSourceValue(added, removed, subSourceValueChange);
                        }
                    }
                }

                RaiseEvents(added, removed, null);
                return(notification);
            }
Exemplo n.º 8
0
        public virtual void Delete(IEnumerable <FeatureDataRow <TOid> > features)
        {
            List <TOid> featureIds = new List <TOid>();

            foreach (FeatureDataRow <TOid> fdr in features)
            {
                featureIds.Add(fdr.Id);
            }

            ExpressionTreeToSqlCompilerBase <TOid> compiler = CreateSqlCompiler(null);

            using (IDbConnection conn = DbUtility.CreateConnection(ConnectionString))
            {
                using (IDbCommand cmd = DbUtility.CreateCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText =
                        String.Format(
                            "DELETE FROM {0} WHERE {1} in ({2})",
                            QualifiedTableName,
                            OidColumn,
                            String.Join(",",
                                        Enumerable.ToArray(
                                            Processor.Select(featureIds,
                                                             delegate(TOid o)
                    {
                        return
                        (compiler.CreateParameter(o).ParameterName);
                    })))
                            );
                    conn.Open();
                    foreach (IDataParameter p in compiler.ParameterCache.Values)
                    {
                        cmd.Parameters.Add(p);
                    }

                    cmd.ExecuteNonQuery();
                }
            }
        }
Exemplo n.º 9
0
        public static IList <T> GetInstances <T>(List <Type> excludedTypes = null)
        {
            List <TypeInfo> excludedTypeInfos = null;

            if (excludedTypes != null)
            {
                excludedTypeInfos = Enumerable.ToList(
                    Enumerable.Select(excludedTypes, type => type.GetTypeInfo()));
            }

            if (excludedTypes == null)
            {
                excludedTypes = new List <Type>();
            }

            var instances = new List <T>();
            var assemblie = GetAssembly(typeof(T));

            foreach (var type in assemblie.DefinedTypes)
            {
                if (!type.IsAbstract && type.IsSubclassOf(typeof(T)))
                {
                    try
                    {
                        if (!excludedTypeInfos.Contains(type))
                        {
                            instances.Add((T)Activator.CreateInstance(type.AsType()));
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            return(instances);
        }
Exemplo n.º 10
0
 public override IEnumerator <TResult> GetEnumerator()
 {
     return(SL.Select(Results.Values, t => t.Value).GetEnumerator());
 }
Exemplo n.º 11
0
        private void SourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Move)
            {
                return;
            }
            if (e.Action != NotifyCollectionChangedAction.Reset)
            {
                if (e.Action == NotifyCollectionChangedAction.Remove && e.OldItems != null)
                {
                    var removed = new List <TResult>();
                    foreach (TSource item in e.OldItems)
                    {
                        SubSourcePair wrapper;
                        if (sourceItems.TryGetValue(item, out wrapper))
                        {
                            removed.AddRange(SL.Select(wrapper.Values.Values, res => res.Value));
                            DetachSubSource(item);
                        }
                    }
                    OnRemoveItems(removed);
                }
                if (e.Action == NotifyCollectionChangedAction.Add && e.NewItems != null)
                {
                    var added = new List <TResult>();
                    foreach (TSource item in e.NewItems)
                    {
                        var subSource = func.Observe(item);
                        var wrapper   = new SubSourcePair(subSource, item, this);
                        sourceItems.Add(item, wrapper);
                        AttachSubSource(wrapper);
                        subSource.ValueChanged += wrapper.OnSourceChanged;
                        added.AddRange(SL.Select(wrapper.Values.Values, res => res.Value));
                    }
                    OnAddItems(added);
                }
                if (e.Action == NotifyCollectionChangedAction.Replace)
                {
                    var removed = new List <TResult>();
                    var added   = new List <TResult>();
                    for (int i = 0; i < e.OldItems.Count; i++)
                    {
                        var oldItem = (TSource)e.OldItems[i];
                        var newItem = (TSource)e.NewItems[i];

                        var newSubSource = func.Observe(newItem);

                        SubSourcePair wrapper;
                        if (sourceItems.TryGetValue(oldItem, out wrapper))
                        {
                            if (wrapper.SubSource.Value != newSubSource.Value)
                            {
                                removed.AddRange(SL.Select(wrapper.Values.Values, res => res.Value));
                                DetachSubSource(oldItem);

                                wrapper = new SubSourcePair(newSubSource, newItem, this);
                                sourceItems.Add(newItem, wrapper);
                                AttachSubSource(wrapper);
                                newSubSource.ValueChanged += wrapper.OnSourceChanged;
                                added.AddRange(SL.Select(wrapper.Values.Values, res => res.Value));
                            }
                            else
                            {
                                wrapper.SubSource.ValueChanged -= wrapper.OnSourceChanged;
                                wrapper.SubSource = newSubSource;
                                wrapper.SubSource.ValueChanged += wrapper.OnSourceChanged;
                                sourceItems.Remove(oldItem);
                                sourceItems.Add(newItem, wrapper);
                                wrapper.ReplaceItem(newItem);
                            }
                        }
                        else
                        {
                            wrapper = new SubSourcePair(newSubSource, newItem, this);
                            sourceItems.Add(newItem, wrapper);
                            AttachSubSource(wrapper);
                            newSubSource.ValueChanged += wrapper.OnSourceChanged;
                            added.AddRange(SL.Select(wrapper.Values.Values, res => res.Value));
                        }
                    }
                    OnAddItems(added);
                    OnRemoveItems(removed);
                }
            }
            else
            {
                DetachSource();
                OnCleared();
            }
        }
Exemplo n.º 12
0
 public override IEnumerator <TResult> GetEnumerator()
 {
     return(SL.Select(
                SL.SelectMany(sourceItems.Values, sub => sub.Values.Values), res => res.Value).GetEnumerator());
 }
Exemplo n.º 13
0
 private TOutput ProcessInternal <TInput, TOutput>(TInput input, TOutput defaultOutput)
 {
     return(new Chain.StrategyProcessor <TInput, TOutput>(
                Processor.Select(_strategies,
                                 delegate(SridMapStrategyBase o) { return (Chain.IStrategy <TInput, TOutput>)o; })).Process(input, defaultOutput));
 }
 internal XsdValidationException(System.Collections.Generic.IEnumerable <XsdValidationInfo> validationInfos)
     : base(string.Format(Format, CollectionsExtension.Stringify(Enumerable.Select(validationInfos, info => info.ToString()))))
 {
 }
Exemplo n.º 15
0
        private void SetStyle(
            GeometryStyle style,
            string stroke,
            string strokeWidth,
            string strokeOpacity,
            string strokeLinejoin,
            string strokeLineCap,
            string strokeDasharray,
            string strokeDashOffset,
            string fill,
            string fillOpacity,
            string pointSymbolPath
            )
        {
            if (!String.IsNullOrEmpty(stroke))
            {
                Color  color   = ColorTranslator.FromHtml(stroke);
                int    opacity = 255;
                double width   = 1;

                if (!String.IsNullOrEmpty(strokeOpacity))
                {
                    opacity = Convert.ToInt32(Math.Round(Convert.ToDouble(strokeOpacity) / 0.0039215, 0));
                    if (opacity > 255)
                    {
                        opacity = 255;
                    }
                }

                if (!String.IsNullOrEmpty(strokeWidth))
                {
                    width = Convert.ToDouble(strokeWidth);
                }

                StyleBrush brush =
                    new SolidStyleBrush(new StyleColor(Convert.ToInt32(color.B), Convert.ToInt32(color.G),
                                                       Convert.ToInt32(color.R), opacity));
                StylePen pen = new StylePen(brush, width);

                if (!String.IsNullOrEmpty(strokeLinejoin))
                {
                    switch (strokeLinejoin.ToLower())
                    {
                    case "mitre":
                        pen.LineJoin = StyleLineJoin.Miter;
                        break;

                    case "round":
                        pen.LineJoin = StyleLineJoin.Round;
                        break;

                    case "bevel":
                        pen.LineJoin = StyleLineJoin.Bevel;
                        break;

                        //case "miterclipped": // Not in SLD
                        //    pen.LineJoin = StyleLineJoin.MiterClipped;
                        //    break;
                    }
                }

                if (!String.IsNullOrEmpty(strokeLineCap))
                {
                    switch (strokeLineCap.ToLower())
                    {
                    case "butt":
                        pen.StartCap = StyleLineCap.Flat;
                        pen.EndCap   = StyleLineCap.Flat;
                        break;

                    case "round":
                        pen.StartCap = StyleLineCap.Round;
                        pen.EndCap   = StyleLineCap.Round;
                        break;

                    case "square":
                        pen.StartCap = StyleLineCap.Square;
                        pen.EndCap   = StyleLineCap.Square;
                        break;

                        // N.B. Loads of others not used in SLD
                    }
                }

                if (!String.IsNullOrEmpty(strokeDasharray))
                {
                    string[] Numbers = strokeDasharray.Split(Char.Parse(" "));

                    IEnumerable <float> dbls = Processor.Select(Numbers, delegate(string o) { return(float.Parse(o)); });
                    pen.DashPattern = Enumerable.ToArray(dbls);
                }

                if (!String.IsNullOrEmpty(strokeDashOffset))
                {
                    float dashOffset;
                    bool  success;
                    success = float.TryParse(strokeDashOffset, out dashOffset);
                    if (success)
                    {
                        pen.DashOffset = dashOffset;
                    }
                }

                // Set pen
                style.Line = pen;
            }

            if (!String.IsNullOrEmpty(fill))
            {
                Color color   = ColorTranslator.FromHtml(fill);
                int   opacity = 255;

                if (!String.IsNullOrEmpty(fillOpacity))
                {
                    opacity = Convert.ToInt32(Math.Round(Convert.ToDouble(fillOpacity) / 0.0039215, 0));
                    if (opacity > 255)
                    {
                        opacity = 255;
                    }
                }

                StyleBrush brush =
                    new SolidStyleBrush(new StyleColor(Convert.ToInt32(color.B), Convert.ToInt32(color.G),
                                                       Convert.ToInt32(color.R), opacity));

                style.Fill = brush;
            }


            if (!String.IsNullOrEmpty(pointSymbolPath))
            {
                Uri source = new Uri(pointSymbolPath);

                if (source.IsFile && File.Exists(source.AbsolutePath))
                {
                    Bitmap b = new Bitmap(source.AbsolutePath);

                    MemoryStream ms = new MemoryStream();
                    b.Save(ms, ImageFormat.Png);
                    ms.Seek(0, SeekOrigin.Begin);

                    style.Symbol = new Symbol2D(ms, new Size2D(12, 10));
                }
                else if (source.IsAbsoluteUri)
                {
                    ///TODO
                }
            }

            style.Enabled       = true;
            style.EnableOutline = true;
        }
Exemplo n.º 16
0
        protected override DataTable BuildSchemaTable(Boolean withGeometryColumn)
        {
            DataTable dt = null;

            using (NpgsqlConnection conn = new NpgsqlConnection(ConnectionString))
            {
                conn.Open();

                CollectionExpression <PropertyNameExpression> attributes = null;
                if (DefaultProviderProperties != null)
                {
                    attributes = GetProviderPropertyValue
                                 <AttributesCollectionExpression, CollectionExpression <PropertyNameExpression> >(
                        DefaultProviderProperties.ProviderProperties,
                        null);
                }

                string columns = attributes == null
                                     ?
                                 "*"
                                     :
                                 string.Join(",", Enumerable.ToArray(Processor.Select(attributes,
                                                                                      delegate(
                                                                                          PropertyNameExpression
                                                                                          o)
                {
                    return
                    (QualifyColumnName
                     (
                         o.
                         PropertyName));
                })));

                if (columns != "*")
                {
                    if (!columns.Contains(QualifyColumnName(GeometryColumn)))
                    {
                        columns = string.Format("{0},{1}", QualifyColumnName(GeometryColumn), columns);
                    }
                    if (!columns.Contains(QualifyColumnName(OidColumn)))
                    {
                        columns = string.Format("{0},{1}", QualifyColumnName(OidColumn), columns);
                    }
                }

                using (
                    NpgsqlCommand cmd =
                        new NpgsqlCommand(string.Format("SELECT {0} FROM {1} LIMIT 1;", columns, QualifiedTableName),
                                          conn))
                {
                    NpgsqlDataAdapter da = new NpgsqlDataAdapter(cmd);
                    DataSet           ds = new DataSet();
                    da.FillSchema(ds, SchemaType.Source);
                    dt = ds.Tables["Table"];
                }

                conn.Close();
            }

            if (!dt.Columns.Contains("oid") && HasOids)
            {
                dt.Columns.Add(new DataColumn("oid", typeof(Int64)));
                DataColumn dc = dt.Columns["oid"];
                dc.SetOrdinal(0);
                if (dt.Constraints.Count == 0)
                {
                    dt.Constraints.Add("PK", dt.Columns[0], true);
                }
            }

            for (int i = 0; i < dt.Columns.Count; i++)
            {
                if (dt.Columns[i].ColumnName == GeometryColumn)
                {
                    dt.Columns[i].DataType = typeof(Byte[]);
                }
            }

            if (!withGeometryColumn)
            {
                dt.Columns.Remove(GeometryColumn);
            }

            //remove Primary Key to avoid possibliy mismatched PrimaryKey of FeatureDataTable
            dt.PrimaryKey = null;
            return(dt);
        }