Friday, August 24, 2018

SMO Restoring Took Forever

I use this SMO to restore a backup:

        Server myServer = new Server(@"PC-1\Instance1");
        Restore restoreDB = new Restore();
        restoreDB.Database = "Sample";
        restoreDB.Action = RestoreActionType.Database;
        restoreDB.Devices.AddDevice(@"D:\Sample.bak", DeviceType.File);
        restoreDB.ReplaceDatabase = true;
        restoreDB.NoRecovery = true;
        restoreDB.SqlRestore(myServer);

But when I open SSMS the restoring took forever

enter image description here

I use this to backup database and able to backup the database

            Server myServer = new Server(@"PC-1\Instance1");
            Backup bkpDBFull = new Backup();
            bkpDBFull.Action = BackupActionType.Database;
            bkpDBFull.Database = "Sample";
            bkpDBFull.Devices.AddDevice(@"D:\Sample.bak", DeviceType.File);
            bkpDBFull.BackupSetName = "Sample";
            bkpDBFull.BackupSetDescription = "Sample";
            bkpDBFull.ExpirationDate = DateTime.Today.AddDays(5);
            bkpDBFull.Initialize = false;
            bkpDBFull.SqlBackup(myServer);

Solved

You have the following line in your code:

restoreDB.NoRecovery = true;

Hence the database will stay showing as restoring in SSMS forever until you run

RESTORE DATABASE [sample] WITH RECOVERY

Or its SMO equivalent, I'm not sure exactly what that would be.


Monday, August 20, 2018

How do I make calls to a boardgamegeek api using c#?

I am calling www.boardgamegeek.com API.

I am using below code:

    HttpClient client = new HttpClient();
    client.BaseAddress = new Uri("http://www.boardgamegeek.com/xmlapi/collection/dhasmain");
    client.DefaultRequestHeaders.Accept.Add(
    new MediaTypeWithQualityHeaderValue("application/xml"));

    // List data response.
    HttpResponseMessage response = client.GetAsync("?own=1").Result; 
    if (response.IsSuccessStatusCode)
    {
        var dataObjects = response.Content.ReadAsStringAsync().Result;
    }
    else
    {
        Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
    }

But it is showing Result=Not yet computed.

Can anyone please suggest to me what the issue is?

I am also using the below code but it is not returning anything.

string dataObjects = ""; HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://www.boardgamegeek.com/xmlapi/collection/zefquaavius"); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/xml"));

    client.GetStringAsync("?own=1").ContinueWith(task =>
    {
        dataObjects = task.Result;
    });

Solved

It appears that you are calling the get asynchronously and not giving the call enough time for the call to complete when you access the result. You can use ContinueWith to respond to the call once the request is completed:

client.GetStringAsync("?own=1").ContinueWith(task =>
    {
        string dataObjects = task.Result;
    });

EDIT: Based on your comments, I see your UTF-8 encoding issue. The code below will handle the encoding issue so you have a string of XML from the response.

byte[] dataObjects = null;
client.GetByteArrayAsync("?own=1").ContinueWith(task => { dataObjects = task.Result; }).Wait();
string xmlResponse = System.Text.Encoding.UTF8.GetString(dataObjects);

Sunday, August 19, 2018

Git rm --cached and checkout

I've issued the following command

git rm --cached .idea

on my develop branch, 'cause i don't want to track ide config files. Files have been removed from index but they're still on filesystem, which is exactly my original goal.

Now when i try to checkout another branch, git fails because they're still in the index of the other branch - this is expected.

However, i need to remove these files from the index of any branch, so how can i issue the same git rm --cached command on a branch i can't checkout to?

Solved

If the file on the other branch is the same as the untracked file on the disk, you can git checkout -f, and then git rm --cached. If not, and you want to save the untracked file without git's knowledge, you must do exactly that: put it away in ~/tmp or something, clean up git's view, and mv it back to the repository directory. Also, put it in .gitignore immediately to avoid tracking it by mistake.


Faced with the same situation, I tend do this until all BRANCH_WHERE_FILE_REMAINS are gone.

git rebase BRANCH_WHERE_FILE_IS_REMOVED BRANCH_WHERE_FILE_REMAINS

Note: This doesn't cause checking out of commits where .idea remains, because rebase's cherry-picking is based after the commit where the file is already removed.

However, note that if at any point you do git rebase --abort, rebase will try going back to a commit where .idea was still in the index, and you'll probably face trouble there. (Backing up of .idea is recommended before attempting.)

BRANCH_WHERE_FILE_IS_REMOVED can just be the commit-id if there's no such branch.


Saturday, August 18, 2018

Generate Code from activity Diagram using Enterprise Architect

I am really struggling trying to second guess how to get EA to generate C++ code from Activity diagrams. I have EA 13 Ultimate and I can generate code from the example EAP project’s activity diagram, specifically the TestSelectionPort example in the "Java Model with Behaviours" package.

I can now generate if statements using an activity diagram of my own. But I want to use a while loop, for loop or do while loop …. then I am lost. I can see the example has 2 while loops, and I can generate that code from the example but I cannot for the life of me see HOW to get EA to generate a while loop rather than the if statement. It must be magic!! ha-ha. I can find no property setting or action type that creates a while loop but it must be there somewhere.

I really like the idea of being able to generate an activity diagram form a use case, and it seems to me it would be IDEAL to then embellish to generate boiler plate code from the activity diagram, but man its worse than pulling hen's teeth to work out how. Whilst EA is very good tool, its help is seriously lacking in the help on this area of functionality.

Anybody got any ideas?

thanks in advance!

Terry