当前位置: 首页>>代码示例>>C#>>正文


C# System.Uri类代码示例

本文整理汇总了C#中System.Uri的典型用法代码示例。如果您正苦于以下问题:C# Uri类的具体用法?C# Uri怎么用?C# Uri使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Uri类属于System命名空间,在下文中一共展示了Uri类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReturnsSafeUriString

            public void ReturnsSafeUriString()
            {
                var inputUri = new Uri("/Views/MainPage.xaml", UriKind.RelativeOrAbsolute);
                var uri = UrlHelper.GetSafeUriString(inputUri);

                Assert.AreEqual("/Views/MainPage.xaml", uri);
            }
开发者ID:justdude,项目名称:DbExport,代码行数:7,代码来源:UrlHelperFacts.cs

示例2: MainForm_Load

        private void MainForm_Load(object sender, EventArgs e)
        {
            if (!loadConfigFile())
            {
                MessageBox.Show("Can't read configuration file!");
                Application.Exit();
            }
            try
            {
                project_uri = new Uri(getCfgValue("projecturl"));
            }
            catch (UriFormatException)
            {
                MessageBox.Show("Malformed projecturl tag in the configuration file!");
                Application.Exit();
            }

            var value = new Uri(project_uri, getCfgValue("updates_page_url", "updates.html"));            

            webBrowser1.Navigate(value); 
            update_state = UpdateStates.Ready;

            this.Text = getCfgValue("application_title");

            runWhenFinished = (RunApplications)getCfgValueInt("runWhenFinished");

            workInBackground.DoWork += new DoWorkEventHandler(UpdateTheClient);
            workInBackground.RunWorkerCompleted += new RunWorkerCompletedEventHandler(UpdateTheClientCompleted);
            workInBackground.ProgressChanged += new ProgressChangedEventHandler(UpdateTheClientProgressChanged);
        }
开发者ID:WildGenie,项目名称:mul-updater,代码行数:30,代码来源:MainForm.cs

示例3: SetGitHubBuildStatus

        internal static void SetGitHubBuildStatus(
            Build build,
            CommitState state,
            Func<string, string, BuildConfiguration> getBuildConfiguration,
            Func<Build, string> getBuildDescription,
            Func<string> getHost,
            Action<string, string, string, string, CommitState, Uri, string> createGitHubCommitStatus)
        {
            var buildConfiguration = getBuildConfiguration(
                build.RepositoryOwner,
                build.RepositoryName);

            if (buildConfiguration == null)
                throw new Exception("Could not find build configuration.");

            var targetUrl = new Uri(String.Format(
                "http://{0}/{1}/{2}/builds/{3}",
                getHost(),
                build.RepositoryOwner,
                build.RepositoryName,
                build.Id));

            createGitHubCommitStatus(
                buildConfiguration.Token,
                build.RepositoryOwner,
                build.RepositoryName,
                build.Revision,
                state,
                targetUrl,
                getBuildDescription(build));
        }
开发者ID:Tradingangel,项目名称:qed,代码行数:31,代码来源:SetGitHubBuildStatus.cs

示例4: GenerateRelativePath

        public static string GenerateRelativePath(string from, string to)
        {
            if(String.IsNullOrWhiteSpace(from) || String.IsNullOrWhiteSpace(to))
            {
                throw new ArgumentNullException("Requires paths");
            }

            Uri fromUri = new Uri(from);
            Uri toUri = new Uri(to);

            //The URI schemes have to match in order for the path to be made relative
            if(fromUri.Scheme != toUri.Scheme)
            {
                return to;
            }

            Uri relativeUri = fromUri.MakeRelativeUri(toUri);
            string relative = Uri.UnescapeDataString(relativeUri.ToString());

            //If neccessary to do so, normalise the use of slashes to always be the default for this platform
            if(toUri.Scheme.ToUpperInvariant() == "FILE")
            {
                relative = relative.Replace(Path.AltDirectorySeparatorChar,
                    Path.DirectorySeparatorChar);
            }

            return relative;
        }
开发者ID:JoshKeegan,项目名称:CVWS.NET,代码行数:28,代码来源:Paths.cs

示例5: MockWebRequest

 /// <summary>Initializes a new instance of <see cref="MockWebRequest"/>
 /// with the response to return.</summary>
 public MockWebRequest(Uri uri, string response)
 {
     m_requestUri = uri;
     m_requestStream = new MemoryStream();
     Stream m_responseStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(response));
     m_mockResponse = new MockWebResponse(m_responseStream);
 }
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:9,代码来源:MockWebRequest.cs

示例6: ProcessRedirection

        public IRedirect ProcessRedirection(string url)
        {
            var redirectResponse = new Redirect();

            // Check that we've received the url parameter
            if (string.IsNullOrEmpty(url))
            {
                redirectResponse.ErrorMessage = string.Format("Url parameter was missing or malformed - ({0}).", url);
                return redirectResponse;
            }

            // Check that url is valid as we don't want a broken redirect
            var uri = new Uri(url);
            redirectResponse.Allowed = true;
            redirectResponse.Url = uri;

            if (_siteConfiguration.SecureMode)
            {
                // Secure mode activated
                if (!uri.Host.EndsWith(_siteConfiguration.WebsiteDomain) || !uri.IsAbsoluteUri)
                {
                    redirectResponse.Allowed = false;
                    redirectResponse.Url = null;
                    redirectResponse.ErrorMessage =
                        string.Format(
                            "Potentially dangerous redirect detected and blocked. Submitted url ({0}) did not match allowed domain list or was malformed.",
                            url);
                }
            }

            return redirectResponse;
        }
开发者ID:AshleyPoole,项目名称:OWASP-2013-Demo,代码行数:32,代码来源:RedirectProvider.cs

示例7: fiHash

        /**
         * Creates the fiHash-object and prepares the internal fields for the call to GetFileStream.
         *
         * \param file An Uri-object pointing to the file, that the hash should be calculated for. Only supports file:/ URLs!
        */
        public fiHash(Uri file)
        {
            if (file.Scheme != Uri.UriSchemeFile)
                throw new ArgumentException("Unsupported Uri Schema!");

            filename = file.LocalPath;
        }
开发者ID:philwo,项目名称:crossfade,代码行数:12,代码来源:fiHash.cs

示例8: GetAllStyleSheets

        public static IEnumerable<string> GetAllStyleSheets(string searchFrom, IEnumerable<string> allowedExtensions)
        {
            var project = ProjectHelpers.GetProject(searchFrom);
            var projectPath = project.Properties.Item("FullPath").Value.ToString();
            var projectUri = new Uri(projectPath, UriKind.Absolute);
            var fileNames = new HashSet<string>();
            var projectDir = Path.GetDirectoryName(projectPath);

            if (projectDir == null)
            {
                return new string[0];
            }

            foreach (var extension in allowedExtensions)
            {
                var matchingFiles = Directory.GetFiles(projectDir, "*" + extension, SearchOption.AllDirectories);

                foreach (var file in matchingFiles)
                {
                    var mappedFile = GetStyleSheetFileForUrl(file, project, projectUri);

                    if (mappedFile != null)
                    {
                        fileNames.Add(mappedFile);
                    }
                }
            }

            return fileNames;
        }
开发者ID:hmendezm,项目名称:WebEssentials2013,代码行数:30,代码来源:StyleSheetHelpers.cs

示例9: using

        IResource IResourceResolver.Resolve(Uri uri)
        {
            IResource resource = null;
            try
            {

                string fileName = uri.LocalPath;
                string ext = Path.GetExtension(fileName).ToLower();
                if (ext == m_ext)
                {
                    using (Stream stream = File.OpenRead(fileName))
                    {
                        var reader = new CustomDomXmlReader(Globals.ResourceRoot, m_schemaLoader);
                        DomNode node = reader.Read(stream, uri);                        
                        resource = Prefab.Create(node, uri);
                    }
                }
            }
            catch (System.IO.IOException e)
            {
                Outputs.WriteLine(OutputMessageType.Warning, "Could not load resource: " + e.Message);
            }

            return resource;
        }
开发者ID:BeRo1985,项目名称:LevelEditor,代码行数:25,代码来源:PrefabService.cs

示例10: SubscriptionClient

	    public SubscriptionClient(IServiceBus bus, SubscriptionRouter router, Uri subscriptionServiceUri,
		                          TimeSpan startTimeout)
		{
			_bus = bus;
			_router = router;
			_subscriptionServiceUri = subscriptionServiceUri;
			_startTimeout = startTimeout;
			_network = router.Network;

			if (_log.IsDebugEnabled)
				_log.DebugFormat("Starting SubscriptionClient using {0}", subscriptionServiceUri);

			VerifyClientAndServiceNotOnSameEndpoint(bus);

			_ready.Reset();

			var consumerInstance = new SubscriptionMessageConsumer(_router, _network);

			_unsubscribeAction = _bus.ControlBus.SubscribeInstance(consumerInstance);
		    _unsubscribeAction += _bus.ControlBus.SubscribeContextHandler<SubscriptionRefresh>(Consume);

		    _subscriptionEndpoint = _bus.GetEndpoint(subscriptionServiceUri);
		    _producer = new SubscriptionServiceMessageProducer(router, _subscriptionEndpoint);

			WaitForSubscriptionServiceResponse();
		}
开发者ID:vinayreddym,项目名称:MassTransit,代码行数:26,代码来源:SubscriptionClient.cs

示例11: ReturnsSafeUriStringForUriWithMultipleStartingSlashes

            public void ReturnsSafeUriStringForUriWithMultipleStartingSlashes()
            {
                var inputUri = new Uri("//Views/MainPage.xaml", UriKind.RelativeOrAbsolute);
                var uri = UrlHelper.GetSafeUriString(inputUri);

                Assert.AreEqual("/Views/MainPage.xaml", uri);
            }
开发者ID:justdude,项目名称:DbExport,代码行数:7,代码来源:UrlHelperFacts.cs

示例12: ItemCrawler

 public ItemCrawler(Uri url)
 {
     _htmlDocument = new HtmlDocument();
     var html = new WebClient().DownloadString(url.OriginalString);
     _htmlDocument.LoadHtml(html);
     _document = _htmlDocument.DocumentNode;
 }
开发者ID:stiano,项目名称:ShopperDopper,代码行数:7,代码来源:ItemCrawler.cs

示例13: SetupAutoCADIOContainer

        /// <summary>
        /// Does setup of AutoCAD IO. 
        /// This method will need to be invoked once before any other methods of this
        /// utility class can be invoked.
        /// </summary>
        /// <param name="autocadioclientid">AutoCAD IO Client ID - can be obtained from developer.autodesk.com</param>
        /// <param name="autocadioclientsecret">AutoCAD IO Client Secret - can be obtained from developer.autodesk.com</param>
        public static void SetupAutoCADIOContainer(String autocadioclientid, String autocadioclientsecret)
        {
            try
            {
                String clientId = autocadioclientid;
                String clientSecret = autocadioclientsecret;

                Uri uri = new Uri("https://developer.api.autodesk.com/autocad.io/us-east/v2/");
                container = new AIO.Operations.Container(uri);
                container.Format.UseJson();

                using (var client = new HttpClient())
                {
                    var values = new List<KeyValuePair<string, string>>();
                    values.Add(new KeyValuePair<string, string>("client_id", clientId));
                    values.Add(new KeyValuePair<string, string>("client_secret", clientSecret));
                    values.Add(new KeyValuePair<string, string>("grant_type", "client_credentials"));
                    var requestContent = new FormUrlEncodedContent(values);
                    var response = client.PostAsync("https://developer.api.autodesk.com/authentication/v1/authenticate", requestContent).Result;
                    var responseContent = response.Content.ReadAsStringAsync().Result;
                    var resValues = JsonConvert.DeserializeObject<Dictionary<string, string>>(responseContent);
                    _accessToken = resValues["token_type"] + " " + resValues["access_token"];
                    if (!string.IsNullOrEmpty(_accessToken))
                    {
                        container.SendingRequest2 += (sender, e) => e.RequestMessage.SetHeader("Authorization", _accessToken);
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(String.Format("Error while connecting to https://developer.api.autodesk.com/autocad.io/v2/", ex.Message));
                container = null;
                throw;
            }
        }
开发者ID:CADblokeCADforks,项目名称:library-dotnet-autocad.io,代码行数:42,代码来源:AutoCADIOUtilities.cs

示例14: AbstractMsmqListener

        protected AbstractMsmqListener(
            IQueueStrategy queueStrategy,
            Uri endpoint,
            int threadCount,
            IMessageSerializer messageSerializer,
            IEndpointRouter endpointRouter,
            TransactionalOptions transactional,
            IMessageBuilder<Message> messageBuilder)
        {
            this.queueStrategy = queueStrategy;
            this.messageSerializer = messageSerializer;
            this.endpointRouter = endpointRouter;
            this.endpoint = endpoint;

            this.threadCount = threadCount;
            threads = new Thread[threadCount];

            switch (transactional)
            {
                case TransactionalOptions.Transactional:
                    this.transactional = true;
                    break;
                case TransactionalOptions.NonTransactional:
                    this.transactional = false;
                    break;
                case TransactionalOptions.FigureItOut:
                    this.transactional = null;
                    break;
                default:
                    throw new ArgumentOutOfRangeException("transactional");
            }
            this.messageBuilder = messageBuilder;
            this.messageBuilder.Initialize(Endpoint);
        }
开发者ID:helge,项目名称:rhino-esb,代码行数:34,代码来源:AbstractMsmqListener.cs

示例15: Main

        public static void Main()
        {
            var url = new Uri(ApiUrl + "?auth-id=" + AuthenticationID + "&auth-token=" + AuthenticationToken);
            var request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";

            using (var stream = request.GetRequestStream())
            using (var writer = new StreamWriter(stream))
                writer.Write(RequestPayload);

            using (var response = request.GetResponse())
            using (var stream = response.GetResponseStream())
            using (var reader = new StreamReader(stream))
            {
                var rawResponse = reader.ReadToEnd();
                Console.WriteLine(rawResponse);

                // Suppose you wanted to use Json.Net to pretty-print the response (delete the next two lines if not):
                // Json.Net: http://http://json.codeplex.com/
                dynamic parsedJson = JsonConvert.DeserializeObject(rawResponse);
                Console.WriteLine(JsonConvert.SerializeObject(parsedJson, Formatting.Indented));

                // Or suppose you wanted to deserialize the json response to a defined structure (defined below):
                var candidates = JsonConvert.DeserializeObject<CandidateAddress[]>(rawResponse);
                foreach (var address in candidates)
                    Console.WriteLine(address.DeliveryLine1);
            }

            Console.ReadLine();
        }
开发者ID:42shadow42,项目名称:LiveAddressSamples,代码行数:30,代码来源:street-address-batch.cs


注:本文中的System.Uri类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。