Ejemplo n.º 1
0
        private void DoOperation(StorageServicesAdapter storageServiceAdapter, SynchronizedFile file)
        {
            try
            {
                var operation = file.Operation;
                if (operation == SynchronizationOperation.Delete)
                {
                    storageServiceAdapter.Delete(file.ObjectOnDevice);
                    file.IsOnDevice     = false;
                    file.SizeOnDevice   = 0;
                    file.ObjectOnDevice = null;
                }

                if (operation == SynchronizationOperation.Copy)
                {
                    StorageServicesAdapter.PushProgressReport pushProgressReport = (int totalBytesRead) =>
                    {
                        _userInterface.ReportInformation(string.Format("\tCopy: {0} out of {1} = {2}%",
                                                                       FormatFileSize(totalBytesRead),
                                                                       FormatFileSize(file.SizeOnComputer),
                                                                       100 * totalBytesRead / file.SizeOnComputer
                                                                       ));
                    };
                    file.ObjectOnDevice = (PortableDeviceFileObject)storageServiceAdapter.Push(file.Parent.ObjectOnDevice, file.ObjectOnComputer.OpenRead(), file.Name, (ulong)file.SizeOnComputer, pushProgressReport);
                    file.IsOnDevice     = true;
                    file.SizeOnDevice   = file.SizeOnComputer;
                }
            }
            catch (Exception e)
            {
                _userInterface.ReportError(string.Format("Exception: {0}", e.Message));
            }
        }
Ejemplo n.º 2
0
        private void DoOperation(StorageServicesAdapter storageServiceAdapter, SynchronizedDirectory directory)
        {
            try
            {
                var operation = directory.Operation;
                if (operation == SynchronizationOperation.Delete)
                {
                    storageServiceAdapter.Delete(directory.ObjectOnDevice);
                    directory.IsOnDevice     = false;
                    directory.ObjectOnDevice = null;
                }

                if (operation == SynchronizationOperation.Copy)
                {
                    directory.ObjectOnDevice = (PortableDeviceContainerObject)storageServiceAdapter.Mkdir(directory.Parent.ObjectOnDevice, directory.Name);
                    directory.IsOnDevice     = true;
                }
            }
            catch (Exception e)
            {
                _userInterface.ReportError(string.Format("Exception: {0}", e.Message));
            }
        }