예제 #1
0
        /// <summary>
        /// Creates a new Discord RPC Client using the steam uri scheme.
        /// </summary>
        /// <param name="applicationID">The ID of the application created at discord's developers portal.</param>
        /// <param name="steamID">The steam ID of the app. This is used to launch Join / Spectate through steam URI scheme instead of manual launching</param>
        /// <param name="registerUriScheme">Should a URI scheme be registered for Join / Spectate functionality? If false, the Join / Spectate functionality will be disabled.</param>
        /// <param name="pipe">The pipe to connect too. -1 for first available pipe.</param>
        /// <param name="client">The pipe client to use and communicate to discord through</param>
        /// <param name="logger">The logger used to report messages. Its recommended to assign here so it can report the results of RegisterUriScheme.</param>
        public DiscordRpcClient(string applicationID, string steamID, bool registerUriScheme, int pipe, INamedPipeClient client, ILogger logger = null)
        {
            //Store our values
            ApplicationID          = applicationID;
            SteamID                = steamID;
            HasRegisteredUriScheme = registerUriScheme;
            ProcessID              = System.Diagnostics.Process.GetCurrentProcess().Id;
            _pipe   = pipe;
            _logger = logger == null ? new NullLogger() : logger;

            //If we are to register the URI scheme, do so.
            //The UriScheme.RegisterUriScheme function takes steamID as a optional parameter, its null by default.
            //   this means it will handle a null steamID for us :)
            if (registerUriScheme)
            {
                UriScheme.RegisterUriScheme(_logger, applicationID, steamID);
            }

            //Create the RPC client
            connection = new RpcConnection(ApplicationID, ProcessID, TargetPipe, client)
            {
                ShutdownOnly = _shutdownOnly
            };
            connection.Logger = this._logger;
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NetWatcher"/> class.
        /// </summary>
        /// <param name="requestUri">The request URI to monitor for changes.</param>
        /// <param name="period">The time interval between periodic signaling for changes of provided <paramref name="requestUri"/>.</param>
        /// <param name="dueTime">The amount of time to delay before the associated <see cref="Watcher"/> starts signaling. Specify negative one (-1) milliseconds to prevent the signaling from starting. Specify zero (0) to start the signaling immediately.</param>
        /// <param name="checkResponseData">if set to <c>true</c>, a MD5 hash check of the response data is used to determine a change state of the resource; <c>false</c> to check only for the last modification of the resource.</param>
        /// <remarks>Monitors the provided <paramref name="requestUri"/> for changes in an interval specified by <paramref name="period"/>, determined by <paramref name="checkResponseData"/>.</remarks>
        public NetWatcher(Uri requestUri, TimeSpan dueTime, TimeSpan period, bool checkResponseData) : base(dueTime, period)
        {
            if (requestUri == null)
            {
                throw new ArgumentNullException(nameof(requestUri));
            }
            UriScheme scheme = UriSchemeConverter.FromString(requestUri.Scheme);

            switch (scheme)
            {
            case UriScheme.File:
            case UriScheme.Ftp:
            case UriScheme.Http:
            case UriScheme.Https:
                break;

            default:
                throw new ArgumentException("The provided Uri does not have a valid scheme attached. Allowed schemes for now is File, FTP, HTTP or HTTPS.", nameof(requestUri));
            }
            RequestUri        = requestUri;
            Scheme            = scheme;
            UtcCreated        = DateTime.UtcNow;
            CheckResponseData = checkResponseData;
            Signature         = SignatureDefault;
        }
예제 #3
0
        public void CreateWithUriRequestReturnsCorrectResult()
        {
            // Fixture setup
            var    request           = typeof(Uri);
            object expectedUriScheme = new UriScheme("ftp");
            object expectedAuthority = Guid.NewGuid().ToString();
            var    context           = new DelegatingSpecimenContext
            {
                OnResolve = r =>
                {
                    if (typeof(UriScheme).Equals(r))
                    {
                        return(expectedUriScheme);
                    }

                    if (typeof(string).Equals(r))
                    {
                        return(expectedAuthority);
                    }

                    return(new NoSpecimen(r));
                }
            };
            var sut = new UriGenerator();
            // Exercise system
            var result = (Uri)sut.Create(request, context);
            // Verify outcome
            var expectedUri = new Uri(expectedUriScheme + "://" + expectedAuthority);

            Assert.Equal(expectedUri, result);
            // Teardown
        }
 public void ExistingSchemeIsUpdated(UriScheme scheme, string expectedScheme)
 {
     FluentUriBuilder.From(fullTestUri)
     .Scheme(scheme)
     .ToUri()
     .Scheme
     .Should().Be(expectedScheme);
 }
예제 #5
0
        public static string ToName(this UriScheme uriScheme)
        {
            var tokensByUriScheme = UriSchemeNames.NamesByUriScheme.Value;

            var token = tokensByUriScheme[uriScheme];

            return(token);
        }
 public BindingConfiguration(string url, UriScheme scheme, SiteType siteType, string certificate, bool requireSni = false)
 {
     Url = url;
     Scheme = scheme;
     SiteType = siteType;
     Certificate = certificate;
     RequireSni = requireSni;
 }
 public BindingConfiguration(string url, UriScheme scheme, SiteType siteType, string certificate, bool requireSni = false)
 {
     Url         = url;
     Scheme      = scheme;
     SiteType    = siteType;
     Certificate = certificate;
     RequireSni  = requireSni;
 }
예제 #8
0
 /// <summary>
 /// <c>BasicClient</c> constructor.
 /// </summary>
 /// <param name="host">The hostname of the InSites server.</param>
 /// <param name="username">A username associated with an InSites login.</param>
 /// <param name="password">The password of the specified user.</param>
 public APIClient(UriScheme scheme, string host, string username, string password, int port)
 {
     Byte[] byteAuthorizationToken = System.Text.Encoding.ASCII.GetBytes(username + ":" + password);
     this.authHeaderValue = Convert.ToBase64String(byteAuthorizationToken);
     this.hostIP          = host;
     this.scheme          = scheme.ToString().ToLower();
     this.sessionCookie   = string.Empty;
 }
예제 #9
0
        /// <summary>
        /// Converts the specified <paramref name="value"/> of a protocol-relative <see cref="string"/> to its equivalent <see cref="Uri"/>.
        /// </summary>
        /// <param name="value">The <see cref="string"/> to be converted.</param>
        /// <param name="protocol">The desired protocol of the <paramref name="value"/> to be converted.</param>
        /// <param name="relativeReference">The relative reference that <paramref name="value"/> must begin with. Default is <see cref="StringUtility.NetworkPathReference"/>.</param>
        /// <returns>An <see cref="Uri"/> that is equivalent to <paramref name="value"/> with the specified <paramref name="protocol"/> as <see cref="Uri.Scheme"/>.</returns>
        public static Uri FromProtocolRelativeUri(string value, UriScheme protocol, string relativeReference)
        {
            Validator.ThrowIfNullOrEmpty(value, nameof(value));
            Validator.ThrowIfNullOrEmpty(relativeReference, nameof(relativeReference));
            Validator.ThrowIfFalse(value.StartsWith(relativeReference, StringComparison.OrdinalIgnoreCase), nameof(value), string.Format(CultureInfo.InvariantCulture, "The specified value did not start with the the expected value of: {0}.", relativeReference));
            int relativeReferenceLength = relativeReference.Length;

            return(new Uri(value.Remove(0, relativeReferenceLength).Insert(0, string.Format(CultureInfo.InvariantCulture, "{0}://", StringConverter.FromUriScheme(protocol)))));
        }
 public void SchemeIsUsedIfSpecified(UriScheme scheme, string expectedScheme)
 {
     FluentUriBuilder.Create()
     .Scheme(scheme)
     .Host("example.com")
     .ToUri()
     .Scheme
     .Should().Be(expectedScheme);
 }
예제 #11
0
        public void SutIsEquatable()
        {
            // Arrange
            // Act
            var sut = new UriScheme();

            // Assert
            Assert.IsAssignableFrom <IEquatable <UriScheme> >(sut);
        }
예제 #12
0
파일: Uri.cs 프로젝트: ForNeVeR/pnet
        internal static int DefaultPortForScheme(String name)
        {
            UriScheme entry = (UriScheme)schemes[name];

            if ((entry = (UriScheme)schemes[name]) != null)
            {
                return(entry.port);
            }
            return(-1);
        }
예제 #13
0
        public void SutIsEquatable()
        {
            // Fixture setup
            // Exercise system
            var sut = new UriScheme();

            // Verify outcome
            Assert.IsAssignableFrom <IEquatable <UriScheme> >(sut);
            // Teardown
        }
예제 #14
0
 public ToggleHttpHttpsAttribute(
     UriScheme uriScheme = UriScheme.Http)
 {
     TargetUriScheme = uriScheme;
     #if DEBUG
     //set DEBUG ports
     HttpPort  = 55892;
     HttpsPort = 44301;
     #endif
 }
예제 #15
0
        public void SutEqualsOtherSutWhenBothSchemesAreDefault()
        {
            // Arrange
            var sut   = new UriScheme();
            var other = new UriScheme();
            // Act
            bool result = sut.Equals(other);

            // Assert
            Assert.True(result);
        }
예제 #16
0
        public void InitializeWithDefaultConstructorSetsCorrectScheme()
        {
            // Arrange
            var    sut            = new UriScheme();
            string expectedScheme = "http";
            // Act
            string result = sut.Scheme;

            // Assert
            Assert.Equal(expectedScheme, result);
        }
예제 #17
0
        /// <summary>
        /// Create the specified URI.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <returns></returns>
        private UriScheme Creat(Uri uri)
        {
            UriScheme temp = new UriScheme
            {
                Host       = uri.Host,
                Segments   = Segments(uri).ToList(),
                Parameters = Parameters(uri).ToList()
            };

            return(temp);
        }
예제 #18
0
        public void GetHashCodeWhenSchemeIsDefaultReturnsCorrectResult()
        {
            // Arrange
            var sut = new UriScheme();
            // Act
            int result = sut.GetHashCode();
            // Assert
            int expectedHashCode = "http".GetHashCode();

            Assert.Equal(expectedHashCode, result);
        }
예제 #19
0
        public void SutDoesNotEqualNullObject()
        {
            // Arrange
            var    sut   = new UriScheme();
            object other = null;
            // Act
            bool result = sut.Equals(other);

            // Assert
            Assert.False(result);
        }
예제 #20
0
        public void ToStringReturnsCorrectResult()
        {
            // Arrange
            string expected = "http";
            var    sut      = new UriScheme("http");
            // Act
            var result = sut.ToString();

            // Assert
            Assert.Equal(expected, result);
        }
예제 #21
0
        public void InitializeWithSchemeParameterSetsCorrectScheme()
        {
            // Arrange
            string expectedScheme = "http";
            var    sut            = new UriScheme("http");
            // Act
            string result = sut.Scheme;

            // Assert
            Assert.Equal(expectedScheme, result);
        }
예제 #22
0
        public void SutDoesNotEqualAnonymousObject()
        {
            // Arrange
            var sut             = new UriScheme();
            var anonymousObject = new object();
            // Act
            bool result = sut.Equals(anonymousObject);

            // Assert
            Assert.False(result);
        }
예제 #23
0
 public void InitializeWithSchemeParameterSetsCorrectScheme()
 {
     // Fixture setup
     string expectedScheme = "http";
     var sut = new UriScheme("http");
     // Exercise system
     string result = sut.Scheme;
     // Verify outcome
     Assert.Equal(expectedScheme, result);
     // Teardown
 }
예제 #24
0
        public void SutDoesNotEqualOtherSutWhenSchemesDiffer()
        {
            // Arrange
            var sut   = new UriScheme("a");
            var other = new UriScheme("b");
            // Act
            bool result = sut.Equals(other);

            // Assert
            Assert.False(result);
        }
예제 #25
0
 public void ToStringReturnsCorrectResult()
 {
     // Fixture setup
     string expected = "http";
     var sut = new UriScheme("http");
     // Exercise system
     var result = sut.ToString();
     // Verify outcome
     Assert.Equal(expected, result);
     // Teardown
 }
예제 #26
0
 public void InitializeWithDefaultConstructorSetsCorrectScheme()
 {
     // Fixture setup
     var sut = new UriScheme();
     string expectedScheme = "http";
     // Exercise system
     string result = sut.Scheme;
     // Verify outcome
     Assert.Equal(expectedScheme, result);
     // Teardown
 }
예제 #27
0
        public void ToStringReturnsCorrectResult()
        {
            // Fixture setup
            string expected = "http";
            var    sut      = new UriScheme("http");
            // Exercise system
            var result = sut.ToString();

            // Verify outcome
            Assert.Equal(expected, result);
            // Teardown
        }
예제 #28
0
        public void InitializeWithSchemeParameterSetsCorrectScheme()
        {
            // Fixture setup
            string expectedScheme = "http";
            var    sut            = new UriScheme("http");
            // Exercise system
            string result = sut.Scheme;

            // Verify outcome
            Assert.Equal(expectedScheme, result);
            // Teardown
        }
예제 #29
0
        public void GetHashCodeWhenSchemeIsDefaultReturnsCorrectResult()
        {
            // Fixture setup
            var sut = new UriScheme();
            // Exercise system
            int result = sut.GetHashCode();
            // Verify outcome
            int expectedHashCode = "http".GetHashCode();

            Assert.Equal(expectedHashCode, result);
            // Teardown
        }
예제 #30
0
        public void InitializeWithDefaultConstructorSetsCorrectScheme()
        {
            // Fixture setup
            var    sut            = new UriScheme();
            string expectedScheme = "http";
            // Exercise system
            string result = sut.Scheme;

            // Verify outcome
            Assert.Equal(expectedScheme, result);
            // Teardown
        }
예제 #31
0
        public void SutEqualsOtherSutWhenBothSchemesAreDefault()
        {
            // Fixture setup
            var sut   = new UriScheme();
            var other = new UriScheme();
            // Exercise system
            bool result = sut.Equals(other);

            // Verify outcome
            Assert.True(result);
            // Teardown
        }
예제 #32
0
        public void SutDoesNotEqualNullObject()
        {
            // Fixture setup
            var    sut   = new UriScheme();
            object other = null;
            // Exercise system
            bool result = sut.Equals(other);

            // Verify outcome
            Assert.False(result);
            // Teardown
        }
예제 #33
0
        public HttpRequestUriBuilder(UriScheme uriScheme, string host, string path = "")
        {
            // https://tools.ietf.org/html/rfc7230#section-2.7.3
            // The scheme and host are case-insensitive and normally provided in lowercase;
            // all other components are compared in a case-sensitive manner.

            if (host is null)
            {
                throw new FormatException("Host identifier cannot be null.");
            }

            var h = host.Trim().TrimEnd('/').TrimStart(uriScheme.ToString() + "://", StringComparison.OrdinalIgnoreCase);

            // https://tools.ietf.org/html/rfc7230#section-2.7.1
            // A sender MUST NOT generate an "http" URI with an empty host identifier.
            if (h == "")
            {
                throw new FormatException("Host identifier is empty.");
            }

            Host = h;

            Scheme = uriScheme.ToString().ToLowerInvariant();
            if (uriScheme == UriScheme.http)
            {
                // https://tools.ietf.org/html/rfc7230#section-2.7.1
                // [http] If the port subcomponent is empty or not given, TCP port 80(the reserved port
                // for WWW services) is the default.
                Port = 80;
            }
            else if (uriScheme == UriScheme.https)
            {
                // https://tools.ietf.org/html/rfc7230#section-2.7.2
                // [https] TCP port 443 is the default if the port subcomponent is empty or not given
                Port = 443;
            }

            // Because we want to tolerate http:// and https:// in the host we also want to make sure it does not contradict the scheme
            foreach (UriScheme scheme in Enum.GetValues(typeof(UriScheme)))
            {
                // if host starts with http:// or https:// then check
                if (host.StartsWith(scheme.ToString() + "://", StringComparison.OrdinalIgnoreCase))
                {
                    // if the currently iterated scheme does not equal the provided scheme
                    if (scheme != uriScheme)
                    {
                        throw new FormatException("uriScheme not consistent with host identifier.");
                    }
                }
            }

            Path = path;
        }
예제 #34
0
        /// <summary>
        /// Konstruktor
        /// </summary>
        /// <param name="scheme"></param>
        /// <param name="authority">Die Zuständigkeit (z.B. [email protected]:8080)</param>
        /// <param name="uri">Die Uri</param>
        public UriAbsolute(UriScheme scheme, UriAuthority authority, IUri uri)
        {
            Scheme    = scheme;
            Authority = authority;

            if (uri != null)
            {
                (Path as List <IUriPathSegment>).AddRange(uri.Path.Select(x => new UriPathSegment(x.Value, x.Tag) as IUriPathSegment));
                (Query as List <UriQuerry>).AddRange(uri.Query.Select(x => new UriQuerry(x.Key, x.Value)));
                Fragment = uri.Fragment;
            }
        }
 public void CreateWithUriSchemeRequestReturnsCorrectResult()
 {
     // Fixture setup
     var sut = new UriSchemeGenerator();
     var request = typeof(UriScheme);
     // Exercise system
     var dummyContext = new DelegatingSpecimenContext();
     var result = sut.Create(request, dummyContext);
     // Verify outcome
     var expectedResult = new UriScheme();
     Assert.Equal(expectedResult, result);
     // Teardown
 }
예제 #36
0
 public void SutDoesNotEqualOtherSutWhenSchemesDiffer()
 {
     // Fixture setup
     var sut = new UriScheme("a");
     var other = new UriScheme("b");
     // Exercise system
     bool result = sut.Equals(other);
     // Verify outcome
     Assert.False(result);
     // Teardown
 }
예제 #37
0
 public void SutDoesNotEqualNullObject()
 {
     // Fixture setup
     var sut = new UriScheme();
     object other = null;
     // Exercise system
     bool result = sut.Equals(other);
     // Verify outcome
     Assert.False(result);
     // Teardown
 }
예제 #38
0
        public BindingConfiguration(string url, UriScheme scheme, SiteType siteType)
            : this(url, scheme, siteType, null, false)
        {

        }
예제 #39
0
 public void SutIsEquatable()
 {
     // Fixture setup
     // Exercise system
     var sut = new UriScheme();
     // Verify outcome
     Assert.IsAssignableFrom<IEquatable<UriScheme>>(sut);
     // Teardown
 }
예제 #40
0
 public void GetHashCodeWhenSchemeIsNotDefaultReturnsCorrectResult()
 {
     // Fixture setup
     var scheme = "https";
     var sut = new UriScheme(scheme);
     // Exercise system
     int result = sut.GetHashCode();
     // Verify outcome
     int expectedHashCode = scheme.GetHashCode();
     Assert.Equal(expectedHashCode, result);
     // Teardown
 }
예제 #41
0
 private static Uri CreateAnonymous(UriScheme scheme, string authority)
 {
     return new Uri(scheme + "://" + authority);
 }
예제 #42
0
 public void SutEqualsOtherSutWhenSchemesAreEqual()
 {
     // Fixture setup
     var scheme = "https";
     var sut = new UriScheme(scheme);
     var other = new UriScheme(scheme);
     // Exercise system
     bool result = sut.Equals(other);
     // Verify outcome
     Assert.True(result);
     // Teardown
 }
 public void ExistingSchemeIsUpdated(UriScheme scheme, string expectedScheme)
 {
     FluentUriBuilder.From(fullTestUri)
         .Scheme(scheme)
         .ToUri()
         .Scheme
         .Should().Be(expectedScheme);
 }
예제 #44
0
        public void CreateWithUriRequestReturnsCorrectResult()
        {
            // Fixture setup
            var request = typeof(Uri);
            object expectedUriScheme = new UriScheme("ftp");
            object expectedAuthority = Guid.NewGuid().ToString();
            var context = new DelegatingSpecimenContext
            {
                OnResolve = r =>
                {
                    if (typeof(UriScheme).Equals(r))
                    {
                        return expectedUriScheme;
                    }

                    if (typeof(string).Equals(r))
                    {
                        return expectedAuthority;
                    }

                    return new NoSpecimen(r);
                }
            };
            var sut = new UriGenerator();
            // Exercise system
            var result = (Uri)sut.Create(request, context);
            // Verify outcome
            var expectedUri = new Uri(expectedUriScheme + "://" + expectedAuthority);
            Assert.Equal(expectedUri, result);
            // Teardown
        }
예제 #45
0
파일: UrlBuilder.cs 프로젝트: vip32/cadru
 /// <summary>
 /// Initializes a new instance of the <see cref="UrlBuilder"/> class 
 /// with the specified scheme and host.
 /// </summary>
 /// <param name="scheme">An Internet access protocol.</param>
 /// <param name="host">A DNS-style domain name or IP address.</param>
 /// <param name="port">An IP port number for the service.</param>
 /// <param name="path">The path to the Internet resource.</param>
 /// <param name="extraValue">A query string or fragment identifier.</param>
 /// <exception cref="System.ArgumentException">
 /// <paramref name="extraValue"/> is neither <see langword="null"/>
 /// nor <see cref="System.String.Empty">System.String.Empty</see>, nor
 /// does a valid fragment identifier begin with a number sign (#), nor
 /// a valid query string begin with a question mark (?).
 /// </exception>
 /// <exception cref="System.ArgumentOutOfRangeException">
 /// <paramref name="port"/> is less than -1 or greater than 65,535.
 /// </exception>
 public UrlBuilder(UriScheme scheme, string host, int port, string path, string extraValue)
 {
     this.builder = new UriBuilder(scheme, host, port, path, extraValue);
     this.queryParameters = new QueryStringParametersDictionary(this.builder.Query);
 }
예제 #46
0
 public void SutDoesNotEqualAnonymousObject()
 {
     // Fixture setup
     var sut = new UriScheme();
     var anonymousObject = new object();
     // Exercise system
     bool result = sut.Equals(anonymousObject);
     // Verify outcome
     Assert.False(result);
     // Teardown
 }
예제 #47
0
파일: UrlBuilder.cs 프로젝트: vip32/cadru
 /// <summary>
 /// Initializes a new instance of the <see cref="UrlBuilder"/> class 
 /// with the specified scheme and host.
 /// </summary>
 /// <param name="scheme">An Internet access protocol.</param>
 /// <param name="host">A DNS-style domain name or IP address.</param>
 /// <param name="port">An IP port number for the service.</param>
 /// <param name="path">The path to the Internet resource.</param>
 /// <exception cref="System.ArgumentOutOfRangeException">
 /// <paramref name="port"/> is less than -1 or greater than 65,535.
 /// </exception>
 public UrlBuilder(UriScheme scheme, string host, int port, string path)
 {
     this.builder = new UriBuilder(scheme, host, port, path);
     this.queryParameters = new QueryStringParametersDictionary();
 }
예제 #48
0
 public void SutEqualsOtherObjectWhenBothSchemesAreDefault()
 {
     // Fixture setup
     var sut = new UriScheme();
     object other = new UriScheme();
     // Exercise system
     bool result = sut.Equals(other);
     // Verify outcome
     Assert.True(result);
     // Teardown
 }
        /// <summary>
        ///     Sets or updates the protocol scheme of the URI.
        /// </summary>
        /// <param name="scheme">
        ///     The new value of the protocol scheme.
        /// </param>
        /// <returns>
        ///     A <see cref="FluentUriBuilder"/> instance to allow chaining.
        /// </returns>
        public FluentUriBuilder Scheme(UriScheme scheme)
        {
            switch (scheme)
            {
                case UriScheme.File:
                    this.scheme = "file";
                    break;
                case UriScheme.Ftp:
                    this.scheme = "ftp";
                    break;
                case UriScheme.Gopher:
                    this.scheme = "gopher";
                    break;
                case UriScheme.Http:
                    this.scheme = "http";
                    break;
                case UriScheme.Https:
                    this.scheme = "https";
                    break;
                case UriScheme.Mailto:
                    this.scheme = "mailto";
                    break;
                case UriScheme.News:
                    this.scheme = "news";
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(scheme));
            }

            return this;
        }
 public void SchemeIsUsedIfSpecified(UriScheme scheme, string expectedScheme)
 {
     FluentUriBuilder.Create()
         .Scheme(scheme)
         .Host("example.com")
         .ToUri()
         .Scheme
         .Should().Be(expectedScheme);
 }