I try many ways but all fails. Some can help me. Thank you very much.
I tried this, but fail too: https://github.com/s13524801/android-fresco-blur/blob/master/app/src/main/java/com/android/blur/MainActivity.java
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(<your url>))
.setPostprocessor(new IterativeBoxBlurPostProcessor(7))
.build();
then
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setImageRequest(request)
.setOldController(<your imageView>.getController())
.build();
imageRest.setController(controller);
Here is the simple solution:
Postprocessor postprocessor = new BlurPostprocessor(this,50);
ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url))
.setPostprocessor(postprocessor)
.build();
PipelineDraweeController controller = (PipelineDraweeController) Fresco.newDraweeControllerBuilder()
.setImageRequest(imageRequest)
.setOldController(background.getController())
.build();
background.setController(controller);
Related
I'm trying to migrate from the deprecated Microsoft.WindowsAzure.Storage to Azure.Storage. In my API app, I have a method that I call occasionally to programmatically set the CORS rules in my Azure Storage account.
How do I add CORS rules to the properties using the new Azure.Storage.Blobs?
My original code that worked under Microsoft.WindowsAzure.Storage is as follows. In the following code, the _client is an instance of CloudBlobClient. I understand that in Azure.Storage.Blobs, I need to use BlobServiceClient which I now do but as I said, some parts of the following code are not working because some methods/properties are no longer there. I'm sure they're moved somewhere else but I haven't been able to figure out where.
public async Task ConfigureCors()
{
var ALLOWED_CORS_ORIGINS = new List<String> { "http://localhost:49065", "https://myappdomain.com", "https://www.myappdomain", "https://login.microsoftonline.com" };
var ALLOWED_CORS_HEADERS = new List<String> { "x-ms-meta-qqfilename", "Content-Type", "x-ms-blob-type", "x-ms-blob-content-type" };
const CorsHttpMethods ALLOWED_CORS_METHODS = CorsHttpMethods.Get | CorsHttpMethods.Delete | CorsHttpMethods.Put | CorsHttpMethods.Options;
const int ALLOWED_CORS_AGE_DAYS = 5;
var properties = await _client.GetServicePropertiesAsync();
properties.DefaultServiceVersion = "2013-08-15";
await _client.SetServicePropertiesAsync(properties);
var addRule = true;
if (addRule)
{
var ruleWideOpenWriter = new CorsRule()
{
AllowedHeaders = ALLOWED_CORS_HEADERS,
AllowedOrigins = ALLOWED_CORS_ORIGINS,
AllowedMethods = ALLOWED_CORS_METHODS,
MaxAgeInSeconds = (int)TimeSpan.FromDays(ALLOWED_CORS_AGE_DAYS).TotalSeconds
};
properties.Cors.CorsRules.Clear();
properties.Cors.CorsRules.Add(ruleWideOpenWriter);
await _client.SetServicePropertiesAsync(properties);
}
}
Looks like I can get and set properties by changing _client.GetServicePropertiesAsync() to _client.GetPropertiesAsync() but DefaultServiceVersion is no longer there. Also I can't seem to find the right way to set CORS rules.
I'd appreciate your suggestions. Thanks!
You can use the code below when using Azure.Storage.Blobs(I'm using sync method, please change it to async method if you need that):
var properties = blobServiceClient.GetProperties().Value;
properties.DefaultServiceVersion = "xxx";
BlobCorsRule rule = new BlobCorsRule();
rule.AllowedHeaders= "x-ms-meta-qqfilename,Content-Type,x-ms-blob-type,x-ms-blob-content-type";
rule.AllowedMethods = "GET,DELETE,PUT,OPTIONS";
rule.AllowedOrigins = "http://localhost:49065,https://myappdomain.com,https://www.myappdomain,https://login.microsoftonline.com";
rule.MaxAgeInSeconds = 3600; // in seconds
properties.Cors.Add(rule);
blobServiceClient.SetProperties(properties);
My every attempt to call ManagementClient.Subscriptions.Get() hangs forever.
If I change it to ManagementClient.Subscriptions.GetAsync(), and run it on its own thread, the task stays in WaitingForActivation state forever.
Any suggestions?
Sample Code: (it's the last line that hangs.)
using System;
using Microsoft.Azure;
using Microsoft.WindowsAzure.Management;
using Microsoft.WindowsAzure.Management.Models;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
class Program1
{
static void Main1(string[] args)
{
AuthenticationContext context = new AuthenticationContext(...);
AuthenticationResult authResult = context.AcquireToken(...);
TokenCloudCredentials token = new TokenCloudCredentials(authResult.AccessToken);
ManagementClient client = new ManagementClient(token);
SubscriptionGetResponse subresp = client.Subscriptions.Get();
}
}
Thanks in advance.
Apparently, error recovery is lacking in Subscriptions.Get and friends. My problem was that the URL in context.AcquireToken was wrong. I had "https://management.core.windows.net", but needed "https://management.core.windows.net/" (i.e., the trailing slash made all of the difference.)
In ASP.Net Core1.0 RTM, I'm trying to create Identity using this method:
userManager.CreateIdentityAsync()
but I get this error:
'UserManager' doesnot contain a definition for 'CreateIdentityAsync'.
What is going wrong?
You can try IUserClaimsPrincipalFactory
ClaimsPrincipal claimsPrincipal = await _claimsPrincipalFactory.CreateAsync(user);
((ClaimsIdentity) claimsPrincipal.Identity).AddClaim(new Claim("user_id", user.Id.ToString()));
I use ClaimsIdentityFactory(). Here is my code:
public async Task<ClaimsIdentity>
GenerateUserIdentityAsync(UserManager<ApplicationUser> manager,
string AuthenticationType)
{
var factory = new ClaimsIdentityFactory<ApplicationUser>();
return await factory.CreateAsync(manager, this, AuthenticationType);
}
Try this: signInManager.SignInAsync(user, false);
Using the Azure Active Directory Graph Client API, how would I configure the underlying HttpClient to use an HttpClientHander, where I can define an authenticated application proxy?
var proxy = new WebProxy(...);
proxy.Credentials = ...;
var handler = new HttpClientHandler { Proxy = proxy, UseProxy = true};
var auth = new AuthenticationContext(...);
var client = new ActiveDirectoryClient(...);
Or, can I not use the Graph Client behind a proxy?
Thanks
I was exploring the same problem. It took some digging, but I found a solution. Now, I realize you asked specifically how to apply an HttpClientHandler. I don't know if this can be done; however, you can apply a proxy. Here's how.
The ActiveDirectoryClient class provides a DataServiceContextWrapper property called Context, which is, not surprisingly, a wrapper to a DataServiceContext.
This is good. It reduces the problem to figuring out how to apply a proxy to the DataServiceContext class. I used some old code I had sitting around, and things pretty much exploded. This is because I used the deprecated SendingRequest event to intercept a request and apply a proxy before it goes out the door. This client is not compatible with the deprecated event.
It took a little more digging to figure out how to do it with the SendingRequest2 event; it only required a little type casting.
Do this:
var client = new ActiveDirectoryClient(...);
client.Context.SendingRequest2 += OnSendingRequest2;
// ...
static void OnSendingRequest2(object sender, SendingRequest2EventArgse)
{
var request = ((HttpWebRequestMessage)e.RequestMessage).HttpWebRequest;
request.Proxy = new WebProxy("http://myproxy:port");
}
Don't Do This: (It is deprecated and will produce an exception.)
var client = new ActiveDirectoryClient(...);
client.Context.SendingRequest += OnSendingRequest;
// ...
static void OnSendingRequest(object sender, SendingRequestEventArgs e)
{
e.Request.Proxy = new WebProxy("http://myproxy:port");
}
a bit late but i ran into the same issue.
using the code below in app.config saved my day !
<system.net>
<defaultProxy useDefaultCredentials="true" />
</system.net>
I am trying to use NTLM authentication for my REST calls to TeamCity using RestSharp.
IRestClient _client=new RestClient(_url);
_client.Authenticator = new NtlmAuthenticator
(System.Net.CredentialCache.DefaultNetworkCredentials);
However it is not working. Please suggest if I am missing something.
This now appears to be working properly and can be done very easily utilizing the NTLMAuthenticator like so:
RestClient client = new RestClient(_baseURL);
client.Authenticator = new NtlmAuthenticator();
Try this:
var client = new RestClient(_baseURL)
{
Authenticator = new RestSharp.Authenticators.NtlmAuthenticator()
};
As of RestSharp v107, The NtlmAuthenticator is deprecated.
This worked for me:
var credentials = new NetworkCredential(username, password, domain);
var options = new RestClientOptions(_settings.ServiceEndPoint)
{
UseDefaultCredentials = false,
Credentials=credentials
};
var client = new RestClient(options);
Not supported currently. Refer to the below thread.
http://devnet.jetbrains.com/thread/451079?tstart=0