• A Day Late and a Property Declaration Short

    I know this is a bit late to the game, but this morning, as I’m refactoring a bunch of old code to be shared with a new project, I’m cleaning up the C# 2.0 property declarations we all know and love:

        public class SaleResponse : Response
        {
            protected bool _addressVerificationSuccess;
            public virtual bool AddressVerificationSuccess
            {
                [DebuggerStepThrough]
                get { return _addressVerificationSuccess; }
                [DebuggerStepThrough]
                set { _addressVerificationSuccess = value; }
            }
    
            protected bool _cvvVerificationSuccess;
            public virtual bool CvvSuccess
            {
                [DebuggerStepThrough]
                get { return _cvvVerificationSuccess; }
                [DebuggerStepThrough]
                set { _cvvVerificationSuccess = value; }
            }
    
            protected string _authorizationCode = string.Empty;
            public virtual string AuthorizationCode
            {
                [DebuggerStepThrough]
                get { return _authorizationCode; }
                [DebuggerStepThrough]
                set { _authorizationCode = value; }
            }
    
            protected string _referenceNumber = string.Empty;
            public virtual string ReferenceNumber
            {
                [DebuggerStepThrough]
                get { return _referenceNumber; }
                [DebuggerStepThrough]
                set { _referenceNumber = value; }
            }
    
            protected decimal? _authorizedAmount;
            public virtual decimal? AuthorizedAmount
            {
                [DebuggerStepThrough]
                get { return this._authorizedAmount; }
                [DebuggerStepThrough]
                set { this._authorizedAmount = value; }
            }
        }

    This code is, of course because I wrote it, wonderful and has no flaws, and I used the prop snippet to create the private variable and public property getter and setter. However, I have all those DebuggerStepThrough attributes in there, due to the lovely fun of stepping through code that references properties. That avoids stepping in and out of the property declarations.

    Thank the flying spaghetti monster that now, in C# 3.0 (and of course 3.5, 4.0 and on), Microsoft has given us auto-implemented properties. This is now the equivalent code, avoiding the stepping in/out of the get/set and not requiring the declaration of a private variable:

        public class SaleResponse : Response
        {
            public virtual bool AddressVerificationSuccess { get; set; }
            public virtual bool CvvSuccess { get; set; }
            public virtual string AuthorizationCode { get; set; }
            public virtual string ReferenceNumber { get; set; }
            public virtual decimal? AuthorizedAmount { get; set; }
        }

    When I first learned this trick, I was extremely thankful to be able to do this as an even shorter shortcut to using the prop snippet and it makes the code a lot prettier. What I didn’t immediately realize is how to control scoping. Let’s say, for instance, I want that AuthorizationCode property to only be able to be set from inside the class itself, and I only want the AuthorizedAmount property to be able to get set from inside the class and inherited classes. I can then change those declarations like this:

        public class SaleResponse : Response
        {
            public virtual bool AddressVerificationSuccess { get; set; }
            public virtual bool CvvSuccess { get; set; }
            // This can now only be set from inside the class
            public virtual string AuthorizationCode { get; private set; }
            public virtual string ReferenceNumber { get; set; }
            // This can now only be set from inside the class and those that inherit from it
            public virtual decimal? AuthorizedAmount { get; protected set; }
        }

    This allows you to control the scoping of the getter and setter independently. By default, they inherit the visibility of the property declaration, in this case, public for all. I’m always thankful for the tools Microsoft gives me to make my life easier and to give me more time to spend on the actual work, rather than installing plumbing.


  • It’s Really Hot… Inside

    Yesterday, it got up to 93 degrees (Fahrenheit) in our office and I actually started sweating. Now I know how Joan of Arc felt when she was being burned alive at the stake. The air conditioner went out Tuesday (6/30/2009) and they just got the part(s) in today (7/2/2009) to fix it. What follows is what I like to believe is at least a good a version as Boston Globe’s Big Picture of our harrowing experience.

    89 at One End of the Hall

    92 at the Other End of the Hall

    It's really hot

    All Kinds of Fans at the Other End of the Hall

    Dave's Fan

    The "King of Fans" (brand name)

    Now I’ve gotten my pictures out to the world at large. It is similar to what the Iranians are having to do since the election. Thanks Pete Hoekstra!


  • Out of Memory Exception While Attempting to Do SQL CLR

    Update: We figured out how to make it work with the help of our DBA and Jonathan Kehayias (see comments). We increased SQL Server’s MEM_TO_LEAVE property, by adjusting the –g command line switch for the service, to 448MB. This increase of the shared memory pool gave SQL Server enough breathing room for its worker threads, and now we are able to return 1536 records in 1 minute 21 seconds, including the Bitmap conversion.

    Furthermore, we found a workaround using our reporting engine, which we will implement when we have some breathing room ourselves in our rollout timeline. This will “get it working” for now, which is the requirement handed down from above. Soon though, we will have this working in our application tier, where it belongs.

    SQL Server’s CLR abilities are really cool. I have done some benchmarking, performing the same computations in both T-SQL and CLR and I have found CLR to outperform T-SQL by factors of greater than 10 to 1. It’s fantastic for this use.

    Unfortunately, it has won a battle against me today. I’ll provide a bit of background first. I am currently working on the Point of Sale component of my company’s pharmacy system, and in particular, I am writing all of the code associated with interacting with the signature pad. I’ve abstracted everything nicely, such that we can support multiple pad’s, and I just have to write a .Net class that implements the ISignaturePad interface.

    Obviously, other than the navigational aspects of buttons and listboxes and sale line items being displayed on the pad, capturing signatures themselves is paramount. Because each signature pad can spew out the signature data in a different way, and we want to store the “perfect” vector information, I’ve abstracted the signature data into two classes. The Signature and SignaturePoint classes’ definitions look like this:

        [Serializable]
        public partial class Signature
        {
            public virtual SignaturePoint[] Points { get; protected set; }
            public virtual SignaturePoint TopLeft { get; set; }
            public virtual SignaturePoint BottomRight { get; set; }
            public int Width
            {
                get
                {
                    return BottomRight.X - TopLeft.X;
                }
            }
            public int Height
            {
                get
                {
                    return BottomRight.Y - TopLeft.Y;
                }
            }
            public int XDpi { get; set; }
            public int YDpi { get; set; }
    
            private Signature()
            {
            }
    
            public static Signature CreateFromTT8500String(string signaturePoints)
            {
                var sig = new Signature();
                sig.Points = sig.CreateFromTT8500PointsData(signaturePoints);
                return sig;
            }
    
            public virtual byte[] Serialize()
            {
                using (var ms = new MemoryStream())
                {
                    var bf = new BinaryFormatter();
                    bf.Serialize(ms, this);
                    return ms.ToArray();
                }
            }
    
            public static Signature Deserialize(byte[] serializedSignatureBytes)
            {
                using (var ms = new MemoryStream(serializedSignatureBytes))
                {
                    var bf = new BinaryFormatter();
                    return (Signature)bf.Deserialize(ms);
                }
            }
    
            protected virtual SignaturePoint[] CreateFromTT8500PointsData(string signaturePoints)
            {
                List list = new List();
    
                // Do a lot of work here to change the strange format that we get
                // as a string into bytes and transform them into an array of my custom class
    
                return list.ToArray();
            }
    
            protected void CropPoints(List list)
            {
                foreach (var point in list)
                {
                    point.X -= TopLeft.X;
                    point.Y -= TopLeft.Y;
                }
    
                BottomRight.X -= TopLeft.X;
                BottomRight.Y -= TopLeft.Y;
                TopLeft.X = 0;
                TopLeft.Y = 0;
            }
        }
    
        [Serializable]
        public class SignaturePoint
        {
            public int X { get; set; }
            public int Y { get; set; }
            public bool PenUp { get; set; }
    
            public SignaturePoint()
            {
            }
    
            public SignaturePoint(int x, int y)
                : this(x, y, false)
            {
            }
    
            public SignaturePoint(int x, int y, bool penUp)
                : this()
            {
                X = x;
                Y = y;
                PenUp = penUp;
            }
    
            public Point ToPoint()
            {
                return new Point(X, Y);
            }
    
            public override string ToString()
            {
                return ToPoint().ToString();
            }
        }

    As you might have noticed, Signature is marked as Serializable, and that’s exactly what we’re doing to store the “perfect” information in the database. We call the Serialize() method on my Signature class, and store the resulting byte array in the database as VARBINARY(MAX). It works fine when we pull that back with ADO.NET and re-hydrate a Signature object with my static Deserialize() method.

    To actually draw a signature on a picture box on a Windows form for example, we call my ToBitmap() method, that is in another file (partial class), and it generates a bitmap of the requested width, height, and pen width, suitable for display on a receipt, screen, report, etc.

    However, as a limitation of our ridiculous reporting engine (and we are currently trying to work around it’s oddities), for an upcoming beta, we are trying to get SQL server to create the bitmaps for passing back up to our reporting engine. Yes, I do know that is application tier logic and shouldn’t be performed at the database level. We are still trying to work around it using custom controls with the reporting engine.

    So, I create a SQL CLR scalar function in my Signature class (SqlBytes CreateBitmap(SqlBytes serializedSignatureBytes, SqlInt32 width, SqlInt32 height)), moved Signature and SignaturePoint to a CompanyName.SignaturePad.Common assembly, added a reference to System.Drawing. I added the assembly to SQL Serverand fought it a bit (setting TRUSTWORTHY to ON for the database). I had to manually add System.Drawing as well, because the version on my computer didn’t match exactly on the server, yet another pain and indication I shouldn’t be doing this. And another indication was SQL server warning me that System.Drawing hadn’t been tested and that the universe will indeed explode if they change something in it. I accept the risks, at the moment.

    Everything worked great… for 3 signatures. As soon as the 4th signature is added, I get this:

    Msg 6532, Level 16, State 49, Line 1
    .NET Framework execution was aborted by escalation policy because of out of memory.
    System.Threading.ThreadAbortException: Thread was being aborted.
    System.Threading.ThreadAbortException:
       at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
       at System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y, Int32 width, Int32 height)
       at CompanyName.SignaturePad.Common.Signature.ToBitmap(Int32 width, Int32 height, Int32 penWidth, Color foregroundColor, Color backgroundColor)
       at CompanyName.SignaturePad.Common.Signature.ToBitmap(Int32 width, Int32 height)
       at CompanyName.SignaturePad.Common.Signature.CreateBitmap(SqlBytes serializedSignatureBytes, SqlInt32 width, SqlInt32 height)

    Looking at that code, I’m doing everything that I know to do. I’m making sure to Dispose() all Bitmaps, Graphics, Streams, etc. I even tried explicitly setting this to null. SQL Server just runs out of memory after about 3 signatures. I’m not sure if this is a side effect of its execution plan (perhaps forking to multiple workers?).

    So… now I’m stuck, and I’m not really sure what to do, until we get a workaround in the reporting engine, which someone else is currently working on. I’ll update this post if we get a working solution.


  • The Law of Circle K Registers

    Circle K LineCircle K always has way more employees working at any given time than the number of registers open. I believe they pride themselves on how long they can back the line up at the register. There were four employees there today, including the manager. I took the picture at the right today! I complained to him and asked him to open another register. He said it was shift change time and that they had to keep one register closed. The only problem with this is that it is always shift change time.

    Chris Leon and I go often for ICEE time, and at different times of the work day, but we’ve always run into this, and we came up with The Law of Circle K Registers:

    1. Let n = number of Circle K employees on the clock
    2. Let r = number of Circle K registers open
    3. n >= 2r + 1

    It’s really annoying, and I wish there was a Valero near my work.


  • Comcast’s New Network Management Technique: Protocol Agnostic

    comcastlogo I got an email from Comcast titled "Improving Your Online Experience Through Congestion Management". After my previous experiences I’ve had with Comcast lately, I thought "great, now they’re going to screw over my bandwidth too". Generally, I’m pretty satisfied with their Internet service, even though their TV service sucks. I actually like their Powerboost, and I don’t think I’m paying too much money for the service.

    The email had no details in it whatsoever, and the FAQ said (emphasis mine):

    [The technique] will identify which customer accounts are using the greatest amounts of bandwidth and their Internet traffic will be temporarily managed until the period of congestion passes.

    The "managed" bit scared me a little bit. Saying you’re going to "manage" me for downloading too much sounds a bit like you’re going to send a hit man to my house to take me out. I decided to dig further and noticed they had a link to documents the filed with the FCC at the top right of the Comcast network management page. I had to read through 20 pages of boring crap, which is probably actually necessary to explain simple concepts to the FCC, in order to figure out exactly what this technique employs as its counter-congestion tactics.

    I plan to explain, in simple terms, how the new management technique works. Please ask any questions in the comments section.

    The important thing to realize about the new technique versus the old technique is that the new technique is protocol agnostic, meaning it doesn’t discriminate against certain kinds of traffic versus other types. For example, it doesn’t prioritize web surfing or VoIP calling above using BitTorrent to download the latest blockbuster movie *cough* Linux distribution release.

    Users hated Comcast for the previous incarnation of their network management, and the FCC forced them to stop it and come up with another protocol agnostic scheme. What they ended up with, is in my opinion, a fair process that doesn’t penalize anyone unless the network is in serious danger of being degraded, and even then, doesn’t actually do anything until it actually is degraded. I am, in a word, satisfied.

    All information and pictures that follow are from Comcast’s document and are probably copyrighted by Comcast, even though they were submitted to the FCC. I have a reasonable basis to believe I can reproduce this information for informative purposes.

    Comcast Network Design First, you must understand how your home cable connection reaches the Internet. Your home coax (screw on cable that connects to your modem) connects to an optical node in your neighborhood area, which then connects to a CMTS (Cable Modem Termination System) at the headend (local office), which then connects to a series of routers and finally to Comcast’s Internet backbone connections.

    Each of the CMTS boxes have a number of ports on them, with separate ports for downstream (stuff you download) and upstream (stuff you upload back to the Internet). Comcast says that there are about 275 cable modems, on average, sharing a downstream port, and about 100 sharing an upstream port. Your cable modem has what is called a "bootfile" which is assigned by the DOCSIS protocol on startup. The bootfile contains a lot of information about your cable service, perhaps most importly, how fast you can download/upload.

    The traffic management occurs based on activity at the CMTS ports and is actually applied with a combination of flags set on your cable modem and those flags being processed on Comcast’s routers.

    Comcast Upstream Congestion Management Decision Flowchart The process is really quite simple. Here’s how it works:

    1. Each port (keeping in mind it is either upload or download) is monitored independently.
    2. Each cable modem has a flag for its current state
      1. PBE – Priority Best Effort. The default state.
      2. BE – Best Effort. A lower priority state. PBE traffic is prioritized below BE.
    3. If a port reaches "Near Congestion State", which means that it has average over a certain threshold of utilization over a 15 minute period, network management will commence.
      1. Downstream threshold: 80% utilization
      2. Upstream threshold: 70% utilization
    4. The network searches for users on that CMTS port that are in an "Extended High Consumption State", which means they have averaged over a certain threshold of utilization over a 15 minute period.
      1. The user’s modem is set to BE.
      2. Downstream and upstream threshold: 70% utilization
    5. The network keeps the user in "Extended High Consumption State" until the user’s average utilization has dropped below the threshold for 15 minutes
      1. User’s modem is set back to PBE.
      2. Downstream and upstream threshold: 50% utilization
    6. When in the BE state, all PBE traffic will be processed by the Comcast Internet routers before the BE traffic, regardless of the type of traffic, however the likelihood of it reaching a congested status is very low, and even in that case, the probability of dropped traffic is even lower.

    This means, while doing my large USENET downloads, if the network is in danger of being congested, I’ll likely be set to BE. However, Comcast has been using several trial markets with this new technique, and they have this to say:

    For example, in Colorado Springs, CO, the largest test market, on any given day in August 2008, an average of 22 users out of 6,016 total subscribers in the trial had their traffic priority status changed to BE at some point during the day.

    NetForecast, Inc. explored the potential risk of a worst-case scenario for users whose traffic is in a BE state:  the possibility of “bandwidth starvation” in the theoretical case where 100 percent of the CMTS bandwidth is taken up by PBE traffic for an extended period of time.  In theory, such a condition could mean that a given user whose traffic is designated BE would be unable to effectuate an upload or download (as noted above, both are managed separately) for some period of time.  However, when these management techniques were tested, first in company testbeds and then in our real-world trials conducted in the five markets, such a theoretical condition did not occur.

    Comcast High Level Managemetn Flows

    I think it’s a very sane system, and I hope they continue to add bandwidth so that the network doesn’t get congested in the first place. However, I think this system is very fair, and a lot better than the previous one.

    Below, I reproduce the original email they sent me:

    (more…)


  • Comcast Sucks and is the Worst Company Ever

    comcastlogo I really hate Comcast, a lot. I hated them before, and I hate them more now. Before anyone tells me to, I’m going to send this to Comcast Frank (comcastcares) when I’m finished.

    All I wanted to do was get the hours of the local office, but you can’t get that on their web site, because they have no "Store Locator" type function that every other business has. I thought I’d do the live chat option to find the information, but knowing the problems that my coworker Dave Anderson had trying to get the phone number for the local office before, I was very specific.

    I ended up spending 32 minutes, more than half and hour, and ended up with nothing to show for it. They first gave me the address of a grocery store that hasn’t dealt with Comcast in over 5 years and then gave me the address of a shopping center in Shreve City that has no Comcast there. I’m not sure what business they intended me to contact.

    Then, amazingly, they gave me the same information for Thrifty Liquor that they gave Dave before, except this time, I noticed they’re not giving the name of the business where they’re referring you anymore. Way to go on the changes Frank!

    She then tried to get me to leave the chat by telling me to call the "local" number because she’s in Canada. She gave me the wrong number to the local office, giving me an "out of service" message! Ridiculous! I knew far more about the cable locations and numbers than she did, which isn’t saying much.

    The reason I’m returning 3 cable boxes in the first place and canceling all of the digital cable is because of the absolutely horrible "SARA" software they put on the Comcast DVRs. The old "Passport" software wasn’t exactly TiVo, but it was completely usable, and actually intuitive. The new software "looks like an old Nintendo game" (actual quote), according to my girlfriend, and I completely agree.

    My father hates SARA. My mother hates SARA. All of my coworkers hate SARA. Two of my coworkers are canceling cable for their household because of SARA. Everyone I know hates SARA, but according to Comcast Frank, it’s here to stay, because of some contractual agreement with TV Guide.

    If you’d like to read the absolutely excruciating transcript with their support agent that took me over 32 minutes to make it through, please read on. She did end it with an amusing mistake: "I do apologize for the Chris."

    (more…)


  • Wesla’s Bank Network is Down

    Update: It’s back up, 24 hours later, but the auto payment still isn’t posted.

    wesla I use Wesla Federal Credit Union as my credit union. I don’t actually use it as my primary checking anymore, although I used to. Today when I tried to login, I was greeted with what you see on the right:

    "Could not retrieve your information… Please try again later."

    All I wanted to do was check to see if they had applied my auto loan payment I mailed Saturday. Well, I thought perhaps their online system was down or having trouble connecting to their database, and I couldn’t remember my "Touch Tone Teller" PIN to check via phone, so I called and pressed the option to speak with a loan officer.

    The conversation went something quite similar to this:

    Me: Are you having an issue with your online banking? When I log in it says "Could not retrieve your information… Please try again later."

    Lady: Yes, our network is down right now.

    Me: Oh, ok. I just wanted to see if my auto loan payment that I mailed Saturday has been applied. Can you check for me?

    Lady: I can’t check that. Our entire network is down so I can’t access anything on the computer.

    Me: …

    Me: …

    Me: So if I wanted to come take my money out of the bank right now, could I?

    Lady: You can withdraw $200. That’s the limit.

    Me: Um, ok. Thanks. *click*

    That doesn’t make me too confident in their ability to do business, but I just use them for a low interest auto loan right now, on which I’m making very successful, long strides in paying off early.

    In other news, my boss is taking Chris Leon and me to lunch tomorrow at Red Lobster! Yay! I love their cheese biscuits!


  • What Are These Ugly Bugs in Shreveport?

    Ugly Bug

    Update 2: The local news covered it.  More gross!

    Update: Kevin Messenger, my coworker, commented and said that they are Mayflies!  Gross!

    What are all these ugly bugs in Shreveport? They were all over our stairs this morning, completely covering them at work.  Jenny’s girlfriend said that when she was crossing the bridge into Bossier City,Ugly Bug the bridge was covered with them.

    What are they? They’re ugly and they were acting like they were dying on the stairs, flapping their little wings.  I’m creeped out by them.  What is this fuzzy bugEverybody knows birds can’t talk.

     


  • Do You Have a Job???

    Those radio commercials are pretty ubiquitous.  Every car dealership wants to know:

    Do you have a job??? Do you have $149??? Then you could be approved for a brand new Kia from Elkins Kia!

    What occurred to me the other day was that a person that doesn’t have one or both of those might get upset at having the radio rub it in their face.  That cracked me up in the car on the way home, and I thought I’d share it here.  Imagine the following:

    Radio: Do you have a job???
    Person: No…
    Radio: Do you have $149???
    Person: No… I just said I don’t even have a job.
    Radio: Then you could be approved!…
    Person: Sigh.

    I know that blog post was of little substance, but it still amused me, and as Chris and I always say, something is always better than nothing.


Posts navigation