示例#1
0
        private bool HandleMemoryOutput(IDatasource ds, OutputLayerInfo outputInfo)
        {
            if (!ds.IsVector)
            {
                throw new ApplicationException("Memory layers can only be used for vector datasources.");
            }

            if (!outputInfo.AddToMap)
            {
                throw new ApplicationException("Memory layer option can only be used with add to map option.");
            }

            bool result = _layerService.AddDatasource(ds, outputInfo.Name);

            if (result)
            {
                outputInfo.DatasourcePointer = new DatasourcePointer(_layerService.LastLayerHandle, outputInfo.Name);
                outputInfo.Result            = null;
            }
            else
            {
                if (outputInfo.Result != null)
                {
                    outputInfo.Result.Dispose();
                    outputInfo.Result = null;
                }
            }

            // report failure if we haven't added datasource to the map
            return(result);
        }
示例#2
0
        // Create -------------------------------------

        /// <summary>
        /// Creates a connector.
        /// </summary>
        /// <param name="scope">The scope to consider.</param>
        /// <param name="dataSource">The data source to consider.</param>
        /// <param name="connectorDefinitionUniqueId">The connector definition name to consider.</param>
        /// <param name="log">The log of execution to consider.</param>
        /// <returns>Returns True if the connector has been opened. False otherwise.</returns>
        public static T Open <T>(
            this IBdoScope scope,
            IDatasource dataSource,
            string connectorDefinitionUniqueId,
            IBdoLog log = null)
            where T : class, IBdoConnection
        {
            if (log == null)
            {
                log = new BdoLog();
            }

            if (dataSource == null)
            {
                log.AddError("Data source missing");
            }
            else if (!string.IsNullOrEmpty(connectorDefinitionUniqueId) && dataSource.HasConfiguration(connectorDefinitionUniqueId))
            {
                log.AddError("Connection not defined in data source", description: "No connector is defined in the specified data source.");
            }
            else if (!string.IsNullOrEmpty(connectorDefinitionUniqueId))
            {
                return(scope.Open <T>(dataSource.GetConfiguration(connectorDefinitionUniqueId), log));
            }
            else if (dataSource.Configurations.Count > 0)
            {
                return(scope.Open <T>(dataSource.Configurations[0], log));
            }

            return(default);
示例#3
0
        private bool HandleDiskOutput(IDatasource ds, OutputLayerInfo outputInfo)
        {
            string filename = outputInfo.Filename;

            if (File.Exists(filename) && !outputInfo.Overwrite)
            {
                return(HandleOverwriteFailure());
            }

            bool result = SaveDatasource(ds, filename);

            ds.Dispose();
            outputInfo.Result = null;

            if (!result)
            {
                return(false);
            }

            outputInfo.DatasourcePointer = new DatasourcePointer(filename);

            if (outputInfo.AddToMap)
            {
                // don't report error if layer isn't added to the map
                // user might cancel it because of projection mismatch
                _layerService.AddLayersFromFilename(filename);
            }

            return(true);
        }
        public void MethodWithLiteralArgument_HasValueDatasource()
        {
            IEngineConfigurationTypeMember member = mEngineConfigurationType.GetRegisteredMember(mSingleArgMethod);
            IEngineConfigurationDatasource configurationSource = member.GetDatasources().Single();
            IDatasource source = configurationSource.Build();

            Assert.AreEqual(typeof(ValueSource <object>), source.GetType());
        }
        public void MethodWithTwoArguments_HasCorrectDatasource(int skip, Type expectedType)
        {
            IEngineConfigurationTypeMember member       = mEngineConfigurationType.GetRegisteredMember(mDoubleArgMethod);
            IEngineConfigurationDatasource sourceConfig = member.GetDatasources().Skip(skip).First();
            IDatasource source = sourceConfig.Build();

            Assert.AreEqual(expectedType, source.GetType());
        }
示例#6
0
        /// <summary>
        /// Returns a list of suggested values by field mapping key.
        /// </summary>
        /// <param name="fieldMappingKeys">List of field mapping keys</param>
        /// <returns>Collection of suggested value</returns>
        public virtual IEnumerable <string> GetSuggestedValues(IDatasource selectedDatasource, IEnumerable <RemoteFieldInfo> remoteFieldInfos)
        {
            if (selectedDatasource == null || remoteFieldInfos == null)
            {
                return(Enumerable.Empty <string>());
            }

            if (!this.Datasources.Any(ds => ds.Id == selectedDatasource.Id) || // datasource belong to this system
                !remoteFieldInfos.Any(mi => mi.DatasourceId == selectedDatasource.Id))       // and remoteFieldInfos is for our system datasource
            {
                return(Enumerable.Empty <string>());
            }

            var activeRemoteFieldInfo = remoteFieldInfos.FirstOrDefault(mi => mi.DatasourceId == selectedDatasource.Id);

            switch (activeRemoteFieldInfo.ColumnId)
            {
            case "staticds1email":
                return(new List <string> {
                    "*****@*****.**",
                    "*****@*****.**",
                    "*****@*****.**",
                    "*****@*****.**"
                });

            case "staticds1firstname":
                return(new List <string> {
                    "Hung",
                    "Phu",
                    "Tuan",
                    "Thach"
                });

            case "staticds2avatar":
                return(new List <string> {
                    "tuan.png",
                    "thach.jpg"
                });

            case "staticds2name":
                return(new List <string> {
                    "Tuan Do",
                    "Thach Nguyen",
                    "Hung Phan",
                    "Phu Nguyen"
                });

            case "staticds2bio":
                return(new List <string> {
                    "I am from Vietnam",
                    "I am from Sweden"
                });

            default:
                return(Enumerable.Empty <string>());
            }
        }
示例#7
0
        /// <summary>
        /// Gets the initial data source kind of this instance.
        /// </summary>
        /// <returns>Returns the initial data source kind of this instance.</returns>
        public DatasourceKind GetDatasourceKind()
        {
            IDatasource dataSource = GetDatasource();

            if (dataSource != null)
            {
                return(dataSource.Kind);
            }

            return(DatasourceKind.None);
        }
示例#8
0
        public EnumerableSource(int minCount, int maxCount, object[] args)
        {
            mMinCount = minCount;
            mMaxCount = maxCount;
            mArgs     = args;

            var factory = new DatasourceFactory(typeof(TSource));

            factory.SetParams(mArgs);
            mSource = (IDatasource <T>)factory.Build();
        }
示例#9
0
        /// <summary>
        /// Saves datasource or (and) adds it to the map depending on options specified in OutputLayerInfo instance.
        /// </summary>
        public bool Save(IDatasource ds, OutputLayerInfo outputInfo)
        {
            ds.Callback = null;

            if (outputInfo.MemoryLayer)
            {
                return(HandleMemoryOutput(ds, outputInfo));
            }

            return(HandleDiskOutput(ds, outputInfo));
        }
示例#10
0
        public void SetSource_SetsCorrectDatasource()
        {
            IEngineConfigurationDatasource source = null;

            mMemberMock.Setup(x => x.SetDatasource(It.IsAny <IEngineConfigurationDatasource>())).Callback((IEngineConfigurationDatasource configSource) =>
            {
                source = configSource;
            });
            mContext.SetSource <TestSource>();
            IDatasource datasource = source.Build();

            Assert.AreEqual(typeof(TestSource), datasource.GetType());
        }
示例#11
0
        public void SetValue_SetsValueDataSource()
        {
            IEngineConfigurationDatasource source = null;

            mMemberMock.Setup(x => x.SetDatasource(It.IsAny <IEngineConfigurationDatasource>())).Callback((IEngineConfigurationDatasource configSource) =>
            {
                source = configSource;
            });
            mContext.SetValue(10);
            IDatasource datasource = source.Build();

            Assert.AreEqual(10, datasource.Next(null));
        }
示例#12
0
        void SetDatasource()
        {
            switch (_datasource)
            {
            case "memory":
                _ds = new CacheService(_cache);
                break;

            default:
                //database by default
                _ds = new DbService(_context);
                break;
            }
        }
        /// <summary>
        /// Returns a list of suggested values by field mapping key.
        /// </summary>
        /// <param name="fieldMappingKeys">List of field mapping keys</param>
        /// <returns>Collection of suggested value</returns>
        public virtual IEnumerable <string> GetSuggestedValues(IDatasource selectedDatasource, IEnumerable <RemoteFieldInfo> remoteFieldInfos)
        {
            if (selectedDatasource == null || remoteFieldInfos == null)
            {
                return(Enumerable.Empty <string>());
            }

            if (this.Datasources.Any(ds => ds.Id == selectedDatasource.Id) && // datasource belong to this system
                remoteFieldInfos.Any(mi => mi.DatasourceId == selectedDatasource.Id))       // and remoteFieldInfos is for our system datasource
            {
                return(new[] { "Hanoi", "Episerver", "Forms" });
            }

            return(Enumerable.Empty <string>());
        }
示例#14
0
        private bool SaveDatasource(IDatasource ds, string filename)
        {
            if (!GeoSource.Remove(filename))
            {
                return(HandleOverwriteFailure());
            }

            if (LayerSourceHelper.Save(ds, filename))
            {
                Logger.Current.Info("Layer ({0}) is created.", filename);
                return(true);
            }

            Logger.Current.Error("Failed to save datasource: " + ds.LastError);
            return(false);
        }
示例#15
0
        public static IEnumerable <ILayerSource> GetLayers(this IDatasource ds)
        {
            var vs = ds as VectorDatasource;

            if (vs != null)
            {
                foreach (var layer in vs)
                {
                    yield return(layer);
                }
            }
            else
            {
                yield return(ds as ILayerSource);
            }
        }
        public override void Configure(XDocument config)
        {
            base.Configure(config);

            XElement              xElements        = new XElement("root", (config?.FirstNode as XElement)?.Elements());
            XDocument             dependencyConfig = new XDocument(xElements);
            IEnumerable <IPlugin> dependencies     = PluginLoader.Load(dependencyConfig).ToArray(); // force immediate execution

            if (!dependencies.Any(p => p is IDatasource) || !dependencies.Any(p => p is IDatasink))
            {
                throw new ConfigurationErrorsException("Interactive plugin requires a valid Datasource and a valid Datasink.");
            }

            _datasource = dependencies.First(p => p is IDatasource) as IDatasource;
            _datasink   = dependencies.First(p => p is IDatasink) as IDatasink;
        }
        /// <summary>
        /// Creates this object builder
        /// </summary>
        /// <param name="type"></param>
        public ObjectBuilder(IEngineConfigurationType type)
        {
            this.InnerType = type.RegisteredType;

            if (type.GetFactory() != null)
            {
                mFactory = type.GetFactory().Build();
            }

            type.GetRegisteredMembers()
            .ToList()
            .ForEach(x =>
            {
                var sources = x.GetDatasources().Select(s => s.Build()).ToList();

                if (x.Member.IsField)
                {
                    if (sources.Count == 0)
                    {
                        return;
                    }

                    this.AddAction(new ObjectFieldSetFromSourceAction(
                                       (EngineTypeFieldMember)x.Member,
                                       sources.First()));
                }
                else if (x.Member.IsProperty)
                {
                    if (sources.Count == 0)
                    {
                        return;
                    }

                    this.AddAction(new ObjectPropertySetFromSourceAction(
                                       (EngineTypePropertyMember)x.Member,
                                       sources.First()));
                }
                else if (x.Member.IsMethod)
                {
                    this.AddAction(new ObjectMethodInvokeFromSourceAction(
                                       (EngineTypeMethodMember)x.Member,
                                       sources
                                       ));
                }
            });
        }
        /// <summary>
        /// Creates this object builder
        /// </summary>
        /// <param name="type"></param>
        public ObjectBuilder(IEngineConfigurationType type)
        {
            InnerType = type.RegisteredType;

            if (type.GetFactory() != null)
            {
                mFactory = type.GetFactory().Build();
            }

            type.GetRegisteredMembers()
                .ToList()
                .ForEach(x =>
                             {
                                 List<IDatasource> sources = x.GetDatasources().Select(s => s.Build()).ToList();

                                 if (x.Member.IsField)
                                 {
                                     if (sources.Count == 0)
                                     {
                                         return;
                                     }

                                     AddAction(new ObjectFieldSetFromSourceAction(
                                                   (EngineTypeFieldMember) x.Member,
                                                   sources.First()));
                                 }
                                 else if (x.Member.IsProperty)
                                 {
                                     if (sources.Count == 0)
                                     {
                                         return;
                                     }

                                     AddAction(new ObjectPropertySetFromSourceAction(
                                                   (EngineTypePropertyMember) x.Member,
                                                   sources.First()));
                                 }
                                 else if (x.Member.IsMethod)
                                 {
                                     AddAction(new ObjectMethodInvokeFromSourceAction(
                                                   (EngineTypeMethodMember) x.Member,
                                                   sources
                                                   ));
                                 }
                             });
        }
示例#19
0
        public static bool Save(IDatasource ds, string filename)
        {
            var fs = ds as IFeatureSet;

            if (fs != null)
            {
                return(fs.SaveAsEx(filename, true));
            }

            var raster = ds as IRasterSource;

            if (raster != null)
            {
                return(raster.Save(filename));
            }

            throw new ApplicationException("Failed to save. Unsupported format.");
        }
示例#20
0
        public bool AddDatasource(IDatasource ds, string layerName = "")
        {
            int addedCount = 0;

            var layers = _context.Map.Layers;

            foreach (var layer in ds.GetLayers())
            {
                // projection mistmatch testing
                var newLayer = TestProjectionMismatch(layer, out _aborted);

                if (_aborted)
                {
                    return(false);
                }

                if (newLayer == null)
                {
                    continue;
                }

                // ask plugins if they don't object
                var args = new DatasourceCancelEventArgs(newLayer);
                _broadcaster.BroadcastEvent(p => p.BeforeLayerAdded_, _context.Map, args);

                if (args.Cancel)
                {
                    return(false);
                }

                int layerHandle = layers.Add(newLayer);
                if (layerHandle != -1)
                {
                    var ll = layers.ItemByHandle(layerHandle);
                    ll.Name = string.IsNullOrWhiteSpace(layerName) ? layer.Name : layerName;

                    addedCount++;
                    _lastLayerHandle = layerHandle;
                }
            }

            return(addedCount > 0); // currently at least one should be success to return success
        }
示例#21
0
        private static bool SaveToTempDatasource(ITempFileService tempFileService, IDatasource ds)
        {
            // We can't the resulting shapefile directly, because it was created by background thread
            // therefore is located in another apartment. This will cause creation of proxies and marshalling
            // for COM, which in turn no always supported by implementation of particular classes in MapWinGIS.
            // Therefore the best option we have is to save into temp file, open it, read into memory, delete the source.
            string filename = tempFileService.GetTempFilename(".shp");
            bool   saved    = SaveDatasource(ds, filename);

            ds.Dispose();

            if (!saved)
            {
                Logger.Current.Warn("Failed to save datasource to temp file.");
                return(false);
            }

            return(true);
        }
 public PrivateMemberSetFromSourceAction(EngineTypeMember member, IDatasource source)
 {
     _member     = member;
     _datasource = source;
 }
 private void SetSelectedDatasource(IDatasource datasource)
 {
     Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { SelectedDatasource = datasource; }));
 }
 public ObjectFieldSetFromSourceAction(EngineTypeFieldMember member, IDatasource source)
 {
     _member = member;
     _datasource = source;
 }
示例#25
0
 public ContactRepository(IDatasource datasource)
 {
     this.datasource = datasource;
 }
        public override void PopulateDatabases(IDatasource datasource)
        {
            DatabaseObjectsCollection <IDatabase> databases = new DatabaseObjectsCollection <IDatabase>(datasource);

            SqlConnection sqlConnection = null;

            sqlConnection = new SqlConnection();
            sqlConnection.ConnectionString = datasource.ConnectionString;
            try
            {
                sqlConnection.Open();
            }
            catch (SqlException ex)
            {
                switch (ex.Number)
                {
                case 2:
                case 3:
                case 53:
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
                    {
                        Datasources.Remove(datasource as SQLServerDatasource);
                    }));
                    break;

                default:
                    break;
                }

                throw ex;
            }

            Version version = new Version(sqlConnection.ServerVersion);
            string  manifestToken;

            if (!IsVersionSupported(version, out manifestToken))
            {
                throw new NotSupportedException(string.Format("Version '{0}' is not supported!", version == null ? "unknown" : version.ToString()));
            }

            string sql = string.Empty;

            if (version.Major >= 9)
            {
                sql = "use master; select name from sys.databases order by name";
            }
            else
            {
                sql = "use master; select name from sysdatabases order by name";
            }

            SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection);

            sqlCommand.CommandTimeout = 20;

            SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();

            while (sqlDataReader.Read())
            {
                databases.Add(new Database(datasource)
                {
                    Name = sqlDataReader["name"].ToString()
                });
            }

            sqlDataReader.Close();

            datasource.Databases = databases;

            if (sqlConnection != null && sqlConnection.State == ConnectionState.Open)
            {
                sqlConnection.Close();
            }
        }
示例#27
0
 public DatasourceFactory(IDatasource sourceInstance)
 {
     this.sourceInstance = sourceInstance;
 }
		private void SetSelectedDatasource(IDatasource datasource)
		{
			Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { SelectedDatasource = datasource; }));
		}
示例#29
0
        public IObjectGenerator <T> Source <TMember>(Expression <Func <T, TMember> > propertyExpr, IDatasource dataSource)
        {
            var member = ReflectionHelper.GetMember(propertyExpr);

            if (member.IsField)
            {
                this.AddAction(new ObjectFieldSetFromSourceAction((EngineTypeFieldMember)member, dataSource));
            }
            else if (member.IsProperty)
            {
                this.AddAction(new ObjectPropertySetFromSourceAction((EngineTypePropertyMember)member, dataSource));
            }

            return(this);
        }
示例#30
0
 public ConversationCache(IDatasource <Conversation> Conversations)
 {
     this.Conversations = Conversations;
     ConversationMap    = new Dictionary <string, ConversationWrapper>();
 }
 public ObjectPropertySetFromSourceAction(EngineTypePropertyMember member, IDatasource source)
 {
     mMember = member;
     mDatasource = source;
 }
 public SQLEventBusInfrastructure(IDatasource datasource)
 {
     _datasource = datasource;
 }
        public static ICollectionSequenceSelectionContext <TPoco, TCollection> SourceForPrivatePropety <TPoco, TCollection, TMember>(this ICollectionSequenceSelectionContext <TPoco, TCollection> context, Expression <Func <TPoco, TMember> > propertyExpr, IDatasource dataSource)
            where TCollection : ICollection <TPoco>
        {
            var member = ReflectionHelper.GetMember(propertyExpr);

            var collectionContext = (CollectionSequenceSelectionContext <TPoco, TCollection>)context;
            var generators        = (IEnumerable <IObjectGenerator <TPoco> >)collectionContext.GetFieldValue("mSelected", Flags.InstancePrivate);

            foreach (var generator in generators.OfType <ObjectGenerator <TPoco> >())
            {
                generator.AddAction(new PrivateMemberSetFromSourceAction(member, dataSource));
            }
            return(context);
        }
示例#34
0
 public ICollectionContext <TPoco, TCollection> Source <TMember>(Expression <Func <TPoco, TMember> > propertyExpr, IDatasource dataSource)
 {
     foreach (var item in mGenerators)
     {
         item.Source(propertyExpr, dataSource);
     }
     return(this);
 }
示例#35
0
 public ContractorController(IDatasource _db)
 {
     db = _db;
 }