예제 #1
0
        internal async Task <IIpcResult> AddFileAsync(IDropItem dropItem, Func <string, bool> symlinkTester)
        {
            Contract.Requires(dropItem != null);

            // Check if the file is a symlink, only if the file exists on disk at this point; if it is a symlink, reject it outright.
            if (System.IO.File.Exists(dropItem.FullFilePath) && symlinkTester(dropItem.FullFilePath))
            {
                return(new IpcResult(IpcResultStatus.ExecutionError, SymlinkAddErrorMessagePrefix + dropItem.FullFilePath));
            }

            return(await WrapDropErrorsIntoIpcResult(async() =>
            {
                IDropClient dropClient = await m_dropClientTask;
                AddFileResult result = await dropClient.AddFileAsync(dropItem);

                switch (result)
                {
                case AddFileResult.Associated:
                case AddFileResult.UploadedAndAssociated:
                case AddFileResult.SkippedAsDuplicate:
                    return IpcResult.Success(I($"File '{dropItem.FullFilePath}' {result} under '{dropItem.RelativeDropPath}' in drop '{DropName}'."));

                case AddFileResult.RegisterFileForBuildManifestFailure:
                    return new IpcResult(IpcResultStatus.ExecutionError, $"Failure during BuildManifest Hash generation for File '{dropItem.FullFilePath}' {result} under '{dropItem.RelativeDropPath}' in drop '{DropName}'.");

                default:
                    return new IpcResult(IpcResultStatus.ExecutionError, $"Unhandled drop result: {result}");
                }
            }));
        }
예제 #2
0
 internal AddFileItem(IDropItem item)
 {
     TaskSource = TaskSourceSlim.Create <AddFileResult>();
     m_dropItem = item;
     m_fileBlobDescriptorForUpload    = null;
     m_fileBlobDescriptorForAssociate = null;
 }
예제 #3
0
 internal AddFileItem(IDropItem item)
 {
     DropResultTaskSource             = TaskSourceSlim.Create <AddFileResult>();
     m_dropItem                       = item;
     m_fileBlobDescriptorForUpload    = null;
     m_fileBlobDescriptorForAssociate = null;
     BuildManifestTaskSource          = TaskSourceSlim.Create <RegisterFileForBuildManifestResult>();
 }
예제 #4
0
        /// <summary>
        ///     Calculates the hash for the given file (if not given) and queues it up
        ///     to be batch-processed later (<see cref="ProcessAddFilesAsync"/>).
        /// </summary>
        public async Task <AddFileResult> AddFileAsync(IDropItem dropItem)
        {
            Contract.Requires(dropItem != null);

            m_logger.Verbose("Queued file '{0}'", dropItem);

            Interlocked.Increment(ref Stats.NumAddFileRequests);

            var addFileItem = new AddFileItem(dropItem);
            await m_batchBlock.SendAsync(addFileItem);

            return(await addFileItem.TaskSource.Task);
        }
예제 #5
0
        internal async Task <IIpcResult> AddFileAsync(IDropItem dropItem, Func <string, bool> symlinkTester)
        {
            Contract.Requires(dropItem != null);

            // Check if the file is a symlink, only if the file exists on disk at this point; if it is a symlink, reject it outright.
            if (System.IO.File.Exists(dropItem.FullFilePath) && symlinkTester(dropItem.FullFilePath))
            {
                return(new IpcResult(IpcResultStatus.ExecutionError, SymlinkAddErrorMessagePrefix + dropItem.FullFilePath));
            }

            return(await WrapDropErrorsIntoIpcResult(async() =>
            {
                IDropClient dropClient = await m_dropClientTask;
                AddFileResult result = await dropClient.AddFileAsync(dropItem);
                return IpcResult.Success(I($"File '{dropItem.FullFilePath}' {result} under '{dropItem.RelativeDropPath}' in drop '{DropName}'."));
            }));
        }
예제 #6
0
        /// <summary>
        ///     Calculates the hash for the given file (if not given) and queues it up
        ///     to be batch-processed later (<see cref="ProcessAddFilesAsync"/>).
        /// </summary>
        public async Task <AddFileResult> AddFileAsync(IDropItem dropItem)
        {
            Contract.Requires(dropItem != null);

            m_logger.Verbose("Queued file '{0}'", dropItem);

            Interlocked.Increment(ref Stats.NumAddFileRequests);

            var addFileItem = new AddFileItem(dropItem);
            await m_batchBlock.SendAsync(addFileItem);

            var manifestResult = await addFileItem.BuildManifestTaskSource.Task;
            var dropResult     = await addFileItem.DropResultTaskSource.Task;

            return(manifestResult == RegisterFileForBuildManifestResult.Failed
                ? AddFileResult.RegisterFileForBuildManifestFailure
                : dropResult);
        }
예제 #7
0
        public void Drop(IDropItem drop)
        {
            var value = (int)_formula.Calculate(drop.Value);

            switch (drop.Item.Type)
            {
            case DropType.Inventory:
                _inventory.AddItem(drop.Item.ItemId, value);
                break;

            case DropType.Money:
                var data1 = _scorers.Static.MoneyTypes[drop.Item.MoneyId];
                var dict  = _scorers.State.Values;
                dict.TryGetValue(data1.ScorerId, out var oldValue);
                dict[data1.ScorerId] = oldValue + value;
                if (data1.AchievScorerId != 0)
                {
                    if (!dict.ContainsKey(data1.AchievScorerId))
                    {
                        dict[data1.AchievScorerId] = 0;
                    }
                    dict[data1.AchievScorerId] += value;
                }
                break;

            case DropType.Shard:
                _units.AddUnitShard(drop.Item.UnitId, value);
                var data = _units.State.Units.FirstOrDefault(x => x.Id == drop.Item.UnitId);
                if (data != null)
                {
                    TryUpdateNullRarity(data);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
예제 #8
0
 /// <summary>
 ///     Invokes the 'drop addfile' operation by delegating to <see cref="IDropClient.AddFileAsync"/>.
 ///     Handles drop-related exceptions by omitting their stack traces.
 /// </summary>
 public Task <IIpcResult> AddFileAsync(IDropItem dropItem)
 {
     return(AddFileAsync(dropItem, IsSymLinkOrMountPoint));
 }
예제 #9
0
        public Task <AddFileResult> AddFileAsync(IDropItem item)
        {
            Contract.Requires(item != null);

            return(m_addFileFunc(item));
        }