public DataControler(IDataLoader loader)
        {
            antsList = new List<Ant>();
            this.loader = loader;

            addTestAnts();
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="CachingTableDataLoaderFactory" /> 
 ///     class. 
 ///     Enabling the <paramref name="locking"/> flag makes the caching factory 
 ///     instances to work in a cooperative way. They ensure that only one of wrapped
 ///     factory objects initialized with the same configuration is utilized at the same
 ///     time. 
 /// </summary>
 /// <param name="wrappedDataLoader"> 
 ///     The wrapped data loader. 
 /// </param>
 /// <param name="locking"> 
 ///     Indicates if the wrapped data loader should be used only once at the same time.
 /// </param>
 public CachingTableDataLoaderFactory(IDataLoader wrappedDataLoader, bool locking)
     : this(
         wrappedDataLoader,
         locking ? CreateLatch(wrappedDataLoader) : null,
         new CachingTableDataLoaderStoreProxy())
 {
 }
 public ReadLaterListViewModel()
 {
     readLaterManager = ServiceLocator.Current.GetInstance<IReadLaterManager>();
     dataLoader = ServiceLocator.Current.GetInstance<IDataLoader>();
     settings = ConfigurationSerializer.Load();
     recommendations = new ObservableCollection<RecommendationViewModel>();
 }
Beispiel #4
0
 public HomeViewModel()
 {
     this.loader = ServiceLocator.Current.GetInstance<IDataLoader>();
     this.avatarService = ServiceLocator.Current.GetInstance<IAvatarService>();
     this.readLaterManager = ServiceLocator.Current.GetInstance<IReadLaterManager>();
     Recommendations = new BindableCollection<RecommendationViewModel>();
 }
        /// <summary>
        ///     Initializes a new instance of the <see cref="CachingDataLoader" /> class.
        /// </summary>
        /// <param name="wrappedDataLoader"> 
        ///     The wrapped data loader. 
        /// </param>
        public CachingDataLoader(IDataLoader wrappedDataLoader)
        {
            if (wrappedDataLoader == null)
            {
                throw new ArgumentNullException("wrappedDataLoader");
            }

            this.wrappedDataLoader = wrappedDataLoader;
        }
 public DataProvider(IDataLoader dataLoader)
 {
     this.dataLoader = dataLoader;
     ConnectedDevices = Observable.Interval(TimeSpan.FromSeconds(5)).Select(x =>
     {
         var result = dataLoader.GetConnectedDevices().Result;
         var devices = result.ConnectedBeacons.Select(beacon => new DeviceIdentifier(Constants.BeaconGuid, Constants.MajorId, beacon.Id)).ToList();
         Log.Debug("Received data", $"Received connected devices: {string.Join(";", devices)}");
         return devices;
     });
 }
        /// <summary>
        ///     Creates a <see cref="T:EntityConnection"/> object that rely on an in-memory 
        ///     database instance that lives during the complete application lifecycle. If the 
        ///     database is accessed the first time, then it will be constructed based on the 
        ///     metadata referenced by the provided entity connection string and its state is 
        ///     initialized by the provided <see cref="T:IDataLoader"/> object.
        /// </summary>
        /// <param name="entityConnectionString">
        ///     The entity connection string that identifies the in-memory database and
        ///     references the metadata that is required for constructing the schema.
        /// </param>
        /// <param name="dataLoader">
        ///     The <see cref="T:IDataLoader"/> object that might initialize the state of the 
        ///     in-memory database.
        /// </param>
        /// <returns>
        ///     The <see cref="T:EntityConnection"/> object.
        /// </returns>
        public static EntityConnection CreatePersistent(
            string entityConnectionString, 
            IDataLoader dataLoader)
        {
            MetadataWorkspace metadata = GetEffortCompatibleMetadataWorkspace(ref entityConnectionString);

            DbConnection connection = 
                DbConnectionFactory.CreatePersistent(entityConnectionString, dataLoader);

            return CreateEntityConnection(metadata, connection);
        }
Beispiel #8
0
        // ctor
        public MainViewModel(
            IDataImporterClass dataImporter,
            IDatabaseChecker databaseChecker,
            IDatabaseSeeder databaseSeeder, IDataLoader dataLoader)
        {
            _dataImporter = dataImporter;
            _databaseChecker = databaseChecker;
            _databaseSeeder = databaseSeeder;
            _dataLoader = dataLoader;

            ImportCommand = new RelayCommand(Import);
            LoadedCommand = new RelayCommand(Loaded);

            Games = new ObservableCollection<Game>();
        }
        public void classify(string titanicTeachingDataFile, string titanicTestingDataFile,string titanicOutputDataFile)
        {
            this._dataLoader = new DataLoader();
            this._category = this.PrepareCategoryFromFile();

            Console.WriteLine("Loading data");
            List<ITargetObject> targetObjects = this._dataLoader.LoadTeachingData(_category, titanicTeachingDataFile);

            Console.WriteLine("Teaching category engine");
            _category.Engine.TeachCategory(targetObjects);

            _category.Engine.PrepareToClassification();

            var fileInfo = new FileInfo(titanicTestingDataFile);

            TextReader reader = fileInfo.OpenText();
            TextWriter writer = new StreamWriter(titanicOutputDataFile);

            string text;
            double survivedProbability, notSurvivedProbability;
            List<string> attributes;

            Console.WriteLine("Classifing");
            do
            {
                text = reader.ReadLine();
                if (String.Equals(text, NewObjectCommand))
                {
                    ITargetObject titanicPassenger = new TargetObject(_category, String.Empty);

                    attributes = getAttributes(_category, reader);

                    foreach (string attribute in attributes)
                    {
                        titanicPassenger.SetAttributeExist(attribute);
                    }

                    GetProbabilities(titanicPassenger, _category, out survivedProbability, out notSurvivedProbability);

                    writer.WriteLine(number + " " + survivedProbability + " " + notSurvivedProbability);
                    writer.Flush();
                }
            } while (text != null);
            writer.Close();
            reader.Close();
        }
        public void classify(string mushroomTeachingDataFile, string mushroomTestingDataFile, string outputDataFile)
        {
            this._dataLoader = new DataLoader();
            this._category = this.PrepareCategoryFromFile();

            Console.WriteLine("Loading data");
            List<ITargetObject> targetObjects = this._dataLoader.LoadTeachingData(_category, mushroomTeachingDataFile);

            Console.WriteLine("Teaching category engine");
            _category.Engine.TeachCategory(targetObjects);

            _category.Engine.PrepareToClassification();

            var fileInfo = new FileInfo(mushroomTestingDataFile);
            TextReader reader = fileInfo.OpenText();
            TextWriter writer = new StreamWriter(outputDataFile);

            string text;
            double edible, poisonous;
            List<string> attributes;

            Console.WriteLine("Classifing");
            do
            {
                text = reader.ReadLine();
                if (String.Equals(text, NewObjectCommand))
                {
                    ITargetObject mushroom = new TargetObject(_category, String.Empty);
                    string categoryType = String.Empty;

                    attributes = getAttributes(_category, reader,out categoryType);

                    foreach (string attribute in attributes)
                    {
                        mushroom.SetAttributeExist(attribute);
                    }

                    GetProbabilities(mushroom, _category, out edible, out poisonous);

                    writer.WriteLine(edible + " " + poisonous + " " + categoryType);
                    writer.Flush();
                }
            } while (text != null);
            writer.Close();
            reader.Close();
        }
Beispiel #11
0
 public LPController(IDataLoader <LPData> dataLoader, IDataAggregator <LPData> dataAggregator, ILogger <LPController> logger)
 {
     _dataLoader     = dataLoader;
     _dataAggregator = dataAggregator;
     _logger         = logger;
 }
Beispiel #12
0
 protected abstract bool BackgroundLoad(IDataLoader loader, Func <OrderSelectTask, List <SingleServerSearchTask>, List <SearchData> > merge);
        /// <summary>
        ///     Creates a <see cref="T:DbConnection"/> object that rely on an in-memory 
        ///     database instance that lives during the connection object lifecycle. If the 
        ///     connection object is disposed or garbage collected, then underlying database 
        ///     will be garbage collected too. The initial state of the database is initialized
        ///     by the provided <see cref="T:IDataLoader"/> object.
        /// </summary>
        /// <param name="dataLoader">
        ///     The <see cref="T:IDataLoader"/> object that initializes the state of the 
        ///     in-memory database.
        /// </param>
        /// <returns>
        ///     The <see cref="T:DbConnection"/> object.
        /// </returns>
        public static DbConnection CreateTransient(IDataLoader dataLoader)
        {
            string instanceId = Guid.NewGuid().ToString();

            EffortConnection connection = Create(instanceId, dataLoader);
            connection.MarkAsPrimaryTransient();

            return connection;
        }
        /// <summary>
        ///     Creates a <see cref="T:DbConnection"/> object that rely on an in-memory 
        ///     database instance that lives during the complete application lifecycle. If the
        ///     database is accessed the first time, then its state will be initialized by the
        ///     provided <see cref="T:IDataLoader"/> object.
        /// </summary>
        /// <param name="instanceId">
        ///     The identifier of the in-memory database.
        /// </param>
        /// <param name="dataLoader">
        ///     The <see cref="T:IDataLoader"/> object that might initialize the state of the 
        ///     in-memory database.
        /// </param>
        /// <returns>
        ///     The <see cref="T:DbConnection"/> object.
        /// </returns>
        public static DbConnection CreatePersistent(string instanceId, IDataLoader dataLoader)
        {
            EffortConnection connection = Create(instanceId, dataLoader);

            return connection;
        }
        private void Run(IChannel ch)
        {
            IDataLoader      loader  = null;
            IPredictor       rawPred = null;
            IDataView        view;
            RoleMappedSchema trainSchema = null;

            if (_model == null)
            {
                if (string.IsNullOrEmpty(Args.InputModelFile))
                {
                    loader      = CreateLoader();
                    rawPred     = null;
                    trainSchema = null;
                    Host.CheckUserArg(Args.LoadPredictor != true, nameof(Args.LoadPredictor),
                                      "Cannot be set to true unless " + nameof(Args.InputModelFile) + " is also specifified.");
                }
                else
                {
                    LoadModelObjects(ch, _loadPredictor, out rawPred, true, out trainSchema, out loader);
                }

                view = loader;
            }
            else
            {
                view = _model.Apply(Host, new EmptyDataView(Host, _model.InputSchema));
            }

            // Create the ONNX context for storing global information
            var assembly    = System.Reflection.Assembly.GetExecutingAssembly();
            var versionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
            var ctx         = new OnnxContextImpl(Host, _name, ProducerName, versionInfo.FileVersion,
                                                  ModelVersion, _domain, Args.OnnxVersion);

            // Get the transform chain.
            IDataView source;
            IDataView end;
            LinkedList <ITransformCanSaveOnnx> transforms;

            GetPipe(ctx, ch, view, out source, out end, out transforms);
            Host.Assert(transforms.Count == 0 || transforms.Last.Value == end);

            // If we have a predictor, try to get the scorer for it.
            if (rawPred != null)
            {
                RoleMappedData data;
                if (trainSchema != null)
                {
                    data = new RoleMappedData(end, trainSchema.GetColumnRoleNames());
                }
                else
                {
                    // We had a predictor, but no roles stored in the model. Just suppose
                    // default column names are OK, if present.
                    data = new RoleMappedData(end, DefaultColumnNames.Label,
                                              DefaultColumnNames.Features, DefaultColumnNames.GroupId, DefaultColumnNames.Weight, DefaultColumnNames.Name, opt: true);
                }

                var scorePipe = ScoreUtils.GetScorer(rawPred, data, Host, trainSchema);
                var scoreOnnx = scorePipe as ITransformCanSaveOnnx;
                if (scoreOnnx?.CanSaveOnnx(ctx) == true)
                {
                    Host.Assert(scorePipe.Source == end);
                    end = scorePipe;
                    transforms.AddLast(scoreOnnx);
                }
                else
                {
                    Contracts.CheckUserArg(_loadPredictor != true,
                                           nameof(Arguments.LoadPredictor), "We were explicitly told to load the predictor but we do not know how to save it as ONNX.");
                    ch.Warning("We do not know how to save the predictor as ONNX. Ignoring.");
                }
            }
            else
            {
                Contracts.CheckUserArg(_loadPredictor != true,
                                       nameof(Arguments.LoadPredictor), "We were explicitly told to load the predictor but one was not present.");
            }

            HashSet <string> inputColumns = new HashSet <string>();

            //Create graph inputs.
            for (int i = 0; i < source.Schema.ColumnCount; i++)
            {
                string colName = source.Schema.GetColumnName(i);
                if (_inputsToDrop.Contains(colName))
                {
                    continue;
                }

                ctx.AddInputVariable(source.Schema.GetColumnType(i), colName);
                inputColumns.Add(colName);
            }

            //Create graph nodes, outputs and intermediate values.
            foreach (var trans in transforms)
            {
                Host.Assert(trans.CanSaveOnnx(ctx));
                trans.SaveAsOnnx(ctx);
            }

            //Add graph outputs.
            for (int i = 0; i < end.Schema.ColumnCount; ++i)
            {
                if (end.Schema.IsHidden(i))
                {
                    continue;
                }

                var idataviewColumnName = end.Schema.GetColumnName(i);

                // Since the last IDataView also contains columns of the initial IDataView, last IDataView's columns found in
                // _inputToDrop should be removed too.
                if (_inputsToDrop.Contains(idataviewColumnName) || _outputsToDrop.Contains(idataviewColumnName))
                {
                    continue;
                }

                var variableName     = ctx.TryGetVariableName(idataviewColumnName);
                var trueVariableName = ctx.AddIntermediateVariable(null, idataviewColumnName, true);
                ctx.CreateNode("Identity", variableName, trueVariableName, ctx.GetNodeName("Identity"), "");
                ctx.AddOutputVariable(end.Schema.GetColumnType(i), trueVariableName);
            }

            var model = ctx.MakeModel();

            using (var file = Host.CreateOutputFile(_outputModelPath))
                using (var stream = file.CreateWriteStream())
                    model.WriteTo(stream);

            if (_outputJsonModelPath != null)
            {
                using (var file = Host.CreateOutputFile(_outputJsonModelPath))
                    using (var stream = file.CreateWriteStream())
                        using (var writer = new StreamWriter(stream))
                        {
                            var parsedJson = JsonConvert.DeserializeObject(model.ToString());
                            writer.Write(JsonConvert.SerializeObject(parsedJson, Formatting.Indented));
                        }
            }

            if (!string.IsNullOrWhiteSpace(Args.OutputModelFile))
            {
                Contracts.Assert(loader != null);

                ch.Trace("Saving the data pipe");
                // Should probably include "end"?
                SaveLoader(loader, Args.OutputModelFile);
            }
        }
 void StartDownloadTask(DataTaskComplited OnComplete, IDataLoader loader, IDataLoadTaskData data)
 {
     var item = new DownloadTaskItem(data, loader);
     lock (_Tasks)
     {
         _Tasks.Add(item);
     }
     Task.Factory.StartNew(() =>
     {
         switch (StartDownload(OnComplete, loader, data))
         {
             case DataLoadingResult.Suspended:
             case DataLoadingResult.LoaderErr:
                 var task = new Tuple<IDataLoadTaskData, DataTaskComplited>(data, OnComplete);
                 lock (PrivateTasks)
                 {
                     PrivateTasks.Add(task);
                     _ready.Set();
                 }
                 break;
         }
         lock (_Tasks)
         {
             _Tasks.Remove(item);
         }
     }, item.Data.Token);
 }
Beispiel #17
0
        private static async Task <IReadOnlyList <T> > LoadManyAsync <TKey, T>(IDataLoader <TKey, T> dataLoader, ICollection <TKey> keys) where T : class
        {
            var contents = await Task.WhenAll(keys.Select(x => dataLoader.LoadAsync(x).GetResultAsync()));

            return(contents.NotNull().ToList());
        }
Beispiel #18
0
        public InventoryQuery(IDataLoaderContextAccessor accessor, ICategory category, IProduct product, IReview review, IUser user, IOrder order)
        {
            Name = "MarketAppQuery";

            #region Category
            Field <CategoryType, Category>()
            .Name("CategoryById")
            .Description("This field returns the category of the submitted id")
            .Argument <NonNullGraphType <IntGraphType> >(Name = "CategoryId", Description = "Category Id")
            .ResolveAsync(ctx =>
            {
                return(category.GetByIdAsync(ctx.GetArgument <int>("CategoryId")));
            });

            Field <ListGraphType <CategoryType>, IEnumerable <Category> >()
            .Name("getAllCategories")
            .Description("This field returns all categories")
            .ResolveAsync(ctx =>
            {
                IDataLoader <IEnumerable <Category> > loader = accessor.Context.GetOrAddLoader("GetAllCategories", () => category.GetAllAsync());
                return(loader.LoadAsync());
            });

            #endregion

            #region Product
            Field <ProductType>(
                "getProductById",
                Description = "This field returns the product of the submitted id",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "ProductId"
            }
                    ),
                resolve: context => product.GetByIdAsync(context.GetArgument <int>("ProductId"))
                );

            Field <ListGraphType <ProductType>, IEnumerable <Product> >()
            .Name("getAllProducts")
            .Description("This field returns all products")
            .ResolveAsync(ctx =>
            {
                var loader = accessor.Context.GetOrAddLoader("GetAllProducts", () => product.GetAllAsync());
                return(loader.LoadAsync());
            });
            #endregion

            #region Review
            Field <ReviewType>(
                "getReviewById",
                Description = "This field returns the review of the submitted id",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "ReviewId"
            }
                    ),
                resolve: context => review.GetByIdAsync(context.GetArgument <int>("ReviewId"))
                );

            Field <ListGraphType <ReviewType>, IEnumerable <Review> >()
            .Name("getAllReviews")
            .Description("This field returns all reviews")
            .ResolveAsync(ctx =>
            {
                var loader = accessor.Context.GetOrAddLoader("GetAllReviews", () => review.GetAllAsync());
                return(loader.LoadAsync());
            });
            #endregion

            #region User
            Field <UserType>(
                "getUserById",
                Description = "This field returns the user of the submitted id",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "UserId"
            }
                    ),
                resolve: context => user.GetByIdAsync(context.GetArgument <int>("UserId"))
                );

            Field <ListGraphType <UserType>, IEnumerable <User> >()
            .Name("getAllUsers")
            .Description("This field returns all reviews")
            .ResolveAsync(ctx =>
            {
                var loader = accessor.Context.GetOrAddLoader("GetAllUsers", () => user.GetAllAsync());
                return(loader.LoadAsync());
            });
            #endregion

            #region Order
            Field <OrderType>(
                "getOrderById",
                Description = "This field returns the order of the submitted id",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "OrderId"
            }
                    ),
                resolve: context => order.GetByIdAsync(context.GetArgument <int>("OrderId"))
                );

            Field <ListGraphType <OrderType>, IEnumerable <Order> >()
            .Name("getAllOrders")
            .Description("This field returns all orders")
            .ResolveAsync(ctx =>
            {
                var loader = accessor.Context.GetOrAddLoader("GetAllOrders", () => order.GetAllAsync());
                return(loader.LoadAsync());
            });

            #endregion
            Description = "MarketApp Query Fields for, You can query about categories, products, users, reviews and orders";
        }
Beispiel #19
0
 public override void ResolvedTaskFromCache(IDataLoader dataLoader, TaskCacheKey cacheKey, Task task)
 {
     ResolvedTaskFromCacheTouched = true;
 }
Beispiel #20
0
 public override IDisposable ExecuteBatch <TKey>(IDataLoader dataLoader, IReadOnlyList <TKey> keys)
 {
     ExecuteBatchTouched = true;
     return(base.ExecuteBatch(dataLoader, keys));
 }
Beispiel #21
0
 public VkNetwork(IDataLoader dataLoader, IConfiguration configuration, IPathSearcher <long, long> pathSearcher) : base(pathSearcher)
 {
     this.dataLoader = dataLoader;
     _configuration  = configuration;
 }
 public ApplicationSettingsDbRepository(IDbContext dbContext, Havit.NewProjectTemplate.DataLayer.DataSources.Common.IApplicationSettingsDataSource dataSource, IEntityKeyAccessor <Havit.NewProjectTemplate.Model.Common.ApplicationSettings, int> entityKeyAccessor, IDataLoader dataLoader, ISoftDeleteManager softDeleteManager, IEntityCacheManager entityCacheManager)
     : base(dbContext, dataSource, entityKeyAccessor, dataLoader, softDeleteManager, entityCacheManager)
 {
 }
Beispiel #23
0
 protected UserDbRepositoryBase(IDbContext dbContext, Havit.NewProjectTemplate.DataLayer.DataSources.Security.IUserDataSource dataSource, IEntityKeyAccessor <Havit.NewProjectTemplate.Model.Security.User, int> entityKeyAccessor, IDataLoader dataLoader, ISoftDeleteManager softDeleteManager, IEntityCacheManager entityCacheManager)
     : base(dbContext, dataSource, entityKeyAccessor, dataLoader, softDeleteManager, entityCacheManager)
 {
 }
Beispiel #24
0
 /// <summary>
 /// Gets or creates a <see cref="IDynamicCommand"/> that will refresh
 /// the specified <see cref="IDataLoader"/>.
 /// </summary>
 /// <param name="viewModel">The <see cref="IViewModel"/>.</param>
 /// <param name="dataLoader">The <see cref="IDataLoader"/> to refresh.</param>
 /// <param name="name">The command name.</param>
 /// <param name="configure">The optional func to configure the command builder.</param>
 /// <returns>The <see cref="IDynamicCommand"/>.</returns>
 public static IDynamicCommand GetCommandFromDataLoaderRefresh(
     this IViewModel viewModel,
     IDataLoader dataLoader,
     Func <IDynamicCommandBuilder, IDynamicCommandBuilder> configure = null,
     [CallerMemberName] string name = null
     ) => viewModel.GetOrCreateCommand(name, n => viewModel.GetDynamicCommandBuilderFactory().CreateFromTask(n, ct => RefreshDataLoader(ct, dataLoader), viewModel), configure);
 public static EntityConnection CreateInspectedFakeEntityConnection(string entityConnectionString, IResultSetComposer resultSetComposer, IDataLoader dataLoader)
 {
     return(CreateInspectedFakeEntityConnection(entityConnectionString, resultSetComposer, true, dataLoader));
 }
 public MainViewModel(IDataLoader loader)
 {
     loader.Load().ToList().ForEach(item => clippingsList.Add(item));
 }
        private static EntityConnection CreateInspectedFakeEntityConnection(string entityConnectionString, IResultSetComposer resultSetComposer, bool createFake, IDataLoader dataLoader)
        {
            EntityConnectionStringBuilder connectionString = new EntityConnectionStringBuilder(entityConnectionString);

            if (!string.IsNullOrEmpty(connectionString.Name))
            {
                string resolvedConnectionString = ConfigurationManager.ConnectionStrings[connectionString.Name].ConnectionString;
                connectionString = new EntityConnectionStringBuilder(resolvedConnectionString);
            }

            List <XElement> csdl = new List <XElement>();
            List <XElement> ssdl = new List <XElement>();
            List <XElement> msl  = new List <XElement>();

            MetadataWorkspaceHelper.ParseMetadata(connectionString.Metadata, csdl, ssdl, msl);

            foreach (XElement ssdlFile in ssdl)
            {
                XAttribute providerAttribute = ssdlFile.Attribute("Provider");
                XAttribute providerManifestTokenAttribute = ssdlFile.Attribute("ProviderManifestToken");

                if (createFake)
                {
                    EffortProviderConfiguration.VerifyProvider();
                    UniversalStorageSchemaModifier.Instance.Modify(ssdlFile, new EffortProviderInformation());
                }

                string oldProviderInvariantName = providerAttribute.Value;
                string oldProviderManifestToken = providerManifestTokenAttribute.Value;

                providerAttribute.Value = DataReaderInspectorProviderConfiguration.ProviderInvariantName;
                providerManifestTokenAttribute.Value = string.Format("{0};{1}", oldProviderInvariantName, oldProviderManifestToken);
            }

            MetadataWorkspace convertedWorkspace = MetadataWorkspaceHelper.CreateMetadataWorkspace(csdl, ssdl, msl);

            DbConnection storeConnection = null;

            if (createFake)
            {
                storeConnection = Effort.DbConnectionFactory.CreateTransient(dataLoader);
            }
            else
            {
                storeConnection = ProviderHelper.CreateConnection(connectionString.Provider);
                storeConnection.ConnectionString = connectionString.ProviderConnectionString;
            }

            DbConnectionWrapper inspectorConnection = new DataReaderInspectorConnection(resultSetComposer);

            inspectorConnection.WrappedConnection = storeConnection;

#if !EFOLD
            EntityConnection entityConnection =
                new EntityConnection(convertedWorkspace, inspectorConnection, true);
#else
            EntityConnection entityConnection =
                new EntityConnection(convertedWorkspace, inspectorConnection);

            FieldInfo owned =
                typeof(EntityConnection)
                .GetField(
                    "_userOwnsStoreConnection",
                    BindingFlags.Instance | BindingFlags.NonPublic);

            owned.SetValue(entityConnection, false);
#endif

            if (createFake)
            {
                using (ObjectContext objectContext = new ObjectContext(entityConnection))
                {
                    if (!objectContext.DatabaseExists())
                    {
                        objectContext.CreateDatabase();
                    }
                }
            }

            return(entityConnection);
        }
Beispiel #28
0
        private static IDataLoader ApplyTransformsCore(IHost host, IDataLoader srcLoader,
                                                       KeyValuePair <string, string>[] tagData, Func <IHostEnvironment, int, IDataView, IDataView> createTransform)
        {
            Contracts.AssertValue(host, "host");
            host.AssertValue(srcLoader, "srcLoader");
            host.AssertNonEmpty(tagData);
            host.AssertValue(createTransform, "createTransform");

            // If the loader is a composite, we need to start with its underlying pipeline end.
            var         exes      = new List <TransformEx>();
            var         composite = srcLoader as CompositeDataLoader;
            IDataView   srcView;
            IDataLoader pipeStart;

            if (composite != null)
            {
                srcView = composite.View;
                exes.AddRange(composite._transforms);
                pipeStart = composite._loader;
            }
            else
            {
                srcView = pipeStart = srcLoader;
            }

            IDataView view = srcView;

            using (var ch = host.Start("Transforms"))
            {
                int count        = Utils.Size(tagData);
                var newlyCreated = new List <TransformEx>();
                for (int i = 0; i < count; i++)
                {
                    // REVIEW: this might cause silent automatic tag conflicts if the pipeline is short-circuited.
                    // Maybe it's better to allow empty tags?
                    var tag = tagData[i].Key;
                    if (string.IsNullOrEmpty(tag))
                    {
                        tag = GenerateTag(exes.Count);
                    }

                    var newDataView = createTransform(host, i, view);
                    // Append the newly created transforms to the exes list.
                    // If the newTransform is a 'no-op' transform, i.e. equal to the original view,
                    // the exes array will not be modified: there's no reason to record details of a no-op transform,
                    // especially since this would overwrite the useful details of the upstream transform.
                    newlyCreated.Clear();
                    IDataView curDataView = newDataView;
                    while (true)
                    {
                        var cur = curDataView as IDataTransform;
                        if (cur == null)
                        {
                            // We reached all the way back to the pipe start. The exes accumulated so far are irrelevant.
                            ch.Check(curDataView == pipeStart,
                                     "The transform has corrupted the chain (chain no longer starts with the same loader).");
                            exes.Clear();
                            break;
                        }

                        int index = exes.FindLastIndex(x => x.Transform == cur);
                        if (index >= 0)
                        {
                            // We found a transform in exes to attach to.
                            if (index < exes.Count - 1)
                            {
                                // The transform short-circuited some of the existing ones, remove them.
                                exes.RemoveRange(index + 1, exes.Count - index - 1);
                            }
                            break;
                        }

                        newlyCreated.Add(new TransformEx(tag, tagData[i].Value, cur));
                        curDataView = cur.Source;
                    }

                    newlyCreated.Reverse();
                    exes.AddRange(newlyCreated);

                    view = newDataView;
                }
            }

            return(view == srcView ? srcLoader : new CompositeDataLoader(host, exes.ToArray()));
        }
Beispiel #29
0
 public WeatherForecastViewModel(IDataLoader loader)
 {
     this.loader = loader;
 }
 DataLoadingResult StartDownload(DataTaskComplited OnComplete, IDataLoader loader, IDataLoadTaskData data)
 {
     DataLoadingResult result = DataLoadingResult.LoaderErr;
     var ts = CancellationTokenSource.CreateLinkedTokenSource(Core.Core.globalCTS.Token, data.Token);
     foreach (var uri in data.Uri)
     {
         if (ts.IsCancellationRequested)
             return DataLoadingResult.Cancelled;
         result = loader.LoadMethod(uri, ts.Token, data.OnProcessCallback, 1024);
         if (result == DataLoadingResult.Ok || result == DataLoadingResult.Suspended || result == DataLoadingResult.Cancelled)
             break;
     }
     if (OnComplete != null && result != DataLoadingResult.Suspended && result != DataLoadingResult.LoaderErr && !Core.Core.globalCTS.IsCancellationRequested)
         OnComplete(data, result == DataLoadingResult.Ok ? TaskResult.Completed : result == DataLoadingResult.Cancelled ? TaskResult.Cancelled : TaskResult.Error);
     return result;
 }
 public DownloadTaskItem(IDataLoadTaskData Data, IDataLoader Loader)
 {
     _Data = Data;
     _Loader = Loader;
 }
 public DataLoaderResolver(Func <TSource, TKey> keySelector, IDataLoader <TKey, TReturn> loader)
 {
     _keySelector         = keySelector;
     _captureFieldContext = false;
     _loader = loader;
 }
        /// <summary>
        ///     Creates the default latch for the data loader configuration locking.
        /// </summary>
        /// <param name="dataLoader"> The data loader. </param>
        /// <returns> The latch. </returns>
        private static IDataLoaderConfigurationLatch CreateLatch(IDataLoader dataLoader)
        {
            DataLoaderConfigurationKey key = new DataLoaderConfigurationKey(dataLoader);

            return new DataLoaderConfigurationLatchProxy(key);
        }
        /// <summary>
        ///     Creates an EffortConnection object with a connection string that represents the 
        ///     specified parameter values.
        /// </summary>
        /// <param name="instanceId"> The instance id. </param>
        /// <param name="dataLoader"> The data loader. </param>
        /// <returns> The EffortConnection object. </returns>
        private static EffortConnection Create(string instanceId, IDataLoader dataLoader)
        {
            EffortProviderConfiguration.VerifyProvider();

            EffortConnectionStringBuilder connectionString = 
                new EffortConnectionStringBuilder();

            connectionString.InstanceId = instanceId;

            if (dataLoader != null)
            {
                connectionString.DataLoaderType = dataLoader.GetType();
                connectionString.DataLoaderArgument = dataLoader.Argument;
            }

            EffortConnection connection = new EffortConnection();
            connection.ConnectionString = connectionString.ConnectionString;

            return connection;
        }
Beispiel #35
0
 public ProxyDbParserProvider(IDataLoader dataLoader)
 {
     _dataLoader = dataLoader;
     _offset     = 15;
 }
        /// <summary>
        ///     Initializes a new instance of the <see cref="CachingTableDataLoaderFactory" /> 
        ///     class.
        /// </summary>
        /// <param name="wrappedDataLoader"> The wrapped data loader. </param>
        /// <param name="latch"> The latch that locks the data loader configuration. </param>
        /// <param name="dataStore"> The store that contains the cached data. </param>
        internal CachingTableDataLoaderFactory(
            IDataLoader wrappedDataLoader,
            IDataLoaderConfigurationLatch latch,
            ICachingTableDataLoaderStore dataStore)
        {
            if (wrappedDataLoader == null)
            {
                throw new ArgumentNullException("wrappedDataLoader");
            }

            if (dataStore == null)
            {
                throw new ArgumentNullException("dataStoreProxy");
            }

            this.wrappedDataLoader = wrappedDataLoader;
            this.latch = latch;
            this.dataStore = dataStore;
        }
 protected DetailOverViewPageModel(IDataLoader <TViewModel, TModel> dataLoader)
     : base(dataLoader)
 {
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="CachingTableDataLoaderFactory" /> 
 ///     class.
 /// </summary>
 /// <param name="wrappedDataLoader"> 
 ///     The wrapped data loader.
 /// </param>
 public CachingTableDataLoaderFactory(IDataLoader wrappedDataLoader)
     : this(wrappedDataLoader, false)
 {
 }
 public void Delete(IDataLoader loader) => DataLoaders.Remove(loader);
Beispiel #40
0
 public Graph(IDataLoader weightLoader, IDataLoader edgesLoader)
 {
     _weightLoader = weightLoader;
     _edgesLoader = edgesLoader;
 }
 private MySqlAndSqLiteExcelReportGenerator(IDataLoader loader)
 {
     this.dataLoader = loader;
 }
        /// <summary>
        ///     Initializes a new instance of the <see cref="CachingDataLoader" /> class.
        ///     Enabling the <paramref name="locking"/> flag makes the caching data loader 
        ///     instances to work in a cooperative way. They ensure that only one of wrapped
        ///     data loaders initialized with the same configuration is utilized at the same
        ///     time. 
        /// </summary>
        /// <param name="wrappedDataLoader"> 
        ///     The wrapped data loader. 
        /// </param>
        /// <param name="locking">
        ///     Indicates if the wrapped data loader should be used only once at the same time.
        /// </param>
        public CachingDataLoader(IDataLoader wrappedDataLoader, bool locking)
        {
            if (wrappedDataLoader == null)
            {
                throw new ArgumentNullException("wrappedDataLoader");
            }

            this.wrappedDataLoader = wrappedDataLoader;
            this.locking = locking;
        }
Beispiel #43
0
 public SpikeDetectionStrategy(string appName, string algorithmName, IDataLoader dataLoader)
 {
     _applicationName = appName;
     _algorithmName   = algorithmName;
     _dataLoader      = dataLoader;
 }
        public ValueCopyDesignerControl()
        {
            Grid LayoutRoot = new Grid();
            LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            LayoutRoot.RowDefinitions.Add(new RowDefinition());

            // ТУЛБАР 
            m_ToolBar = new RanetToolBar();
            m_ToolBar.Margin = new Thickness(0, 0, 0, 4);
            LayoutRoot.Children.Add(m_ToolBar);
            Grid.SetRow(m_ToolBar, 0);

            // Контрол копирования данных
            m_CopyControl = new ValueCopyControl();
            m_CopyControl.IsAdminMode = true;
            LayoutRoot.Children.Add(m_CopyControl);
            Grid.SetRow(m_CopyControl, 1);

            RanetToolBarButton m_ImportLayout = new RanetToolBarButton();
            m_ImportLayout.Content = UiHelper.CreateIcon(UriResources.Images.FileImport16);
            m_ImportLayout.Click += new RoutedEventHandler(m_ImportLayout_Click);
            ToolTipService.SetToolTip(m_ImportLayout, Localization.ValueCopyControl_ImportSettings_ToolTip);
            m_ToolBar.AddItem(m_ImportLayout);

            RanetToolBarButton m_ExportLayout = new RanetToolBarButton();
            m_ExportLayout.Content = UiHelper.CreateIcon(UriResources.Images.FileExport16);
            m_ExportLayout.Click += new RoutedEventHandler(m_ExportLayout_Click);
            ToolTipService.SetToolTip(m_ExportLayout, Localization.ValueCopyControl_ExportSettings_ToolTip);
            m_ToolBar.AddItem(m_ExportLayout);

            m_ToolBar.AddItem(new RanetToolBarSplitter());

            RanetToolBarButton m_PreviewButton = new RanetToolBarButton();
            m_PreviewButton.Content = UiHelper.CreateIcon(UriResources.Images.Run16);
            m_PreviewButton.Click += new RoutedEventHandler(m_PreviewButton_Click);
            ToolTipService.SetToolTip(m_PreviewButton, Localization.ValueCopyControl_RunCopyForm_Tooltip);
            m_ToolBar.AddItem(m_PreviewButton);

            m_OlapDataLoader = GetOlapDataLoader();
            m_StorageManager = GetStorageManager();

            m_StorageManager.InvokeCompleted += new EventHandler<DataLoaderEventArgs>(StorageManager_ActionCompleted);
            m_OlapDataLoader.DataLoaded += new EventHandler<DataLoaderEventArgs>(OlapDataLoader_DataLoaded);

            grdIsWaiting = new Grid() { Background = new SolidColorBrush(Color.FromArgb(125, 0xFF, 0xFF, 0xFF)) };
            grdIsWaiting.Visibility = Visibility.Collapsed;
            BusyControl m_Waiting = new BusyControl();
            m_Waiting.Text = Localization.Loading;
            grdIsWaiting.Children.Add(m_Waiting);

            LayoutRoot.Children.Add(grdIsWaiting);
            Grid.SetColumnSpan(grdIsWaiting, LayoutRoot.ColumnDefinitions.Count > 0 ? LayoutRoot.ColumnDefinitions.Count : 1);
            Grid.SetRowSpan(grdIsWaiting, LayoutRoot.RowDefinitions.Count > 0 ? LayoutRoot.RowDefinitions.Count : 1);

            this.Content = LayoutRoot;
        }
Beispiel #45
0
 public EmployeeCsvParser(IDataLoader loader)
 {
     _loader = loader;
 }
 public void SetUp()
 {
     this._dataLoader = new DataLoader();
 }
 public UkJsonRaceDataProvider(IDataLoader dataLoader)
 {
     this.dataLoader = dataLoader;
 }
 public MongoDbDataImporter(IDataLoader loader)
 {
     this.subscribers = new List<IObserver>();
     this.dataLoader = loader;
 }
Beispiel #49
0
 public ContactManager(IDataLoader dataLoader)
 {
     this.dataLoader = dataLoader;
 }
Beispiel #50
0
 Program()
 {
     this.loader = DependencyInjection.Container.Resolve<IDataLoader>();
     this.processor = DependencyInjection.Container.Resolve<IDataProcessor>();
 }
Beispiel #51
0
        private void RunCore(IChannel ch, string cmd)
        {
            Host.AssertValue(ch);

            IPredictor inputPredictor = null;

            if (Args.ContinueTrain && !TrainUtils.TryLoadPredictor(ch, Host, Args.InputModelFile, out inputPredictor))
            {
                ch.Warning("No input model file specified or model file did not contain a predictor. The model state cannot be initialized.");
            }

            ch.Trace("Constructing data pipeline");
            IDataLoader loader = CreateRawLoader();

            // If the per-instance results are requested and there is no name column, add a GenerateNumberTransform.
            var preXf = Args.PreTransform;

            if (!string.IsNullOrEmpty(Args.OutputDataFile))
            {
                string name = TrainUtils.MatchNameOrDefaultOrNull(ch, loader.Schema, nameof(Args.NameColumn), Args.NameColumn, DefaultColumnNames.Name);
                if (name == null)
                {
                    preXf = preXf.Concat(
                        new[]
                    {
                        new KeyValuePair <string, IComponentFactory <IDataView, IDataTransform> >(
                            "", ComponentFactoryUtils.CreateFromFunction <IDataView, IDataTransform>(
                                (env, input) =>
                        {
                            var args    = new GenerateNumberTransform.Arguments();
                            args.Column = new[] { new GenerateNumberTransform.Column()
                                                  {
                                                      Name = DefaultColumnNames.Name
                                                  }, };
                            args.UseCounter = true;
                            return(new GenerateNumberTransform(env, args, input));
                        }))
                    }).ToArray();
                }
            }
            loader = CompositeDataLoader.Create(Host, loader, preXf);

            ch.Trace("Binding label and features columns");

            IDataView pipe = loader;
            var       stratificationColumn = GetSplitColumn(ch, loader, ref pipe);
            var       scorer    = Args.Scorer;
            var       evaluator = Args.Evaluator;

            Func <IDataView> validDataCreator = null;

            if (Args.ValidationFile != null)
            {
                validDataCreator =
                    () =>
                {
                    // Fork the command.
                    var impl = new CrossValidationCommand(this);
                    return(impl.CreateRawLoader(dataFile: Args.ValidationFile));
                };
            }

            FoldHelper fold = new FoldHelper(Host, RegistrationName, pipe, stratificationColumn,
                                             Args, CreateRoleMappedData, ApplyAllTransformsToData, scorer, evaluator,
                                             validDataCreator, ApplyAllTransformsToData, inputPredictor, cmd, loader, !string.IsNullOrEmpty(Args.OutputDataFile));
            var tasks = fold.GetCrossValidationTasks();

            var eval = evaluator?.CreateComponent(Host) ??
                       EvaluateUtils.GetEvaluator(Host, tasks[0].Result.ScoreSchema);

            // Print confusion matrix and fold results for each fold.
            for (int i = 0; i < tasks.Length; i++)
            {
                var dict = tasks[i].Result.Metrics;
                MetricWriter.PrintWarnings(ch, dict);
                eval.PrintFoldResults(ch, dict);
            }

            // Print the overall results.
            if (!TryGetOverallMetrics(tasks.Select(t => t.Result.Metrics).ToArray(), out var overallList))
            {
                throw ch.Except("No overall metrics found");
            }

            var overall = eval.GetOverallResults(overallList.ToArray());

            MetricWriter.PrintOverallMetrics(Host, ch, Args.SummaryFilename, overall, Args.NumFolds);
            eval.PrintAdditionalMetrics(ch, tasks.Select(t => t.Result.Metrics).ToArray());
            Dictionary <string, IDataView>[] metricValues = tasks.Select(t => t.Result.Metrics).ToArray();
            SendTelemetryMetric(metricValues);

            // Save the per-instance results.
            if (!string.IsNullOrWhiteSpace(Args.OutputDataFile))
            {
                var perInstance = EvaluateUtils.ConcatenatePerInstanceDataViews(Host, eval, Args.CollateMetrics,
                                                                                Args.OutputExampleFoldIndex, tasks.Select(t => t.Result.PerInstanceResults).ToArray(), out var variableSizeVectorColumnNames);
                if (variableSizeVectorColumnNames.Length > 0)
                {
                    ch.Warning("Detected columns of variable length: {0}. Consider setting collateMetrics- for meaningful per-Folds results.",
                               string.Join(", ", variableSizeVectorColumnNames));
                }
                if (Args.CollateMetrics)
                {
                    ch.Assert(perInstance.Length == 1);
                    MetricWriter.SavePerInstance(Host, ch, Args.OutputDataFile, perInstance[0]);
                }
                else
                {
                    int i = 0;
                    foreach (var idv in perInstance)
                    {
                        MetricWriter.SavePerInstance(Host, ch, ConstructPerFoldName(Args.OutputDataFile, i), idv);
                        i++;
                    }
                }
            }
        }