Beispiel #1
0
        private void OnEntryUpdated(IDbTransaction tx, ICommit commit, EntryUpdated @event)
        {
            var sqlParams = @event.ToDynamic();

            sqlParams.Id = commit.AggregateId();

            const string sql = @"

				DECLARE @UserId int;  
				SELECT @UserId = [PlacementProjector_Entry].[UserId]
				FROM [dbo].[PlacementProjector.Entry] AS [PlacementProjector_Entry]
				WHERE Id = @Id;

				UPDATE [PlacementProjector_Entry]
				SET [Title] = @Title
					,[Description] = @Description
					,[Where] = @Where
					,[When] = @When
					,[PlacementId] = [PlacementProjector_Placement].[Id]
				FROM [dbo].[PlacementProjector.Entry] AS [PlacementProjector_Entry] 
				INNER JOIN [dbo].[PlacementProjector.Placement] AS [PlacementProjector_Placement]
						ON [PlacementProjector_Placement].[FullyQualifiedTitle] = @Where
						AND [PlacementProjector_Placement].[UserId] = @UserId
				WHERE [PlacementProjector_Entry].Id = @Id;

				DELETE FROM [dbo].[PlacementProjector.Entry]
				WHERE [Id] = @Id
				AND [Where] != @Where;"                ;

            tx.Connection.Execute(sql, (object)sqlParams, tx);
        }
Beispiel #2
0
 void Apply(EntryUpdated @event)
 {
     Title         = @event.Title;
     Description   = @event.Description;
     Where         = @event.Where;
     When          = @event.When;
     LastUpdatedAt = @event.LastUpdatedAt;
 }
        private void OnMessageReceived(object sender, IMessageEventArgs e)
        {
            var message = e.Message;
            var jObject = JObject.Parse(message);

            EntryUpdater.UpdateObject(jObject);
            EntryUpdated?.Invoke(this, new EventArgs());
        }
Beispiel #4
0
        private void OnEntryUpdated(IDbTransaction tx, ICommit commit, EntryUpdated @event)
        {
            var sqlParams = @event.ToDynamic();

            sqlParams.Id = commit.AggregateId();

            // Get the original where entry.
            const string sql1          = @"
				SELECT [Where]
					  ,[UserId]
				FROM [dbo].[WhereProjector.Entry]
				WHERE [EntryId] = @Id;"                ;
            var          row           = tx.Connection.QuerySingle <dynamic>(sql1, (object)sqlParams, tx);
            var          originalWhere = row.Where;
            var          userId        = row.UserId;

            const string sql2 = @"
				UPDATE [dbo].[WhereProjector.Entry]
				SET [Where] = @Where
				WHERE [EntryId] = @Id;"                ;

            tx.Connection.Execute(sql2, (object)sqlParams, tx);

            sqlParams = new {
                UserId        = userId,
                Where         = @event.Where,
                OriginalWhere = originalWhere
            };

            const string sql = @"
				UPDATE [dbo].[WhereProjector.Where]
				SET [UsageCount] = [UsageCount] - 1
				WHERE [UserId] = @UserId AND [Name] = @OriginalWhere;

				DELETE FROM [dbo].[WhereProjector.Where]
				WHERE [UserId] = @UserId 
				AND [Name] = @OriginalWhere
				AND [UsageCount] = 0;

				UPDATE [dbo].[WhereProjector.Where]
				SET [UsageCount] = [UsageCount] + 1
				WHERE [UserId] = @UserId AND [Name] = @Where;

				INSERT INTO [dbo].[WhereProjector.Where]
					   ([UserId]
					   ,[Name]
					   ,[UsageCount])
				 SELECT
					   @UserId
					   ,@Where
					   ,1
				WHERE NOT EXISTS(SELECT * FROM [dbo].[WhereProjector.Where] WHERE [UserId] = @UserId AND [Name] = @Where);"                ;

            tx.Connection.Execute(sql, (object)sqlParams, tx);
        }
Beispiel #5
0
        private void OnEntryUpdated(IDbTransaction tx, ICommit commit, EntryUpdated @event)
        {
            var sqlParams = @event.ToDynamic();

            sqlParams.Id = commit.AggregateId();

            const string sql = @"
				UPDATE [dbo].[EntryProjector.Entry]
				SET [Title] = @Title
					,[Description] = @Description
					,[Where] = @Where
					,[When] = @When
					,[LastUpdatedAt] = @LastUpdatedAt
				WHERE Id = @Id;"                ;

            tx.Connection.Execute(sql, (object)sqlParams, tx);
        }
Beispiel #6
0
        private void OnEntryUpdated(IDbTransaction tx, ICommit commit, EntryUpdated @event)
        {
            var sqlParams = @event.ToDynamic();

            sqlParams.Id = commit.AggregateId();

            // Get the original where entry.
            const string sql    = @"
				SELECT [UserId]
				FROM [dbo].[ActivityProjector.Entry]
				WHERE [EntryId] = @Id;"                ;
            var          userId = tx.Connection.QuerySingle <int>(sql, (object)sqlParams, tx);

            RecordActivity(tx, new Models.Activity {
                UserId = userId,
                Type   = (int)ActivityType.EntryUpdated,
                When   = @event.LastUpdatedAt,
                Link   = commit.AggregateId().ToString()
            });
        }
Beispiel #7
0
        public async Task Move(FileExplorerEntry entry, string path)
        {
            path = NormalizePath(path);

            if (entry.Type == FileExplorerEntryType.File)
            {
                await FileSystemResource.MoveFile(entry.Path, path, _restClient);
            }
            else
            {
                await FileSystemResource.MoveDirectory(entry.Path, path, _restClient);
            }

            var oldPath = NormalizePath(entry.Path);

            entry.Path = path;
            entry.Name = Path.GetFileName(path);

            EntryUpdated?.Invoke(this, new EntryUpdatedEventArgs(entry, oldPath));

            if (entry.Type != FileExplorerEntryType.File)
            {
                foreach (var cachedEntry in _localCache.Where(x => x.Key.StartsWith(oldPath, PathStringComparison)))
                {
                    _localCache.TryRemove(cachedEntry.Key, out _);
                    var newPath = path + cachedEntry.Key.Substring(oldPath.Length);
                    cachedEntry.Value.Directory.Path = newPath;

                    lock (cachedEntry.Value.EntriesLock)
                    {
                        foreach (var fileExplorerEntry in cachedEntry.Value.Entries)
                        {
                            fileExplorerEntry.Path = path + fileExplorerEntry.Path.Substring(oldPath.Length);
                        }
                    }

                    _localCache[newPath] = cachedEntry.Value;
                }
            }
        }
Beispiel #8
0
 protected virtual void OnEntryUpdated(EyeStateEntry entry)
 {
     EntryUpdated?.Invoke(this, entry);
 }
Beispiel #9
0
        private async Task <SetStatus> SetValueCoreAsyncCore(TKey key, Stream value)
        {
            ulong      totalBytesRead = 0;
            const long bufferSize     = 4096;

            var    tmpFileName = Path.Combine(CachePath.FullName, Guid.NewGuid().ToString());
            string hash        = null;

            using (var shaHasher = new SHA256Managed())
            {
                using (var writer = File.OpenWrite(tmpFileName))
                {
                    byte[] oldBuffer;
                    int    oldBytesRead;

                    var buffer    = new byte[bufferSize];
                    var bytesRead = await value.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false);

                    totalBytesRead += Convert.ToUInt32(bytesRead);

                    do
                    {
                        oldBytesRead = bytesRead;
                        oldBuffer    = buffer;

                        buffer    = new byte[bufferSize];
                        bytesRead = await value.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false);

                        totalBytesRead += Convert.ToUInt32(bytesRead);

                        if (bytesRead == 0)
                        {
                            shaHasher.TransformFinalBlock(oldBuffer, 0, oldBytesRead);
                            await writer.WriteAsync(oldBuffer, 0, oldBytesRead).ConfigureAwait(false);
                        }
                        else
                        {
                            shaHasher.TransformBlock(oldBuffer, 0, oldBytesRead, oldBuffer, 0);
                            await writer.WriteAsync(oldBuffer, 0, oldBytesRead).ConfigureAwait(false);
                        }
                    }while (bytesRead != 0 && totalBytesRead <= MaximumStorageCapacity);
                }

                if (totalBytesRead > MaximumStorageCapacity)
                {
                    File.Delete(tmpFileName); // remove the file, we can't keep it anyway
                    return(SetStatus.DataTooLarge);
                }

                var shaHashBytes = shaHasher.Hash;
                hash = BitConverter.ToString(shaHashBytes).Replace("-", string.Empty);
            }

            var isNew = !await ContainsKeyAsync(key).ConfigureAwait(false);

            var cachePath    = GetPath(hash);
            var cachePathDir = Path.GetDirectoryName(cachePath);

            if (!Directory.Exists(cachePathDir))
            {
                Directory.CreateDirectory(cachePathDir);
            }
            File.Move(tmpFileName, cachePath);
            var cacheFileInfo = new FileInfo(cachePath);

            _fileLookup[key] = new FileEntry <TKey>(key, cachePath);  //cachePath;
            var cacheEntry = new CacheEntry <TKey>(key, Convert.ToUInt64(cacheFileInfo.Length));

            _entryLookup[key] = cacheEntry;

            if (isNew)
            {
                EntryAdded?.Invoke(this, cacheEntry);
            }
            else
            {
                EntryUpdated?.Invoke(this, cacheEntry);
            }

            ApplyCachePolicy();
            return(SetStatus.Success);
        }
Beispiel #10
0
 private void Repository_Updated(object sender, EntryEventArgs e)
 {
     EntryUpdated?.Invoke(sender, e);
 }