Not able to retrieve OriginalValues in Entity Framework 5
I am writing a asp.net mvc4 app and I am using entity framework 5. Each of
my entities have fields like EnteredBy, EnteredOn, LastModifiedBy and
LastModifiedOn.
I am trying to auto-save them by using the SavingChanges event. The code
below has been put together from numerous blogs, SO answeres etc.
public partial class myEntities : DbContext
{
public myEntities()
{
var ctx = ((IObjectContextAdapter)this).ObjectContext;
ctx.SavingChanges += new EventHandler(context_SavingChanges);
}
private void context_SavingChanges(object sender, EventArgs e)
{
ChangeTracker.DetectChanges();
foreach (ObjectStateEntry entry in
((ObjectContext)sender).ObjectStateManager
.GetObjectStateEntries
(EntityState.Added | EntityState.Modified))
{
if (!entry.IsRelationship)
{
CurrentValueRecord entryValues = entry.CurrentValues;
if (entryValues.GetOrdinal("LastModifiedBy") > 0)
{
HttpContext currContext = HttpContext.Current;
string userName = "";
DateTime now = DateTime.Now;
if (currContext.User.Identity.IsAuthenticated)
{
if (currContext.Session["userId"] != null)
{
userName =
(string)currContext.Session["userName"];
}
else
{
userName = currContext.User.Identity.Name;
}
}
entryValues.SetString(
entryValues.GetOrdinal("LastModifiedBy"), userName);
entryValues.SetDateTime(
entryValues.GetOrdinal("LastModifiedOn"), now);
if (entry.State == EntityState.Added)
{
entryValues.SetString(
entryValues.GetOrdinal("EnteredBy"), userName);
entryValues.SetDateTime(
entryValues.GetOrdinal("EnteredOn"), now);
}
else
{
string enteredBy =
entry.OriginalValues.GetString(entryValues.GetOrdinal("EnteredBy"));
DateTime enteredOn =
entry.OriginalValues.GetDateTime(entryValues.GetOrdinal("EnteredOn"));
entryValues.SetString(
entryValues.GetOrdinal("EnteredBy"),enteredBy);
entryValues.SetDateTime(
entryValues.GetOrdinal("EnteredOn"), enteredOn);
}
}
}
}
}
}
My problem is that
entry.OriginalValues.GetString(entryValues.GetOrdinal("EnteredBy")) and
entry.OriginalValues.GetDateTime(entryValues.GetOrdinal("EnteredOn")) are
not returning the original values but rather the current values which is
null. I tested with other fields in the entity and they are returning the
current value which were entered in the html form.
How do I get the original value here?
Bushfield
Sunday, 1 September 2013
How to create my own SocketServer
How to create my own SocketServer
I have been trying to create a simple Tic-Tac-Toe multiplayer game via
ActionScript3 with more than 1k concurrent connections.
My researches shows should i use some available socket-servers like
SmartFoxServer or electroServer etc... But these servers has less than 50
concurrent connections for free.
Those are so powerful and expensive as well. My budget don't allow me to
buy available servers.
I've decided to create my own Socket-Server.
Please tell me what i must to learn for creating Socket-Server. If you
know any tutorial books mention here.
Any helps would be appreciated.
I have been trying to create a simple Tic-Tac-Toe multiplayer game via
ActionScript3 with more than 1k concurrent connections.
My researches shows should i use some available socket-servers like
SmartFoxServer or electroServer etc... But these servers has less than 50
concurrent connections for free.
Those are so powerful and expensive as well. My budget don't allow me to
buy available servers.
I've decided to create my own Socket-Server.
Please tell me what i must to learn for creating Socket-Server. If you
know any tutorial books mention here.
Any helps would be appreciated.
Saturday, 31 August 2013
Maximum purchased toys time out
Maximum purchased toys time out
So yeah, I have a homework sort of question which I've solved but keeps
giving a timeout error on test cases and I can't figure out why.
You need to buy your nephew toys for his birthday. But you only have
limited money. However, you want to buy as many unique toys as you can for
your nephew. Write a function that will return the max number of unique
toys you can buy.
The arguments to the functions are the integer array costs that contains
the costs for each toy and the integer budget which is the max amount of
money you can spend.
Return the integer representing the max number of unique toys you can buy
Constraints
If N is the number of toys and K is the budget... 1<=N<=105 1<=K<=109
1<=price of any toy<=109
Sample Input
costs: {1, 12, 5, 111, 200, 1000, 10} budget: 50 Sample Return Value
4 Explanation
He can buy only 4 toys at most. These toys have the following prices:
1,12,5,10.
so this is what I wrote and it keeps giving a timeout error on 10
testcases. I can't figure out why
function maxPurchasedToys(costs, budget) {
var costsLess=[];
var removeFromArray=function(arr, value){
for(i in arr){
if(arr[i]==value){
arr.splice(i,1);
break;
}
}
return costsLess;
}
//First let's get a new array consisting only of costs that are equal
to or below the budget
costs.map(function(x){x<budget?costsLess.push(x):1;})
var sum=0;
costsLess.map(function(x){sum+=x;});//Get the sum of budget
while(sum>=budget){
var max=Math.max.apply( Math, costsLess );
costsLess=removeFromArray(costsLess,max);//Remove the biggest
element to ensure that the costs fall within budget
sum=0;
costsLess.map(function(x){sum+=x;});//Get the new sum of budget
}
return costsLess.length;
}
I tried the following cases: the original test case, [5000,2000,20,200],50
and a few more. All executed fine
So yeah, I have a homework sort of question which I've solved but keeps
giving a timeout error on test cases and I can't figure out why.
You need to buy your nephew toys for his birthday. But you only have
limited money. However, you want to buy as many unique toys as you can for
your nephew. Write a function that will return the max number of unique
toys you can buy.
The arguments to the functions are the integer array costs that contains
the costs for each toy and the integer budget which is the max amount of
money you can spend.
Return the integer representing the max number of unique toys you can buy
Constraints
If N is the number of toys and K is the budget... 1<=N<=105 1<=K<=109
1<=price of any toy<=109
Sample Input
costs: {1, 12, 5, 111, 200, 1000, 10} budget: 50 Sample Return Value
4 Explanation
He can buy only 4 toys at most. These toys have the following prices:
1,12,5,10.
so this is what I wrote and it keeps giving a timeout error on 10
testcases. I can't figure out why
function maxPurchasedToys(costs, budget) {
var costsLess=[];
var removeFromArray=function(arr, value){
for(i in arr){
if(arr[i]==value){
arr.splice(i,1);
break;
}
}
return costsLess;
}
//First let's get a new array consisting only of costs that are equal
to or below the budget
costs.map(function(x){x<budget?costsLess.push(x):1;})
var sum=0;
costsLess.map(function(x){sum+=x;});//Get the sum of budget
while(sum>=budget){
var max=Math.max.apply( Math, costsLess );
costsLess=removeFromArray(costsLess,max);//Remove the biggest
element to ensure that the costs fall within budget
sum=0;
costsLess.map(function(x){sum+=x;});//Get the new sum of budget
}
return costsLess.length;
}
I tried the following cases: the original test case, [5000,2000,20,200],50
and a few more. All executed fine
PHP message sends message as success, but no messages received?
PHP message sends message as success, but no messages received?
Hi I have simple contact form for email on my site, and the form works
including the success of a message sent,however, I am not receiving email
to the designated webemail server. I am running the latest PHP. Do some
webservers cache mail or is there some error in this code I am not seeing.
<?php
$EmailFrom = "email@mydomain.com";
$EmailTo = "email@mydomain.com";
$Subject = "Contacting Me";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\"
content=\"0;URL=http:blake-schermer.com\home">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
<div id="contact-area">
<form method="post" action="contactengine.php">
<label for="Name">Name:</label>
<input type="text" name="Name" id="Name" />
<label for="Email">Email:</label>
<input type="text" name="Email" id="Email" />
<label for="Message">Thought:</label><br />
<textarea name="Message" rows="20" cols="20"
id="Message"></textarea>
<input type="submit" name="submit" value="Transmit"
class="submit-button" />
</form>
<div style="clear: both;"></div></div>
Hi I have simple contact form for email on my site, and the form works
including the success of a message sent,however, I am not receiving email
to the designated webemail server. I am running the latest PHP. Do some
webservers cache mail or is there some error in this code I am not seeing.
<?php
$EmailFrom = "email@mydomain.com";
$EmailTo = "email@mydomain.com";
$Subject = "Contacting Me";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\"
content=\"0;URL=http:blake-schermer.com\home">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
<div id="contact-area">
<form method="post" action="contactengine.php">
<label for="Name">Name:</label>
<input type="text" name="Name" id="Name" />
<label for="Email">Email:</label>
<input type="text" name="Email" id="Email" />
<label for="Message">Thought:</label><br />
<textarea name="Message" rows="20" cols="20"
id="Message"></textarea>
<input type="submit" name="submit" value="Transmit"
class="submit-button" />
</form>
<div style="clear: both;"></div></div>
File size limit for boost memory mapped files?
File size limit for boost memory mapped files?
I am using the below code to open files which are approximately 400 to
800MB in size:
#include <boost\interprocess\file_mapping.hpp>
#include <boost\interprocess\mapped_region.hpp>
#include <iostream>
#include <vector>
#include <string>
using namespace boost::interprocess;
using namespace std;
int main(){
file_mapping fm("C:\\test\\1.txt",read_only);
mapped_region region(fm,read_only);
const char* const data = static_cast<const char*>(region.get_address());
const size_t max_size = region.get_size();
cout << max_size;
int b;
cin >> b;
}
If I point the above code to a small file I get no exception. However,
when looking at the several-hundred-MB-files (on an external USB) I get an
exception:
Unhandled exception at at 0x7521C41F in ReadingFiles.exe: Microsoft C++
exception: boost::interprocess::interprocess_exception at memory location
0x0040FBD4.
I have 2.4GB of RAM free- so it shouldnt be that I have run out of memory?
I am using the below code to open files which are approximately 400 to
800MB in size:
#include <boost\interprocess\file_mapping.hpp>
#include <boost\interprocess\mapped_region.hpp>
#include <iostream>
#include <vector>
#include <string>
using namespace boost::interprocess;
using namespace std;
int main(){
file_mapping fm("C:\\test\\1.txt",read_only);
mapped_region region(fm,read_only);
const char* const data = static_cast<const char*>(region.get_address());
const size_t max_size = region.get_size();
cout << max_size;
int b;
cin >> b;
}
If I point the above code to a small file I get no exception. However,
when looking at the several-hundred-MB-files (on an external USB) I get an
exception:
Unhandled exception at at 0x7521C41F in ReadingFiles.exe: Microsoft C++
exception: boost::interprocess::interprocess_exception at memory location
0x0040FBD4.
I have 2.4GB of RAM free- so it shouldnt be that I have run out of memory?
Declaring array as static won't crash program
Declaring array as static won't crash program
When I initialise array of 1,000,000 integers, program crashes, but when I
put keyword static in front everything works perfectly, why?
int a[1000000] <- crash
static int a[1000000] <- runs correctly
When I initialise array of 1,000,000 integers, program crashes, but when I
put keyword static in front everything works perfectly, why?
int a[1000000] <- crash
static int a[1000000] <- runs correctly
401 - "You are not authorized to view this page error for rdlc files
401 - "You are not authorized to view this page error for rdlc files
I am using .rdlc file in my application to show the reports. When i
deployed my application on staging, the rdlc file rendered without any
issue. But when i deploy the same code on my production server i am
getting 401 - "You are not authorized to view this page" error. Is there
any special previleges required for .rdlc files? My reports are in folder
called 'Reports', which has full privileges for Everyone. Also the
anonymous access is enable for application. Other aspx pages are rendered
and display without any issue.
Thanks in advance. Brijen Patel
I am using .rdlc file in my application to show the reports. When i
deployed my application on staging, the rdlc file rendered without any
issue. But when i deploy the same code on my production server i am
getting 401 - "You are not authorized to view this page" error. Is there
any special previleges required for .rdlc files? My reports are in folder
called 'Reports', which has full privileges for Everyone. Also the
anonymous access is enable for application. Other aspx pages are rendered
and display without any issue.
Thanks in advance. Brijen Patel
Subscribe to:
Comments (Atom)