async static Task <BackgroundTaskModel> PopFromBackgroundQueue(int TaskTypeId, bool getLatest = true)
        {
            Service = new SimpleDataService <BackgroundTaskModel>(Connection, TableConsts.BACKGROUND_TASK_TABLE);
            var backgroundQueue = await Service.GetItemsAsync();

            var elements = backgroundQueue;

            BackgroundTaskModel popedElement = null;

            if (TaskTypeId != -1)
            {
                elements = backgroundQueue.Where(t => t.ID_TaskType == TaskTypeId);
            }

            if (getLatest)
            {
                popedElement = elements
                               .OrderByDescending(x => x.CreationDateTime)
                               .FirstOrDefault();
            }

            popedElement = elements
                           .OrderBy(x => x.CreationDateTime)
                           .FirstOrDefault();

            if (popedElement != null)
            {
                await RemoveElementFromQueue(Connection, popedElement);
            }

            return(popedElement);
        }
        protected SimpleDataService GetPrimaryImplementer(ICollection <SimpleDataService> implementers)
        {
            if (CollectionUtils.IsNullOrEmpty(implementers))
            {
                return(null);
            }
            if (implementers.Count == 1)
            {
                return(CollectionUtils.NthItem(implementers, 0));
            }
            SimpleDataService primaryImplementer = null;

            foreach (SimpleDataService implementer in implementers)
            {
                if (primaryImplementer == null)
                {
                    primaryImplementer = implementer;
                }
                else
                {
                    if (primaryImplementer.Version < implementer.Version)
                    {
                        primaryImplementer = implementer;
                    }
                }
            }
            return(primaryImplementer);
        }
        public string getSimpleDataList(string financePageJson, string start_date, string stop_date)
        {
            //分页对象
            FinancePage <SimpleData> financePage = null;

            try
            {
                //创建service层实例
                simpleDataService = new SimpleDataService();
                //处理json
                financePage = FinanceJson.getFinanceJson().toObject <FinancePage <SimpleData> >(financePageJson);
                //获取处理过的分页对象
                financePage = simpleDataService.getSimpleDataList(financePage, start_date, stop_date);

                return(FinanceResultData.getFinanceResultData().success(200, financePage, "成功"));
            }
            catch (InvalidOperationException ex)
            {
                //身份验证不通过
                return(FinanceResultData.getFinanceResultData().fail(401, null, ex.Message));
            }
            catch (Exception ex)
            {
                //未知的错误
                return(FinanceResultData.getFinanceResultData().fail(500, null, "未知的错误"));
            }
        }
        public string addSimpleData(string simpleDataJson)
        {
            try
            {
                //创建service层实例
                simpleDataService = new SimpleDataService();
                //处理json
                SimpleData simpleData = FinanceJson.getFinanceJson().toObject <SimpleData>(simpleDataJson);

                if (simpleDataService.newSimpleData(simpleData))
                {
                    return(FinanceResultData.getFinanceResultData().success(200, null, "新增成功"));
                }
                else
                {
                    return(FinanceResultData.getFinanceResultData().fail(500, null, "新增失败"));
                }
            }
            catch (InvalidOperationException ex)
            {
                //身份验证不通过
                return(FinanceResultData.getFinanceResultData().fail(401, null, ex.Message));
            }
            catch (Exception ex)
            {
                //未知的错误
                return(FinanceResultData.getFinanceResultData().fail(500, null, "未知的错误"));
            }
        }
        public static async Task <bool> EmptyQueue(SQLiteConnection connection)
        {
            Connection = connection;

            Service = new SimpleDataService <BackgroundTaskModel>(Connection, TableConsts.BACKGROUND_TASK_TABLE);
            return(await Service.DeleteItemsAsync());
        }
        public string delSimpleData(string idsJson)
        {
            try
            {
                //创建service层实例
                simpleDataService = new SimpleDataService();
                //处理json
                int[] ids = FinanceJson.getFinanceJson().toObject <int[]>(idsJson);

                if (simpleDataService.delSimpleData(ids))
                {
                    return(FinanceResultData.getFinanceResultData().success(200, null, "删除成功"));
                }
                else
                {
                    return(FinanceResultData.getFinanceResultData().fail(500, null, "删除失败"));
                }
            }
            catch (InvalidOperationException ex)
            {
                //身份验证不通过
                return(FinanceResultData.getFinanceResultData().fail(401, null, ex.Message));
            }
            catch (Exception ex)
            {
                //未知的错误
                return(FinanceResultData.getFinanceResultData().fail(500, null, "未知的错误"));
            }
        }
        public static async Task <int> GetQueueElementCount(SQLiteConnection connection)
        {
            Connection = connection;

            Service = new SimpleDataService <BackgroundTaskModel>(Connection, TableConsts.BACKGROUND_TASK_TABLE);
            var queue = await Service.GetItemsAsync();

            return(queue.Count());
        }
        static void Main(string[] args)
        {
            var loggerSvc = new ConsoleLogger();
            var dataSvc   = new SimpleDataService();
            var repo      = new PersonRepository(loggerSvc, dataSvc);
            var person    = repo.GetPerson(5);

            Console.WriteLine($"Fetched from repo: {person}");
        }
Beispiel #9
0
        public void TestSimpleDataServiceGetItemsFromWaterModels()
        {
            SimpleDataService <WaterModel> simpleService = new SimpleDataService <WaterModel>(_connection, "WaterModels");

            IEnumerable <WaterModel> result = simpleService.GetItemsAsync().Result;

            Assert.NotNull(result);

            List <WaterModel> waterModels = (List <WaterModel>)result;

            Assert.True(waterModels.Count > 0);
        }
 async static Task <BackgroundTaskModel> PushToBackgroundQueue(BackgroundTaskModel model)
 {
     try
     {
         Service = new SimpleDataService <BackgroundTaskModel>(Connection, TableConsts.BACKGROUND_TASK_TABLE);
         return(await Service.SaveItemAsync(model));
     }
     catch (Exception ex)
     {
         throw;
     }
 }
        public static async Task <bool> RemoveElementFromQueue(SQLiteConnection connection, BackgroundTaskModel model)
        {
            try
            {
                Connection = connection;

                Service = new SimpleDataService <BackgroundTaskModel>(Connection, TableConsts.BACKGROUND_TASK_TABLE);
                return(await Service.DeleteItemAsync(model));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Beispiel #12
0
        public void GetSpot()
        {
            DataServiceFactory.Connection = _connection;

            SimpleDataService <SpotModel> factory = DataServiceFactory.GetSpotFactory();

            Assert.NotNull(factory);

            Guid spotId = Guid.Parse("610b3ec0-0d70-40a6-9d9f-5167a8135410");

            SpotModel existingSpot = factory.GetItemAsync(spotId).Result;

            Assert.True(existingSpot.SpotMarker.Count > 0);
        }
            public bool FindPluginInstances(string inAssemblyPath, ref OrderedSet <SimpleDataService> ioImplementers)
            {
                FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(inAssemblyPath);
                Assembly        assembly        = Assembly.LoadFile(inAssemblyPath);

                Type[] exportedTypes = assembly.GetExportedTypes();
                Type   findType      = typeof(BaseWNOSPlugin);
                bool   addedAny      = false;

                foreach (Type exportedType in exportedTypes)
                {
                    if (exportedType.IsClass && !exportedType.IsAbstract && findType.IsAssignableFrom(exportedType))
                    {
                        ExecutableInfo executableInfo =
                            new ExecutableInfo(exportedType.Assembly.ManifestModule.Name,
                                               exportedType.FullName);

                        BaseWNOSPlugin plugin;
                        try
                        {
                            plugin =
                                AppDomainInstanceLoader.GetInstance <BaseWNOSPlugin>(AppDomain.CurrentDomain, inAssemblyPath,
                                                                                     exportedType.FullName);
                        }
                        catch (Exception)
                        {
                            continue;
                        }
                        SimpleDataService dataService = new SimpleDataService();
                        if (!CollectionUtils.IsNullOrEmpty(plugin.ConfigurationArguments))
                        {
                            dataService.Args = new List <string>(plugin.ConfigurationArguments.Keys);
                        }
                        if (!CollectionUtils.IsNullOrEmpty(plugin.DataProviders))
                        {
                            dataService.DataSources = new List <string>(plugin.DataProviders.Keys);
                        }
                        dataService.Type = PluginLoader.GetServiceType(plugin);
                        if (dataService.Type != ServiceType.None)
                        {
                            dataService.PluginInfo = executableInfo;
                            dataService.Version    = new VersionInfo(fileVersionInfo);
                            ioImplementers.Add(dataService);
                            addedAny = true;
                        }
                    }
                }
                return(addedAny);
            }
Beispiel #14
0
        public async void TestGetSettings()
        {
            DataServiceFactory.Connection = _connection;

            SimpleDataService <SettingModel> factory = DataServiceFactory.GetSettingFactory();

            Assert.NotNull(factory);

            IEnumerable <SettingModel> settings = await factory.GetItemsAsync();

            Assert.NotNull(settings);

            List <SettingModel> settingsList = (List <SettingModel>)settings;

            Assert.True(settingsList.Count > 0);
        }
Beispiel #15
0
        public void TestSimpleDataServiceGetSingleWaterModelWithID()
        {
            Guid idNotExists = Guid.NewGuid();
            Guid idExists    = Guid.Parse("2a3eeecf-472c-4b0f-9df0-73386cb3b3f7");

            SimpleDataService <WaterModel> simpleService = new SimpleDataService <WaterModel>(_connection, "WaterModels");

            WaterModel result = simpleService.GetItemAsync(idNotExists).Result;

            Assert.Null(result);

            result = simpleService.GetItemAsync(idExists).Result;

            Assert.NotNull(result);

            Assert.True(result.Id == idExists);
        }
Beispiel #16
0
        public void SaveExistingFishingArea()
        {
            DataServiceFactory.Connection = _connection;

            SimpleDataService <FishingAreaModel> factory = DataServiceFactory.GetFishingAreaFactory();

            Assert.NotNull(factory);

            Guid areaId = Guid.Parse("0c46a2fd-9a56-4663-9ead-0d92ff39db7c");

            FishingAreaModel existingArea = factory.GetItemAsync(areaId).Result;

            Assert.NotNull(existingArea);

            FishingAreaModel success = factory.SaveItemAsync(existingArea).Result;

            Assert.True(success.Id != Guid.Empty);
        }
Beispiel #17
0
        public void SaveFishingArea()
        {
            DataServiceFactory.Connection = _connection;

            SimpleDataService <FishingAreaModel> factory = DataServiceFactory.GetFishingAreaFactory();

            Assert.NotNull(factory);

            Guid areaId = Guid.NewGuid();

            FishingAreaModel tstFishingArea = new FishingAreaModel();

            tstFishingArea.Id            = areaId;
            tstFishingArea.ID_WaterModel = Guid.Parse("2a3eeecf-472c-4b0f-9df0-73386cb3b3f7");
            tstFishingArea.Lat           = 48.46;
            tstFishingArea.Lng           = 13.9267;
            tstFishingArea.FishingArea   = "Donau Obermühl";
            tstFishingArea.IsNew         = true;

            FishingAreaModel success = factory.SaveItemAsync(tstFishingArea).Result;

            Assert.True(success.Id != Guid.Empty);

            FishingAreaModel storedFishingArea = factory.GetItemAsync(areaId).Result;

            Assert.True(storedFishingArea.Id == areaId);


            Guid      spotId  = Guid.NewGuid();
            SpotModel newSpot = new SpotModel();

            newSpot.FishingArea    = storedFishingArea;
            newSpot.Id             = spotId;
            newSpot.Spot           = "Zanderfelsen";
            newSpot.ID_FishingArea = storedFishingArea.Id;
            newSpot.ID_SpotType    = Guid.Parse("1fb8243b-a672-496b-955a-5930cb706250");
            newSpot.IsNew          = true;

            storedFishingArea.Spots.Add(newSpot);

            success = factory.SaveItemAsync(storedFishingArea).Result;

            Assert.True(success.Id != Guid.Empty);
        }
Beispiel #18
0
        public void BasicOperations()
        {
            var           service = new SimpleDataService();
            var           data    = service.GetAll();
            int           count   = data.Count;
            bool          result;
            NameValuePair pair;

            var testPair = new NameValuePair
            {
                Id    = Guid.NewGuid(),
                Name  = "TestName",
                Value = "TestValue",
            };

            // Add
            result = service.Add(testPair);
            Assert.IsTrue(result);

            data = service.GetAll();
            Assert.IsTrue(count + 1 == data.Count);

            pair = data.Find(x => x?.Id == testPair.Id);
            Assert.IsNotNull(pair);
            Assert.IsTrue(pair.Equals(testPair));

            // Delete
            result = service.Delete(pair.Id);
            Assert.IsTrue(result);

            data = service.GetAll();
            Assert.IsTrue(count == data.Count);

            pair = data.Find(x => x?.Id == testPair.Id);
            Assert.IsNull(pair);
        }
Beispiel #19
0
 protected void SyncControlsToCurrentImplementer()
 {
     if (implementerDropDownList.Items.Count > 1)
     {
         SimpleDataService implementer = GetDataServiceImplementer(implementerDropDownList.SelectedValue);
         if (implementer != null)
         {
             if (implementer.Type == ServiceType.None)
             {
                 typeDropDownList.Items.Clear();
                 typeDropDownList.Items.Add(SERVICE_TYPE_NONE);
                 typeDropDownList.SelectedValue = SERVICE_TYPE_NONE;
                 typeDropDownList.Enabled       = false;
             }
             else
             {
                 var allDescriptions = EnumUtils.GetAllDescriptions(implementer.Type);
                 typeDropDownList.DataSource = allDescriptions;
                 typeDropDownList.DataBind();
                 typeDropDownList.Enabled = true;
                 if (!CollectionUtils.IsNullOrEmpty(allDescriptions))
                 {
                     try
                     {
                         if ((Model != null) && (Model.DataService != null) && (Model.DataService.Type != ServiceType.None))
                         {
                             typeDropDownList.SelectedValue = EnumUtils.ToDescription(Model.DataService.Type);
                         }
                         else
                         {
                             typeDropDownList.SelectedValue = EnumUtils.ToDescription(implementer.Type);
                         }
                     }
                     catch (Exception)
                     {
                         typeDropDownList.SelectedIndex = 0;
                     }
                 }
             }
             argsRepeater.DataSource = CreateArgumentModelList(implementer.Args);
             argsRepeater.DataBind();
             argumentsTableRow.Visible      = (argsRepeater.DataSource != null);
             dataSourcesRepeater.DataSource = CreateDataSourcesModelList(implementer.DataSources);
             dataSourcesRepeater.DataBind();
             dataSourcesTableRow.Visible = (dataSourcesRepeater.DataSource != null);
         }
         else
         {
             typeDropDownList.Items.Clear();
             typeDropDownList.Items.Add(SERVICE_TYPE_NONE);
             typeDropDownList.SelectedValue = SERVICE_TYPE_NONE;
             typeDropDownList.Enabled       = false;
             argsRepeater.DataSource        = null;
             argsRepeater.DataBind();
             argumentsTableRow.Visible      = false;
             dataSourcesRepeater.DataSource = null;
             dataSourcesRepeater.DataBind();
             dataSourcesTableRow.Visible = false;
         }
     }
     else
     {
     }
 }
Beispiel #20
0
        public void BasicOperations()
        {
            var             service     = new SimpleDataService();
            var             initialData = service.GetAll();
            var             target      = new SimpleUtilityViewModel(service);
            ICollectionView listView    = CollectionViewSource.GetDefaultView(target.ListViewItems);

            // Check ListViewItems before running commands
            bool result = initialData.SequenceEqual(target.ListViewItems);

            Assert.IsTrue(result);

            // Add items
            target.AddCommand.Execute("test1 = value1");
            var item1 = target.ListViewItems.Last();

            Assert.IsTrue(item1.Name == "test1" && item1.Value == "value1");

            target.AddCommand.Execute("test2 = value2");
            var item2 = target.ListViewItems.Last();

            Assert.IsTrue(item2.Name == "test2" && item2.Value == "value2");

            // Delete items
            var selected = new List <object> {
                item1, item2
            };

            target.DeleteCommand.Execute(selected);

            // Check ListViewItems after running commands
            result = initialData.SequenceEqual(target.ListViewItems);
            Assert.IsTrue(result);

            // Sorting
            target.SortCommand.Execute(SimpleUtilityViewModel.Mode.ByName.ToString());
            Assert.IsTrue(listView.SortDescriptions.Count == 1);
            SortDescription desc = listView.SortDescriptions.FirstOrDefault();

            Assert.IsTrue(desc.PropertyName == "Name");
            Assert.IsTrue(desc.Direction == ListSortDirection.Ascending);

            target.SortCommand.Execute(SimpleUtilityViewModel.Mode.ByValue.ToString());
            Assert.IsTrue(listView.SortDescriptions.Count == 1);
            desc = listView.SortDescriptions.FirstOrDefault();
            Assert.IsTrue(desc.PropertyName == "Value");
            Assert.IsTrue(desc.Direction == ListSortDirection.Ascending);

            var filterTestPair = new NameValuePair
            {
                Id    = Guid.NewGuid(),
                Name  = "FilterTestName",
                Value = "FilterTestValue",
            };

            // Filtering
            target.ApplyFilterCommand.Execute("Name = FilterTestName");
            Assert.IsNotNull(listView.Filter);
            Assert.IsTrue(listView.Filter(filterTestPair));

            target.ApplyFilterCommand.Execute("Value = FilterTestValue");
            Assert.IsNotNull(listView.Filter);
            Assert.IsTrue(listView.Filter(filterTestPair));

            target.ClearFilterCommand.Execute(null);
            Assert.IsNull(listView.Filter);

            target.ApplyFilterCommand.Execute("WrongFilterType = Value");
            Assert.IsNull(listView.Filter);
        }
 async static Task <BackgroundTaskModel> GetElementById(Guid id)
 {
     Service = new SimpleDataService <BackgroundTaskModel>(Connection, TableConsts.BACKGROUND_TASK_TABLE);
     return(await Service.GetItemAsync(id));
 }
        private string InstallPluginForFlow(byte[] zipFileContent, string flowId, string modifiedById,
                                            bool validateAgainstDbVersion, out string pluginFolderPath)
        {
            string parentFolderPath = GetPluginRootFolderForFlow(flowId);
            string tempDirPath      =
                Path.Combine(parentFolderPath, INSTALLING_DIRECTORY_PREFIX + Guid.NewGuid().ToString());

            try
            {
                // Extract files to installing directory
                _compressionHelper.UncompressDirectory(zipFileContent, tempDirPath);

                // Locate a valid base plugin and version #
                ICollection <SimpleDataService> implementers =
                    GetDataServiceImplementersInDirectory(tempDirPath, false);

                SimpleDataService primaryImplementer = GetPrimaryImplementer(implementers);
                if (primaryImplementer == null)
                {
                    throw new FileNotFoundException("A valid plugin implementer was not found in the zip file");
                }

                string installFolderPath = Path.Combine(parentFolderPath, primaryImplementer.Version.ToString());

                // Check that the incoming version is greater than any existing installed version
                VersionInfo curVersion;
                string      rtnPath = GetPluginSubFolderWithHighestVersion(flowId, out curVersion);

                if (validateAgainstDbVersion && (_pluginDao != null))
                {
                    PluginItem pluginItem = _pluginDao.GetHighestVersionPlugin(flowId);
                    if (pluginItem != null)
                    {
                        if (curVersion != null)
                        {
                            if (pluginItem.BinaryVersion > curVersion)
                            {
                                curVersion = pluginItem.BinaryVersion;
                            }
                        }
                        else
                        {
                            curVersion = pluginItem.BinaryVersion;
                        }
                    }
                }

                if (curVersion != null)
                {
                    if (primaryImplementer.Version < curVersion)
                    {
                        throw new InvalidOperationException(string.Format("A plugin with a newer version \"{0}\" is already installed for the flow \"{1}\"",
                                                                          curVersion.ToString(), _flowDao.GetDataFlowNameById(flowId)));
                    }
                }

                if ((_pluginDao != null) && !string.IsNullOrEmpty(modifiedById))
                {
                    PluginItem pluginItem = new PluginItem();
                    pluginItem.FlowId        = flowId;
                    pluginItem.BinaryVersion = primaryImplementer.Version;
                    pluginItem.ModifiedById  = modifiedById;
                    ITransactionOperations transactionTemplate = _pluginDao.GetTransactionTemplate();
                    transactionTemplate.Execute(delegate
                    {
                        _pluginDao.SavePlugin(pluginItem, zipFileContent);
                        // Rename the plugin directory with the version name
                        MoveInstalledPluginDirectory(tempDirPath, installFolderPath);
                        return(null);
                    });
                }
                else
                {
                    // Rename the plugin directory with the version name
                    MoveInstalledPluginDirectory(tempDirPath, installFolderPath);
                }

                pluginFolderPath = installFolderPath;
                return(string.Format("Successfully installed the plugin: \"{0}\"", primaryImplementer.ToString()));
            }
            catch (Exception)
            {
                FileUtils.SafeDeleteDirectory(tempDirPath);
                throw;
            }
        }