VS Extension: Git branch change event? - visual-studio-extensions

Is there an event available to extensions that fires when the current branch changes? I need to retrieve data from GitHub any time this happens.

Solved: I set up a FileSystemWatcher on %projectroot%.git\HEAD that handles the Created event, since Git deletes and recreates on branch change. Hot tip: set EnableRaisingEvents AFTER the object is instantiated with the path parameter. Otherwise you'll get an InvalidOperationException.

Related

How do you delete classes from a Jade database

When I try to delete a class using the "Remove" option in the Jade class browser, I get the error:
"Class xxx cannot be deleted because:
Classes in an SDS Primary database cannot be deleted from the current schema context".
How can I remove a class?
In the context of an SDS environment, you need to version the schema before you can remove a class (using the 'Remove' option via the IDE for the latest schema version).
The re-org used to transition schema versions is then replayed on the SDS environment, as part of which its cached metadata is refreshed to reflect structural changes. I believe class removals is included with this (even if there's no persistent instances), because it'd need to discard the redundant class number.
You will want to use the Jade Schema Loader, with a command file.
According to the JADE Schema Load User's Guide, the syntax for the command file is:
JadeCommandFile
JadeVersionNumber 7.1.00
Commands
Delete Class ErewhonInvestmentsModelSchema::TenderSale
And you load it on your database server using:
jade.exe schema=RootSchema app=JadeSchemaLoader path=d:\jade\system ini=d:\jade\myjade.ini startAppParameters commandFile=d:\temp\DeleteClass.jcf loadStyle=currentSchemaVersion
Be sure to shutdown your database before running the command, or it will not run.

Can EF Code First work with LocalDB in a ClickOnce application?

So, I'm trying out EF Code First, so that I can have the code drive updates to the database. I'm working on a ClickOnce app using LocalDB, so figured this may be the best solution for me, since otherwise changes to the MDF file will cause it to be overwritten on the client when deployed, thus losing everything entered before.
However, I'm now having my fair share of all new problems around Code First Migrations. I've followed through a Code First Migrations on MSDN, and I've managed to get the initial Configuration created, as well as the initial database creation.
The problems begin when I try to make my first actual migration. I added one single field to one of my models, and tried to make an explicit migration to handle that schema change for the next time I publish. Well...
PM> Add-Migration AddIsPercentField
Unable to generate an explicit migration because the following explicit migrations are pending: [201601052011180_InitialCreate]. Apply the pending explicit migrations before attempting to generate a new explicit migration.
Ok... I'll run update and try again:
PM> Update-Database
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Applying explicit migrations: [201601052011180_InitialCreate].
Applying explicit migration: 201601052011180_InitialCreate.
Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration.
You can use the Add-Migration command to write the pending model changes to a code-based migration.
PM> Add-Migration AddIsPercentField
Unable to generate an explicit migration because the following explicit migrations are pending: [201601052011180_InitialCreate]. Apply the pending explicit migrations before attempting to generate a new explicit migration.
That's familiar, as that's the error (blatant lie?) it just told me earlier. Well, maybe if I undo my changes and update again, it will move to a valid state:
PM> Update-Database
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Applying explicit migrations: [201601052011180_InitialCreate].
Applying explicit migration: 201601052011180_InitialCreate.
Running Seed method.
Ok, no warning this time. Should be golden. Field added back, project rebuilt. Here we go:
PM> Add-Migration AddIsPercentField
Unable to generate an explicit migration because the following explicit migrations are pending: [201601052011180_InitialCreate]. Apply the pending explicit migrations before attempting to generate a new explicit migration.
So... is there actually a working way to generate explicit migrations for any changes beyond the first?
EDIT: I made some forward progress on this, I believe. I did notice that the __MigrationHistory table was not generated in my .mdf after running Update-Database, even though it said everything completed just fine. I believe the issue is actually around how the local database works within the application. The connection string references AttachDbFilename=|DataDirectory|. What I think is going on is that it is deploying the .mdf temporarily, updating that temporary deployment, thus ultimately not committing the changes.
I'm working on a solution I have in mind, which is to have migrations work against a copy of the blank .mdf put in a static location, so that the static .mdf will be used to track and determine changes, while the blank .mdf will be what goes out to clients with the deployment.
I found that the root of my problem was that the console commands were not actually able to make changes, thus track migrations, to my data file. This was due to the connection string to the data file referencing a deployed location, so the file being updated was merely temporary.
This was in part a good thing, because the whole point of using Code First Migrations in my project was to avoid a hash signature change to my .mdf (which should have simply remained blank, as a placeholder) when publishing, so that the data from previous versions would never be overridden and discarded. However, that also introduced the obvious (in retrospect) problem that EF could not track changes due to there never being a __MigrationHistory table.
The solution upon which I arrived was to have two .mdf files. The blank one, for deployments, and a second one, to which I would interact with Code First Migrations. So, I have the initial MyData.mdf of Build Action Content, and a second MyDataDesignTime.mdf of Build Action None. (The "Design Time" migration database shouldn't be deployed.)
Using this approach, I found that I could now work successfully with migrations, calling Update-Database and Add-Migration, making sure to pass the -ConnectionString parameter with AttachDbFilename pointed to the full path to my design time database.
Later, getting lazy to supply a long -ConnectionString parameter on every migration command, I added the design time path to my config connection strings, and updated my DbContext so that it uses the design time path initially, but which I would change at the beginning of run-time to use my actual target data file:
public partial class MyData : DbContext
{
public const string DesignTimeConnection = "MyDataConnectionStringDesignTime";
public static string ConnectionName { get; set; } = DesignTimeConnection;
public MyData()
: base("name=" + ConnectionName)
{
}
...
}
And at application initialization:
MyData.ConnectionName = "MyDataConnectionString";
This works, and it makes things simpler on me. However, the one minor issue I'm left with is that I have a full static path which applies only to my environment left in the app.config file. Not currently an issue, as I'm the only dev on this project, but it's a code smell that I'm not happy with. Is there some path variable that I can use, such that it still points to the actual design time data (not any temporary, deployed file), but does so relative to the active, open project?

Tridion Publishing using code (PublisherFramework)

I'm trying to publish a page during Workflow. There are two environment that we are publishing to during workflow process: one to test and one to live. During the first automatic activity we are publishing to test and during that process the Components on the Pages don't need to be approved. We got that to work.
However when we approve the Page and the Page is being published to live, we need to make sure that we only publish approved Components (i.e. major versions).
In my code I'm using the Page.Publish method, but with that I can't specify that it should only publish approved items.
The publish method accepts an argument called activateWorkflow. When set to True it publishes both approved and unapproved items; but when set to False it gets added to the queue and we get a success message, but nothing gets published.
Anyone have any ideas how I can fix this, using the publishing method and without manually checking?
Thanks.
I ran into a similar issue when going through Component Workflow and having to publish static pages (no dynamic component presentations).
When publishing to test, as you mentioned, simply do activateWorkflow=true. For your Live environment you need to kick off publishing after workflow completes. I've resolved the issue via the event system for this. Here an article that discusses this in more detail that may help you:
http://www.tridiondeveloper.com/autopublishing-on-workflow-finish
It is not clear where you are performing the activities, are you doing this from within your workflow activities in Visio?
Publishing will always only publish items that are either in the approved status for that target and items that have finished workflow (major versions).
All that said, I believethe reason you are getting empty PublishTransacctions is because you are calling the Publish() method on new items before you finish the page workflow activity (which means your new item is still in workflow, so the false value means there is nothing to publish which is not in workflow). Try calling FinishActivity() before the Publish() method is called.
Perhaps you could post your code from the final step so we can see exactly what you are doing.

Failure to update Service Reference

The problem is that when i try to update the service reference i get the following error.
The checkout was cancelled by the user.(0x80004004)
I can't seem to do anything that will solve it since if i do try to do something then i have problem with pending changes.
When you Update Service References, changes are made to files in ProjectDirectory/Service References/Your Service Namespace.
These files aren't shown in the solution explorer, but they should be in source control so other team members don't have to manually update references.
Try checking out these files and updating again.

MEF container auto-update using a directory-catalog

This is possible if we manually create a FileSystemWatcher and watch the 'parts' directory (here some dlls inside the folder) and track any changes, then we reflect the changes into a container which allows for recomposition.
Does MEF support auto-updating when the Container is using a DirectoryCatalog and it automatically for us ?
You need to call the Refresh method of the DirectoryCatalog for it to update with new contents. This will trigger recomposition in any containers hooked up to the catalog. You can create a FileSystemWatcher and call the Refresh method when anything changes.

Resources