예제 #1
0
        public void TestGetStatus01()
        {
            Clipboard.SetText("hogetext");
            var target = new Paster();

            Assert.IsTrue(target.CanPaste());
        }
예제 #2
0
        public void TestGetClipType01()
        {
            Clipboard.SetText("hogetext");
            var target = new Paster();

            Assert.AreEqual(ClipDataType.Text, target.GetClipType());
        }
예제 #3
0
        public void TestGetClipType04()
        {
            Clipboard.SetText(@"testdatas\TestSmartPaster\example_folder\");
            var target = new Paster();

            Assert.AreEqual(ClipDataType.Folder, target.GetClipType());
        }
예제 #4
0
        public void TestGetClipType02()
        {
            Image bitmap = new Bitmap(100, 100);

            Clipboard.SetImage(bitmap);
            var target = new Paster();

            Assert.AreEqual(ClipDataType.Image, target.GetClipType());
        }
예제 #5
0
        public void TestExportFile01()
        {
            Clipboard.SetText("hogetext");

            MemoryStream ms = new MemoryStream();

            var target = new Paster();

            target.ExportFile(ms);

            Assert.AreEqual("hogetext", Encoding.ASCII.GetString(ms.ToArray()));
        }
예제 #6
0
        Action CreateActionFor( XmlNode paste )
        {
            var paster = new Paster() { Provider = this };

            foreach ( XmlNode text in paste.SelectNodes("text") ) {
                string lang   = "default";
                string to     = null;
                string post   = null;
                string scrape = null;

                foreach ( XmlAttribute attribute in text.Attributes )
                switch ( attribute.Name )
                {
                case "lang"  : lang   = attribute.Value; break;
                case "to"    : to     = attribute.Value; break;
                case "post"  : post   = attribute.Value; break;
                case "scrape": scrape = attribute.Value; break;

                default:
                    throw new FormatException( "Unexpected attribute "+attribute.Name+" in <text> tag" );
                }

                if ( to   == null ) throw new FormatException( "Expected an attribute, to, in <text> tag" );
                if ( post == null ) throw new FormatException( "Expected an attribute, post, in <text> tag" );

                paster.TextPasteLanguages.Add( lang, new Action<String>( (code) => PostTextTo(post,to,code,scrape==null?null:new Regex(scrape)) ) );
            }

            foreach ( XmlNode image in paste.SelectNodes("image") ) {
                string to     = null;
                string post   = null;
                string scrape = null;

                foreach ( XmlAttribute attribute in image.Attributes )
                switch ( attribute.Name )
                {
                case "to"    : to     = attribute.Value; break;
                case "post"  : post   = attribute.Value; break;
                case "scrape": scrape = attribute.Value; break;

                default:
                    throw new FormatException( "Unexpected attribute "+attribute.Name+" in <image> tag" );
                }

                if ( to   == null ) throw new FormatException( "Expected an attribute, to, in <image> tag" );
                if ( post == null ) throw new FormatException( "Expected an attribute, post, in <image> tag" );

                paster.ImagePaste = new Action<Image>( (img) => PostImageTo(post,to,img,scrape==null?null:new Regex(scrape)) );
            }

            return new Action( () => Post(paster) );
        }
예제 #7
0
        public void TestGetStatus02()
        {
            var target = new Paster();

            Assert.IsFalse(target.CanPaste());
        }
예제 #8
0
        void Post( Paster paster )
        {
            var poster = View.ProviderDisplayNickname;
            var code  = Clipboard.GetText();
            var image = Clipboard.GetImage();

            if ( image != null ) {
                if ( paster.ImagePaste != null ) paster.ImagePaste(image);
            } else if ( code != "" ) {
                string language = "C#";
                foreach ( var lk in LanguageKeywords ) {
                    foreach ( var keyword in lk.Value )
                    if ( code.Contains(keyword) )
                    {
                        language = lk.Key;
                        break;
                    }
                }

                if ( !paster.TextPasteLanguages.ContainsKey(language) ) language = "default";
                paster.TextPasteLanguages[language](code);
            }
        }