I have developed Attendance Management System using ZkemKeeper SDK in C# Code.I would like to know how to clear Log in Machine for Specific Date Range.
I have tried ClearGLog() mothod,but its clear all log in Machine.Please advise how to do that....
Please follow write these line after connecting bio-matric device
if (IsConnecetd == true)
{
bool delete = axCZKEM1.ClearGLog(dwMachineNumber);
if (delete == true)
{
// Deleted Successfully
}
}
I have web application in which user can enter date of birth only from one form. I have asp.net validators as well as server side validation methods that are called before save method is called.
Following is the code for server side validation:
private bool ValidateData(out string error)
{
error = string.Empty;
//Validate Date of Birth
TextBox txtDOB = (TextBox)clientinfo.FindControl("txtDOB");
if (!string.IsNullOrEmpty(txtDOB.Text.Trim()))
{
DateTime dob = Convert.ToDateTime(txtDOB.Text.Trim());
if (dob >= DateTime.Now.Date)
{
error = error + "Client can not be less than 7 years and greater than 100 years old.";
}
else if (dob < DateTime.Now.Date && (DateTime.Now.Date.Year - dob.Year) > 100)
{
error = error + "Client can not be less than 7 years and greater than 100 years old.";
}
}
else
{
error = error + "Please enter date of birth.";
}
return error.Length > 0 ? false : true;
}
Some how there is one record with date of birth as '07/19/2045' (MM/DD/YYYY). Every time I test, I can see validation is working.
I can disable clint side validation from browser. But is there any way we can disable server side validation?..
I need to know how a wrong entry happened in order to prevent any future issues.
Please let me know if there is any way user can override server validation or I am doing something wrong in my method.
The user can't modify the server, the error more than likely exist in your conversion from a String to DateTime. You could try the following approach:
var date = DateTime.Now;
if(DateTime.TryParse(txtAge.Text, out date))
if(date <= DateTime.Now.AddYears(-7) && date >= DateTime.Now.AddYears(-100))
Console.WriteLine("Valid Date");
You would need to add your else statements to implement those errors, you may have to play with the comparison, but that should work for a nice starting point.
According to me it will not be possible to disable the server side validation as I could not see any config entry which could stop the entry into this code and I think only way to handle this issue will be copy the dlls onto the local system and try out the various scenarios. Regarding the wrong entry you can do the same input in another machine or a sample console app to see which part of the validation is failing for it. Hope this helps.
Update: Se bottom: Added CreateArticleRelations code example.
Ok, this is a tricky one. I am experiencing a massive performance problem in hyper-v when it comes to preview and production environments.
First of all, here is the setup.
.NET 4.0 on all servers.
Preview
Webserver : Virtual machine, 8gb ram, 4 cpu, windows server 2008 r2 (64)
Database: Virtual server, 6gb ram, 2 cpu, windows server 2008 r2 (64)
Production:
Webserver: Virtual machine, 8gb ram, 4 cpu, windows server 2008 r2 (64)
Database: Physical machine, 48 gb ram, 16 cpu, windows server 2008 r2 (64)
This is a B2B shop running on these. And when running integration for one product the results are mind blowing for me. I will provide pictures.
Running for one product in preview takes: 83 seconds for everything to update.
Running for one product in production takes 301 seconds (!) for everything to update. Same product!
If I run this locally it takes about 40 seconds to complete.
I have ran dotTrace profiling remote on the both servers to actually see what is taking time. I use EnterpriseLibrary for logging, umbraco for cms and uCommerce as a commerce platform. Look at the picture example below of one finding I have seen.
First of all, CreateArticleRelations takes 140 seconds on the production server but only 46 on the preview. Same product, same data. Then to the really funky stuff. On the production site at the top we see enterpriselogging taking 64 seconds, but on the preview run it is way down so can't even say it taking absolutley no time.
The implementation of the logging looks like this.
private string LogMessage(string message, int priority, string category, TraceEventType severity, int code, int skipFrames = 2)
{
//Check if "code" exists in eCommerceB2B.LogExceptions
var dbf = new ThirdPartSources();
var exeptions = dbf.GetLogExeptions();
foreach (var exeption in exeptions)
{
if (code.ToString() == exeption)
return DateTime.Now.ToString();
}
try
{
var stack = new StackTrace(skipFrames);
if (_logWriter.IsLoggingEnabled())
{
var logEntry = new LogEntry
{
Title =
stack.GetFrame(0).GetMethod().ReflectedType.FullName + " " +
stack.GetFrame(0).GetMethod(),
Message = message,
Priority = priority,
Severity = severity,
TimeStamp = DateTime.Now,
EventId = code
};
logEntry.Categories.Add(category);
_logWriter.Write(logEntry);
return logEntry.TimeStampString;
}
Logging is set up to a rolling flatfile and a database. I have tried to disable the logging and that saves about 20 seconds, but still the LogMessage is up at the top.
This has blown my mind for days and i can't seem to find a solution. Sure I can remove logging completely but I wan't to find the cause of the problem.
What bothers me is that for example running one method (CreateArticleRelations) takes almost 4 times as long on the production server. The cpu level is never over 30 % and 5 gb ram is available. The applications is ran as a console application.
Someone please save me! :) I can provide more data if needed. My bet is that is has something to do with the virtual server but I have no idea what to check.
Update:
Per comment, i tried to comment out the LogMessage completly. It saves about 100 seconds totally which tells me that something is terribly wrong. Still taking 169 seconds to create the relations vs 46 seconds in preview, and in preview logging is still enabled. What can be wrong to enterprise library to make it behave this way? And still, why i code running 4x slower on the production server? Se image after I remove LogMessage. It is from PRODUCTION.
CreateArticleRelations
private void CreateArticleRelations(Product uCommerceProduct, IStatelessSession session)
{
var catalogues = _jsbArticleRepository.GetCustomerSpecificCatalogue(uCommerceProduct.Sku).CustomerRelations;
var defaultCampaignName = _configurationManager.GetValue(ConfigurationKeys.UCommerceDefaultCampaignName);
var optionalArticleCampaignName = _configurationManager.GetValue(ConfigurationKeys.UCommerceDefaultOptionalArticleCampaignName);
var categoryRelations =
session.Query<CategoryProductRelation>()
.Fetch(x => x.Category)
.Fetch(x => x.Product)
.Where(
x =>
x.Category.Definition.Name == _customerArticleCategory && x.Product.Sku == uCommerceProduct.Sku)
.ToList();
var relationsAlreadyAdded = _categoryRepository.RemoveCataloguesNotInRelation(catalogues, categoryRelations,
session);
_categoryRepository.SetArticleCategories(session, relationsAlreadyAdded, uCommerceProduct, catalogues,
_customerCategories, _customerArticleCategory,
_customerArticleDefinition);
//set campaigns and optional article
foreach (var jsbArticleCustomerRelation in catalogues)
{
// Article is in campaign for just this user
if (jsbArticleCustomerRelation.HasCampaign)
{
_campaignRepository.CreateCampaignAndAddProduct(session, jsbArticleCustomerRelation, defaultCampaignName);
}
else // remove the article from campaign for user if exists
{
_campaignRepository.DeleteProductFromCampaign(session, jsbArticleCustomerRelation, defaultCampaignName);
}
// optional article
if(jsbArticleCustomerRelation.IsOptionalArticle)
{
_campaignRepository.CreateCampaignAndAddProduct(session, jsbArticleCustomerRelation, optionalArticleCampaignName);
}
else
{
_campaignRepository.DeleteProductFromCampaign(session, jsbArticleCustomerRelation, optionalArticleCampaignName);
}
}
}
We hit the database almost on every row here in some way. For example in the DeleteProductFromCampaign the following code take 43 seconds in the preview environment and 169 seconds in the production environment.
public void DeleteProductFromCampaign(IStatelessSession session, JSBArticleCustomerRelation jsbArticleCustomerRelation, string campaignName)
{
var productTarget =
session.Query<ProductTarget>()
.FirstOrDefault(
x =>
x.CampaignItem.Campaign.Name == jsbArticleCustomerRelation.CustomerNumber &&
x.CampaignItem.Name == campaignName &&
x.Sku == jsbArticleCustomerRelation.ArticleNumber);
if (productTarget != null)
{
session.Delete(productTarget);
}
}
So this code for example runs 4x slower on the production server. The biggest difference between the servers are that the production (physical) server in set up with noumerous instances and I am using one of them (20 gb om ram).
I have a particular situation where my client require to import (periodically) an ms-access database into his mysql website database (so it's a remote database).
Because the hosting plan is a shared hosting (not a vps), the only way to do it is through PHP through an SQL query, because I don't have ODBC support on hosting.
My current idea is this one (obviusly the client has a MS-Windows O.S.):
Create a small C# application that convert MS-Access database into a big SQL query written on a file
The application will then use FTP info to send the file into a specified directory on the website
A PHP script will then run periodically (like every 30 minutes) and check if file exists, eventually importing it into the database
I know it's not the best approach so I'm proposing a question to create a different workaround for this problem. The client already said that he wants keep using his ms-access database.
The biggest problem I have is that scripts can last only 30 seconds, which is obviusly a problem to import data.
To work around the 30-second limit, call your script repeatedly, and keep track of your progress. Here's one rough idea:
if(!file_exists('upload.sql')) exit();
$max = 2000; // the maximum number you want to execute.
if(file_exists('progress.txt')) {
$progress = file_get_contents('progress.txt');
} else {
$progress = 0;
}
// load the file into an array, expecting one query per line
$file = file('upload.sql');
foreach($file as $current => $query) {
if($current < $progress) continue; // skip the ones we've done
if($current - $progress >= $max) break; // stop before we hit the max
mysql_query($query);
}
// did we finish the file?
if($current == count($file) - 1) {
unlink('progress.txt');
unlink('upload.sql');
} else {
file_put_contents('progress.txt', $current);
}
Using asp.net mvc2 on vs2008 on local machine and hosting on a shared server at discountasp.net
Problem started when I could not make the .UTCNow deliver the correct "Office is open/closed" string as follows:
In the view user control:
<div><%=OfficeTimes.LondonOpenOfficeMessage() %></div>
And in the helper file:
public static class OfficeTimes
{
public string LondonOpenOfficeMessage()
{
if (DateTime.UtcNow.Hour < 17 && DateTime.UtcNow.Hour > 7)
{
return "Office is currently closed";
}
else
{
return "Office is currently open";
}
}
}
so I changed the return string to the UTC (as below) to see if it was returning the correct time and still compiled as if it was the original.
public static class OfficeTimes
{
public string LondonOpenOfficeMessage()
{
if (DateTime.UtcNow.Hour < 17 && DateTime.UtcNow.Hour > 7)
{
return DateTime.UtcNow.Hour.ToString(); //"Office is currently closed";
}
else
{
return DateTime.UtcNow.Hour.ToString(); //"Office is currently open";
}
}
}
I tried deleting the file...it still compiled.
All worked fine on the local machine.
Does anyone know the server does not refresh this helper file?
In contrast to a web site project, ASP.NET MVC uses a web application project meaning that it needs to be compiled for your changes to take effect. When you are working on the local machine and you are running the site inside Visual Studio source code is automatically compiled and changes take effect. For your changes to take effect you need to deploy all the assemblies that are generated in the bin folder. No need to copy any source files to the server (except of course aspx and ascx pages).