public void convert_honors_fallback_behavior_if_conversion_fails()
        {
            var converter = new MapConverter();

            converter.Mappings.Add(new Mapping("from", "to"));

            converter.FallbackBehavior = FallbackBehavior.ReturnUnsetValue;

            Assert.Same(DependencyProperty.UnsetValue, converter.Convert(null, null, null, null));
            Assert.Same(DependencyProperty.UnsetValue, converter.Convert("abc", null, null, null));
            Assert.Same(DependencyProperty.UnsetValue, converter.Convert(123, null, null, null));

            converter.FallbackBehavior = FallbackBehavior.ReturnOriginalValue;

            Assert.Null(converter.Convert(null, null, null, null));
            Assert.Same("abc", converter.Convert("abc", null, null, null));
            Assert.Equal(123, converter.Convert(123, null, null, null));

            converter.FallbackBehavior = FallbackBehavior.ReturnFallbackValue;
            converter.FallbackValue    = "my fallback value";

            Assert.Equal("my fallback value", converter.Convert(null, null, null, null));
            Assert.Equal("my fallback value", converter.Convert("abc", null, null, null));
            Assert.Equal("my fallback value", converter.Convert(123, null, null, null));
        }
        public void convert_returns_mapped_value_if_mapping_exists()
        {
            var converter = new MapConverter();
            converter.Mappings.Add(new Mapping("from", "to"));
            converter.Mappings.Add(new Mapping(null, "NULL"));
            converter.Mappings.Add(new Mapping(123, 123.5d));

            Assert.Same("to", converter.Convert("from", null, null, null));
            Assert.Same("NULL", converter.Convert(null, null, null, null));
            Assert.Equal(123.5d, converter.Convert(123, null, null, null));
        }
        public void convert_returns_mapped_value_if_mapping_exists()
        {
            var converter = new MapConverter();

            converter.Mappings.Add(new Mapping("from", "to"));
            converter.Mappings.Add(new Mapping(null, "NULL"));
            converter.Mappings.Add(new Mapping(123, 123.5d));

            Assert.Same("to", converter.Convert("from", null, null, null));
            Assert.Same("NULL", converter.Convert(null, null, null, null));
            Assert.Equal(123.5d, converter.Convert(123, null, null, null));
        }
Esempio n. 4
0
        /// <summary>
        /// Runs the Mode.
        /// </summary>
        /// <param name="args"></param>
        public override void Run(string[] args)
        {
            List <string> files = Files.GetFilesRecursive(args[1]);

            foreach (var file in files)
            {
                if (!file.EndsWith(".gwmap"))
                {
                    TextWriter fOutMap;
                    if (File.Exists(file + ".gwmap"))
                    {
                        fOutMap = new StreamWriter(new FileStream(file +
                                                                  ".gwmap", FileMode.Truncate, FileAccess.Write));
                    }
                    else
                    {
                        fOutMap = new StreamWriter(new FileStream(file +
                                                                  ".gwmap", FileMode.CreateNew, FileAccess.Write));
                    }
                    var s = new StreamReader(new FileStream(file, FileMode.Open, FileAccess.Read));
                    try {
                        fOutMap.Write(MapConverter.Convert(s));
                        System.Console.WriteLine("\tWriting... (" + file + ")");
                    } catch {
                    }
                    fOutMap.Close( );
                    s.Close( );
                }
            }
        }
Esempio n. 5
0
        public async Task <IList <FileDTO> > SearchAsync(string path, string query, uint startIndex = 0, uint takeCount = UInt16.MaxValue, bool includeContent = false)
        {
            SearchMode serachMode = includeContent
                ? SearchMode.FilenameAndContent.Instance
                : (SearchMode)SearchMode.Filename.Instance;

            var result = await _dropbox.Files.SearchAsync(path, query, startIndex, takeCount, serachMode);

            return(result.Matches.Select(x => MapConverter.Convert <FileDTO>(x.Metadata)).ToList());
        }
        public void convert_honors_fallback_behavior_if_conversion_fails()
        {
            var converter = new MapConverter();
            converter.Mappings.Add(new Mapping("from", "to"));

            converter.FallbackBehavior = FallbackBehavior.ReturnUnsetValue;

            Assert.Same(DependencyProperty.UnsetValue, converter.Convert(null, null, null, null));
            Assert.Same(DependencyProperty.UnsetValue, converter.Convert("abc", null, null, null));
            Assert.Same(DependencyProperty.UnsetValue, converter.Convert(123, null, null, null));

            converter.FallbackBehavior = FallbackBehavior.ReturnOriginalValue;

            Assert.Null(converter.Convert(null, null, null, null));
            Assert.Same("abc", converter.Convert("abc", null, null, null));
            Assert.Equal(123, converter.Convert(123, null, null, null));

            converter.FallbackBehavior = FallbackBehavior.ReturnFallbackValue;
            converter.FallbackValue = "my fallback value";

            Assert.Equal("my fallback value", converter.Convert(null, null, null, null));
            Assert.Equal("my fallback value", converter.Convert("abc", null, null, null));
            Assert.Equal("my fallback value", converter.Convert(123, null, null, null));
        }
Esempio n. 7
0
        public async Task <AccountDTO> GetAccountAsync()
        {
            var account = await _dropbox.Users.GetCurrentAccountAsync();

            return(MapConverter.Convert <AccountDTO>(account));
        }
Esempio n. 8
0
        public async Task <SharedMetaDataDTO> ShareAsync(string path)
        {
            var sharedMetadata = await _dropbox.Sharing.CreateSharedLinkWithSettingsAsync(path);

            return(MapConverter.Convert <SharedMetaDataDTO>(sharedMetadata));
        }
Esempio n. 9
0
        public async Task <FileDTO> UploadAsync(string path, Stream stream)
        {
            var fileMetadata = await _dropbox.Files.UploadAsync(path, WriteMode.Overwrite.Instance, body : stream);

            return(MapConverter.Convert <FileDTO>(fileMetadata));
        }
Esempio n. 10
0
        public async Task <FolderDTO> CreateFolderAsync(string path)
        {
            var folderMetadata = await _dropbox.Files.CreateFolderAsync(path, autorename : true);

            return(MapConverter.Convert <FolderDTO>(folderMetadata));
        }
Esempio n. 11
0
        public async Task <MetaDataDTO> MoveAsync(string pathFrom, string pathTo)
        {
            var metadata = await _dropbox.Files.MoveAsync(pathFrom, pathTo, allowSharedFolder : true, autorename : true);

            return(MapConverter.Convert <MetaDataDTO>(metadata));
        }
Esempio n. 12
0
        public async Task <MetaDataDTO> DeleteAsync(string path)
        {
            var metadata = await _dropbox.Files.DeleteAsync(path);

            return(MapConverter.Convert <MetaDataDTO>(metadata));
        }