I have integrated openstack to my .net solution. I am using CloudFilesProvider to create and delete a container. Is there any provision to check for the existence of a container using C#.
I know it is possible to check by getting ObjectStore and find ContainerExists property. But i am not sure how to get this property filled.
Any help will be greatly appreciated.
ObjectStore is an enumeration that defines the possible values returned by calls like IObjectStorageProvider.CreateContainer. For example, you could get an ObjectStore by attempting to create the container you're checking, and the return value would be ContainerExists if the container already exists. Unfortunately you could always end up with ContainerCreated returned by that call, i.e. if you use CreateContainer to check for a container's existence, then even if the container didn't exist before "checking", it would afterwards.
While it's definitely not clean, one option is calling GetContainerMetadata. The call will throw an ItemNotFoundException if the container doesn't exist.
Are you, by chance, using this Container as a CDN?
When deleting a CDN, you must also call the method "DisableCDNOnContainer" against the Container. Also, if you call the method "ListCDNContainers", you must filter out deleted CDN Containers by checking the property "CDNEnabled".
This is because deleted Containers "hang around" until their ttl expires.
Related
When I generate resources, methods etc. using "for_each", how can I make a deployment depend on them? Terraform requires a static list as value for "depends_on"
I think what you are looking for here is this (somewhat hidden) reference in terraform documents about triggers
I was facing the same issue (using for_each to create gateway methods, integrations) but was not able to reliably trigger api-gateway redeployment, until this...
... or removing the .id references to calculate a hash against whole resources. Be aware that using whole resources will show a difference after the initial implementation. It will stabilize to only change when resources change afterwards
This allow us to do the following in triggers
triggers = {
redeployment = sha1(jsonencode([
aws_api_gateway_resource.gateway_resources,
aws_api_gateway_method.gateway_methods,
aws_api_gateway_integration.gateway_integrations,
]))}
By removing .id (and thus not needing to reference each.key, or any element in the dynamic list) you let terraform decide if the hash of the file changed. If it did it will redeploy, if it doesnt change, then no redeploy required :)
Reference https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_deployment#terraform-resources
Look at the comments on 'triggers'
I have a problem that i need to solve using DATANUCLEUS (JDO), maybe a limitation of something that was not covered by JDO specs.
I need to catch when objects are loaded in a Query - there is NO InstanceLifecycleListener for this! (Queried objects should be treated as LOADED objects after all - they can be changed, detached, etc)
Query query=pm.newQuery(...);
Collection col=(Collection)query.execute();
Another way to do it would be to catch when objects are made TRANSIENT. I found no way of doing that either!
pm.makeTransientAll(col,true);
Any ideas?
For detached Query elements, i use the DetachLifecycleListener over the PMF, that listens to the DETACH method. That's the only way I've found to make InstanceLifecycleListener work on queries.
Here's what i found out with a lot of DEBUG:
1) Queries DO NOT trigger any InstanceLifecycleListener (except when elements are DETACHED) if the DEFAULT fetch group (aka METADATA default-fetch-group) is REMOVED from the PersistentManager prior to the query. In other words: one cannot use the pm.getFetchPlan().clearGroups() method, or one has to ADD the DEFAULT fetch group back before executing the query. SO... if there is a need to define a programmatic fetch group, it needs to take into account that the DEFAULT fetch group will (must!) be present (aka, all the fields defined in the metadata!) for the InstanceLifecycleListener to work.
The workaround would be to DEFINE the DEFAULT fetch group with ONLY the KEY (it's needed) and just change the logic to work with that. What i did exactly... The result?
2) the getObjectById method STOPS triggering the postLoad!!! After debug i found that for this to work, the DEFAULT fetch plan MUST define another field apart from the KEY one!
There is a total lack of information about the way the FETCH GROUPS affect the way the InstanceLifecycleListener are triggered, and Apache JDO (at least) should revise the way this works (or at least the DOCS), so that JDO users don't go nuts with implementation.
According to StructureMap's documentation the default behavior of containers is that a Parent Container resolves a new object instance each time one is requested and Nested Containers resolve the same object instance.
In 99% of cases this is fine - however I'm keen to know if there's a way I can set a nested container to behave similarly to the Parent Container and resolve new object instances by default - without the need to rely on the .AlwaysUnique() method.
Is this possible or is .AlwaysUnique the only way to do it on an object by object basis?
I think that beside explicit specification of nested container configuration there is no support for that as it was designed around creating temporary context for objects resolution. IIRC in SM 3.0 HttpContextScoped lifecycle was implemented with usage of nested container.
If you want to have the flexibility of resolving existing object from the container or creating a new one you can implement factory that would handle it for you through injected context into the factory or based on explicit method call (factory.Create() or factory.ReuseIfExistsOrCreate()).
Hope this helps!
Is there a way to set HttpContext.Current.Request.Browser.Type in ASP.NET. That is a read-only, string property. So you cannot really just assign a string to it. Tried initializing Browser property which is of type HttpBrowserCapabilities, but it has only one constructor and does not take any parameters and browser Type is still null. The reason why I want to be able to set Type for browser is that my unit test is failing as Type property is null.
Edit per null check comments:
I could definitely modify code to check for null, but that will be just for my unit test as when the requests come from browsers, that value is never null. Hence not quite excited about doing that. But it can be my last resort.
You can define your own browser definition files which ASP.net will then use. Check out http://forums.asp.net/p/955969/1176101.aspx.
So if you know what browser it's failing on you could setup a browser file for it. However, I agree that checking for null values makes more sense as it accounts for a lot more possiblities that way.
You might want to think about refactoring your code to use HttpContextBase instead of relying directly on the concrete type.
By doing so you could simply create a stub object that provides the behavior you want. Eventually implementing your own HttpBrowserCapabilitiesBase object.
You would then have full control to use your mock types during unit testing. Indeed that is what they were created for.
I am sort of new to Unity all seems to be fine but I am kind of lost when to use
ResolvedParameter in Unity.
Googled and looked on MSDN but still cannot understand when to use it.
Do you have a simple example that could illustrate it's use.
Thanks a lot for your help
You may wish to configure a Type with constructor parameters of a resolved service and a string. In this case you would use ResolvedParameter.
Container.RegisterType<IRepository, Repository>(
new InjectionConstructor(
new ResolvedParameter<IClassifier>(),
"ConnectionString"));
It's for method injection; see Entering Configuration Information on MSDN. Scroll down to "Dynamically Configuring Constructor, Property, and Method Injection" and note that the ResolvedParameter is actually a parameter to the InjectionMethod constructor.
I've never encountered a need to use it. Constructor injection will solve 95% of your issues, and property injection will solve the other 5%. (Caveat: I've only used Unity on a couple of projects, so I don't claim to be an expert.)
As I see it its to be used when you have a constructor where at least one parameter can not be obtained from the container while the rest can. In such a situation you declare how to resolve each ctor parameter when actually creating a new instance of that type.
Container.RegisterSingleton<IConnectionManager, ConnectionManager>(new InjectionConstructor(new ResolvedParameter<INetworkClientFactory>(), Container.Resolve<IBackoffAlgorithm>(), 10));
In my example, the IConnectionManager instance obtains the first parameter from the container (via ResolvedParameter), the 2nd one via Container.Resolve<>, and the 3rd one is a hard-coded integer.
ResolvedParameter should behave equal to a direct Container.Resolve<> but looks a tad cleaner.