move a div

June 28, 2017

with position

xpos = xpos + x;
ypos = ypos + y;

$(".inner").parent().css({ position: 'relative' });
$(".inner").css({ left: xpos + 'px', top: ypos + 'px', position: 'absolute' });

console.log('AFTER x:' + $('.inner').position().left + ' y:' + $('.inner').position().top);

with offset

console.log('BEFORE x:' + $('.inner').position().left + ' y:' + $('.inner').position().top);

xpos = xpos + x;
ypos = ypos + y;

$(".inner:last").offset({top: ypos,left: xpos});
console.log('AFTER x:' + $('.inner').position().left + ' y:' + $('.inner').position().top);

all unit tests failing! debug won’t step in!

April 26, 2017

the sky is falling!

really, not being able to debug/step into is a shock to someone who uses visual studio day in / day out

what I had done yesterday to cause this was to change the copy local to “false” on the dll being tested.

that did it.

the exception message was “System.IO.FileNotFoundException: Could not load file or assembly”

webapi debugging fail? on simple GET?

March 15, 2017

the situation:
* web api 2
* simple project built from template – the Value controller works as expected

I added a controller … and I’m still learning. (aren’t we all)

I tried calling action methods from my controller … I won’t show my apiconfig, because it’s not relevant to my point.

My point is, I got to a situation where it appeared that the debugger would not step into my controller methods.

Or would it?

One thing I learned is that if I put [HttpGet] attribute tags on multiple methods in the controller, then the original “Get” method may not be called. After I removed those attributes, then the default Get method was again called.

a good read: https://docs.microsoft.com/en-us/aspnet/web-api/overview/web-api-routing-and-actions/routing-in-aspnet-web-api

Entity framework problem : EntityFramework.SqlServer’ registered in the application config file for the ADO.NET provider with invariant name ‘System.Data.SqlClient’ could not be loaded

September 27, 2016

EntityFramework.SqlServer’ registered in the application config file for the ADO.NET provider with invariant name ‘System.Data.SqlClient’ could not be loaded
See: http://stackoverflow.com/questions/21175713/no-entity-framework-provider-found-for-the-ado-net-provider-with-invariant-name
I followed their advice in my dbContext class
///

/// A partial class extention to the auto generated code created by Entity Framework.
/// this allows us to create a normal connection string, then create an entity connection string, and pass it into the
/// entity data model.
/// So we can use DEV, QA, and PROD versions of our database based on switches in our config file.
///

public partial class SoftwareCatalogEntities : DbContext
{
private volatile System.Type _dependency;
// http://stackoverflow.com/questions/21175713/no-entity-framework-provider-found-for-the-ado-net-provider-with-invariant-name

///

/// An additional Constructor for the Entity Framework Model
/// that allows us to customize the connection String before a
/// context is created and returned.
///

/// Modified connection string instead of default connection string used by default constructor that takes no parameters.
public SoftwareCatalogEntities(string EntityConnectionString) : base(EntityConnectionString)
{
_dependency = typeof(System.Data.Entity.SqlServer.SqlProviderServices); // will cause the sql server dll to be copied
}

Telerik radGrid -ItemTemplate,EditTemplate

August 22, 2016

Points

  • Browser side: Use normal controls – a lot like asp.net gridview (label, hidden, etc)
  • Server side a little different
  • Must grab control[1]. Control[0] is a literal – I suppose the start of the <td>.

Browser Side:

<telerik:GridTemplateColumn Display=”false” UniqueName=”ReceiptItemID”>

<ItemTemplate>

<asp:HiddenField ID=”hdnReceiptItemID” runat=”server” Value=”<%# Item.ParkedReceiptItemID %>” />

</ItemTemplate>

<EditItemTemplate>

<asp:HiddenField ID=”hdnReceiptItemID” runat=”server” Value=”<%# Item.ParkedReceiptItemID %>” />

</EditItemTemplate>

</telerik:GridTemplateColumn>

 

<telerik:GridTemplateColumn HeaderText=”AccountNumber” UniqueName=”AccountNumber” >

<ItemTemplate>

<asp:Label ID=”lblAccountNumber” runat=”server” Text='<%# Item.AccountNumber %>’ ></asp:Label>

</ItemTemplate>

<EditItemTemplate>

<uc1:ctlCombo ID=”cboAccountNumber” ClientIDMode=”Static” runat=”server” Text='<%# Item.AccountNumber %>’ />

</EditItemTemplate>

</telerik:GridTemplateColumn>

 

Server side:

//Get all the new values of the edited row.

GridEditableItem rgEditedItem = (GridEditableItem) e.Item;

 

 

// Label lbl = (Label) rgEditedItem[“ReceiptItemID”].Controls[1];

HiddenField hdn = (HiddenField)rgEditedItem[“ReceiptItemID”].Controls[1];

 

// int ReceiptItemID = lbl.Text.toInt(0);

int ReceiptItemID = hdn.Value.toInt(0);

 

// update account number if it changed

ctlCombo cbo = (ctlCombo)rgEditedItem[“AccountNumber”].Controls[1];

if (cbo.PreviousValue != cbo.Text && ReceiptItemID > 0)

{

int iret = _parkedReceiptItem.update_Account(ReceiptItemID, cbo.Text, globals.StaffID, ref iError, ref strErrorShort, ref strErrorLong);

if (iError < 0) globals.lblError = globals.ErrorMessage(strErrorShort, strErrorLong, “Problem with account”, “rgItems_UpdateCommand.account”, -2223);

}

 

Telerik radgrid inline editing command not firing

August 19, 2016

oops – my problem was old school .net

in my OnLoad, I was reloading and rebinding the radGrid

that blew away all events

shades of .Net 2003!

 

how to test if a temp locking table is locked or not

April 30, 2015

sorry, minimal explanation. you’ll figure it out.
What’s the purpose? to prevent multiple updates from multiple servers in our webfarm.

BEGIN TRY

SET XACT_ABORT ON;
SET LOCK_TIMEOUT 100;

if OBJECT_ID('tempdb..##MyTempLockingTable') is not null
BEGIN
select 1 as [IsLocked]
end
else
begin
select -1 as [IsLocked]
end

end try
begin catch
-- when we test this with a second id, we find that the above object_id statement hangs
select 1 as [IsLocked]
end catch

Mutex – single instance of program – VB – Winforms

February 19, 2015

Three ways to use mutexes to guarantee that your VB.Net winforms application only runs one instance at a time on a given host.
I don’t know why I redid this three times yesterday – I must have made some mistake that led me to believe that the first two tries weren’t working!


Public Class globals

Public Shared unique_mutex As Mutex

'ref: http://odetocode.com/blogs/scott/archive/2004/08/20/the-misunderstood-mutex.aspx
' http://renren.io/questions/35665/how-to-force-c-sharp-net-app-to-run-only-one-instance-in-windows
' flavor: TryOpenExisting
Public Shared Function guarantee_unique_instance_of_program() As String
Dim sMutexName As String = "Global\VcProcessPaymentsMutex"
Dim bAlreadyExisting As Boolean = False
Dim bFirstTimeCreated As Boolean = False

' http://renren.io/questions/5447537/c-sharp-mutex-issue-to-prevent-second-instance

bAlreadyExisting = Mutex.TryOpenExisting(sMutexName, globals.unique_mutex)

Select Case bAlreadyExisting
Case True
Return "FAILURE Instance already running"
Case False
globals.unique_mutex = New Mutex(False, sMutexName, bFirstTimeCreated)
Return "SUCCESS"
End Select

End Function

'ref: http://odetocode.com/blogs/scott/archive/2004/08/20/the-misunderstood-mutex.aspx
' http://renren.io/questions/35665/how-to-force-c-sharp-net-app-to-run-only-one-instance-in-windows
' I think this is the ScottGu method (more or less)
Public Shared Function guarantee_unique_instance_of_program_GOOD3() As String
Dim bFirstTimeCreated As Boolean = False
globals.unique_mutex = New Mutex(False, "Global\VcProcessPaymentsMutex")
If (Not unique_mutex.WaitOne(0, False)) Then
Return "FAILURE Instance already running"
Else
Return "SUCCESS"
End If
GC.Collect()
End Function

Public Shared Sub release_mutex()
unique_mutex.ReleaseMutex()
End Sub

' this is the "FirstTimeCreated" flavor
' ALSO GOOD (why did I redo this yesterday?)
' flavor: TryOpenExisting
_
Public Shared Function guarantee_unique_instance_of_program_GOOD2() As String

'1) try to open one that is existing
Dim bTryToOpenExisting As Boolean = False
bTryToOpenExisting = Mutex.TryOpenExisting("Global\VcProcessPaymentsMutex", unique_mutex)
If (bTryToOpenExisting) Then
Return "FAILURE Instance already running"
End If

' 2) if it didn't exist yet, then create it
Dim bFirstTimeCreated As Boolean = False
Using unique_mutex As New Mutex(False, "Global\VcProcessPaymentsMutex", bFirstTimeCreated)

If (Not bFirstTimeCreated) Then ' this should never be hit
Return "FAILURE Instance already running"
End If

GC.Collect()
End Using

Return "SUCCESS"

End Function


Read the rest of this entry »

mvc – feel my pain – view model is null on postback

January 17, 2015

I just spent two to three hours because I forgot to put get/set on the public members of my ViewModel.

The “etiology” (symptoms, bad behavior) was that my form posted back but the view model was always null.

Oops!

Correct:
public int logkey { get; set;}
public string logtitle { get; set;}
public string bywhom { get; set;}
public string slogdate { get; set;}
public DateTime logdate { get; set;}
public string logentry { get; set;}

I had been copying some working code, but not this part!

dynamically select StateServer based on machinename (for PROD,QA,DEV selection)

December 4, 2014

First go have a look at Maartens post.

My purpose – to use one line in web config, but use the correct stateserver ip address when deployed.
And I tested this to make sure it worked.

web config entry

VB version (I’m running)

Imports System

' purpose - dynamically return a state server ip address based on DEV/PROD/QA deployment
' ref http://blog.maartenballiauw.be/post/2008/01/23/ASPNET-Session-State-Partitioning.aspx
Public Class WebConfigSessionStateServer
Implements System.Web.IPartitionResolver

Private Shared m_DynamicStateServerAddress As String = ""
Private ReadOnly Property DynamicStateServerAddress As String
Get
If (String.IsNullOrEmpty(m_DynamicStateServerAddress)) Then Initialize()

Return m_DynamicStateServerAddress
End Get
End Property

Public Function ResolvePartition(key As Object) As String Implements IPartitionResolver.ResolvePartition

Return DynamicStateServerAddress

End Function

Private Sub Initialize() Implements IPartitionResolver.Initialize
Dim sDEV As String = "tcpip=666.666.238.252:42424"
Dim sPROD As String = "tcpip=666.666.79.176:42424"
Dim sQA As String = "tcpip=666.666.238.249:42424"

Select Case DeploymentType
Case "QA"
m_DynamicStateServerAddress = sQA
Case "DEV"
m_DynamicStateServerAddress = sDEV
Case "PROD"
m_DynamicStateServerAddress = sPROD
Case Else
m_DynamicStateServerAddress = sPROD
End Select

End Sub

Private Shared m_DeploymentType As String = ""
Public Shared ReadOnly Property DeploymentType As String
Get
If (m_DeploymentType = "") Then
Dim sname As String = Environment.MachineName 'utils_SysNetInfo.machinename
m_DeploymentType = "PROD"
If (sname.ToUpper().IndexOf("DEV") > -1) Then m_DeploymentType = "DEV"
If (sname.ToUpper().IndexOf("QA") > -1) Then m_DeploymentType = "QA"
End If

Return m_DeploymentType

End Get
End Property

End Class

C# version (translated by Telerik. Bless them. Buy things from them What a great service.)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace utils_lib
{

// purpose - dynamically return a state server ip address based on DEV/PROD/QA deployment
// ref http://blog.maartenballiauw.be/post/2008/01/23/ASPNET-Session-State-Partitioning.aspx
public class utils_SessionStateServer_Dynamic : System.Web.IPartitionResolver
{

private static string m_DynamicStateServerAddress = "";
private string DynamicStateServerAddress
{
get
{
if ((string.IsNullOrEmpty(m_DynamicStateServerAddress)))
Initialize();

return m_DynamicStateServerAddress;
}
}

// ************************************************************
public string ResolvePartition(object key)
{

return DynamicStateServerAddress;

}

// ************************************************************
public void Initialize()
{
string sDEV = "tcpip=666.666.238.252:42424";
string sPROD = "tcpip=666.666.79.176:42424";
string sQA = "tcpip=666.666.238.249:42424";

switch (DeploymentType)
{
case "QA":
m_DynamicStateServerAddress = sQA;
break;
case "DEV":
m_DynamicStateServerAddress = sDEV;
break;
case "PROD":
m_DynamicStateServerAddress = sPROD;
break;
default:
m_DynamicStateServerAddress = sPROD;
break;
}

}

// ************************************************************
// use machine name to decide PROD DEV QA
private static string m_DeploymentType = "";
public static string DeploymentType
{
get
{
if ((string.IsNullOrEmpty(m_DeploymentType)))
{
string sname = Environment.MachineName;
//utils_SysNetInfo.machinename
m_DeploymentType = "PROD";
if ((sname.ToUpper().IndexOf("DEV") > -1))
m_DeploymentType = "DEV";
if ((sname.ToUpper().IndexOf("QA") > -1))
m_DeploymentType = "QA";
}

return m_DeploymentType;

}
}

} // class

}

//=======================================================
//Service provided by Telerik (www.telerik.com)
//Conversion powered by NRefactory.
//Twitter: @telerik
//Facebook: facebook.com/telerik
//=======================================================