I am trying to create some cookies as I cannot fetch the cookies and a normal way so I will run through the whole header and just create the cookie manually. However whenever I try to use Response.Cookies and HttpCookie I get an error:
The name Response does not exist in the current content
and
The type or namespace name 'HttpCookie' could not be found (are you missing a using directive or an assembly reference?).
I read around and understood I will need to reference
System.Web
So I am clicking on Project -> Add Reference -> .NET and select System.Web. Then I add using System.Web;.
And still I am unable to access them.
From what code are you trying to access the item?
There are essentially two steps that need to be taken to reference a class:
Add a reference to the class' assembly in the project.
Add a using directive to the class' namespace in the code file.
It sounds like you're performed the first step. What about the second? That's what this error means:
The type or namespace name 'HttpCookie' could not be found (are you missing a using directive or an assembly reference?).
To perform step 2 above, you actually have a couple of options:
Fully-qualify the class name. So, instead of using HttpCookie you would use System.Web.HttpCookie.
Add a using directive to the code file. At the top of the file (and this would need to be done for any file which uses classes in this namespace), you would add using System.Web. Then you could just reference HttpCookie directly.
Additionally, the first part of your question brings up a separate issue entirely:
The name Response does not exist in the current context
This again goes back to my question about where you're accessing this value. When you're writing code in, say, the code-behind for an ASPX page, you have access to the various bits of ASP.NET web contexts by default. These are provided by the base Page class. Things like Request and Response are readily available.
However, if you're trying to access these objects from outside of that context (such as from a custom class or another assembly), you'll need to reference that context manually. This can be done by using a factory on the System.Web.HttpContext class:
Request becomes System.Web.HttpContext.Current.Request
Response becomes System.Web.HttpContext.Current.Response
This is because Request and Response aren't actual classes. They're properties on the current web context which are of type HttpRequest and HttpResponse. Those properties are mapped for you when you're in the same context, but outside of that context you'd need to reference them fully as demonstrated above.
One thing to note is that it's not generally considered good practice to have dependencies on the web context outside of where it's already available. So if you're creating a custom class or another assembly then you might want to take a step back and think about the design.
If your custom classes depend on the existence of a current instance of HttpContext then that code can never be used outside of a fully-aware web application context. So the code is less re-usable. So, depending on what you need from that context, you can re-factor the code to not need the context itself but only to require that the necessary items from the context be provided.
This isn't necessary to get you past your current issue, but it's something to keep in mind going forward.
Related
I am working on the SAP Commerce (formally known as Hybris) ecommerice system.
The Warehousing extension is being added to a B2B site. Upon adding it, On the Stock Level item the Invoice Event collection is visable on the admin tab. An ATP Formula has been set on the Base Store. The stock is now displayed on the PDP. In an OTB site I have seen an OTB instance adjust the stock levels accordingly upon completing an order, but that is not happening on the local dev instance. The question is why?
Is the impression correct that some facade within the warehousing extension is called during the order-processing process? If so, how exactly is that wired up? There doesn't seem to be any relationship to the warehousing extension and any other code.
UPDATE 1:
Here is an example of the question: After adding a new product populator to the custom facade, a few entries are added to the *-spring.xml file, one of them being adding the populator to the configurablePopulatorModification. Finally the option needs to be added to the ProductOptions list in the controller. Then the populator is called when that controller is called.
In this example the connection between the controller and the popular is clear, once it is understood how things are wired up. There is a connection to the ProductOptions in the custom core extension, custom facade extension, and custom accelerator. Once someone knows how this is "wired up" it can be easily duplicated.
What I am trying to understand is this: The warehousing extension has been added to the localextensions.xml, but there is NO reference to any aspect of that anywhere else in the system, AT ALL. Somehow some extension between the storefront accelerator and the platform code has to know about the new functionality found in the warehousing extension so that it is called. How?????
UPDATE 2:
After adding the warehousing extension, there are new attributes added to existing itemTypes that show up in Backoffice. It is my understanding that this is the concept which Modifying Lists and Maps in Spring Context explains.
The issue I am having problems understanding is how the business logic within the warehousing extension is being called to modify the stock levels. My best guess is that the function doing the change is WarehousingStockLevelFacade.createStockLevelAdjustements(...). I have searched high and low for where createStockLevelAdjustements(...) is called and it is ONLY called in the warehousingwebservices.
I am at a total loss on how exactly any of the facades wihtin warehousingfacades or warehousingwebservices is being called by
Hmmm, your text contains more than one question I think. So I try to answer each part of them separately.
In an OTB site I have seen an OTB instance adjust the stock levels accordingly upon completing an order, but that is not happening on the local dev instance
There should be no difference on the systems. You should always look, that you have the same configuration on each system. Normally the 'config' folder here is the part where you define the configuration. From system to system there can be small difference. But for example, the 'localextensions.xml' shold always be the same.
Is the impression correct that some facade within the warehousing extension is called during the order-processing process?
No. You define your extensions in the 'localextensions.xml' and than the new parts are on any system. Have you done an 'UPDATE' on each system, so that the new types are also imported in the type system and the database?
So overall. You define your extensions. And than hybris includes all needed extensions automatically. You can see this, when you start the server, which extensions are loaded.
UPDATE 1
I think, now I got your point. I try to stay in common and not to specify on the 'warehouse' extension. Hybris has some funtionalities how to modify code 'afterwards'. Here are some useful links
Modifying Spring beans afterwards
Extension Dependency
Also have a look left in the navigation about the 'Extnsion Concept'. Maybe some points will than be clear.
So in your example, think what happens is: first new attributes in the *-items.xml, than there will be a 'modifiyPopulatorList' bean somewhere.
UPDATE 2
I don't know the 'warehousing' extension. But I think there must be a part that overwrites the 'normal' beans with the 'warehousing' beans. Something like:
<bean id="stockLevelBean" ...>
<property name="normalProvider" ref="normalProvider"/>
</bean>
<bean id="stockLevelBean" ...>
<property name="warehousingProvider" ref="warehousingProvider"/>
</bean>
When i run the entity framework Reverse Engineer Code First in an asp mvc project, it runs fine and generates all the mapping and poco classes, but i now have two context and conflicting classes in both the ApplicationDbContext and the new Auto Generated DbContext.
When generating EF Classes using Code First from Database, often there are more steps as the generated code is not always exactly as you want. I typically rename all files to "EntityNameDAO" I then right click refactor all classes to "EntityNameDAO" to match the file name appropriately.
After this, you will typically find that you have additional or less needs or perhaps even circular dependencies in the json result from these generated classes. To deal with this, I create specific domain objects for each objective EntityName_SpecificUseCase.
You will notice I use EntityName"AdditionalData" so that the alphabetic sorting keeps each of my entities next to eachother and I can verify I have the right flavors for each entity quickly and easily.
To deal with the circular json, you will need to add this code to your appconfig.cs:
var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling =
Newtonsoft.Json.PreserveReferencesHandling.All;
I love using the Node Reference URL module but in the case of my current project I need something similar and with a slightly different effect.
I have a node type called Event which needs to have exactly 3 webforms referenced to each event I create.
With node_reference_url the configuration means I will setup the node reference fields in the webform node type with my Event type selected as the target.
However, I need to find a way of reversing that. I'm looking for code tips (or a module if it exists) which will allow me to configure the Event type so that I can have links on each event page to create a total of 3 webforms and their NIDs to be saved as references to the parent event page.
I am using entity reference to do such a thing. It allows you to add one or more reference fields to your content types. These references can be to nodes, profiles, etc.
If you would add these to your Event you could probably select the webforms from there.
I know this plugin also integrates with views (under advanced > relations), allowing you access the fields of the referred content. (Incuding the title and link to node options.)
Want to take it a step further?
Have a look at reference dialog. This module allows you to build similar reference fields combined with Add, Edit and Delete buttons. If the content you are referring to is not yet created, you can do so in an overlay.
What I want to do is really similar to this and this except I'm trying to figure out how to put an ArrayExtension inside a module.
I'm trying to get something similar to the way C# extension methods work, that way I can just import the module and I'll have my extra methods. The links I provided show how to extend an existing object, but I haven't been able to figure out how to encapsulate that into a module.
If you're targeting non-browser environments like node.js this will be possible because you will be able to pass references to your module's global members, such as Array, to other modules. Those other modules can then extend the passed in object and/or its prototype with extra functionality which will be only accessible by the calling module. Other modules would have to do the same in order to get these extensions; therefore, conflicts are minimized since imports are explicit.
However, in browser environments this is not the case since there is only one window object and any changes to its members are available everywhere. As soon as any of your modules extended Array those extensions would be available to all other modules -- increasing the possibility for conflicts and making the code harder to reason about.
With that said, there are patterns in JS, and therefore TypeScript, which should accomplish what you want. One such pattern is the 'mixin' pattern which allows you to add on extra functionality on an object instance basis. You could separate re-usable code into mixin modules which could then be applied to an object when needed, or even automatically in constructors. Take a look at this for a decent overview and implementation examples: http://javascriptweblog.wordpress.com/2011/05/31/a-fresh-look-at-javascript-mixins/
If you're trying to extend the built in Array type you can't do that within a module. You're extension will need to live in an ArrayEx.ts file and occur outside of any modules. The reason for that is that if you did it within a module you'd be extending the Foo.Array type which isn't the same as Array.
But you said you just want to be able import the module to have your extra methods show up and all you really need to do is add a /// <reference path='ArrayEx.ts' /> to any file you want the extension methods to be available to. This is essentially the same thing.
at compile time we have
using MyNamespace;
This works till now but recently the requirement got change and it needs to handle at run time based on the application type selected by the user.
So, How can I add the "Using" namespace statement using c# code in the IWizard?
I know how to add the reference at run time ass under
var appProject = project.Object as VSProject;
appProject.References.Add(Mydll);
What I want is that at runtime
using System.IO;
using MyNamespace-> should come at runtime based on the application selected
Thanks
I just hit a similar issue and while it is not exactly changing the namespace at run time it does all you to get objects etc from a different namespace at run time. If you want to be changing namespaces chances are you have classes with the same names and interfaces but different implementations otherwise your code would need to be changed. What you need to do if make a new lib and namespace that just contains the interfaces for all the classes you want to use. You then make the classes in the different namespaces inherit these interfaces so you can code your class to just use the interface not the particular implementation. Then to select the implementation to use at run time you use "Dependancy Injection" to choose the correct implementation to insert via config file or let some other part of your application configure the injection. Dependancy Injection can be a little hard to get started with but once you get your head around it, it will make your life a lot easier. Ninject is a nice easy dependancy injection framework to start with.