Ejemplo n.º 1
0
        /// <summary>
        /// Remove the Data item if it is in the list
        /// </summary>
        /// <param name="data"></param>
        /// <returns>True for success, else false</returns>
        public bool Delete(string Id, DataSourceEnum dataSourceEnum = DataSourceEnum.Unknown)
        {
            if (string.IsNullOrEmpty(Id))
            {
                return(false);
            }

            StudentModel data;

            // If using the defaul data source, use it, else just do the table operation
            if (dataSourceEnum == DataSourceEnum.Unknown)
            {
                data = DataList.Find(n => n.Id == Id);
                if (data == null)
                {
                    return(false);
                }

                if (DataList.Remove(data) == false)
                {
                    return(false);
                }
            }

            // Storage Delete
            DataSourceBackendTable.Instance.Delete <StudentModel>(tableName, "student", Id, dataSourceEnum);
            DataSourceBackendTable.Instance.Delete <AvatarCompositeModel>(tableName, "composite", Id, dataSourceEnum);
            DataSourceBackendTable.Instance.Delete <List <AvatarItemModel> >(tableName, "avatarinventory", Id, dataSourceEnum);
            DataSourceBackendTable.Instance.Delete <List <FactoryInventoryModel> >(tableName, "inventory", Id, dataSourceEnum);
            DataSourceBackendTable.Instance.Delete <List <AttendanceModel> >(tableName, "attendance", Id, dataSourceEnum);
            DataSourceBackendTable.Instance.Delete <ShopTruckFullModel>(tableName, "truck", Id, dataSourceEnum);

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Delete the record
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool Delete <T>(string tableName, string pk, string rk, DataSourceEnum dataSourceEnum = DataSourceEnum.Unknown)
        {
            if (string.IsNullOrEmpty(tableName))
            {
                return(false);
            }

            if (string.IsNullOrEmpty(pk))
            {
                return(false);
            }

            if (string.IsNullOrEmpty(rk))
            {
                return(false);
            }

            // If under Test, return True;
            if (DataSourceBackend.GetTestingMode())
            {
                return(true);
            }

            return(DeleteDirect <T>(tableName, pk, rk, dataSourceEnum));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Change the data source
        /// </summary>
        /// <returns></returns>
        // GET: Settings
        public ActionResult DataSource(string id = null)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(RedirectToAction("Index", "Admin"));
            }

            DataSourceEnum SetEnum = DataSourceEnum.Mock;

            switch (id)
            {
            case "Mock":
                SetEnum = DataSourceEnum.Mock;
                break;

            case "SQL":
                SetEnum = DataSourceEnum.SQL;
                break;

            case "Unknown":
            default:
                SetEnum = DataSourceEnum.Unknown;
                break;
            }

            DataSourceBackend.Instance.SetDataSource(SetEnum);
            DataSourceBackend.Instance.SetDataSource(SetEnum);

            return(RedirectToAction("Index", "Admin"));
        }
Ejemplo n.º 4
0
        public bool DataBackup(DataSourceEnum Source, DataSourceEnum Destination)
        {
            if (Source == Destination)
            {
                return(false);
            }

            if (Source == DataSourceEnum.Mock)
            {
                return(false);
            }


            DataSourceBackend.Instance.AvatarItemBackend.BackupData(Source, Destination);

            DataSourceBackend.Instance.FactoryInventoryBackend.BackupData(Source, Destination);

            DataSourceBackend.Instance.IdentityBackend.BackupData(Source, Destination);

            DataSourceBackend.Instance.SchoolCalendarBackend.BackupData(Source, Destination);

            DataSourceBackend.Instance.SchoolDismissalSettingsBackend.BackupData(Source, Destination);

            DataSourceBackend.Instance.StudentBackend.BackupData(Source, Destination);

            DataSourceBackend.Instance.KioskSettingsBackend.BackupData(Source, Destination);

            return(true);
        }
        public string GetDataSourceName(string fileName, out DataSourceEnum dataSourceType)
        {
            var companyName = string.Empty;

            dataSourceType = DataSourceEnum.Default;

            if (fileName.Contains(DataSourceEnum.Catalog.GetDescription(), StringComparison.InvariantCultureIgnoreCase))
            {
                dataSourceType = DataSourceEnum.Catalog;
                companyName    = fileName.Replace(DataSourceEnum.Catalog.GetDescription(), "",
                                                  StringComparison.InvariantCultureIgnoreCase)
                                 .Replace(".csv", "");
            }
            else if (fileName.Contains(DataSourceEnum.Supplier.GetDescription(),
                                       StringComparison.InvariantCultureIgnoreCase))
            {
                dataSourceType = DataSourceEnum.Supplier;
                companyName    = fileName.Replace(DataSourceEnum.Supplier.GetDescription(), "",
                                                  StringComparison.InvariantCultureIgnoreCase)
                                 .Replace(".csv", "");
            }
            else if (fileName.Contains(DataSourceEnum.Barcode.GetDescription(),
                                       StringComparison.InvariantCultureIgnoreCase))
            {
                dataSourceType = DataSourceEnum.Barcode;
                companyName    = fileName.Replace(DataSourceEnum.Barcode.GetDescription(), "",
                                                  StringComparison.InvariantCultureIgnoreCase)
                                 .Replace(".csv", "");
            }

            return(companyName);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Insert or Replace the Record
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public T Update <T>(string tableName, string pk, string rk, T data, DataSourceEnum dataSourceEnum = DataSourceEnum.Unknown)
        {
            var myReturn = default(T);

            if (string.IsNullOrEmpty(tableName))
            {
                return(myReturn);
            }

            if (string.IsNullOrEmpty(pk))
            {
                return(myReturn);
            }

            if (string.IsNullOrEmpty(rk))
            {
                return(myReturn);
            }

            if (data == null)
            {
                return(myReturn);
            }

            // If under Test, return True;
            if (DataSourceBackend.GetTestingMode())
            {
                return(myReturn);
            }

            return(UpdateDirect <T>(tableName, pk, rk, data, dataSourceEnum));
        }
Ejemplo n.º 7
0
        public bool AddAccessHistoryToInitialTable(string tableName, DataSourceEnum dataSourceEnum = DataSourceEnum.Unknown)
        {
            var Table = GetTable(dataSourceEnum, tableName);

            var entity = new DataSourceBackendTableEntity
            {
                Blob         = "{}",
                PartitionKey = "Access",
                RowKey       = DateTimeHelper.Instance.GetDateTimeNowUTC().ToString("yy-mm-dd hh:mm:ss FFFFFF")
            };

            /*
             * Mike Fixup
             * Refactor to work with Core
             *
             * var updateOperation = TableOperation.InsertOrReplace(entity);
             * var query = Table.Execute(updateOperation);
             * if (query.Result == null)
             * {
             *  return false;
             * }
             */

            return(true);
        }
        public DataSourceDto(int id,
                             string sourceName,
                             string fileName,
                             DataSourceEnum dataSourceType)
        {
            SourceId   = id;
            SourceName = sourceName;
            switch (dataSourceType)
            {
            case DataSourceEnum.Catalog:
                CatalogFilename = fileName;
                break;

            case DataSourceEnum.Supplier:
                SupplierFileName = fileName;
                break;

            case DataSourceEnum.Barcode:
                BarcodeFilename = fileName;
                break;

            case DataSourceEnum.Default:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(dataSourceType), dataSourceType, null);
            }
        }
Ejemplo n.º 9
0
        public CloudTable GetTable(DataSourceEnum dataSourceServerMode, string tableName)
        {
            /*
             * Mike Fixup
             *
             * Refacotor to work with core
             *
             * // If the DataSource is unknown, then assume the global one
             * if (dataSourceServerMode == DataSourceEnum.Unknown)
             * {
             *  dataSourceServerMode = SystemGlobalsModel.Instance.DataSourceValue;
             * }
             *
             * CloudTableClient DestinationTableClient;
             *
             * var DestinationStorageConnectionString = GetDataSourceConnectionString(dataSourceServerMode);
             *
             * var Connection = CloudConfigurationManager.GetSetting(DestinationStorageConnectionString);
             *
             * CloudStorageAccount DestinationStorageAccount = CloudStorageAccount.Parse(Connection
             * );
             *
             * DestinationTableClient = DestinationStorageAccount.CreateCloudTableClient();
             * var DestinationTable = DestinationTableClient.GetTableReference(tableName);
             * DestinationTable.CreateIfNotExists();
             *
             * return DestinationTable;
             */

            return(new CloudTable(new System.Uri("http://bogus.com")));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Remove the Data item if it is in the list
        /// </summary>
        /// <param name="data"></param>
        /// <returns>True for success, else false</returns>
        public bool Delete(string Id, DataSourceEnum dataSourceEnum = DataSourceEnum.Unknown)
        {
            if (string.IsNullOrEmpty(Id))
            {
                return(false);
            }

            // If using the default data source, use it, else just do the table operation
            if (dataSourceEnum == DataSourceEnum.Unknown)
            {
                var data = Read(Id);
                if (data == null)
                {
                    return(false);
                }

                // Just Remove it from the list.
                dataset.Remove(data);
            }

            // Storage Delete
            var myReturn = DataSourceBackendTable.Instance.Delete <HistoryAppModel>(tableName, partitionKey, Id, dataSourceEnum);

            return(myReturn);
        }
        /// <summary>
        /// Remove the Data item if it is in the list
        /// </summary>
        /// <param name="data"></param>
        /// <returns>True for success, else false</returns>
        public bool Delete(string Id, DataSourceEnum dataSourceEnum = DataSourceEnum.Unknown)
        {
            if (string.IsNullOrEmpty(Id))
            {
                return(false);
            }

            // If using the defaul data source, use it, else just do the table operation
            if (dataSourceEnum == DataSourceEnum.Unknown)
            {
                var data = DataList.Find(n => n.Id == Id);
                if (data == null)
                {
                    return(false);
                }

                if (DataList.Remove(data) == false)
                {
                    return(false);
                }
            }

            // Storage Delete
            var myReturn = DataSourceBackendTable.Instance.Delete <SchoolDismissalSettingsModel>(tableName, partitionKey, Id, dataSourceEnum);

            return(myReturn);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Backup the Data from Source to Destination
        /// </summary>
        /// <param name="dataSourceSource"></param>
        /// <param name="dataSourceDestination"></param>
        /// <returns></returns>
        public bool BackupData(DataSourceEnum dataSourceSource, DataSourceEnum dataSourceDestination)
        {
            // Read all the records from the Source using current database defaults

            var DataAllSource = LoadAll(dataSourceSource);

            if (DataAllSource == null || !DataAllSource.Any())
            {
                return(false);
            }

            // Empty out Destination Table
            // Get all rows in the destination Table
            // Walk and delete each item, because delete table takes too long...
            var DataAllDestination = LoadAll(dataSourceDestination);

            if (DataAllDestination == null)
            {
                return(false);
            }

            foreach (var data in DataAllDestination)
            {
                Delete(data.ID, dataSourceDestination);
            }

            // Write the data to the destination
            foreach (var data in DataAllSource)
            {
                Create(data, dataSourceDestination);
            }

            return(true);
        }
Ejemplo n.º 13
0
 internal void OnSeriesUpdated(DataSourceEnum source, SVR_AniDB_Anime anime)
 {
     SeriesUpdated?.Invoke(null, new SeriesInfoUpdatedEventArgs
     {
         Type      = source,
         AnimeInfo = anime,
     });
 }
        public void SetupFileNameTest_ValidCases_Barcode(string fileName, DataSourceEnum type, string errorMsg)
        {
            var sourceDto = new DataSourceDto();
            var exception = Record.Exception(() => { sourceDto.SetupFileName(fileName, type); });

            Assert.Null(exception);
            Assert.True(!string.IsNullOrWhiteSpace(sourceDto.BarcodeFilename), errorMsg);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Makes a new AvatarItem
        /// </summary>
        /// <param name="data"></param>
        /// <returns>AvatarItem Passed In</returns>
        public FactoryInventoryModel Create(FactoryInventoryModel data, DataSourceEnum dataSourceEnum = DataSourceEnum.Unknown)
        {
            DataList.Add(data);

            // Add to Storage
            var myResult = DataSourceBackendTable.Instance.Create <FactoryInventoryModel>(tableName, partitionKey, data.Id, data, dataSourceEnum);

            return(data);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Makes a new SchoolCalendar
        /// </summary>
        /// <param name="data"></param>
        /// <returns>SchoolCalendar Passed In</returns>
        public SchoolCalendarModel Create(SchoolCalendarModel data, DataSourceEnum dataSourceEnum = DataSourceEnum.Unknown)
        {
            SchoolCalendarList.Add(data);

            //sort by date
            SchoolCalendarList = SchoolCalendarList.OrderBy(x => x.Date).ToList();

            return(data);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Makes a new AvatarItem
        /// </summary>
        /// <param name="data"></param>
        /// <returns>AvatarItem Passed In</returns>
        public AvatarItemModel Create(AvatarItemModel data, DataSourceEnum dataSourceEnum = DataSourceEnum.Unknown)
        {
            DataList.Add(data);

            // Add to Storage
            var myResult = DataSourceBackendTable.Instance.Create<AvatarItemModel>(tableName, partitionKey, data.Id, data, dataSourceEnum);

            return data;
        }
Ejemplo n.º 18
0
 internal void OnEpisodeUpdated(DataSourceEnum source, SVR_AniDB_Anime anime, SVR_AnimeEpisode episode)
 {
     EpisodeUpdated?.Invoke(null, new EpisodeInfoUpdatedEventArgs
     {
         Type        = source,
         AnimeInfo   = anime,
         EpisodeInfo = episode,
     });
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Add the VersionApp item to the data store
        /// </summary>
        /// <param name="data">
        /// The new VersionApp item to add to the data store
        /// </param>
        /// <returns>return the passed in VersionApp item</returns>
        public VersionAppModel Create(VersionAppModel data, DataSourceEnum dataSourceEnum = DataSourceEnum.Unknown)
        {
            if (data == null)
            {
                return(null);
            }

            dataset.Add(data);
            return(data);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Makes a new Student
        /// </summary>
        /// <param name="data"></param>
        /// <returns>Student Passed In</returns>
        public StudentModel Create(StudentModel data, DataSourceEnum dataSourceEnum = DataSourceEnum.Unknown)
        {
            StudentBackend.SetDataSource(DataSourceEnum.Mock);

            DataSet.Add(data);

            DataSet = DataSet.OrderBy(x => x.Name).ToList();

            return(data);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Add the Example item to the data store
        /// </summary>
        /// <param name="data">
        /// The new Example item to add to the data store
        /// </param>
        /// <returns>return the passed in Example item</returns>
        public ClinicModel Create(ClinicModel data, DataSourceEnum dataSourceEnum = DataSourceEnum.Unknown)
        {
            if (data == null)
            {
                return(null);
            }

            dataset.Add(data);
            return(data);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Add the HistoryOS item to the data store
        /// </summary>
        /// <param name="data">
        /// The new HistoryOS item to add to the data store
        /// </param>
        /// <returns>return the passed in HistoryOS item</returns>
        public HistoryOSModel Create(HistoryOSModel data, DataSourceEnum dataSourceEnum = DataSourceEnum.Unknown)
        {
            if (data == null)
            {
                return(null);
            }

            dataset.Add(data);
            return(data);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Add the ResultLog item to the data store
        /// </summary>
        /// <param name="data">
        /// The new ResultLog item to add to the data store
        /// </param>
        /// <returns>return the passed in ResultLog item</returns>
        public ResultLogModel Create(ResultLogModel data, DataSourceEnum dataSourceEnum = DataSourceEnum.Unknown)
        {
            if (data == null)
            {
                return(null);
            }

            dataset.Add(data);
            return(data);
        }
        public void SetupFileNameTest_InvalidCases(string fileName, DataSourceEnum type)
        {
            // Should throw exception due to data source type invalid.
            var sourceDto = new DataSourceDto();
            var exception = Record.Exception(() => { sourceDto.SetupFileName(fileName, type); });

            Assert.NotNull(exception);
            Assert.Null(sourceDto.BarcodeFilename);
            Assert.Null(sourceDto.CatalogFilename);
            Assert.Null(sourceDto.SupplierFileName);
        }
Ejemplo n.º 25
0
        public List <T> LoadAllDirect <T>(string tableName,
                                          string pk,
                                          DataSourceEnum dataSourceEnum,
                                          bool convert = true)
        {
            var myReturnList = new List <T>();

            if (string.IsNullOrEmpty(tableName))
            {
                return(myReturnList);
            }

            if (string.IsNullOrEmpty(pk))
            {
                return(myReturnList);
            }

            try
            {
                var Table = GetTable(dataSourceEnum, tableName);

                var result = new List <DataSourceBackendTableEntity>();

                var query =
                    new TableQuery <DataSourceBackendTableEntity>().Where(
                        TableQuery.GenerateFilterCondition(
                            "PartitionKey", QueryComparisons.Equal, pk));

                query.TakeCount = takeCount;

                TableContinuationToken tableContinuationToken = null;
                do
                {
                    var queryResponse = Table.ExecuteQuerySegmented(query, tableContinuationToken);
                    tableContinuationToken = queryResponse.ContinuationToken;
                    result.AddRange(queryResponse.Results);
                } while (tableContinuationToken != null);

                foreach (var item in result)
                {
                    if (convert)
                    {
                        myReturnList.Add(ConvertFromEntity <T>(item));
                    }
                    else
                    {
                        myReturnList.Add((T)((Object)item));
                    }
                }
            }
            catch (Exception) { }

            return(myReturnList);
        }
Ejemplo n.º 26
0
        private DataSourceEntity CreateTestDataSource(DataSourceEnum dataSourceEnum)
        {
            var dataSource = new DataSourceEntity {
                DataSource = dataSourceEnum
            };
            var id = (int)m_sessionManager.OpenSession().Save(dataSource);

            var loadedDataSource = m_sessionManager.OpenSession().Get <DataSourceEntity>(id);

            return(loadedDataSource);
        }
Ejemplo n.º 27
0
        public static void SetDataSource(DataSourceEnum dataSourceEnum)
        {
            if (dataSourceEnum == DataSourceEnum.SQL)
            {
                // SQL not hooked up yet...
                throw new NotImplementedException();
            }

            // Default is to use the Mock
            DataSource = StudentDataSourceMock.Instance;
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Changes the data source, does not call for a reset, that allows for how swapping but keeping the original data in place
        /// </summary>
        public void SetDataSource(DataSourceEnum dataSourceEnum)
        {
            SchoolDismissalSettingsBackend.SetDataSource(dataSourceEnum);
            SchoolCalendarBackend.SetDataSource(dataSourceEnum);

            ShopInventoryBackend.SetDataSource(dataSourceEnum);

            // Avatar must be reset before Student, because Student needs the default avatarID
            AvatarBackend.SetDataSource(dataSourceEnum);
            StudentBackend.SetDataSource(dataSourceEnum);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Makes a new Student
        /// </summary>
        /// <param name="data"></param>
        /// <returns>Student Passed In</returns>
        public StudentModel Create(StudentModel data, DataSourceEnum dataSourceEnum = DataSourceEnum.Unknown)
        {
            StudentBackend.SetDataSource(DataSourceEnum.Mock);

            DataSet.Add(data);

            var idResult = IdentityBackend.Instance.CreateNewStudentUserIdRecordOnly(data);

            DataSet = DataSet.OrderBy(x => x.Name).ToList();

            return(data);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Remove the Data item if it is in the list
        /// </summary>
        /// <param name="data"></param>
        /// <returns>True for success, else false</returns>
        public bool Delete(string Id, DataSourceEnum dataSourceEnum = DataSourceEnum.Unknown)
        {
            if (string.IsNullOrEmpty(Id))
            {
                return(false);
            }

            var myData   = DataSet.Find(n => n.Id == Id);
            var myReturn = DataSet.Remove(myData);

            return(myReturn);
        }
Ejemplo n.º 31
0
 /// <summary>
 /// 获取DataAccess
 /// </summary>
 /// <param name="dataSourceEnum"></param>
 /// <returns></returns>
 public static IDataAccess GetDataAccess(DataSourceEnum dataSourceEnum)
 {
     switch (dataSourceEnum)
     {
         case DataSourceEnum.Mongo:
             return new MongoDataAccess();
         case DataSourceEnum.MsSql:
             return new MsSqlDataAccess();
         case DataSourceEnum.MySql:
             return new MySqlDataAccess();
         default:
             return new MongoDataAccess();
     }
 }