Thursday, November 16, 2017

cursors with variables

need to have values set to the variables before declaring the cursor
i had a declaration section with out settings and this failed

Friday, November 10, 2017

example to delay change in status bar

  //only bother setting OK if it isnt set yet
               _textbox.Dispatcher.BeginInvoke((Action)(() =>
               {
                   if (!_textbox.Content.ToString().Equals("System Messages:OK"))
                   {
                            //seperate thread for OK message with delay
                            var t = Task.Run(async delegate
                            {
                                await Task.Delay(TIME_TO_WAIT_TO_CHANGE_MSG_TO_OK_IN_MS);
                                DisplayData(DisplayMessageType.Normal, "OK");
                            });
                        }
                    }
                  ));

schema issues

someone hardcoded in an old program the wrong schema in an update statement

I went ahead and creates a matching schema and put the tables in a s views (select * )


Friday, September 15, 2017

Wednesday, August 16, 2017

Like not vulnerable to injection

create table #test (name varchar(100))   
insert into #test values ('fgdgfdfg'),('cxvxbcvb'),('tryuryry')
declare @like varchar(100) = 'f; select * from #test --'
select * from #test where name like @like + '%'

drop table #test

Friday, June 30, 2017

Tuesday, June 13, 2017

simple example of async saving time

    static async Task<string>  blah()
        {
            await Task.Delay(5000);
            return "blah " + DateTime.Now.ToString();  
        }

        static async Task<string> masterblah()
        {
            Task<string> a =  blah();
            Task<string> b =  blah();
            Task<string> c =  blah();

            string a1 = await a;
            string b1 = await b;
            string c1 = await c;
            Console.WriteLine( string.Format("{0}-{1}-{2}", a1, b1, c1));
            return string.Format("{0}-{1}-{2}", a1, b1, c1); 
        }
       
        static void Main(string[] args)
        {

            Console.WriteLine(DateTime.Now);

            masterblah();

Thursday, June 8, 2017

Lync not starting

I killed the process (communicator.exe) and removed the cache

Monday, June 5, 2017

sp to help create table for user defined table

ALTER  PROCEDURE [ADMIN].[GET_UDF_TABLE_INFO]
(
       @p_NAME VARCHAR(100)
)
AS
BEGIN
       BEGIN TRY
       select tt.name AS TableName, c.name AS ColumnName,st.name AS DataType
       from sys.table_types tt
              INNER JOIN sys.columns c on c.object_id = tt.type_table_object_id
              INNER JOIN sys.systypes AS ST  ON ST.xtype = c.system_type_id
       where  tt.name  = @p_NAME
  order by c.column_id

      
       END TRY

       BEGIN CATCH
              EXECUTE ADMIN.LOG_DB_ERROR;
              return 0
       END CATCH
END

 order by c.column_id is real important because ado.net is ordinal




Context in WCF service is null

make sure
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"  />
is set

Debug Unit Test in VS

  1. Press CTRL+R and then CTRL+T.

Wednesday, May 24, 2017

IManage create workspace with folder structure

/////////////////////////////////////////////////////////////////////////////////////////
$.ajaxSetup({async: false});
var cache = {};
cache[ "group_id" ] ="";//"blah"
cache["baseurl"] = 'https://blah/api/v1/';
cache["user_id"] = "ws_creator";
cache["pwd"] = "test";
cache["FolderIds"] =[];

function getToken( ){
console.log("getToken");
//debugger;
    return $.when(
        $.ajax({
url: cache["baseurl"] +'session/login',
type: 'put',
data: JSON.stringify({
user_id:cache["user_id"],
password:cache["pwd"]
}),
headers: {
'Content-Type': 'application/json'
},
dataType: 'json',
            success: function( resp ){
                cache[ "Token"  ] = resp["X-Auth-Token"];
console.log("getToken:success");
            },
failure: function( resp ){
console.log("getToken:failure");
console.log(resp);
            }
        })
    );
}
/////////////////////////////////////////////////////////////////////////////////////////
function CreateWorkspace(ClientID , EntityID, wsName, groupId,accessType){
console.log("CreateWorkspace");
//debugger;
    return $.when(
        $.ajax({
url: cache["baseurl"] + 'workspaces',
type: 'post',
data: JSON.stringify({
database: "Blah",
custom1:ClientID ,
custom2:EntityID ,
default_security: "private", //change back to private
name: wsName
}),
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
            success: function( resp ){
//debugger;
cache[ "group_id"  ] = groupId;
addGroup(resp.data.id, "workspaces", accessType);
                cache[ "workspace_id"  ] = resp.data.id;
console.log("CreateWorkspace:success");
            },
failure: function( resp ){
console.log("CreateWorkspace:failure");
console.log(resp);
            }
        })
    );
}
/////////////////////////////////////////////////////////////////////////////////////////
function AddFolderToWorkspace(fname,accessType,documentGroup ){
console.log("AddFolderToWorkspace");
//debugger;
    return $.when(
        $.ajax({
url: cache["baseurl"] +'workspaces/' + cache[ "workspace_id"  ]  + '/folders',
type: 'post',
data: JSON.stringify({
 database:"Blah",
 name:fname,
 default_security:"inherit",
 profile:
  {
 author:cache["user_id"],
 class:"DOC",
     comment:"",
 custom29:documentGroup
        }
}),
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
            success: function( resp ){
//debugger;
//cache[ "group_id"  ] = ""; //remove
addGroup(resp.data.id, "folders", accessType);
cache[ "FolderIds"].push({"root":"","name":fname,id :resp.data.id});
console.log("AddFolderToWorkspace:success");
            },
failure: function( resp ){
console.log("AddFolderToWorkspace:failure");
console.log(fname);
console.log(resp);
            }
        })
    );
}
/////////////////////////////////////////////////////////////////////////////////////////////
/*
access levels
"no_access", "read", "read_write", "full_access"

what are the possible values for user types?
"user" or "group"
*/
function addGroup(objectID, type, accessType){
//type documents, workspaces, folders
//debugger;
console.log("cache[ 'group_id'] " + cache[ "group_id" ]  );
if(cache[ "group_id" ] !==""){
 return $.when(
   $.ajax({
url: cache["baseurl"] + type +  '/'  + objectID + "/security",
type: 'post',
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
data: JSON.stringify({
include:
[{access_level: accessType,
id: cache[ "group_id" ],
type: "group"
}]
}),
            success: function( resp ){
//debugger;
//user_type
               //  cache[ "doc_id"  ] = resp.data[0].id;
console.log("addGroup:success");
            },
failure: function( resp ){
//debugger;
console.log("addGroup:failure");
console.log(resp);
            }
        })
    );
}
}
/////////////////////////////////////////////////////////////////////////////////////////
function AddFolderToFolder(root, father, fname ,accessType,taxYear){
console.log("AddFolderToFolder");
console.log(father + "-" + fname);
//debugger;
    return $.when(
        $.ajax({
url: cache["baseurl"] +'workspaces/' + cache["FolderIds"].filter(function (el) {
return el.name == father && el.root == root;
})[0].id + '/folders',
type: 'post',
data: JSON.stringify({
 database:"Blah",
 name:fname,
 default_security:"inherit",
 profile:
  {
 author:cache["user_id"],
 class:"DOC",
     comment:"",
 custom4:taxYear,
 custom29:father
        }
}),
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
            success: function( resp ){
addGroup(resp.data.id, "folders", accessType);
cache[ "FolderIds"].push({"root" : father, name:fname,id :resp.data.id});
console.log("AddFolderToFolder:success");
            },
failure: function( resp ){
console.log("AddFolderToFolder:failure");
console.log(fname);
console.log(resp);
            }
        })
    );
}

/////////////////////////////////////////////////////////////////////////////////////////
getToken()//ClientID , EntityID, wsName, groupId,accessType
    .then(CreateWorkspace("11274","438917","test 2","Blah","read"), function(err) {console.log( err );})
.then(AddFolderToWorkspace("Billing","read","Billing"), function(err) {console.log( err );})
//root, father, fname ,accessType,taxYear
.then(AddFolderToFolder("","Billing","31-Dec-2017","full_access","2017"), function(err) {console.log( err );})
.then(AddFolderToFolder("","Billing","31-Dec-2016","full_access","2016"), function(err) {console.log( err );})

Create Search Folder In Imanage

//########################################################
function GetSearchFolder(SFId ){
  // return either the cached value or jqXHR object wrapped Promise
    return $.when(
       // cache[ "Token" ] ||
        $.ajax({
url: cache["baseurl"] +'search-folders/' + SFId,
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
            success: function( resp ){
debugger;
//temp = $.grep(resp.data, function (d) {
//  return d.name  == WSName;
   //});
                //cache[ "ws_id"  ] = temp[0].id ;
console.log("GetWorkspace:success");
            },
failure: function( resp ){
console.log("GetWorkspace:failure");
console.log(resp);
            }
        })
    );
}

//########################################################
function GetWorkspace(WSName ){
  // return either the cached value or jqXHR object wrapped Promise
    return $.when(
       // cache[ "Token" ] ||
        $.ajax({
url: cache["baseurl"] +'workspaces/search',//  ?name=' + WSName,//until we get the indexer to work
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
            success: function( resp ){
//debugger;
temp = $.grep(resp.data, function (d) {
 return d.name  == WSName;
});
                cache[ "ws_id"  ] = temp[0].id ;
console.log("GetWorkspace:success");
            },
failure: function( resp ){
console.log("GetWorkspace:failure");
console.log(resp);
            }
        })
    );
}

//########################################################
function CreateSearchFolder(folderName, TaxYear ){
var stripped = cache[ "ws_id"].replace(/\D/g,'');
    // return either the cached value or jqXHR object wrapped Promise
    return $.when(
       // cache[ "Token" ] ||
        $.ajax({
url: cache["baseurl"] +'workspaces/' + cache[ "ws_id"  ] + '/search-folders',
type: 'post',
data: JSON.stringify({
database: "Blah",
name: folderName,
default_security: "inherit",
searchprofile:
  {
 "custom4":TaxYear,
 "container": stripped,
 "databases":"Blah"
  }
}),
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
            success: function( resp ){
//debugger;
                //cache[ "folder_id"  ] = resp.data.id;
console.log("CreateSearchFolder:success");
            },
failure: function( resp ){
console.log("CreateSearchFolder:failure");
console.log(resp);
            }
        })
    );
}
//########################################################
// implementation
//########################################################

getToken().then(GetWorkspace("Blah"))
.then(CreateSearchFolder("31-Dec-2017", "2017"))

loading jquery in dev tools

sorry I lost where I got this from for the HT


var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load, then type (or see below for non wait option)
jQuery.noConflict();

Tuesday, May 23, 2017

wcf JSON deserialization

this
new JavaScriptSerializer().Deserialize<Dictionary<string, string>>(results)
will not work with complex objects

you need to create objects

for example, this is the IManage Login JSON

[DataContract]
    public class IManageUser
    {
        [DataMember(Name = "email")]
        public string email { get; set; }
        [DataMember(Name = "full_name")]
        public string full_name { get; set; }
        [DataMember(Name = "user_id")]
        public string user_id { get; set; }
    }

    [DataContract]
    public class IManageLoginInfo
    {
        [DataMember(Name = "X-Auth-Token")]
        public string X_Auth_Token { get; set; }
        [DataMember(Name = "max_age")]
        public int max_age { get; set; }
        [DataMember(Name = "persona")]
        public string persona { get; set; }
        [DataMember(Name = "user")]
        public IManageUser user { get; set; }

    }

then you could do something like this:
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
                StreamReader sr = new StreamReader(resp.GetResponseStream());
                results = sr.ReadToEnd();
                sr.Close();
                IManageLoginInfo info = null;
                using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(results)))
                {
                    DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(IManageLoginInfo));
                    info = (IManageLoginInfo)serializer.ReadObject(ms);
                }
                this.token = info.X_Auth_Token;

Friday, May 19, 2017

Create search folder in IManage API

//########################################################
function GetSearchFolder(SFId ){
  // return either the cached value or jqXHR object wrapped Promise
    return $.when(
       // cache[ "Token" ] ||
        $.ajax({
url: cache["baseurl"] +'search-folders/' + SFId,
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
            success: function( resp ){
debugger;
//temp = $.grep(resp.data, function (d) {
//  return d.name  == WSName;
   //});
                //cache[ "ws_id"  ] = temp[0].id ;
console.log("GetWorkspace:success");
            },
failure: function( resp ){
console.log("GetWorkspace:failure");
console.log(resp);
            }
        })
    );
}

//########################################################
function GetWorkspace(WSName ){
  // return either the cached value or jqXHR object wrapped Promise
    return $.when(
       // cache[ "Token" ] ||
        $.ajax({
url: cache["baseurl"] +'workspaces/search',//  ?name=' + WSName,//until we get the indexer to work
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
            success: function( resp ){
//debugger;
temp = $.grep(resp.data, function (d) {
 return d.name  == WSName;
});
                cache[ "ws_id"  ] = temp[0].id ;
console.log("GetWorkspace:success");
            },
failure: function( resp ){
console.log("GetWorkspace:failure");
console.log(resp);
            }
        })
    );
}

//########################################################
function CreateSearchFolder(folderName, TaxYear ){
var stripped = cache[ "ws_id"].replace(/\D/g,'');
    // return either the cached value or jqXHR object wrapped Promise
    return $.when(
       // cache[ "Token" ] ||
        $.ajax({
url: cache["baseurl"] +'workspaces/' + cache[ "ws_id"  ] + '/search-folders',
type: 'post',
data: JSON.stringify({
database: "Blah",
name: folderName,
default_security: "inherit",
searchprofile:
  {
 "custom4":TaxYear,
 "container": stripped,
 "databases":"Blah"
  }
}),
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
            success: function( resp ){
//debugger;
                //cache[ "folder_id"  ] = resp.data.id;
console.log("CreateSearchFolder:success");
            },
failure: function( resp ){
console.log("CreateSearchFolder:failure");
console.log(resp);
            }
        })
    );
}
//########################################################
// implementation
//########################################################

getToken().then(GetWorkspace("Blah"))
.then(CreateSearchFolder("31-Dec-2017", "2017b"))




"databases" property is wierd

IManage code to add workspace to my matters

/////////////////////////////////////////////////////////////////////////////////////////////
function getWS(wsName ){
    // return either the cached value or jqXHR object wrapped Promise
    return $.when(
        $.ajax({
url: cache["baseurl"] +'workspaces/search',  //goto get the indexer to work - ?name=' +wsName,
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
debugger;
var temp =  resp.data.filter(function(item) {
return item.name == wsName;
});
cache[ "ws_name"  ] =wsName;
                cache[ "ws_id"  ] = temp[0].id;
console.log("getWS:success");
            },
failure: function( resp ){
console.log("getWS:failure");
console.log(resp);
            }
        })
    );
}
/////////////////////////////////////////////////////////////////////////////////////////////
/*
access levels
"no_access", "read", "read_write", "full_access"

what are the possible values for user types?
"user" or "group"
*/
function addWSToMyMatters(){
 return $.when(
        $.ajax({
url: cache["baseurl"] + 'folders/my-matters/subfolders',
type: 'post',
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
data: JSON.stringify({ "name":cache[ "ws_name"  ],
"target":
{ "database":"Blah",
"id":cache[ "ws_id"  ],
"subtype":"work",
"wstype":"workspace"}
}),
            success: function( resp ){
debugger;
//user_type
               //  cache[ "doc_id"  ] = resp.data[0].id;
console.log("addWSToMyMatters:success");
            },
failure: function( resp ){
console.log("addWSToMyMatters:failure");
console.log(resp);
            }
        })
    );
}
/////////////////////////////////////////////////////////////////////////////////////////////
getToken().then(getWS("11Blah)"))
.then(addWSToMyMatters());

IManage search by metadata in API

since IManage has this horrible bug that search by metadata doesn't work here is a horrible kluge

///////////////////////////////////////////////////////////////
function getProfile(docid){
 return $.when(
        $.ajax({
url: cache["baseurl"] +'documents/'  + docid ,
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
            success: function( resp ){
//debugger;
currentProfile = resp;
console.log("getProfile:success "  + docid);
            },
failure: function( resp ){
console.log("getProfile:failure "  + docid);
console.log(resp);
            }
        })
    );
}
/////////////////////////////////////////////////////////////////////////////////////////////
function SearchDoc(params ){
    // return either the cached value or jqXHR object wrapped Promise
var temp;
    return $.when(
        $.ajax({
url: cache["baseurl"] +'documents/search',
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
temp = resp.data.filter(function(item) {
getProfile(item.id)
//debugger;
if(currentProfile !== null){
for(var key in params) {
//debugger;
if(currentProfile.data[key] === undefined || currentProfile.data[key] != params[key])
return false;
}
return true;
}
else{
return false;
}

});
debugger;
//return temp;
              //  cache[ "doc_id"  ] = resp.data[0].id;
console.log("getDoc:success");
            },
failure: function( resp ){
console.log("getDoc:failure");
console.log(resp);
            }
        })
    );
}
///////////////////////////////////////////////////////////////
p ={custom4:"2015"};
getToken().then(SearchDoc(p))