I recently try to create a new account on a relatively old windows 8 computer (one year, several updates).
Account creation was just fine but... impossible to connect due to the inability of the system to load the profile of the newly created user.
After some googling and hours, I finally found that the problem was the inability of the system to create, by copying from c:\Users\Default, the new profile.
I found which files were involved with the windows events observer:
Once the rights fixed, I was able to use the new account.
samedi 8 novembre 2014
mercredi 29 octobre 2014
Setup Apache 2.2 for FastCgi handling of PHP on windows 7
Why ?
Because I used to setup PHP as an Apache Module. But, this morning, after starting my good old 2012 apache2.2 service, it says "mysql driver not installed"! I'm quite sure they were in 2012. In addition, IIS, on the same php.ini, says they are installed. So I try Apache with FastCGI as IIS does. Then, my drivers come back.
We here assume that
Edit httpd.conf as follow:
I'm on a windows 7 64bits professional edition.
Because I used to setup PHP as an Apache Module. But, this morning, after starting my good old 2012 apache2.2 service, it says "mysql driver not installed"! I'm quite sure they were in 2012. In addition, IIS, on the same php.ini, says they are installed. So I try Apache with FastCGI as IIS does. Then, my drivers come back.
We here assume that
- Apache 2.2 is yet installed.
- php5 is in a directory named c:\php-5
Edit httpd.conf as follow:
#LoadModule php5_module "c:/php-5/php5apache2_2.dll"
#AddHandler application/x-httpd-php .php
#PHPIniDir "C:/php-5"
LoadModule fcgid_module modules/mod_fcgid.so
FcgidInitialEnv PHPRC "c:/php-5"
AddHandler fcgid-script .php
FcgidWrapper "c:/php-5/php-cgi.exe" .php
And, to avoid HTTP 403 errors, don't forget ExecCGI in your directory configuration.
By the way, mod_fcgid.so can be found here (http://mir2.ovh.net/ftp.apache.org/dist//httpd/binaries/win32/)Options Indexes FollowSymLinks ExecCGI #...
I'm on a windows 7 64bits professional edition.
lundi 22 septembre 2014
Managing default values for entities in EF II: the just on time way
You probably still know how to create an entity with default values. This is the 'from birth' way.
Well, there is another way to set default values: a 'just on time way'.
The principle is to override the SaveChanges method to explore entities in the tracker to find the one having unset values, just like in the 'from birth way'. Here it is how it can be done.
Before EF6, you may have to look for the tracker in the underlying ObjectContext
A full piece of code:
Well, there is another way to set default values: a 'just on time way'.
The principle is to override the SaveChanges method to explore entities in the tracker to find the one having unset values, just like in the 'from birth way'. Here it is how it can be done.
//the default value for datetime properties
public DateTime DefaultDate { get; set; }
public override int SaveChanges() {
Boolean defaultSet = false;
//seeking only pertinent entities
foreach (DbEntityEntry dbee in ChangeTracker.Entries().
Where(x => x.State != EntityState.Deleted && x.State != EntityState.Detached ) ) {
defaultSet = false;
Object o = dbee.Entity;
Type t = o.GetType();
foreach ( MemberInfo m in t.GetProperties() ) {
PropertyInfo p = t.GetProperty(m.Name);
switch (Type.GetTypeCode(p.PropertyType)) {
case TypeCode.String:
if (p.GetValue(o, null) == null) {
p.SetValue(o, String.Empty, null);
defaultSet = true;
}
break;
case TypeCode.DateTime:
if ((DateTime)p.GetValue(o, null) == DateTime.MinValue) {
p.SetValue(o, DefaultDate, null);
defaultSet = true;
}
break;
}
//update the state if needed
if ( defaultSet ) {
switch ( dbee.State ) {
case EntityState.Unchanged :
dbee.State = EntityState.Modified;
break;
}
}
}
}
return base.SaveChanges();
}
This could be used to implement business rules, such as LastModificationDate.Before EF6, you may have to look for the tracker in the underlying ObjectContext
A full piece of code:
using System;
using System.Linq;
using System.Data.Entity;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Reflection;
using System.Data.Entity.Infrastructure;
namespace testef {
public class Order {
public Int32 Id { get; set; }
public String Title { get; set; }
public virtual ICollection Details { get; set; }
public DateTime OrderDate { get; set; }
public virtual OrderType Type { get; set; }
}
public class OrderType {
public String Code { get; set; }
public String Description { get; set; }
}
public class OrderDetail {
public virtual Order Order { get; set; }
public Int32 Id { get; set; }
public String D { get; set; }
public Boolean IsActive { get; set; }
}
public class OrderDetailConfiguration : EntityTypeConfiguration {
public OrderDetailConfiguration()
: base() {
HasRequired(d => d.Order).WithMany(o => o.Details);
}
}
public class OrderConfiguration : EntityTypeConfiguration {
public OrderConfiguration()
: base() {
HasRequired(d => d.Type).WithMany();
}
}
public class OrderTypeConfiguration : EntityTypeConfiguration {
public OrderTypeConfiguration()
: base() {
Property(x => x.Code).HasColumnType("varchar").HasMaxLength(10);
HasKey(x => x.Code);
}
}
public class TestEFContext : DbContext {
public DbSet Orders { get; set; }
public DbSet Details { get; set; }
public TestEFContext(String cs)
: base(cs) {
Database.SetInitializer(new DropCreateDatabaseAlways());
//Database.SetInitializer(null);
//Database.SetInitializer(new CreateDatabaseIfNotExists());
//Database.SetInitializer(new CustomDataBaseInitializer());
}
protected override void OnModelCreating(DbModelBuilder modelBuilder) {
}
public DateTime DefaultDate { get; set; }
public override int SaveChanges() {
Boolean defaultSet = false;
foreach (DbEntityEntry dbee in ChangeTracker.Entries().
Where(x => x.State != EntityState.Deleted && x.State != EntityState.Detached ) ) {
defaultSet = false;
Object o = dbee.Entity;
Type t = o.GetType();
foreach ( MemberInfo m in t.GetProperties() ) {
PropertyInfo p = t.GetProperty(m.Name);
switch (Type.GetTypeCode(p.PropertyType)) {
case TypeCode.String:
if (p.GetValue(o, null) == null) {
p.SetValue(o, String.Empty, null);
defaultSet = true;
}
break;
case TypeCode.DateTime:
if ((DateTime)p.GetValue(o, null) == DateTime.MinValue) {
p.SetValue(o, DefaultDate, null);
defaultSet = true;
}
break;
}
if ( defaultSet ) {
switch ( dbee.State ) {
case EntityState.Unchanged :
dbee.State = EntityState.Modified;
break;
}
}
}
}
return base.SaveChanges();
}
}
public class CustomDataBaseInitializer : CreateDatabaseIfNotExists {
public CustomDataBaseInitializer()
: base() {
}
}
class Program {
static void Main(string[] args) {
String cs = @"Data Source=ALIASTVALK;Initial Catalog=TestEF;Integrated Security=True; MultipleActiveResultSets=True";
using (TestEFContext ctx = new TestEFContext(cs)) {
ctx.DefaultDate = new DateTime(2000, 1, 1);
OrderType t = new OrderType {
Code = "T1",
Description = "type One"
};
ctx.Orders.Add(new Order {
Title = "first order",
Type = t
});
ctx.SaveChanges();
}
using (TestEFContext ctx = new TestEFContext(cs)) {
Order o = ctx.Orders.First();
Console.WriteLine(o.OrderDate);
}
}
}
}
mardi 9 septembre 2014
Bulleting in MsWord openXml document, using OpenXml SDK: the basics.
As often the most important is the understanding of the model, here of the XML model.
This article is a simplifcation of Working with Numbered Lists in Open XML WordprocessingML.
Remark
If you have a ParagraphProperties at the Paragraph level, the Paragraph stays a bullet (because of Paragraph.NumberingProperties), but the values from Paragraph.ParagraphProperties prevail over those of NumberingProperties.
This article is a simplifcation of Working with Numbered Lists in Open XML WordprocessingML.
- Bulleting is a part of Numbering.
- Numbering is a NumberingProperties (numPr) property in a ParagraphProperties property of a Paragraph from a Document object.
- That is a hierarchy as follow:
<w:document> <w:body> <w:p> <w:pPr> <w:numPr> <w:ilvl>X</w:ilvl> <w:numId val="Y" /> - numId leads to an NumberingInstance (num) in NumberingDefinitionsPart of MainDocumentPart of WordProcessingDocument.
//word/numbering.xml <w:numbering> <w:num w:numId="Y"> <w:abstractNumId w:val="Z" />- abstractNumId leads to a AbstractNum (abstractNum)
//word/numbering.xml <w:numbering> <w:abstractNum w:abstractNumId="Z" > <w:lvl w:ilvl="X"> ... </w:lvl> <w:num w:numId="Y"> <w:abstractNumId w:val="Z" />
Remark
If you have a ParagraphProperties at the Paragraph level, the Paragraph stays a bullet (because of Paragraph.NumberingProperties), but the values from Paragraph.ParagraphProperties prevail over those of NumberingProperties.
mardi 1 juillet 2014
Filter DataGridView out of the DbContext
Imagine you load data into a DataGridView.DataSource from a database.
Then you want to allow end user to filter the results, but without hitting database again.
So you use a TextBox to prompt a filter an, OnTextChanged
Then you want to allow end user to filter the results, but without hitting database again.
So you use a TextBox to prompt a filter an, OnTextChanged
private void tbFilter_TextChanged(object sender, EventArgs e) {
CurrencyManager cm = (CurrencyManager)BindingContext[dgvList.DataSource];
cm.SuspendBinding();
foreach (DataGridViewRow r in dgvList.Rows) {
r.Visible = String.IsNullOrEmpty(tbFilter.Text) || r.Cells[1].Value.ToString().Contains(tbFilter.Text);
}
cm.ResumeBinding();
}
Here the difficulty is the use of a CurrencyManager.
samedi 10 mai 2014
using UserManager/IdentityFramework with an Int32 as TKey for IUser
This article is about how to use Int32 as a key for users in asp.net identity.
First the model. As I seed it, you can also see how to instanciate the UserManage.
For this thank you to SymbolSource and to Microsoft of course!
namespace cclw4c.Models
{
// You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
public class ApplicationUser : IdentityUser <Int32, CustomUserLogin, CustomUserRole, CustomUserClaim>: {
}
public class CustomRole : IdentityRole<Int32, CustomUserRole> {
public CustomRole() { }
public CustomRole(String name) { Name = name; }
}
public class CustomUserRole : IdentityUserRole<Int32> { }
public class CustomUserClaim : IdentityUserClaim<Int32> { }
public class CustomUserLogin : IdentityUserLogin<Int32> { }
public class ApplicationUserDbContext : IdentityDbContext<ApplicationUser, CustomRole, Int32, CustomUserLogin, CustomUserRole, CustomUserClaim>
{
public ApplicationUserDbContext()
: base("ApplicationUser")
{
Database.SetInitializer<ApplicationUserDbContext>(new CreateDatabaseIfNotExistsWithSeedData());
}
}
public class CreateDatabaseIfNotExistsWithSeedData : CreateDatabaseIfNotExists<ApplicationUserDbContext> {
protected override void Seed(ApplicationUserDbContext context) {
base.Seed(context);
var user = new ApplicationUser() { UserName = "root" };
UserManager<ApplicationUser, Int32> am =
new UserManager<ApplicationUser, Int32>(new UserStore<ApplicationUser, CustomRole, Int32, CustomUserLogin, CustomUserRole, CustomUserClaim>(context));
IdentityResult ir = am.Create(user, "******");
if (ir.Succeeded) {
RoleManager<CustomRole, Int32> rm = new RoleManager<CustomRole, Int32>(new RoleStore<CustomRole, Int32, CustomUserRole>(context));
rm.Create(new CustomRole("Root"));
am.AddToRole(user.Id, "Root");
}
}
}
}
Second use Int32.Parse(User.Identity.GetUserId()every where it is needed.
Hightlight on UserManager instanciation
new UserManager<ApplicationUser, Int32>(new UserStore<
ApplicationUser,
CustomRole,
Int32,
CustomUserLogin,
CustomUserRole,
CustomUserClaim
>(context));
jeudi 29 août 2013
Import from excel: the mixed colums issue
From the sas knowledge base I get some usefull information : TypeGuessRows
Basically TypeGuessRows is the number of rows explored by the driver to determine the type of the columns.By default it is set to 8.
I suggest to set it to 0, that is to explore all rows. This may lead to performance issue, but prevents data loss.
According to the cited article the keys are:
Basically TypeGuessRows is the number of rows explored by the driver to determine the type of the columns.By default it is set to 8.
I suggest to set it to 0, that is to explore all rows. This may lead to performance issue, but prevents data loss.
According to the cited article the keys are:
- HKEY_LOCAL_MACHINE/Software/Microsoft/Office/12.0/Access Connectivity Engine/Engines/Excel/TypeGuessRows
- HKEY_LOCAL_MACHINE/Software/Wow6432Node/Microsoft/Office/12.0/Access Connectivity Engine/Engines/Excel/TypeGuessRows
But I also find them :
- HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\14.0\Access Connectivity Engine\Engines\Excel
- HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Jet\4.0\Engines\Excel
The best is to scan the register searching : TypeGuessRows.
Inscription à :
Articles (Atom)
