Monday, October 26, 2009

Dynamically position a Flex popup relative to a button mouse click

I was having trouble with positioning a wide popup window that was in a component nested several containers deep.  The PopUpManager.centerPopUp method would center on the container and push the window off the right edge of the screen.  To correct this, I moved the popup over 100 pixels using:

popup.x = popup.x – 100;

That worked, but the problem would come back if the window grew wider.  Bush league.  To make it a bit more reliable, I changed to use the mouseEvent localX/Y properties.  Note you have to convert the “local” coordinates to “global”:

 

      private function showPopup(event:MouseEvent):void

        {

            pop = EnotaryRegReturnPopup(PopUpManager.createPopUp(this,EnotaryRegReturnPopup,true));

            pop.title = "Please select return reasons.";

            pop.showCloseButton =true;

            pop.enotaryRegReturnList = this.enotaryRegReturnList;

            pop.buildUnselectedReturns();

           

                  // position the window next to the "add" button

            var pt:Point = new Point(event.localX, event.localY);

            pt = event.target.localToGlobal(pt);

            pop.x = pt.x - pop.width;

            pop.y = pt.y;

           

            pop.addEventListener("close",removeMe);

            pop["cancelButton"].addEventListener("click", removeMe);

            pop["okButton"].addEventListener("click",processReturns);

        }

 

 

Monday, October 5, 2009

Delete rows from DataTable using DataRow

I was surprised by the delete functionality in DataTable.  It was my understanding that when you call DataRow.Delete it marks the row for deletion, but waits for a DataTable.AcceptChanges call before actually removing them, but when I tried to delete inside a For Each dr as DataRow in dt.Rows I was getting an error “Collection was modified”.  Thankfully I ran across a thread that suggested walking backwards through the collection to avoid those types of errors.  I ended up with this to solve my problem:

 

        Do While i >= 0

            If dt.Rows(i)("KEEP_ME"))) = False Then dt.Rows(i).Delete()

            i -= 1

        Loop

        dt.AcceptChanges()

 

 

Monday, September 28, 2009

DOS BAT File Copy Rename with String Manipulation

I needed to rename a directory of files to truncate the file names to the first 5 characters (plus the file extension).  I found one example that showed how two write a FOR loop that broke out the filename and extension and passed it to a second BAT file:

for /f %%a IN (’dir /b *.txt’) do call runner.bat %%~na %%~xa

And using a second example that covered DOS string manipulation, I put together this batch file that accepts two parameters and does a substring to get the first 5 characters of the first parameter:

set file=%1
set file=%file:~0,5%
ren %1%2 %file%%2

 

Thursday, September 17, 2009

Creating an Asynchronous ASP.NET Page To Initiate Batch Processes

I recently created a page that gave the user the option of initiating a long-running batch process.  The batch required repeatedly calling external web services that would have taken far too long for a user to wait for the traditional page processing model.  But, by using ASP.NET asynchronous execution to initiate the batch process on a separate thread, the page response is excellent.  I started by working through this excellent tutorial on asynchronous execution, but quickly ran into problems when I began calling web services.  Creating an asynchronous process involves writing a method that can execute without needing anything from the HttpContext (Application, Page, Session, Cache, Configuration, etc.) since this is not available when you use BeginInvoke to run your subroutine.  This presented me with an issue since my project had a library that we used to setup web service instances (with WSE security), but that library relied on the HttpContext’s Application object.  To work around this limitation, I created a private inner class that encapsulated the web service references. 

    Private Class WebSvcInstances

        Public FSI As MyWseSVc1 = GetMyWseSVc1

        Public PSI As MyWseSVc2 = GetMyWseSVc2

    End Class

The inner class was passed into the batch method while the Application object was still available and providing the objects the batch would need later.

To start off, create the subroutine you want to initiate asynchronously:

    Private Sub InitiateBatch(ByVal wsRefs As WebSvcInstances)

Create a Delegate in your code behind with the same signature as the subroutine:

    Private Delegate Sub Batch_Delegate(ByVal wsRefs As WebSvcInstances)

Then you can initiate your subroutine in a page event like so:

    Dim batchDelegate As InitiateBatch_Delegate

    Dim wsRefs As New WebSvcInstances

    batchDelegate = New InitiateBatch_Delegate(AddressOf InitiateBatch)

    Dim asyncResult As IAsyncResult

    asyncResult = batchDelegate.BeginInvoke(wsRefs, Nothing, Nothing)

You can read up on BeginInvoke to learn more about the callback features.  I didn’t need to be notified when the execution finished, so I just set those to Nothing

Before and AFTER


It hasn't taken quite as long as the lack of blog posts would have you believe, but the refurbishment of Flying Scot 338 is nearly complete. In addition to the fairing and painting, I've just finished replacing the gooseneck and standing rigging, installing a boom whoopie, turtle bags and guy hooks. I hope to get the transom port, bow bag, and stem band on before the Boathouse Regatta this weekend. I am SO glad I have a Flying Scot since the class builder has been SUPER helpful including instructions with all of the replacement parts.

Painting recap:

After talking to another club member who did the same paint job (but rolled everything) I should have been more aggressive with sanding the primer. I was concerned about sanding too much off and not hiding the yellow gel coat so I wet sanded with 220. My friend said he used 80-100 on the primer which I now wish I had done (with a long board)...but time was limited. I didn't think I'd have a chance to put a 2nd primer coat on.
I am very impressed with the shine and durability of Interlux Brightsides so far. I don't think I've scratched any paint off, though it's only been a couple months of light use.
During the refurb, I decided to tackle the bottom as well, painting it with VC Performance (a 2-part epoxy) and given that experience, I think I would be more willing to attempt a 2-part poly for the topsides next time. A warning about VC Performance though: it is extremely thin (runny), being designed to spray on. They say it is possible to brush/roll it on, but it would seem far easier to spray given my limited experience. My "spray rig" consisted of a $99 compressor and $15 gravity fed gun, both from Harbor Freight.

Centerboard:

As earlier pictures showed, my centerboard was in terrible shape. The leading edge was so badly damaged, there was actually a large accumulation of clay between the lead balast and the outer fiberglass causing a bulging in the airfoil shape. I ended up cutting out a curved section of fiberglass from the leading edge (both sides) and repairing it with about 4-5 layers of 1.5oz mat. I faired the repair and other leading edge defects with Interlux Watertite and finished with two coast of VC Performance (after removing LOTS of bottom paint) the board looks almost new.

Thursday, May 14, 2009

Removing boat bottom paint


I read somewhere that the best tool for removing bottom paint is your checkbook. After my experience, I would have to agree, but it can be done. Apparently the pros sandblast the stuff off. Not being a pro, I turned to Google and read about several different methods for DIY: scraping, stripping, and sanding being the top three. In the end, I believe the most efficient way is to scrape AND sand.
Important tip: have a file in your pocket and keep the scraper sharp. The copper bottom paint dulls the scraper quickly. To sharpen, you have to lay the file down and hold the scraper perpendicular to the file. Just a few strokes makes a huge difference.
Flying Scot #338 had several layers of bottom paint so scraping removed a bunch of material, but did not remove the last layer of paint. The picture above shows the results of scraping on the right and after sanding on the left. I sanded using a 1-2 punch of a 6" sander with 50 grit lightly and carefully run over the paint to remove 95% and then a 5" orbital sander with 80 grit to get the last bit off and smooth out the agressive grit. This process took about 1 hour for the first side, second side TBD...

Monday, April 27, 2009

Fairing and repainting a Flying Scot

I will be blogging regularly about this year’s refurbishment of Flying Scot 338. Last weekend I removed all of the hardware including rub rails. This weekend I removed the centerboard (with the help of the club hoist). Launched the 338 onto dry land – a very unnaturally feeling. And, with the help of 3 club members, flipped the hull onto low sawhorses. Next up, cutting the bad balsa out of the aft deck and removing the bottom paint. I feel itchy already.

Take a look at that centerboard. I got a chance to give it a close inspection while we were…uh…sideways a few weeks ago. I think I see why light air has never been kind to us!