Unbelievable! After 2 days of research in Microsoft's sites why IE doesn't work the solution was found in non-Microsoft site.
Thank you very much Mr Kai Schätzl!
Link to article
Tuesday, October 15, 2013
Monday, September 30, 2013
How to blink text in all browsers
Javascript:
HTML
Thanks to Steven McConnon
<script type="text/javascript" language="javascript"> window.onload=blinkOn; function blinkOn() { document.getElementById("blink").style.color="Red"; setTimeout("blinkOff()",1000); } function blinkOff() { document.getElementById("blink").style.color=""; setTimeout("blinkOn()",1000); } </script>
HTML
<div id="blink">Hello, World!</div>
Thanks to Steven McConnon
Wednesday, September 18, 2013
Tuesday, February 26, 2013
C# property names without hardcoded strings
public class Person { public int Id { get; set; } public string Name { get; set; } } public class Test { protected void InitDropDownList() { DropDownList ddl = new DropDownList(); ddl.DataSource = new List<Person> { new Person{ Id = 1, Name = "John Smith" }, new Person{ Id = 2,Name = "Moshe Perez" } }; //Old and bad way ddl.DataValueField = "Id"; ddl.DataTextField = "Name"; //New way ddl.DataValueField = GetPropertyName(() => new Person().Id); ddl.DataValueField = GetPropertyName(() => new Person().Name); ddl.DataBind(); } private static string GetPropertyName<T>
(Expression<Func<T>> expression)
{
MemberExpression body = (MemberExpression)expression.Body;
return body.Member.Name;
}
}From here
Wednesday, January 02, 2013
Test value generator
Frequently in the test time required to set random values to variables. The simple class will help you to save a time in the future:
public static class Generator { public static readonly Random RND = new Random(); // Generate IP address public static string GetIP(bool isIPv6 = false) { if (isIPv6) { return string.Format("{0}.{1}.{2}.{3}.{4}.{5}", RND.Next(0,256), RND.Next(0,256), RND.Next(0,256), RND.Next(0,256), RND.Next(0,256), RND.Next(0,256)); } return string.Format("{0}.{1}.{2}.{3}", RND.Next(0,256), RND.Next(0,256), RND.Next(0,256), RND.Next(0,256)); } // Generate GPS coordinate public static System.Device.Location.GeoCoordinate GetGeo() { return new System.Device.Location.GeoCoordinate { Latitude = GetDouble(90), Longitude = GetDouble(90), }; } // Generate string public static string GetString(int size, int percentOfSymbols = 30, int percentOfDigits = 30) { StringBuilder builder = new StringBuilder(); int[] symbol = new[] { 33, 36, 38, 64, 94 }; int[] digits = new[] { 48, 49, 50, 51, 52, 53, 54, 55, 56, 57 }; int symbolsAmount = (int) size * percentOfSymbols /100; int digitAmount = (int)size * percentOfDigits / 100; for (int i = 0; i < size; i++) { int switcher = RND.Next(3); char ch; if (switcher == 0 && symbolsAmount > 0) { int id = RND.Next(symbol.Length); ch = Convert.ToChar(symbol[id]); symbolsAmount--; } else if (switcher == 1 && digitAmount > 0) { int id = RND.Next(digits.Length); ch = Convert.ToChar(digits[id]); digitAmount--; } else { bool isLower = RND.Next(2) == 0 ? false : true; ch = Convert.ToChar( Convert.ToInt32( Math.Floor(26 * RND.NextDouble() + ((isLower) ? 65 : 97)) ) ); } builder.Append(ch); } return builder.ToString(); } // Generate Date public static DateTime GetDate() { return DateTime.Now.AddMinutes( RND.Next(10000000) * (RND.Next() % 2 == 0 ? -1 : 1)); } //Get double public static double GetDouble(int limit = default(int)) { return double.Parse(string.Format("{0}.{1}", limit == default(int) ? RND.Next() : RND.Next(90), RND.Next())) * (RND.Next() % 2 == 0 ? -1 : 1); } }
Sunday, December 23, 2012
Password in SQL
DECLARE @PWD varbinary(128) SELECT @PWD = PWDENCRYPT ( 'password' ) SELECT @PWD -- Correct SELECT PWDCOMPARE('password', @Pwd ) -- 1 -- Failed SELECT PWDCOMPARE('bla-bla-bla', @Pwd ) -- 0
Tuesday, December 18, 2012
Shrink DB log file
USE dbname; GO -- Truncate the log by changing the database recovery model to SIMPLE. ALTER DATABASE dbname SET RECOVERY SIMPLE; GO -- Shrink the truncated log file to 1 MB. DBCC SHRINKFILE (2, 1); -- here 2 is the file ID for trasaction log file,you can also mention the log file name (dbname_log) GO -- Reset the database recovery model. ALTER DATABASE dbname SET RECOVERY FULL; GO
Thanks to Amit kulkarni hubli
Sunday, October 28, 2012
Validation is a boxing value is default
I very like my lovely extension IsDefault but unpossible to use it where a value is boxing. A cool feature of C# default(...) cannot help because a argument required Type. After long research was created small solution:
Also can be implemented as extension.
static bool IsDefault(object o) { if (o == null) { return true; } //Check is type os object is ValueType if (o.GetType().IsValueType) { return Activator.CreateInstance(o.GetType()).Equals(o); } //ReferenceType return false; }
Also can be implemented as extension.
Thursday, October 18, 2012
An error occurred creating the configuration section handler for system.serviceModel/behaviors: Extension element 'XXX' cannot be added to this element. Verify that the extension is registered in the extension collection at system.serviceModel/extensions/behaviorExtensions.
A web.config of project include next rows:
In the start project WCF is throwing exception and message:
"An error occurred creating the configuration section handler for system.serviceModel/behaviors: Extension element 'ELEMENT' cannot be added to this element. Verify that the extension is registered in the extension collection at system.serviceModel/extensions/behaviorExtensions."
A problem exists in file AssemblyInfo of YYY.XXX and not in config.
YYY.XXX change build number in every compilation but WCF is require a full name of assembly (AssemblyQualifiedName) and exact assembly file version number.
Open AssemblyInfo and see last 2 rows:
If a code looks like this:
You not reading current article but if acode looks like this:
This is a time to change it and resolve a problem. Enjoy.
... <extensions> <behaviorExtensions> <add name="ELEMENT" type="YYY.ZZZ,YYY.XXX, Version=1.0.0.0,Culture=neutral, PublicKeyToken=null" /> </behaviorExtensions> </extensions> ... <behavior name="BehaviorName"> ELEMENT /> </behavior>
In the start project WCF is throwing exception and message:
"An error occurred creating the configuration section handler for system.serviceModel/behaviors: Extension element 'ELEMENT' cannot be added to this element. Verify that the extension is registered in the extension collection at system.serviceModel/extensions/behaviorExtensions."
A problem exists in file AssemblyInfo of YYY.XXX and not in config.
YYY.XXX change build number in every compilation but WCF is require a full name of assembly (AssemblyQualifiedName) and exact assembly file version number.
Open AssemblyInfo and see last 2 rows:
[assembly: AssemblyVersion(...)] [assembly: AssemblyFileVersion(...)]
If a code looks like this:
[assembly: AssemblyVersion(5.0.1.0)] [assembly: AssemblyFileVersion(5.0.1.0)]
You not reading current article but if acode looks like this:
[assembly: AssemblyVersion(5.0.1.0)] [assembly: AssemblyFileVersion(5.0.1.*)]
This is a time to change it and resolve a problem. Enjoy.
Sunday, August 12, 2012
Disable the Browser Back Button
if (window.history) {
window.history.forward(1);
}
A script tested in IE 9, Chrome and FireFox.From here
Sunday, August 05, 2012
Culture in .NET. All in one
By inspiration from article Hidden Gems inside .Net Classes I created static class that include short methods for quick retrieval object or properties of Cultures and Time Zones. All data based on build-in functionality of Framework 4.0
public static class Culture { #region Consts private static readonly StringDictionary cultureDetails; private static readonly ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones(); #endregion /// <summary> /// Ctor /// </summary> static Culture() { #region Init culture datails cultureDetails = new StringDictionary(); foreach (CultureInfo cultureInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures)) { RegionInfo regionInfo = new RegionInfo(cultureInfo.Name); if (!cultureDetails.ContainsKey(regionInfo.EnglishName)) { cultureDetails.Add(regionInfo.EnglishName, regionInfo.Name); } } #endregion } /// <summary> /// Get culture name by Country /// </summary> /// <param name="countryName"></param> /// <returns></returns> public static string GetCulture(string countryName) { return cultureDetails.ContainsKey(countryName) ? cultureDetails[countryName] : string.Empty; } /// <summary> /// Get Culture info by culture name /// </summary> /// <param name="cultureName"></param> /// <returns></returns> public static CultureInfo GetCultureInfo(string cultureName) { return CultureInfo.GetCultures(CultureTypes.SpecificCultures).FirstOrDefault(item => item.Name == cultureName); } /// <summary> /// Get month names by culture /// </summary> /// <param name="cultureName"></param> /// <returns></returns> public static string[] GetMonths(string cultureName) { var region = GetCultureInfo(cultureName); return region == null ? null : region.DateTimeFormat.MonthNames; } /// <summary> /// Get day names by culture /// </summary> /// <param name="cultureName"></param> /// <returns></returns> public static string[] GetDays(string cultureName) { var region = GetCultureInfo(cultureName); return region == null ? null : region.DateTimeFormat.DayNames; } /// <summary> /// Get first day of week by culture /// </summary> /// <param name="cultureName"></param> /// <returns></returns> public static DayOfWeek GetFirstDayOfWeek(string cultureName) { var region = GetCultureInfo(cultureName); return region == null ? default(DayOfWeek) : region.DateTimeFormat.FirstDayOfWeek; } /// <summary> /// Get datetime format by culture /// </summary> /// <param name="cultureName"></param> /// <returns></returns> public static string GetDateTimeFormat(string cultureName) { var region = GetCultureInfo(cultureName); return region == null ? string.Empty : region.DateTimeFormat.FullDateTimePattern; } /// <summary> /// Get TimeZone info by DisplayName /// </summary> /// <param name="displayName"></param> /// <returns></returns> public static TimeZoneInfo GetTimeZoneByDisplayName(string name) { return timeZones.FirstOrDefault(item => item.DisplayName == name); } /// <summary> /// Get TimeZone info by Standart Name /// </summary> /// <param name="displayName"></param> /// <returns></returns> public static TimeZoneInfo GetTimeZoneByStandartName(string name) { return timeZones.FirstOrDefault(item => item.StandardName == name); } }
Tuesday, May 15, 2012
Caching in WCF
Full article exists HERE
Sunday, January 22, 2012
Schedule Daily backup of database in MS-SQL Server 2008
1. Open Management Studio.
2. Under "Mangement" select Maintenance Plans.
3. Right click and choose New Plan (it will ask for name).
4. Double click on Subplan_1 and change it to your name.
5. Drag from toolbox "Back Up Database Task" control.
6. Right click on it and choose Edit.
7. Choose Backup Type, Databases and change more fields.
8.OK
9. Click on Job Schedule (in end of row) and set backup date/time.
10. Save plan.
11. Under "Mangement" right click on your job and choose "Execute" for validation.
Enjoy!
2. Under "Mangement" select Maintenance Plans.
3. Right click and choose New Plan (it will ask for name).
4. Double click on Subplan_1 and change it to your name.
5. Drag from toolbox "Back Up Database Task" control.
6. Right click on it and choose Edit.
7. Choose Backup Type, Databases and change more fields.
8.OK
9. Click on Job Schedule (in end of row) and set backup date/time.
10. Save plan.
11. Under "Mangement" right click on your job and choose "Execute" for validation.
Enjoy!
Thursday, January 19, 2012
Wednesday, January 18, 2012
Tuesday, November 08, 2011
Installing and Running IIS and Apache Server Together
We working on project that include web application based on python and several application based on IIS (as WCF , Web application, web site ant etc'). "Python" application use port 80 therefore we cannot use same port in IIS application. HERE was explained solution that based on 2 IP addresses.
p.s. One more note: you must run command prompt as administrator.
p.s. One more note: you must run command prompt as administrator.
Tuesday, September 06, 2011
"The specified metadata path is not valid." error in using Windows Service and Entity Framework
I have project (Windows Service) that use Entity Framework model as external DLL.
I cannot use a metadada as embedded resource and must define connection string in config file of Windows Service. In the Debug mode I got right result, I created setup project and installed service in directory but a immediately I saw the next error:
Where you use Entity Framework you must to define row as this one:
This is a way to define relative path of Service as installed directory.
Enjoy!
I cannot use a metadada as embedded resource and must define connection string in config file of Windows Service. In the Debug mode I got right result, I created setup project and installed service in directory but a immediately I saw the next error:
The specified metadata path is not valid. A valid path must be either an existing directory, an existing file with extension '.csdl', '.ssdl', or '.msl', or a URI that identifies an embedded resource.I'll not tell you what I not tried and a solution was found after deep research in order to understand where is run Windows Service. Bad news! Windows Service not run in installed directory therefore all path's to files in config file must be define as physical path otherwise application cannot find it. Windows service use relative path different to installation directory.
Where you use Entity Framework you must to define row as this one:
...metadata=.\ServiceModel.csdl|.\ServiceModel.ssdl|.\ServiceModel.msl...In order to not change path to physical path just add next row in event OnStart in Windows Service:
System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);
This is a way to define relative path of Service as installed directory.
Enjoy!
Subscribe to:
Posts (Atom)