예제 #1
0
        private static void TestDataSourceCar(IDataSource <int, Car> carDataSource)
        {
            // Initialised
            PrintDataSourceInfo(carDataSource, "init");

            // Read records from DB
            carDataSource.Load();
            PrintDataSourceInfo(carDataSource, "readFromDB");

            // Insert four records
            carDataSource.Create(NextKey(carDataSource.All.Keys.ToList()), new Car("ABC", 100000));
            carDataSource.Create(NextKey(carDataSource.All.Keys.ToList()), new Car("DEF", 120000));
            carDataSource.Create(NextKey(carDataSource.All.Keys.ToList()), new Car("GHI", 140000));
            carDataSource.Create(NextKey(carDataSource.All.Keys.ToList()), new Car("JKL", 160000));
            PrintDataSourceInfo(carDataSource, "insert");

            // Update an object
            Car oldObj = carDataSource.Read(3);
            Car newObj = new Car(oldObj.Plate, oldObj.Price + 15000);

            carDataSource.Update(3, newObj);
            PrintDataSourceInfo(carDataSource, "update");

            // Try to remove three object (only two exist)
            carDataSource.Delete(2);
            carDataSource.Delete(8);
            carDataSource.Delete(4);
            PrintDataSourceInfo(carDataSource, "delete");
        }
예제 #2
0
        private static void TestDataSourceCustomer(IDataSource <int, Customer> custDataSource)
        {
            // Initialised
            PrintDataSourceInfo(custDataSource, "init");

            // Read records from DB
            custDataSource.Load();
            PrintDataSourceInfo(custDataSource, "readFromDB");

            // Insert two records
            int newKeyA = NextKey(custDataSource.All.Keys.ToList());

            custDataSource.Create(newKeyA, new Customer("Erik", "11223344", newKeyA));
            int newKeyB = NextKey(custDataSource.All.Keys.ToList());

            custDataSource.Create(newKeyB, new Customer("Fiona", "44332211", newKeyB));
            PrintDataSourceInfo(custDataSource, "insert");

            // Update an object
            Customer oldObj = custDataSource.Read(3);
            Customer newObj = new Customer(oldObj.Name, "13371337", oldObj.Key);

            custDataSource.Update(newObj.Key, newObj);
            PrintDataSourceInfo(custDataSource, "update");

            // Try to remove three object (only two exist)
            custDataSource.Delete(2);
            custDataSource.Delete(8);
            custDataSource.Delete(4);
            PrintDataSourceInfo(custDataSource, "delete");
        }
예제 #3
0
 public IObservable <IThreadSafeClient> Execute()
 => dataSource.Create(new Client(
                          idProvider.GetNextIdentifier(),
                          workspaceId,
                          clientName,
                          timeService.CurrentDateTime,
                          SyncStatus.SyncNeeded
                          ));
예제 #4
0
        private IObservable <IThreadSafeProject> createProjectPlaceholder(ITimeEntry timeEntry)
        {
            var placeholder = Project.Builder.Create(timeEntry.ProjectId.Value)
                              .SetName(Resources.InaccessibleProject)
                              .SetWorkspaceId(timeEntry.WorkspaceId)
                              .SetColor(Helper.Colors.NoProject)
                              .SetActive(false)
                              .SetAt(default(DateTimeOffset))
                              .SetSyncStatus(SyncStatus.RefetchingNeeded)
                              .Build();

            return(dataSource.Create(placeholder));
        }
예제 #5
0
        private void DoAdd(IDataSource dataSource, ContentItem item, bool wasHandled)
        {
            if (item.Id == Guid.Empty)
            {
                item.Id = Guid.NewGuid();
            }

            if (!wasHandled)
            {
                dataSource.Create(item);
            }

            item.Created     = item.Updated = DateTime.UtcNow;
            item.UserCreated = item.UserUpdated = LyniconSecurityManager.Current.UserId;
        }
예제 #6
0
        private void DoAdd(IDataSource dataSource, ContentItem item, bool wasHandled)
        {
            // Only creates new guid if no guid set: allows client code to preset the id
            if (item.Id == Guid.Empty)
            {
                item.Id = Guid.NewGuid();
            }

            if (!wasHandled)
            {
                dataSource.Create(item);
            }

            item.Created     = item.Updated = DateTime.UtcNow;
            item.UserCreated = item.UserUpdated = SecurityManager.Current?.UserId;
        }
예제 #7
0
 protected virtual void DoAdd(IDataSource dataSource, object item, PropertyInfo idProp, bool wasHandled)
 {
     if (idProp.PropertyType == typeof(Guid) && (Guid)idProp.GetValue(item) == Guid.Empty)
     {
         idProp.SetValue(item, Guid.NewGuid());
     }
     if (item is IBasicAuditable)
     {
         var aud = (IBasicAuditable)item;
         aud.Created     = aud.Updated = DateTime.UtcNow;
         aud.UserCreated = aud.UserUpdated = SecurityManager.Current?.UserId;
     }
     if (!wasHandled)
     {
         dataSource.Create(item);
     }
 }
예제 #8
0
 private void DoAdd(IDataSource dataSource, object item, PropertyInfo idProp, bool wasHandled)
 {
     if (idProp.PropertyType == typeof(Guid) && (Guid)idProp.GetValue(item) == Guid.Empty)
     {
         idProp.SetValue(item, Guid.NewGuid());
     }
     if (!wasHandled)
     {
         object addItem = CompositeTypeManager.Instance.ConvertToComposite(item);
         dataSource.Create(addItem);
     }
     if (item is IBasicAuditable)
     {
         var aud = (IBasicAuditable)item;
         aud.Created     = aud.Updated = DateTime.UtcNow;
         aud.UserCreated = aud.UserUpdated = LyniconSecurityManager.Current.UserId;
     }
 }
예제 #9
0
        /// <summary>
        /// Write the DataJobStatusDetail out as a status log for
        /// either the successful of failed processing of a document.
        /// </summary>
        /// <param name="jobStatusDetail">DataJobStatusDetail object</param>
        /// <param name="logFileFullPath">Full path of the log file to write out to</param>
        /// <returns>Empty task</returns>
        private async Task writeStatusLogFileAsync(DataJobStatusDetail jobStatusDetail,
                                                   ClientDataMessage targetDataMessage,
                                                   HttpResponseMessage httpResponse)
        {
            if (targetDataMessage == null)
            {
                return;
            }

            string logData = string.Empty;

            IDataSource <ClientDataMessage> logDataSource =
                DataSourceFactory.GetDataSourceForMessage(targetDataMessage);

            var logFilePath = Path.Combine(Path.GetDirectoryName(targetDataMessage.FullPath),
                                           (Path.GetFileNameWithoutExtension(targetDataMessage.FullPath) +
                                            "_log.txt"));

            if (null != jobStatusDetail)
            {
                logData = await Task.Factory.StartNew(() => JsonConvert.SerializeObject(jobStatusDetail));
            }
            else if (null != httpResponse)
            {
                logData = await Task.Factory.StartNew(() => JsonConvert.SerializeObject(httpResponse));
            }

            var targetLogDataMessage = new ClientDataMessage()
            {
                Name          = Path.GetFileName(logFilePath),
                FullPath      = logFilePath,
                MessageStatus = targetDataMessage.MessageStatus
            };


            using (var logMemoryStream = new MemoryStream(Encoding.Default.GetBytes(logData)))
            {
                logDataSource.Create(logMemoryStream, targetLogDataMessage);
            }
        }
예제 #10
0
        private async Task moveDataToTargetAsync(ClientDataMessage sourceDataMessage,
                                                 ClientDataMessage targetDataMessage)
        {
            Stream sourceStream = null;

            IDataSource <ClientDataMessage> sourceDataSource =
                DataSourceFactory.GetDataSourceForMessage(sourceDataMessage);

            await Task.Run(() =>
            {
                try
                {
                    sourceStream = sourceDataSource.Read(sourceDataMessage);

                    if (sourceStream != null)
                    {
                        IDataSource <ClientDataMessage> targetDataSource =
                            DataSourceFactory.GetDataSourceForMessage(targetDataMessage);

                        targetDataSource.Create(sourceStream, targetDataMessage);

                        sourceStream.Dispose();

                        sourceDataSource.Delete(sourceDataMessage);
                    }
                }
                catch { }
                finally
                {
                    if (sourceStream != null)
                    {
                        sourceStream.Dispose();
                        sourceStream = null;
                    }
                }
            });
        }
예제 #11
0
 private IObservable <IThreadSafeWorkspace> createOrUpdate(IThreadSafeWorkspace workspace)
 => dataSource
 .GetAll(ws => ws.Id == workspace.Id, includeInaccessibleEntities: true)
 .SelectMany(stored => stored.None()
             ? dataSource.Create(workspace)
             : dataSource.Update(workspace));
예제 #12
0
 /// <inheritdoc cref="ICustomerService" />
 public async Task <Models.Customer> AddCustomer(Models.Customer newCustomer)
 {
     return(await _dataSource.Create("customers", newCustomer));
 }
예제 #13
0
 public void Create(Notebook notebook)
 {
     dataSource.Create(notebook);
 }
예제 #14
0
 public T Execute(IDataSource dataSource)
 {
     dataSource.Create(Entity, Id);
     return(Entity);
 }