close an activity after some time
I'm trying to make a dice rolling app and I want to run an activity which
displays an image of the result when a button is pressed and close it
after a few seconds. So how can I do this?
Maybe there's another way to display an image on top of my activity
without calling a new activity? I'm not sure.
I've read some things about timers but I don't really get it. And I know
people will tell me to let the user tap to dismiss the window but for this
app I'm sure I want it gone automatically.
Wednesday, 11 September 2013
Updating a user that doesn't exist on database
Updating a user that doesn't exist on database
I'm developing a WCF REST service that uses Entity Framework CodeFirst.
I have this method to insert or update a user:
private User InsertOrUpdateUser(User user)
{
OutgoingWebResponseContext ctx =
WebOperationContext.Current.OutgoingResponse;
// Check if user parameter is null
ParameterCheck.CheckUser(user);
// If user.UserId is not set (its value is less than 1), we are
// creating a new user.
bool isPost = (user.UserId == 0);
// Check if user has all its required fields, filled
if (isPost)
ParameterCheck.CheckUserData(user);
try
{
using (var context = new AdnLineContext())
{
context.Entry(user).State = user.UserId == 0 ?
EntityState.Added :
EntityState.Modified;
context.SaveChanges();
// If is POST, we are creating a new resource
if (isPost)
ctx.SetStatusAsCreated(CreateUserUri(user));
else
ctx.StatusCode = System.Net.HttpStatusCode.OK;
}
}
catch (Exception ex)
{
ctx.StatusCode = System.Net.HttpStatusCode.InternalServerError;
ctx.SuppressEntityBody = true;
}
return user;
}
But I get an error when I'm trying to update a user that it isn't on
database.
I think I can check first if that user exists with this code:
var users = from u in context.Users
where u.UserId == userId
select u;
if ((users != null) &&
(users.Count() == 1))
{
user = users.First();
But, do you know another fastest method to check if that user exists?
Maybe I can use context.Entry but I'm very new on Entity Framework.
I'm developing a WCF REST service that uses Entity Framework CodeFirst.
I have this method to insert or update a user:
private User InsertOrUpdateUser(User user)
{
OutgoingWebResponseContext ctx =
WebOperationContext.Current.OutgoingResponse;
// Check if user parameter is null
ParameterCheck.CheckUser(user);
// If user.UserId is not set (its value is less than 1), we are
// creating a new user.
bool isPost = (user.UserId == 0);
// Check if user has all its required fields, filled
if (isPost)
ParameterCheck.CheckUserData(user);
try
{
using (var context = new AdnLineContext())
{
context.Entry(user).State = user.UserId == 0 ?
EntityState.Added :
EntityState.Modified;
context.SaveChanges();
// If is POST, we are creating a new resource
if (isPost)
ctx.SetStatusAsCreated(CreateUserUri(user));
else
ctx.StatusCode = System.Net.HttpStatusCode.OK;
}
}
catch (Exception ex)
{
ctx.StatusCode = System.Net.HttpStatusCode.InternalServerError;
ctx.SuppressEntityBody = true;
}
return user;
}
But I get an error when I'm trying to update a user that it isn't on
database.
I think I can check first if that user exists with this code:
var users = from u in context.Users
where u.UserId == userId
select u;
if ((users != null) &&
(users.Count() == 1))
{
user = users.First();
But, do you know another fastest method to check if that user exists?
Maybe I can use context.Entry but I'm very new on Entity Framework.
Tuesday, 10 September 2013
MySQL C# Query trouble - Updating table
MySQL C# Query trouble - Updating table
I'am having trouble with this function I'm creating to Update my database.
The Update faculty member seems to work perfectly while the Updating of
the person tables does not . I'm presuming that the MySQL Query isn't
correct for updating the person table.
Additional INFO: My code is hooked to an GUI mock as of right now for
testing purposes . the Update string with @Id.. its just to select which
ID I wish to change..
public static void Update(string update,string fName, string lName, string
DOB, string postCode, string address, string phoneNumber,
bool isTenured, string
qualifications, string
previousEmployment)
{
MySqlConnection conn;
MySqlCommand cmd;
string sql = "UPDATE person SET firstName = @FirstName ,
lastName = @LastName, DOB = @DOB, phoneNumber =
@PhoneNumber, address = @Address, postCode = @PostCode
WHERE ID =@Id;";
GetConnection(out conn, out cmd, sql);
try
{
cmd.Parameters.AddWithValue("@Id", update);
cmd.Parameters.AddWithValue("@FirstName", fName);
cmd.Parameters.AddWithValue("@LastName", lName);
cmd.Parameters.AddWithValue("@DOB", DOB);
cmd.Parameters.AddWithValue("@PhoneNumber", phoneNumber);
cmd.Parameters.AddWithValue("@Address", address);
cmd.Parameters.AddWithValue("@PostCode", postCode);
long id = (long)cmd.LastInsertedId;
sql = "UPDATE facultymember SET isTenured =
@IsTenured, qualifications = @Qualifications,
previousEmployment = @PreviousEmployment WHERE
Person_personID=@Id";
cmd = new MySqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@IsTenured", isTenured);
cmd.Parameters.AddWithValue("@Qualifications",
qualifications);
cmd.Parameters.AddWithValue("@PreviousEmployment",
previousEmployment);
cmd.ExecuteNonQuery();
}
catch (NullReferenceException nre)
{
MessageBox.Show(nre.Message);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
finally
{
try
{
MessageBox.Show("Updated");
cmd.Connection.Close();
conn.Close();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
}
I'am having trouble with this function I'm creating to Update my database.
The Update faculty member seems to work perfectly while the Updating of
the person tables does not . I'm presuming that the MySQL Query isn't
correct for updating the person table.
Additional INFO: My code is hooked to an GUI mock as of right now for
testing purposes . the Update string with @Id.. its just to select which
ID I wish to change..
public static void Update(string update,string fName, string lName, string
DOB, string postCode, string address, string phoneNumber,
bool isTenured, string
qualifications, string
previousEmployment)
{
MySqlConnection conn;
MySqlCommand cmd;
string sql = "UPDATE person SET firstName = @FirstName ,
lastName = @LastName, DOB = @DOB, phoneNumber =
@PhoneNumber, address = @Address, postCode = @PostCode
WHERE ID =@Id;";
GetConnection(out conn, out cmd, sql);
try
{
cmd.Parameters.AddWithValue("@Id", update);
cmd.Parameters.AddWithValue("@FirstName", fName);
cmd.Parameters.AddWithValue("@LastName", lName);
cmd.Parameters.AddWithValue("@DOB", DOB);
cmd.Parameters.AddWithValue("@PhoneNumber", phoneNumber);
cmd.Parameters.AddWithValue("@Address", address);
cmd.Parameters.AddWithValue("@PostCode", postCode);
long id = (long)cmd.LastInsertedId;
sql = "UPDATE facultymember SET isTenured =
@IsTenured, qualifications = @Qualifications,
previousEmployment = @PreviousEmployment WHERE
Person_personID=@Id";
cmd = new MySqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@IsTenured", isTenured);
cmd.Parameters.AddWithValue("@Qualifications",
qualifications);
cmd.Parameters.AddWithValue("@PreviousEmployment",
previousEmployment);
cmd.ExecuteNonQuery();
}
catch (NullReferenceException nre)
{
MessageBox.Show(nre.Message);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
finally
{
try
{
MessageBox.Show("Updated");
cmd.Connection.Close();
conn.Close();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
}
Adding ssl to domain stopped the google app mail service
Adding ssl to domain stopped the google app mail service
few days before my google app mail service was working fine but when i
applied SSL certificate to my domain it stopped working(i.e. stopped
sending mails to my clients).
few days before my google app mail service was working fine but when i
applied SSL certificate to my domain it stopped working(i.e. stopped
sending mails to my clients).
Mahout minhash org.apache.hadoop.io.LongWritable cannot be cast to org.apache.hadoop.io.Text
Mahout minhash org.apache.hadoop.io.LongWritable cannot be cast to
org.apache.hadoop.io.Text
I am using :
hadoop-1.2.1 and mahout-distribution-0.8
When I try to run HASHMIN method with following command:
$MAHOUT_HOME/bin/mahout org.apache.mahout.clustering.minhash.MinHashDriver
-i tce-data/cv.vec -o tce-data/out/cv/minHashDriver/ -ow
I get this error:
tce@osy-Inspiron-N5110:~$ $MAHOUT_HOME/bin/mahout
org.apache.mahout.clustering.minhash.MinHashDriver -i tce-data/cv.vec
-o tce-data/out/cv/minHashDriver/ -ow
Warning: $HADOOP_HOME is deprecated.
Running on hadoop, using /home/tce/app/hadoop-1.2.1/bin/hadoop and
HADOOP_CONF_DIR=
MAHOUT-JOB: /home/tce/app/mahout-distribution-0.8/mahout-examples-0.8-job.jar
Warning: $HADOOP_HOME is deprecated.
13/09/10 18:17:46 WARN driver.MahoutDriver: No
org.apache.mahout.clustering.minhash.MinHashDriver.props found on
classpath, will use command-line arguments only
13/09/10 18:17:46 INFO common.AbstractJob: Command line arguments:
{--endPhase=[2147483647], --hashType=[MURMUR], --input=[tce-data/cv.vec],
--keyGroups=[2], --minClusterSize=[10], --minVectorSize=[5],
--numHashFunctions=[10], --numReducers=[2],
--output=[tce-data/out/cv/minHashDriver/], --overwrite=null,
--startPhase=[0], --tempDir=[temp], --vectorDimensionToHash=[value]}
13/09/10 18:17:48 INFO input.FileInputFormat: Total input paths to process
: 1
13/09/10 18:17:50 INFO mapred.JobClient: Running job: job_201309101645_0031
13/09/10 18:17:51 INFO mapred.JobClient: map 0% reduce 0%
13/09/10 18:18:27 INFO mapred.JobClient: Task Id :
attempt_201309101645_0031_m_000000_0, Status : FAILED
java.lang.ClassCastException: org.apache.hadoop.io.LongWritable cannot be
cast to org.apache.hadoop.io.Text
at
org.apache.mahout.clustering.minhash.MinHashMapper.map(MinHashMapper.java:30)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:145)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:764)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:364)
at org.apache.hadoop.mapred.Child$4.run(Child.java:255)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at
org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1190)
at org.apache.hadoop.mapred.Child.main(Child.java:249)
I appreciate any idea
org.apache.hadoop.io.Text
I am using :
hadoop-1.2.1 and mahout-distribution-0.8
When I try to run HASHMIN method with following command:
$MAHOUT_HOME/bin/mahout org.apache.mahout.clustering.minhash.MinHashDriver
-i tce-data/cv.vec -o tce-data/out/cv/minHashDriver/ -ow
I get this error:
tce@osy-Inspiron-N5110:~$ $MAHOUT_HOME/bin/mahout
org.apache.mahout.clustering.minhash.MinHashDriver -i tce-data/cv.vec
-o tce-data/out/cv/minHashDriver/ -ow
Warning: $HADOOP_HOME is deprecated.
Running on hadoop, using /home/tce/app/hadoop-1.2.1/bin/hadoop and
HADOOP_CONF_DIR=
MAHOUT-JOB: /home/tce/app/mahout-distribution-0.8/mahout-examples-0.8-job.jar
Warning: $HADOOP_HOME is deprecated.
13/09/10 18:17:46 WARN driver.MahoutDriver: No
org.apache.mahout.clustering.minhash.MinHashDriver.props found on
classpath, will use command-line arguments only
13/09/10 18:17:46 INFO common.AbstractJob: Command line arguments:
{--endPhase=[2147483647], --hashType=[MURMUR], --input=[tce-data/cv.vec],
--keyGroups=[2], --minClusterSize=[10], --minVectorSize=[5],
--numHashFunctions=[10], --numReducers=[2],
--output=[tce-data/out/cv/minHashDriver/], --overwrite=null,
--startPhase=[0], --tempDir=[temp], --vectorDimensionToHash=[value]}
13/09/10 18:17:48 INFO input.FileInputFormat: Total input paths to process
: 1
13/09/10 18:17:50 INFO mapred.JobClient: Running job: job_201309101645_0031
13/09/10 18:17:51 INFO mapred.JobClient: map 0% reduce 0%
13/09/10 18:18:27 INFO mapred.JobClient: Task Id :
attempt_201309101645_0031_m_000000_0, Status : FAILED
java.lang.ClassCastException: org.apache.hadoop.io.LongWritable cannot be
cast to org.apache.hadoop.io.Text
at
org.apache.mahout.clustering.minhash.MinHashMapper.map(MinHashMapper.java:30)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:145)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:764)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:364)
at org.apache.hadoop.mapred.Child$4.run(Child.java:255)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at
org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1190)
at org.apache.hadoop.mapred.Child.main(Child.java:249)
I appreciate any idea
php xml xpath how to extract desired match
php xml xpath how to extract desired match
I have question on how to access SourceUrl for image with width=400
images/di/47/6b/77/454430384d6d324b413332544a695675313851-400x400-0-0.jpg?p=p2.7f19fe93a466ae45afab&a=1&c=1&l=7000610&r=1&pr=1&lks=43998&fks=35198
By default it is showing me image with width=100 and somehow my zpath
syntax is not picking up 400
<?php
$string = <<<XML
<imageList>
<image available="true" height="100" width="100">
<sourceURL>images/di/47/6b/77/454430384d6d324b413332544a695675313851-100x100-0-0.jpg?p=p2.7f19fe93a466ae45afab&a=1&c=1&l=7000610&r=1&pr=1&lks=43998&fks=35198</sourceURL>
</image>
<image available="true" height="200"
width="200"><sourceURL>images/di/47/6b/77/454430384d6d324b413332544a695675313851-200x200-0-0.jpg?p=p2.7f19fe93a466ae45afab&a=1&c=1&l=7000610&r=1&pr=1&lks=43998&fks=35198</sourceURL></image>
<image available="true" height="300"
width="300"><sourceURL>images/di/47/6b/77/454430384d6d324b413332544a695675313851-300x300-0-0.jpg?p=p2.7f19fe93a466ae45afab&a=1&c=1&l=7000610&r=1&pr=1&lks=43998&fks=35198</sourceURL></image>
<image available="true" height="400"
width="400"><sourceURL>images/di/47/6b/77/454430384d6d324b413332544a695675313851-400x400-0-0.jpg?p=p2.7f19fe93a466ae45afab&a=1&c=1&l=7000610&r=1&pr=1&lks=43998&fks=35198</sourceURL></image>
<image available="true" height="569"
width="500"><sourceURL>images/di/47/6b/77/454430384d6d324b413332544a695675313851-500x569-0-0.jpg?p=p2.7f19fe93a466ae45afab&a=1&c=1&l=7000610&r=1&pr=1&lks=43998&fks=35198</sourceURL></image></imageList>
XML;
$xml = simplexml_load_string($string);
$result = $xml->xpath("//image[@height='400']/sourceURL");
?>
I have question on how to access SourceUrl for image with width=400
images/di/47/6b/77/454430384d6d324b413332544a695675313851-400x400-0-0.jpg?p=p2.7f19fe93a466ae45afab&a=1&c=1&l=7000610&r=1&pr=1&lks=43998&fks=35198
By default it is showing me image with width=100 and somehow my zpath
syntax is not picking up 400
<?php
$string = <<<XML
<imageList>
<image available="true" height="100" width="100">
<sourceURL>images/di/47/6b/77/454430384d6d324b413332544a695675313851-100x100-0-0.jpg?p=p2.7f19fe93a466ae45afab&a=1&c=1&l=7000610&r=1&pr=1&lks=43998&fks=35198</sourceURL>
</image>
<image available="true" height="200"
width="200"><sourceURL>images/di/47/6b/77/454430384d6d324b413332544a695675313851-200x200-0-0.jpg?p=p2.7f19fe93a466ae45afab&a=1&c=1&l=7000610&r=1&pr=1&lks=43998&fks=35198</sourceURL></image>
<image available="true" height="300"
width="300"><sourceURL>images/di/47/6b/77/454430384d6d324b413332544a695675313851-300x300-0-0.jpg?p=p2.7f19fe93a466ae45afab&a=1&c=1&l=7000610&r=1&pr=1&lks=43998&fks=35198</sourceURL></image>
<image available="true" height="400"
width="400"><sourceURL>images/di/47/6b/77/454430384d6d324b413332544a695675313851-400x400-0-0.jpg?p=p2.7f19fe93a466ae45afab&a=1&c=1&l=7000610&r=1&pr=1&lks=43998&fks=35198</sourceURL></image>
<image available="true" height="569"
width="500"><sourceURL>images/di/47/6b/77/454430384d6d324b413332544a695675313851-500x569-0-0.jpg?p=p2.7f19fe93a466ae45afab&a=1&c=1&l=7000610&r=1&pr=1&lks=43998&fks=35198</sourceURL></image></imageList>
XML;
$xml = simplexml_load_string($string);
$result = $xml->xpath("//image[@height='400']/sourceURL");
?>
PHP Array to solve space issue
PHP Array to solve space issue
I have this PHP code
case "category": {
// CHECK IF THE CATEGORY ALREADY EXISTS
if ( is_term( $val, THEME_TAXONOMY ) ){
$term = get_term_by('name', str_replace("_"," ",$val),
THEME_TAXONOMY);
$catID = $term->term_id;
}else{
$args = array('cat_name' => str_replace("_"," ",$val) );
$term = wp_insert_term(str_replace("_"," ",$val), THEME_TAXONOMY,
$args);
if(is_array($term) && isset($term['term_id']) &&
!isset($term['errors'][0]) ){
$catID = $term['term_id'];
}elseif(isset($term->term_id)){
$catID = $term->term_id;
}
}
$my_post['post_category'] = array($catID);
} break;
it was used to import categories in wordpress but issue is as code is
showing it is replace _ with so I want to import multiple categories so
how can I use an array to do it?
I'm importing multiple categories name like abs,test,test12 . So it was
just importing as it is then I did this abs_test_test12 . And it just
removed _ with space and imported. However each name is different
category. It should import each name after a comma or underscore as a new
category name. –
I have this PHP code
case "category": {
// CHECK IF THE CATEGORY ALREADY EXISTS
if ( is_term( $val, THEME_TAXONOMY ) ){
$term = get_term_by('name', str_replace("_"," ",$val),
THEME_TAXONOMY);
$catID = $term->term_id;
}else{
$args = array('cat_name' => str_replace("_"," ",$val) );
$term = wp_insert_term(str_replace("_"," ",$val), THEME_TAXONOMY,
$args);
if(is_array($term) && isset($term['term_id']) &&
!isset($term['errors'][0]) ){
$catID = $term['term_id'];
}elseif(isset($term->term_id)){
$catID = $term->term_id;
}
}
$my_post['post_category'] = array($catID);
} break;
it was used to import categories in wordpress but issue is as code is
showing it is replace _ with so I want to import multiple categories so
how can I use an array to do it?
I'm importing multiple categories name like abs,test,test12 . So it was
just importing as it is then I did this abs_test_test12 . And it just
removed _ with space and imported. However each name is different
category. It should import each name after a comma or underscore as a new
category name. –
Subscribe to:
Posts (Atom)