I'm just starting with my first ASP.Net WebApi 2 project. I have a file like this:
/AppCode/Remits.vb
Public Class Remits
Public Shared Function GetBoolean(id As Integer, id2 As Integer) As Boolean
Return True
End Function
End Class
This function will need to be called from all my controllers. The function checks that the two ID parameters are valid (done using some extensive database logic which is removed for brevity).
/Controllers/TestController.vb
Namespace Controllers
Public Class TestController
Inherits ApiController
<Route("Test/{id}")>
Public Function [Get](id As Int32) As IHttpActionResult
Dim b As Boolean = myNs.Remits.GetBoolean(123, 456) ' <-- error (see below)
Return Ok(b)
End Function
End Class
End Namespace
This won't even compile, with the error
'myNs' is not declared. It may be inaccessible due to its protection
level
Why is the namespace and/or class not accessible from within a controller? Or, what am I doing wrong?
Update
Anything inside App_Code is not recognised by files in the former directories. I've updated the question to reflect this. Here is a (tiny) sample project highlighting the problem.
http://1drv.ms/1kqjwTX
When you add classes to App_Code it is set to build action "Content". You need to change this to "Compile".
So:
Do not use App_Code, rename that folder
Change any class files to "Compile" build action.
For #2. Select the file in Solution Explorer and in the properties window (if you don't have this open by default right click the file and choose properties) there is an option called Build Action. Change that to Compile.
Related
I'm trying to figure out the best way to load a class into PrestaShop that I can use on overriding controllers.
I started off by creating a module that has an override of the Controller class with my files required at the top. Is there a better way to do this?
If you do not want to put class to override folder you can change class_index.php
Who add minus it is his problem but I'm right. If you do not want to use override folder you can set module folder with class
'SomeClass' =>
array (
'path' => 'modules/yourmodulename/class/class_name.php',
It is not normal but you can override without using override folder in particular circumstance.
And if you will read with carfull you will see: If you do not want to put class to override folder
EDITED 2015/10/19
It is craizy to add minus for what you do not know.
1) First look to PrestaShopAutoload class
2) all your class paths in array in the public $index in PrestaShopAutoload
3) what you need to do? just change this array
4) how to change this array? in your module you can get this instance using this PrestaShopAutoload::getInstance()
5) after you got instance you have full controll of your class paths!!! and you can add eny path what you need
6) what we need now? just make our module work maximum befour other class used. How we can do? Just hook in dispacher.
I am new to vb.net and I'm having trouble viewing this class that someone has made.
The link to the class is:
http://www.vbforums.com/attachment.php?attachmentid=86867&d=1323127879
I did the following steps:
1. Create a new project with a form
2. Add the above class
3. Create an object of the class in my form load sub as:
Dim newClass As VisualStudiosTabControl = New VisualStudiosTabControl
But when i try to run it I get a whole bunch of build errors like:
Type 'System.Windows.Forms.Design.ScrollableControlDesigner' is not defined.
and
'Control' is not a member of 'Tab_Control_Example.VisualStudiosTabControl.VisualStudiosTabPage.VisualStudiosTabDesigner'.
Please help me.
Thanks
You are missing many of the parent files and this looks to be designed to be added onto a project. Try to load whiten your solution of your project.
I have solution with few projects included.
One of project is common library project which contain mostly reusable code and functions which shares all other projects under solution and which is referenced to all included projects.
In that project I also have resources like are images and icons and I can access those resources from other projects like that:
Me.Icon = myCommonDll.My.Resources.backup__add__16x16
Question is:
Can it be done somehow that those common resources in myCommonDll will be actual resources for other projects in solution so when I click to "Image" or "Icon" in properties window in designer I get listed images or icons which are present in myCommonDll.My.Resources and how to do that?
EDIT: This is primarily for VS versions prior to VS2008 which did NOT allow you to change the access level modifier for REsources. Other alternatives were external tools or Reflection, but still did not expose resources to the designer.
DLL resources are available at runtime fairly easily but not in the designer. You need to write a small broker in the DLL to fetch images by name. DLL:
Public Class ResMgr
' depending on what else is in the DLL, can just add to an existing class
Public Function GetImage(imgName As String) As Image
Return My.Resources.ResourceManager.GetObject(imgName)
End Function
'' alternatively declare it SHARED eg
''Public Shared Function/Property GetImage As Image
End Class
App:
MyRM = New ResMgr
thisImg = New Image
thisImg = MyRM.GetImage(userImg)
If you construct it as Shared method, it is just:
thisImg = ResMgr.GetImage(userImg)
If you want, you can expose an Enum in the DLL to act as a resource manifest:
Public Enum ResImg
Image1 ' use the names of the images
Backup52
Flag_FR
Flag_RUS
...
End Enum
The DLL function can either act on ResImg and use a big case statement, or you can use [Enum].GetNames to convert/get an array of image resource names.
Edit your .vbproj file and update the two statements below by adding the common directory path of your shared resource files. Good Luck!
<Compile Include="<common Dir>\My Project\Resources.Designer.vb">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<EmbeddedResource Include="<common Dir>\My Project\Resources.resx">
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
<CustomToolNamespace>My.Resources</CustomToolNamespace>
<SubType>Designer</SubType>
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
</EmbeddedResource>
I have a situation like below:
Module Task
def get(a)
fetch(a)
end
def fetch(a)
query(a)
end
def query(a)
puts a
end
end
and only get method is called from outside of module like
Task.get('name')
I want to monkey patch only method query to make some change in response of get method since it calls query intern.
Please suggest a way to do this.
In order to monkey patch in cases like these, we need to include a file in lib folder. In this case you need to make a file inside lib folder of the same name. In that first include the module TASK and then use MODULENAME.module_eval and add the methods in this. In this file u can override the methods in the actual module and add methods to it too.
In order for this to work you will have to require the file u created in lib in config/initializers/app.rb
Incase the module you are over riding is present inside a folder (like in case of a ruby gem) you need to include the whole path. For ex.
Module_1.Module_2.module_eval
where module 2 is inside module 1.
Disclaimer: Complete beginner in Yii, Some experience in php.
In Yii, Is it OK to override the login method of CWebUser?
The reason i want to do this is because the comments in the source code stated that the changeIdentity method can be overridden by child classes but because i want to send more parameters to this method i was thinking of overriding the login method too (of CWebUser).
Also if that isn't such a good idea how do you send the extra parameters into the changeIdentity method.(By retrieving it from the $states argument somehow ??). The extra parameters are newly defined properties of UserIdentity class.
It is better to first try to do what you wish to do by overriding components/UserIdentity.php's authenticate method. In fact, that is necessary to implement any security system more advanced than the default demo and admin logins it starts you with.
In that method, you can use
$this->setState('myVar', 5);
and then access that anywhere in the web app like so:
Yii::app()->user->getState('myVar');
If myVar is not defined, that method will return null by default. Otherwise it will return whatever it was stored as, in my example, 5. These values are stored in the $_SESSION variable, so they persist as long as the session does.
UPDATE: Okay, took the time to learn how this whole mess works in Yii for another answer, so I'm sharing my findings here as well. The below is mostly copy pasted from a similar answer I just gave elsewhere. This is tested as working and persisting from page to page on my system.
You need to extend the CWebUser class to achieve the results you want.
class WebUser extends CWebUser{
protected $_myVar = 'myvar_default';
public function getMyVar(){
$myVar = Yii::app()->user->getState('myVar');
return (null!==$myVar)?$myVar:$this->_myVar;
}
public function setMyVar($value){
Yii::app()->user->setState('myVar', $value);
}
}
You can then assign and recall the myVar attribute by using Yii::app()->user->myVar.
Place the above class in components/WebUser.php, or anywhere that it will be loaded or autoloaded.
Change your config file to use your new WebUser class and you should be all set.
'components'=>
'user'=>array(
'class'=>'WebUser',
),
...
),