hi, i want only the first word of a variable.. example input:
<?php $myvalue = Test me more; ?>
the output should only "Test", the first word of the input.. how can i do this?
I'm trying to write a simple/small Windows Communication Foundation service application in Visual Basic (but I am very novice in VB) and all the good examples I've found on the net are written in C#. So far I've gotten my WCF service application working but now I'm trying to add callback functionality and the program has gotten more complicated. In the C# example code I understand how everything works but I am having trouble translating into VB the portion of code that uses a delegate. Can someone please show the VB equivalent?
Here is the C# code sample I'm using for reference:
namespace WCFCallbacks
{
using System;
using System.ServiceModel;
[ServiceContract(CallbackContract = typeof(IMessageCallback))]
public interface IMessage
{
[OperationContract]
void AddMessage(string message);
[OperationContract]
bool Subscribe();
[OperationContract]
bool Unsubscribe();
}
interface IMessageCallback
{
[OperationContract(IsOneWay = true)]
void OnMessageAdded(string message, DateTime timestamp);
}
}
namespace WCFCallbacks
{
using System;
using System.Collections.Generic;
using System.ServiceModel;
public class MessageService : IMessage
{
private static readonly List<IMessageCallback> subscribers = new List<IMessageCallback>();
//The code in this AddMessage method is what I'd like to see re-written in VB...
public void AddMessage(string message)
{
subscribers.ForEach(delegate(IMessageCallback callback)
{
if (((ICommunicationObject)callback).State == CommunicationState.Opened)
{
callback.OnMessageAdded(message, DateTime.Now);
}
else
{
subscribers.Remove(callback);
}
});
}
public bool Subscribe()
{
try
{
IMessageCallback callback = OperationContext.Current.GetCallbackChannel<IMessageCallback>();
if (!subscribers.Contains(callback))
subscribers.Add(callback);
return true;
}
catch
{
return false;
}
}
public bool Unsubscribe()
{
try
{
IMessageCallback callback = OperationContext.Current.GetCallbackChannel<IMessageCallback>();
if (!subscribers.Contains(callback))
subscribers.Remove(callback);
return true;
}
catch
{
return false;
}
}
}
}
I was thinking I could do something like this but I don't know how to pass the message string from AddMessage to DoSomething...
Dim subscribers As New List(Of IMessageCallback)
Public Sub AddMessage(ByVal message As String) Implements IMessage.AddMessage
Dim action As Action(Of IMessageCallback)
action = AddressOf DoSomething
subscribers.ForEach(action)
'Or this instead of the above three lines:
'subscribers.ForEach(AddressOf DoSomething)
End Sub
Public Sub DoSomething(ByVal callback As IMessageCallback)
'I am also confused by:
'((ICommunicationObject)callback).State
'Is that casting the callback object as type ICommunicationObject?
'How is that done in VB?
End Sub
I'm having trouble with an h:selectOneMenu not having a selected item when there is already something set on the backing bean. I am using seam and have specified a customer converter. When working on my 'creation' page, everything works fine, something from the menu can be selected, and when the page is submitted, the correct value is assigned and persisted to the database as well.
However when I work on my 'edit' page the menu's default selection is not the current selection. i have gone through and confirmed that something is definitely set etc.
My selectOneMenu looks like this:
<h:selectOneMenu id="selVariable"
value="#{customer.variableLookup}"
converter="#{variableLookupConverter}">
<s:selectItems var="source"
value="#{customerReferenceHelper.variableLookups()}"
label="#{source.name}" />
</h:selectOneMenu>
And the converter is below. It very simple and just turns the id from string to int and back etc:
@Name( "sourceOfWealthLookupConverter" )
public class SourceOfWealthLookupConverter implements Serializable, Converter {
@In
private CustomerReferenceHelper customerReferenceHelper;
@Override
public Object getAsObject( FacesContext arg0, UIComponent arg1, String arg2 ) {
VariableLookup variable= null;
try {
if ( "org.jboss.seam.ui.NoSelectionConverter.noSelectionValue".equals( arg2 ) ) {
return null;
}
CustomerReferenceHelper customerReferenceHelper = ( CustomerReferenceHelper ) Contexts.getApplicationContext().get(
"customerReferenceHelper" );
Integer id = Integer.parseInt( arg2 );
source = customerReferenceHelper.getVariable( id );
} catch ( NumberFormatException e ) {
log.error( e, e );
}
return variable;
}
@Override
public String getAsString( FacesContext arg0, UIComponent arg1, Object arg2 ) {
String result = null;
VariableLookup variable= ( VariableLookup ) arg2;
Integer id = variable.getId();
result = String.valueOf( id );
return result;
}
}
I've seen a few things about it possibly being the equals() method on the class, (that doesn't add up with everything else working, but I overrode it anyway as below, where the hashcode is just the id (id is a unique identifier for each item).
Equals method:
@Override
public boolean equals( Object other ) {
if ( other == null ) {
return false;
}
if ( this == other ) {
return true;
}
if ( !( other instanceof VariableLookup ) ) {
return false;
}
VariableLookup otherVariable = ( VariableLookup ) other;
if ( this.hashCode() == otherVariable.hashCode() ) {
return true;
}
return false;
}
I'm at my wits end with this, I can't find what I could have missed?! Any help would be much appreciated
As part of my test automation, I have to start Selenium Server on my server.
As of now I am manually executing a batch file to start selenium server on m,y machine.
Batch file contains the following command.
java -jar selenium-server-standalone-2.16.1.jar -role hub http://server.com:5555/grid/register
But as I required it for my test automation, I want to automate running the selenium server on a remote server from my C# code. How do I do this?
Why does my flex app open a blank page in firefox? Example http://localhost/flexApp/flex_bin/test.html. IE works fine--no blank pop up along with my test page. I'm not asking for one, yet ff feels the need to serve one up. Does anyone know why?
I cant seem to send an email using PHP's mail(). I have also tried PHPMailer and Swiftmail with no success. However, the following command on the server delivers mail successfully.
cat test.txt | mail -s "test mail" [email protected]
Is there a way to trace where the problem is coming from? mail() just seems to return true or false.
I am very inexperienced with PHP and I've having trouble calling a mootools function.
Here's my code:
echo '<script language="JavaScript">';
echo "Sexy.error('Test!');";
echo '</script>';
When I try it with a simple alert('test') it works just fine.. I'm confused?!?
Can someone explain this behaviour?
test.c:
#include <stdio.h>
int main(void)
{
printf("%d, %d\n", (int) (300.6000/0.05000), (int) (300.65000/0.05000));
printf("%f, %f\n", (300.6000/0.05000), (300.65000/0.05000));
return 0;
}
$ gcc test.c
$ ./a.out
6012, 6012
6012.000000, 6013.000000
I checked the assembly code and it puts both the arguments of the first printf as 6012, so it seems to be a compile time bug.
Something strange is going on with NHibernate for me. I can select, and I can insert. But I can't do and update against MySql.
Here is my domain class
public class UserAccount
{
public virtual int Id { get; set; }
public virtual string UserName { get; set; }
public virtual string Password { get; set; }
public virtual bool Enabled { get; set; }
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
public virtual string Phone { get; set; }
public virtual DateTime? DeletedDate { get; set; }
public virtual UserAccount DeletedBy { get; set; }
}
Fluent Mapping
public class UserAccountMap : ClassMap<UserAccount>
{
public UserAccountMap()
{
Table("UserAccount");
Id(x => x.Id);
Map(x => x.UserName);
Map(x => x.Password);
Map(x => x.FirstName);
Map(x => x.LastName);
Map(x => x.Phone);
Map(x => x.DeletedDate);
Map(x => x.Enabled);
}
}
Here is how I'm creating my Session Factory
var dbconfig = MySQLConfiguration
.Standard
.ShowSql()
.ConnectionString(a => a.FromAppSetting("MySqlConnStr"));
FluentConfiguration config = Fluently.Configure()
.Database(dbconfig)
.Mappings(m =>
{
var mapping = m.FluentMappings.AddFromAssemblyOf<TransactionDetail>();
mapping.ExportTo(mappingdir);
});
and this is my NHibernate code:
using (var trans = Session.BeginTransaction())
{
var user = GetById(userId);
user.Enabled = false;
user.DeletedDate = DateTime.Now;
user.UserName = "deleted_" + user.UserName;
user.Password = "--removed--";
Session.Update(user);
trans.Commit();
}
No exceptions are being thrown. No queries are being logged. Nothing.
I have a CSV file I'm importing but am running into an issue. The data is in the format:
TEST 690, "This is a test 1, 2 and 3" ,$14.95 ,4
I need to be able to explode by the , that are not within the quotes...
Is there a way to test the html from the response of:
response = self.client.get('/user/login/')
I want a detailed check like input ids, and other attributes. Also, how about sessions that has been set? is it possible to check their values in the test?
Hi all,
I wonder if we can capture that which button is clicked if there are more than one button.
On this example, can we reach //do something1 and //do something2 parts with joinPoints?
public class Test {
public Test() {
JButton j1 = new JButton("button1");
j1.addActionListener(this);
JButton j2 = new JButton("button2");
j2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
//if the button1 clicked
//do something1
//if the button2 clicked
//do something2
}
}
Hi,
I have various objects in application,and each has isvalid method to test if values of all properties are set correctly(as per business rules).Now,to test that for each violation isvalid throws false,i will have to write as many tests as rules being checked in isvalid.Is there a simpler way to do this? I am using MBunit.
how to get the value of input box while submitting the form in php
i need the url like this
www.example.com/te/?a=test&firstname=blabla
<form action="te/?a=test" method="post">
<input type="text" name="firstname" />
<input type="submit" name="button" />
</form>
Hi all,
Not a VB6 expert... Trying to come up with a VB6 test app that calls InternetCheckConnection. In my test app, InternetCheckConnection always returns false regardless of the URL I use. I copied and pasted this code from a larger spaghetti-code app, but in the spaghetti-code, InternetCheckConnection seems to work fine, returns true.
Is there some other function I have to call first in order for InternetCheckConnection to work?
Hi,
i call a controller action in a unit test.
ViewResult result = c.Index(null,null) as ViewResult;
I cast the result to a ViewResult, because that is what i'm returning in the controller:
return View(model);
But how can i access this model variable in my unit test?
I would like to write application which will iterate trough certain test cases and generated output in HTML file.
For this i would like to have something using which i can keep appending the HTML nodes to the output for each test case. Is there nice way in .NET for doing so ? How ?
Any pointers or suggestions will be helpful.
Basic Question:
If I'm storying/modifying data, should I access elements of a file by index hard-coded index, i.e. targetFile.getElement(5); via a hardcoded identifier (internally translated into index), i.e. target.getElementWithID("Desired Element"), or with some intermediate DESIRED_ELEMENT = 5; ... target.getElement(DESIRED_ELEMENT), etc.
Background:
My program (c++) stores data in lots of different 'dataFile's. I also keep a list of all of the data-files in another file---a 'listFile'---which also stores some of each one's properties (see below, but i.e. what it's name is, how many lines of information it has etc.). There is an object which manages the data files and the list file, call it a 'fileKeeper'.
The entries of a listFile look something like:
filename , contents name , number of lines , some more numbers ...
Its definitely possible that I may add / remove fields from this list --- but in general, they'll stay static.
Right now, I have a constant string array which holds the identification of each element in each entry, something like:
const string fileKeeper::idKeys[] = { "FileName" , "Contents" , "NumLines" ... };
const int fileKeeper::idKeysNum = 6; // 6 - for example
I'm trying to manage this stuff in 'good' programatic form. Thus, when I want to retrieve the number of lines in a file (for example), instead of having a method which just retrieves the '3'rd element... Instead I do something like:
string desiredID = "NumLines";
int desiredIndex = indexForID(desiredID);
string desiredElement = elementForIndex(desiredIndex);
where the function indexForID() goes through the entries of idKeys until it finds desiredID then returns the index it corresponds to. And elementForIndex(index) actually goes into the listFile to retrieve the index'th element of the comma-delimited string.
Problem:
This still seems pretty ugly / poor-form. Is there a way I should be doing this? If not, what are some general ways in which this is usually done?
Thanks!
I have a view: User. In that I have an ascx page : Details
I have a view : Test. I want to access the Details from User from test, using render partial. How can I do that?
<%Html.RenderPartial("Details"); %> doesn`t workin this case.
/*I created this Sign-In page. I start by declaring variables for username/password & buttons. If user enters "test" as username & "test" as password and hits the login button, its supposed to go to the DrinksTwitter.class activity, else throw error message I created. To me the code and login makes perfect sense. I'm not sure why it wont go to the next activity I want it to go to */
package com.android.drinksonme;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Screen2 extends Activity {
// Declare our Views, so we can access them later
private EditText etUsername;
private EditText etPassword;
private Button btnLogin;
private Button btnSignUp;
private TextView lblResult;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Get the EditText and Button References
etUsername = (EditText)findViewById(R.id.username);
etPassword = (EditText)findViewById(R.id.password);
btnLogin = (Button)findViewById(R.id.login_button);
btnSignUp = (Button)findViewById(R.id.signup_button);
lblResult = (TextView)findViewById(R.id.result);
// Check Login
String username = etUsername.getText().toString();
String password = etPassword.getText().toString();
if(username.equals("test") && password.equals("test")){
final Intent i = new Intent(Screen2.this, DrinksTwitter.class);
btnLogin.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
startActivity(i);
}
// lblResult.setText("Login successful.");
else { /* ERROR- Syntax error on token "else", { expected */
lblResult.setText("Invalid username or password.");
}
}
});
final Intent k = new Intent(Screen2.this, SignUp.class);
btnSignUp.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
startActivity(k);
}
}); /* ERROR- Syntax error, insert "}" to complete Statement*/
}
}
I have two buttons that both have onTouchListeners and perform an action when pressed down. Why do they not work if you try to click both at the same time? I'm building for Android 1.6. I don't have a real device to test on, and you can't test clicking two things at the same time in the emulator. Thanks for any help.
Is there a way to have any @property definitions passed through to a json serializer when serializing a Django model class?
example:
class FooBar(object.Model)
name = models.CharField(...)
@property
def foo(self):
return "My name is %s" %self.name
Want to serialize to:
[{
'name' : 'Test User',
'foo' : 'My name is Test User',
},]
I don't have access to my dev environment, but when I write the below:
interface IExample
void Test (HtmlControl ctrl);
class Example : IExample
{
public void Test (HtmlTextArea area) { }
I get an error stating the methods in the class implementation don't match the interface - so this is not possible. HtmlTextArea is a child class of HtmlControl, is there no way this is possible? I tried with .NET 3.5, but .NET 4.0 may be different (I am interested in any solution with either framework).
Thanks
Im trying to get the redirect link from a site by using curl -I then grep to "location" and then sed out the location text so that I am left with the URL.
But this doesn't work, it will outputs the URL to screen and doesn't put it
test=$(curl -I "http://www.redirectURL.com/" 2> /dev/null | grep "location" | sed -E 's/location:[ ]+//g')
echo "1..$test..2"
Which then outputs:
..2http://www.newURLfromRedirect.com/bla
Whats going on?
using :
Dim a As [Assembly] = [Assembly].LoadFile("C:\test.exe")
Dim testTP As Type
testTP = a.GetType("SplashScreen", True, True)
obj1 = Activator.CreateInstance(withoutFOR)
obj1.show()
my prog made reflection to test.exe SplashScreen loaded , also obj1 filled
when SplashScreen disposed - MainForm loaded the obj1 isnothing!
when try to access obj1 VS say :
AccessibilityObject = {"Cannot
access a disposed object. Object name:
'SplashScreen'."}
I want always obj1 filled from the active form!! how????