Monday, August 29, 2011 11:15:00 AM
I had to escape the text inside of the styling generated by AJAX HTMLEditor that was getting displayed by qTip. If I did not escape the data it would break the jQuery code if there were apostrophies or any other special characters. There may be some bugs here...
private string EscapeData(string data)
{
int a,b,last;
string r=string.Empty;
a = 0;
last = 0;
do
{
a = data.IndexOf('<', a);
if (a == -1)
{
if (string.IsNullOrEmpty(r))
return System.Security.SecurityElement.Escape(data);
else
return r + System.Security.SecurityElement.Escape(data.Substring(last));
}
b = data.IndexOf('>', a);
r += System.Security.SecurityElement.Escape(data.Substring(last, a - last)) + data.Substring(a, b - a + 1);
last = b+1;
}while(true);
}
Sunday, July 17, 2011 8:01:00 AM
I was having some issues with rebuilding indexes where it was blocking. The code I found on the database to do this was rebuilding every table with a cursor on sys.tables. Guessing this was blocking the whole system (Rebuilding every table and the cursor on sys.tables) I did some reading up.
I came up with this script:
DECLARE @TableName VARCHAR(255), @IndexName VARCHAR(255), @Frag int
DECLARE @sql NVARCHAR(500)
DECLARE @fillfactor INT
SET @fillfactor = 80
DECLARE @Tables TABLE (TableName varchar(255))
DECLARE @Indexies TABLE (IndexName varchar(255), Frag int)
INSERT INTO @Tables
SELECT OBJECT_SCHEMA_NAME([object_id])+'.'+name AS TableName
FROM sys.tables
DECLARE TableCursor CURSOR FOR
SELECT TableName
FROM @Tables
OPEN TableCursor
FETCH NEXT FROM TableCursor INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO @Indexies
SELECT name as IndexName, avg_fragmentation_in_percent as Frag
FROM sys.dm_db_index_physical_stats (DB_ID(), OBJECT_ID(@TableName),
NULL, NULL, NULL) AS a
JOIN sys.indexes AS b ON a.object_id = b.object_id AND a.index_id = b.index_id
WHERE avg_fragmentation_in_percent >5;
DECLARE Indexies CURSOR FOR
SELECT IndexName, Frag
FROM @Indexies
OPEN Indexies
FETCH NEXT FROM Indexies INTO @IndexName, @Frag
WHILE @@FETCH_STATUS = 0
BEGIN
Print @TableName
Print @IndexName
Print @Frag
IF @Frag> 30
BEGIN
SET @sql = 'ALTER INDEX '+@IndexName+' ON ' + @TableName + ' REBUILD WITH (FILLFACTOR = ' + CONVERT(VARCHAR(3),@fillfactor) + ')'
PRINT @sql
EXEC (@sql)
END
ELSE
BEGIN
SET @sql = 'ALTER INDEX '+@IndexName+' ON ' + @TableName + ' REORGANIZE '
PRINT @sql
EXEC (@sql)
END
FETCH NEXT FROM Indexies INTO @IndexName, @Frag
DELETE FROM @Indexies
END
CLOSE Indexies
DEALLOCATE Indexies
FETCH NEXT FROM TableCursor INTO @TableName
END
CLOSE TableCursor
DEALLOCATE TableCursor
GO
Runs in no time...
Friday, October 22, 2010 12:58:00 PM
While working with WCF I had to call my own service with multiple threads finding that only 2 would work. After that I would get timeouts. To break the 2 limit do the following on the client in the web.config.
Error:
Error - The request channel timed out while waiting for a reply after 00:00:05.7034725. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout.
Solution in Web.Config of Client:
<system.net>
<connectionManagement>
<add address="*" maxconnection="50"/>
</connectionManagement>
</system.net>
Monday, September 20, 2010 4:27:00 PM
0So you want to know if a process is running...
using System.Diagnostics;
public static bool IsProcessAlreadyRunning()
{
Process currentProcess = Process.GetCurrentProcess();
List<Process> processes = Process.GetProcesses().Where(x=>x.ProcessName == currentProcess.ProcessName).ToList<Process>();
return (processes.Count > 1);
}
Monday, June 28, 2010 5:54:00 PM
Took me a few hours and reading a few posts until I got this working. It seems that you must have the service published on HTTP even if you require HTTPS.
<system.serviceModel>
<serviceHostingEnvironmentaspNetCompatibilityEnabled="false" />
<services>
<servicename="Xxxx.API.Order.Sale"behaviorConfiguration="Xxxx.API.Order.SaleBehavior">
<host>
<baseAddresses>
<addbaseAddress="https://zzzz.com/xxxxapi_wcf"/>
</baseAddresses>
</host>
<!-- Service Endpoints -->
<endpointaddress="https://zzzz.com/xxxxapi_wcf/xxxx.svc"binding="wsHttpBinding"bindingConfiguration="HttpsBinding"contract="Xxxx.API.Order.ISale">
<dnsvalue="zzzz.com"/>
</identity>
</endpoint>
</service>
</services>
<bindings>
<wsHttpBinding>
<bindingname="HttpsBinding">
<securitymode="Transport">
<transportclientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behaviorname="Xxxx.API.Order.SaleBehavior">
<serviceMetadatahttpsGetEnabled="true"httpGetUrl="http://zzzz.com/xxxxapi_wcf/xxxx.svc/mex"httpsGetUrl="https://zzzz.com/xxxxapi_wcf/xxxx.svc/mex"httpGetEnabled="true"/>
<serviceDebugincludeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Wednesday, June 02, 2010 9:39:00 AM
So I had to do manipulate data to a PHP app that needed to be pack("H*",...) in the PHP world. After a lot of digging I found
public static byte[] PackH(string hex)
{
if ((hex.Length % 2) == 1) hex += '0';
byte[] bytes = new byte[hex.Length / 2];
for (int i = 0; i < hex.Length; i += 2)
{
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
}
return bytes;
}
Friday, September 18, 2009 12:30:00 PM
Most complete email regex I have found...
It is adaptaion of RFC 2822 from (http://www.regular-expressions.info/email.html) to allow upper & lower case & not allow comma
RegexStringValidator x = new RegexStringValidator("(?:[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x7f\x2c]|\\[\x01-\x09\x0b\x0c\x0e-\x7f\x2c])*\")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f\x2c]|\\[\x01-\x09\x0b\x0c\x0e-\x7f\x2c])+)\\])");
Saturday, September 05, 2009 4:29:00 PM
So I needed to create an audit trail on SQL with ASP_NET authentication. I did some digging and came up with:
http://www.simple-talk.com/sql/database-administration/pop-rivetts-sql-server-faq-no.5-pop-on-the-audit-trail/
http://www.auditdatabase.com/Downloads.html
I took the code from AuditDatabase.com and made some changes.
You can find it all in the downloads area: http://www.nuronconsulting.com/File-Download.aspx in the SQL folder Auditing.
There is also a script there that will generate the triggers for this.
Tuesday, August 18, 2009 8:19:00 AM
I was having a hard time finding a way to calculate holidays. I put together some things I found on the web and came up with Holidays.cs It provides a way to easily get US & Jewish holidays if you are working in C# or VB.NET.
Enjoy! & here is the file.