Beispiel #1
1
        // *no* check version
        private static void InternalRegister(Hashtable table, UriParser uriParser, string schemeName, int defaultPort)
        {
            uriParser.SchemeName = schemeName;
            uriParser.DefaultPort = defaultPort;

            DefaultUriParser parser = new DefaultUriParser();
            parser.SchemeName = schemeName;
            parser.DefaultPort = defaultPort;
            table.Add(schemeName, parser);

            // note: we cannot set schemeName and defaultPort inside OnRegister
            uriParser.OnRegister(schemeName, defaultPort);
        }
Beispiel #2
0
        public static void RegisterPackUriParser()
        {
            if (UriParser.IsKnownScheme(PackUriScheme))
            {
                return;
            }

            UriParser.Register(new GenericUriParser(GenericUriParserOptions.GenericAuthority), PackUriScheme, -1);
        }
 public void Initialize()
 {
     // Required to register bourgeoise XAML URI schemes
     if (!UriParser.IsKnownScheme("pack"))
     {
         new Application();
     }
     _accent = ThemeManager.TryGetAccent("Blue");
 }
Beispiel #4
0
        public void FixtureSetup()
        {
            if (!UriParser.IsKnownScheme("pack"))
            {
                new System.Windows.Application();
            }

            this.tester = new ServiceTester <DirectoryWatch>();
        }
Beispiel #5
0
 public void TestInit()
 {
     if (!UriParser.IsKnownScheme("pack"))
     {
         // ReSharper disable ObjectCreationAsStatement
         new System.Windows.Application();
     }
     // ReSharper restore ObjectCreationAsStatement
 }
        //------------------------------------------------------
        //
        //  Internal Events
        //
        //------------------------------------------------------
        // None
        //------------------------------------------------------
        //
        //  Private Constructors
        //
        //------------------------------------------------------

        #region Private Constructor

        static PackUriHelper()
        {
            // indicate that we want "basic" parsing
            if (!UriParser.IsKnownScheme(System.IO.Packaging.PackUriHelper.UriSchemePack))
            {
                // Indicate that we want a default hierarchical parser with a registry based authority
                UriParser.Register(new GenericUriParser(GenericUriParserOptions.GenericAuthority), System.IO.Packaging.PackUriHelper.UriSchemePack, -1);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Registers the URI.
        /// </summary>
        public static void RegisterUri()
        {
            if (!UriParser.IsKnownScheme("rtsp"))
            {
                UriParser.Register(new HttpStyleUriParser(), "rtsp", 554);
            }

            UriParser.Register(new HttpStyleUriParser(), "rtsp", 8080);
        }
 public void Setup()
 {
     if (!UriParser.IsKnownScheme("pack"))
     {
         new System.Windows.Application();
     }
     this.iconProvider = new IconProvider();
     this.testFileName = Path.GetTempFileName();
     File.Create(testFileName).Close();
 }
Beispiel #9
0
        /// <summary>
        /// Ensures the <see cref="UriParser"/> is registered.
        /// </summary>
        public static void Register()
        {
            if (!registered)
            {
                UriParser.Register(new DynamicUriParser(), DynamicUriHelper.UriSchemeDynamic, -1);
                registered = true;
            }

            DynamicWebRequestFactory.Register();
        }
	    /** 
	     * By default the RTSP uses {@link UriParser} to parse the URI requested by the client
	     * but you can change that behavior by override this method.
	     * @param uri The uri that the client has requested
	     * @param client The socket associated to the client
	     * @return A proper session
	     */
	    protected Session handleRequest(System.String uri, Socket client)
        {
            //TODO
		    Session session = UriParser.parse(uri);
            session.setOrigin(client.LocalAddress.HostAddress);
		    if (session.getDestination()==null) {
			    session.setDestination(client.InetAddress.HostAddress);
		    }
		    return session;
	    }
Beispiel #11
0
 private EquipmentData(Options options)
 {
     if (!UriParser.IsKnownScheme("pack"))
     {
         // Necessary for unit tests. Accessing PackUriHelper triggers static initialization.
         // Without it, creating resource URIs from unit tests would throw UriFormatExceptions.
         var _ = System.IO.Packaging.PackUriHelper.UriSchemePack;
     }
     _itemImageService = new ItemImageService(options);
 }
        public void InitializeAndValidate()
        {
            Assert.IsTrue(UriParser.IsKnownScheme("httpx"), "premise1");

            Uri uri = new Uri("httpx://localhost");
            UriFormatException error;

            parser._InitializeAndValidate(uri, out error);
            Assert.AreEqual(null, error);
        }
        public static Uri ToPackUri(string url)
        {
            if (!UriParser.IsKnownScheme("pack"))
            {
                // Register the pack scheme.
                new Application();
            }

            return(new Uri(url));
        }
Beispiel #14
0
 public void DontCheckHostWithCustomParsers()
 {
     UriParser.Register(new TolerantUriParser(), "assembly", 0);
     try {
         new Uri("assembly://Spring.Core, Version=1.2.0.20001, Culture=neutral, "
                 + "PublicKeyToken=null/Spring.Objects.Factory.Xml/spring-objects-1.1.xsd");
     } catch (UriFormatException) {
         Assert.Fail("Spring Uri is expected to work.");
     }
 }
Beispiel #15
0
        public void SendTest()
        {
            Publication pub = storageManager.getEntityByID <Publication>(11);

            Assert.IsNotNull(pub);

            UriParser.Register(new GoogleDocsUriParser(), "gdocs", -1);

            Assert.IsTrue(serviceManager.Send(pub));
        }
Beispiel #16
0
        public static IEnumerable <CoapOption> DecomposeCoapUri(this Uri resource)
        {
            List <CoapOption> options = new List <CoapOption>();

            GenericUriParser gup = new GenericUriParser(GenericUriParserOptions.NoFragment);

            if (!UriParser.IsKnownScheme("coap"))
            {
                UriParser.Register(gup, "coap", -1);
            }

            if (!resource.IsWellFormedOriginalString())
            {
                throw new UriFormatException("Not well formed URI.");
            }

            if (!resource.IsAbsoluteUri)
            {
                throw new UriFormatException("Not absolute URI.");
            }

            if (resource.Scheme != "coap" && resource.Scheme != "coaps")
            {
                throw new UriFormatException(String.Format("Invalid scheme '{0}'", resource.Scheme));
            }

            options.Add(new CoapOption(OptionType.UriHost, resource.Host));

            if (resource.Port > 0)
            {
                options.Add(new CoapOption(OptionType.UriPort, (uint)resource.Port));
            }

            if (resource.AbsolutePath != "/")
            {
                string[] parts = resource.AbsolutePath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string part in parts)
                {
                    options.Add(new CoapOption(OptionType.UriPath, part));
                }
            }

            if (!string.IsNullOrEmpty(resource.Query))
            {
                NameValueCollection nvc = HttpUtility.ParseQueryString(resource.Query);
                int index = 0;
                while (index < nvc.Count)
                {
                    options.Add(new CoapOption(OptionType.UriQuery, nvc.GetKey(index) + "=" + nvc[index]));
                    index++;
                }
            }

            return(options.ToArray());
        }
Beispiel #17
0
        /// <summary>
        /// Ensures that the pack URI is allowed. Sometimes, when no application object is instantiated
        /// yet, the pack URI is not allowed. This method takes care of that.
        /// </summary>
        internal static void EnsurePackUriIsAllowed()
        {
#if !NETFX_CORE
            if (!UriParser.IsKnownScheme("pack"))
            {
                Log.Debug("Pack uri is not yet allowed, adding it as known scheme");

                UriParser.Register(new GenericUriParser(GenericUriParserOptions.GenericAuthority), "pack", -1);
            }
#endif
        }
        private void RegisterPackScheme()
        {
            if (UriParser.IsKnownScheme("pack"))
            {
                return;
            }

            var packParser = new PackParser();

            UriParser.Register(packParser, "pack", 0);
        }
Beispiel #19
0
        public static void ReRegister()
        {
            string scheme = Prefix + "re.register.mono";

            Assert.False(UriParser.IsKnownScheme(scheme), "IsKnownScheme-false");
            TestUriParser parser = new TestUriParser();

            UriParser.Register(parser, scheme, 2005);
            Assert.True(UriParser.IsKnownScheme(scheme), "IsKnownScheme-true");
            Assert.Throws <InvalidOperationException>(() => UriParser.Register(parser, scheme, 2006));
        }
Beispiel #20
0
        public void ReRegister()
        {
            string scheme = prefix + "re.register.mono";

            Assert.IsFalse(UriParser.IsKnownScheme(scheme), "IsKnownScheme-false");
            UnitTestUriParser p = new UnitTestUriParser();

            UriParser.Register(p, scheme, 2005);
            Assert.IsTrue(UriParser.IsKnownScheme(scheme), "IsKnownScheme-true");
            UriParser.Register(p, scheme, 2006);
        }
Beispiel #21
0
 static ColorizeShaderEffect()
 {
     if (!UriParser.IsKnownScheme("pack"))
     {
         new FlowDocument();
     }
     _pixelShader = new PixelShader()
     {
         UriSource = new Uri("pack://application:,,,/Snoop;component/Shaders/Compiled/colorizeshader.ps", UriKind.RelativeOrAbsolute)
     };
 }
 public MyUriParser(UriParser originalParser) : base()
 {
     if (_originalParser == null)
     {
         _originalParser      = originalParser;
         _getComponentsMethod = typeof(UriParser).GetMethod("GetComponents", BindingFlags.NonPublic | BindingFlags.Instance);
         if (_getComponentsMethod == null)
         {
             throw new MissingMethodException("UriParser", "GetComponents");
         }
     }
 }
        public void InitializeAndValidate2()
        {
            Assert.IsTrue(UriParser.IsKnownScheme("httpx"), "premise1");

            Uri uri = new Uri("file:///usr/local/bin");
            // It results in UriFormatException since it tries
            // to parse file URI with http Uri parser.
            UriFormatException error;

            parser._InitializeAndValidate(uri, out error);
            Assert.IsNotNull(error);
        }
Beispiel #24
0
        public void FixtureSetUp()
        {
            parser = new UnitTestNewsStyleUriParser();
            // unit tests are being reused in CAS tests
            if (!UriParser.IsKnownScheme("newsx"))
            {
                UriParser.Register(parser, "newsx", 2);
            }

            Assert.IsTrue(UnitTestNewsStyleUriParser.Registered, "Registered");
            // our parser code was called
        }
Beispiel #25
0
        public static void ReRegister()
        {
            prefix = "unit.test.";
            string scheme = prefix + "re.register.mono";

            Assert.False(UriParser.IsKnownScheme(scheme), "IsKnownScheme-false");
            TestUriParser parser = new TestUriParser();

            UriParser.Register(parser, scheme, 2005);
            Assert.True(UriParser.IsKnownScheme(scheme), "IsKnownScheme-true");
            Assert.Throws <System.InvalidOperationException>(() => { UriParser.Register(parser, scheme, 2006); });
        }
        public void FixtureSetUp()
        {
            parser = new UnitTestGenericUriParser();
            // unit tests are being reused in CAS tests
            if (!UriParser.IsKnownScheme("generic"))
            {
                UriParser.Register(parser, "generic", 1);
            }

            Assert.IsTrue(UnitTestGenericUriParser.Registered, "Registered");
            // our parser code was called
        }
Beispiel #27
0
        /// <summary>
        /// Registers the parsers.
        /// </summary>
        public static void RegisterParsers()
        {
            if (!UriParser.IsKnownScheme(SvnUri.UriSchemeSvn))
            {
                UriParser.Register(new SvnUriParser(), SvnUri.UriSchemeSvn, 3980);
            }

            if (!UriParser.IsKnownScheme(SvnUri.UriSchemeSvnSsh))
            {
                UriParser.Register(new SvnUriParser(), SvnUri.UriSchemeSvnSsh, 22);
            }
        }
Beispiel #28
0
        static SipMessage()
        {
            if (false == UriParser.IsKnownScheme(SipMessage.TransportScheme))
            {
                UriParser.Register(new HttpStyleUriParser(), SipMessage.TransportScheme, SipMessage.TransportDefaultPort);
            }

            if (false == UriParser.IsKnownScheme(SipMessage.SecureTransportScheme))
            {
                UriParser.Register(new HttpStyleUriParser(), SipMessage.SecureTransportScheme, SipMessage.SecureTransportDefaultPort);
            }
        }
Beispiel #29
0
 public static void RegisterResUriParsers()
 {
     if (!UriParser.IsKnownScheme("avares"))
     {
         UriParser.Register(new GenericUriParser(
                                GenericUriParserOptions.GenericAuthority |
                                GenericUriParserOptions.NoUserInfo |
                                GenericUriParserOptions.NoPort |
                                GenericUriParserOptions.NoQuery |
                                GenericUriParserOptions.NoFragment), "avares", -1);
     }
 }
Beispiel #30
0
        /**
         * 下载文件
         */
        protected bool downloadfile(string url, string savefullpath, ProgressDelegate progress = null)
        {
            //处理下载url不符合rfc规范的情况
            MethodInfo getSyntax  = typeof(UriParser).GetMethod("GetSyntax", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
            FieldInfo  flagsField = typeof(UriParser).GetField("m_Flags", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);

            if (getSyntax != null && flagsField != null)
            {
                foreach (string scheme in new[] { "http", "https" })
                {
                    UriParser parser = (UriParser)getSyntax.Invoke(null, new object[] { scheme });
                    if (parser != null)
                    {
                        int flagsValue = (int)flagsField.GetValue(parser);
                        // Clear the CanonicalizeAsFilePath attribute
                        if ((flagsValue & 0x1000000) != 0)
                        {
                            flagsField.SetValue(parser, flagsValue & ~0x1000000);
                        }
                    }
                }
            }

            NSPLog.log(LogMsgType.NSP_LOG_NOTICE, "请求下载 " + url);
            //文件下载
            WebRequest  req        = WebRequest.Create(url);
            WebResponse pos        = req.GetResponse();
            long        totalbytes = pos.ContentLength;
            Stream      s          = pos.GetResponseStream();
            FileStream  fs         = new FileStream(savefullpath, FileMode.OpenOrCreate, FileAccess.Write);

            byte[] buffer = new byte[1024];

            int  bytesRead = s.Read(buffer, 0, buffer.Length);
            long donebytes = 0;

            while (bytesRead > 0)
            {
                fs.Write(buffer, 0, bytesRead);
                bytesRead = s.Read(buffer, 0, buffer.Length);
                if (progress != null)
                {
                    donebytes += bytesRead;
                    progress(donebytes, totalbytes);
                }
            }

            fs.Close();
            s.Close();
            pos.Close();
            return(true);
        }
Beispiel #31
0
        public static void AnyValidPort_CanBeRegistered()
        {
            for (int i = -1; i <= 65535; i++)
            {
                string scheme = $"custom-port-scheme-{i:X2}";
                UriParser.Register(new HttpStyleUriParser(), scheme, defaultPort: i);
                var uri = new Uri($"{scheme}://host/path");
                Assert.Equal(i, uri.Port);
            }

            Assert.Throws <ArgumentOutOfRangeException>(() => UriParser.Register(new HttpStyleUriParser(), "invalid-port", -2));
            Assert.Throws <ArgumentOutOfRangeException>(() => UriParser.Register(new HttpStyleUriParser(), "invalid-port", 65536));
        }
Beispiel #32
0
        public static void Register(UriParser uriParser, string schemeName, int defaultPort)
        {
            if (uriParser == null)
                throw new ArgumentNullException("uriParser");
            if (schemeName == null)
                throw new ArgumentNullException("schemeName");
            if ((defaultPort < -1) || (defaultPort >= UInt16.MaxValue))
                throw new ArgumentOutOfRangeException("defaultPort");

            CreateDefaults();

            string lc = schemeName.ToLower();
            if (table[lc] != null)
            {
                string msg = "Scheme is already registred.";
                throw new InvalidOperationException(msg);
            }
            InternalRegister(table, uriParser, lc, defaultPort);
        }
Beispiel #33
0
 internal static bool IriParsingStatic(UriParser syntax)
 {
     throw new NotImplementedException();
 }
 // Methods
 public static void Register(UriParser uriParser, string schemeName, int defaultPort)
 {
 }