The combination of parameters is either not valid or not complete. Parameter name: importRequest - azure-devops

I am trying to create a GitImportRequest with the Microsoft.TeamFoundation.SourceControl.WebApi library, but I keep getting this error message:
{"The combination of parameters is either not valid or not complete.\r\nParameter name: importRequest"}
This is what my code to create the GitImportRequest looks like.
var gitSrc = new GitImportGitSource();
gitSrc.Url = gitUrl;
gitSrc.Overwrite = true;
var gitImportParams = new GitImportRequestParameters();
gitImportParams.GitSource = gitSrc;
var gitImportRequest = new GitImportRequest();
gitImportRequest.Repository = targetRepository;
gitImportRequest.Parameters = gitImportParams;
What am I missing? I have looked at the Azure Devops Api Import page with no success.
https://learn.microsoft.com/en-us/rest/api/azure/devops/git/import-requests/create?view=azure-devops-rest-6.0

Related

SharePoint 2013 REST API - Post SocialRestPostCreationData

I’m currently working on a small application to push Post to a SharePoint 2013 SiteFeed using the Social.Feed API.
Basic Posts using the following JSON Object structure are working fine but I’m struggling using a Social-Attachment.
As long I’m referencing to the files located somewhere in the internet everything works. Posts will create listitems in micro-feed list with HTTP-Reference to the Files. The Object I'm using is set up like this
var creationInfo = new
{
restCreationData = new
{
__metadata = new { type = "SP.Social.SocialRestPostCreationData" },
ID = array,
creationData = new
{
__metadata = new { type = "SP.Social.SocialPostCreationData" },
Attachment = new
{
__metadata = new { type = "SP.Social.SocialAttachment" },
AttachmentKind = 0,
ContentUri = "https://www.google.com/images/icons/hpcg/ribbon-black_68.png",
Description = "Look at this",
Name = "Test",
Uri = "https://www.google.com/images/icons/hpcg/ribbon-black_68.png"
},
ContentText = text,
UpdateStatusText = false,
}
}
};
Is there a possibility to use a local file instead? - Removing the google paths and using a local path in ContentUri will end up in a BAD-Request error.
I guess that the files has to be uploaded somehow before.
Thanks for you help.
Iki
After some trying we now ended up with the following solution.
Before we create the SocialPost, we upload the picture into an image gallery where all Feed users have access to.
Then we create the post containing a link to the image
-> This will do the trick.

How do I programmatically set configuration for the ImageResizer SQLReader plugin v4?

I was previously using v3 of ImageResizer but am now trying to use v4.
See: http://imageresizing.net/docs/v4/plugins/sqlreader
I need to programmatically set the several config options for the SQLReader plugin. I had this previous code, but it no longer works, stating that the type SqlReaderSettings could not be found:
// SqlReader Plugin
var fileSettings = new SqlReaderSettings
{
ConnectionString = ApplicationConfigurationContext.Current.DefaultSiteSqlConnectionString,
PathPrefix = "~/Images",
StripFileExtension = true,
ImageIdType = SqlDbType.UniqueIdentifier,
ImageBlobQuery = ???,
ModifiedDateQuery = ???,
ImageExistsQuery = ???,
CacheUnmodifiedFiles = true,
RequireImageExtension = true
};
I cannot use the web.config file to store some of these settings. Specifically the connection string may change at run-time, and cannot be stored un-encrypted in the web.config file due to company policy.
Thanks for the help.
Update: This is the code I now use. I did not add in this plugin from the Web.config as it would be redundant.
new SqlReaderPlugin
{
ConnectionString = ApplicationConfigurationContext.Current.DefaultSiteSqlConnectionString,
ImageIdType = SqlDbType.VarChar,
QueriesAreStoredProcedures = true,
ModifiedDateQuery = "procFileImageResizerSelectTimestamps",
ImageBlobQuery = "procFileImageResizerSelectData",
ExposeAsVpp = true,
VirtualFilesystemPrefix = filesUri,
RequireImageExtension = true,
StripFileExtension = true,
CacheUnmodifiedFiles = true
}.Install(Config.Current);
You can replace SqlReaderSettings with SqlReaderPlugin directly; it no longer uses a separate settings class. Nearly all the class members should be the same, so just change the name of the class you are initializing.

Error "The given key was not present in the dictionary" When Creating New Custom Entity on Update Event

On CRM 2013 on-premise, I'm trying to write a plugin that triggers when an update is made to a field on Quote. The plugin then creates a new custom entity "new_contract".
My plugin is successfully triggered when the update to that field is made. However I keep getting an error message "The given key was not present in the dictionary" when trying to create the new custom entity.
I'm using a "PostImage" in this code. I confirm that it's registered using the same name in Plugin Registration.
Here is the code
var targetEntity = context.GetParameterCollection<Entity>
(context.InputParameters, "Target");
if (targetEntity == null)
{throw new InvalidPluginExecutionException(OperationStatus.Failed,
"Target Entity cannot be null")}
var postImage = context.PostEntityImages["PostImage"];
if (postImage == null)
{throw new InvalidPluginExecutionException(OperationStatus.Failed,
"Post Image is required");}
var quote = context.GenerateCompositeEntity(targetEntity, postImage);
//throw new InvalidPluginExecutionException(OperationStatus.Failed, "Update is captured");
//Guid QuoteId = (Guid)quote.Attributes["quoteid"];
var serviceFactory = (IOrganizationServiceFactory)serviceProvider
.GetService(typeof(IOrganizationServiceFactory));
var service = serviceFactory.CreateOrganizationService(context.UserId);
var contractEntity = new Entity();
contractEntity = new Entity("new_contract");
if (quote.Attributes.Contains("portfolio"))
{
var quotePortfolio = (EntityReference)quote.Attributes["new_portfolio];
contractEntity[Schema.new_contract.PortfolioName] =
new EntityReference(quotePortfolio.LogicalName, quotePortfolio.Id);
}
if (quote.Attributes.Contains(Schema.Quote.QuoteName))
{
var quoteName = (string)quote.Attributes["name"];
contractEntity[Schema.new_contract.contractName] = quoteName;
}
var contractId = service.Create(contractEntity);
I think context does not contain "PostImage" attribute.You should check context to see whether it contains the attribute before getting the data.
Looking at this line in your post above:
var service = serviceFactory.CreateOrganizationService(context.UserId);
I am deducing that the type of your context variable is LocalPluginContext (since this contains the UserId value) which does not expose the images (as another answer states).
To access the images, you need to get to the Plugin Execution Context:
IPluginExecutionContext pluginContext = context.PluginExecutionContext;
Entity postImage = null;
if (pluginContext.PostEntityImages != null && pluginContext.PostEntityImages.Contains("PostImage))
{
postImage = pluginContext.PostEntityImages["PostImage"];
}
In the below code segment, you are checking for the attribute "portfolio" and using "new_portfolio". Can you correct that and let us know whether that worked.
if (quote.Attributes.Contains("portfolio"))
{
var quotePortfolio = (EntityReference)quote.Attributes["new_portfolio];
contractEntity[Schema.new_contract.PortfolioName] = new EntityReference(quotePortfolio.LogicalName, quotePortfolio.Id);
}
First, you don't say what line is throwing the exception. Put in the VS debugger and find the line that is throwing the exception.
I did see that you are trying to read from a dictionary here without first checking if the dictionary contains the key, that can be the source of this exception.
var postImage = context.PostEntityImages["PostImage"];
if (postImage == null)
throw new InvalidPluginExecutionException(OperationStatus.Failed,
"Post Image is required");
Try this:
if(!context.PostEntityImages.Contains("PostImage") ||
context.PostEntityImages["PostImage"] == null)
InvalidPluginExecutionException(OperationStatus.Failed, "Post Image is required");
var postImage = context.PostEntityImages["PostImage"];
Although, I don't think that a PostEntityImage Value will ever be null, if it passes the Contains test you don't really need the null check.

nDepend - how to modify "JustMyCode" queries using nDepend API?

My goal is to modify "JustMyCode" queries using nDepend API. I am using code like:
var justMyCodeGroup = prj.CodeQueries.CodeQueriesSet.ChildGroups.Single(x => x.Name.Contains("JustMyCode"));
var originalQuery = justMyCodeGroup.ChildQueries
.Single(x => x.QueryString.Contains("Discard generated Types from JustMyCode"));
var changedQuery = originalQuery.Controller.CreateQuery(originalQuery.IsActive,
query,
originalQuery.
DisplayStatInReport,
originalQuery.DisplayListInReport,
originalQuery.DisplaySelectionViewInReport,
originalQuery.IsCriticalRule);
var justMyCodeGroupWithModifiedQuery = justMyCodeGroup.ReplaceQuery(originalQuery, changedQuery);
prj.CodeQueries.CodeQueriesSet.ReplaceGroup(justMyCodeGroup, justMyCodeGroupWithModifiedQuery);
However, when I run the code above I get ArgumentException with message:
newGroup.Controller is different than this groupOfGroups.Controller
Any help ?
Update 1:
I also tried code:
var justMyCodeGroup = prj.CodeQueries.CodeQueriesSet.ChildGroups.Single(x => x.Name.Contains("JustMyCode"));
var originalQuery = justMyCodeGroup.ChildQueries
.Single(x => x.QueryString.Contains("Discard generated Types from JustMyCode"));
var changedQuery = originalQuery.Controller.CreateQuery(originalQuery.IsActive,
query,
originalQuery.
DisplayStatInReport,
originalQuery.DisplayListInReport,
originalQuery.DisplaySelectionViewInReport,
originalQuery.IsCriticalRule);
var justMyCodeGroupWithModifiedQuery = justMyCodeGroup.ReplaceQuery(originalQuery, changedQuery);
var newQueries = new List<IQuery>();
foreach (var q in justMyCodeGroup.ChildQueries)
{
if (q.QueryString.Contains("Discard generated Types from JustMyCode"))
{
continue;
}
newQueries.Add(prj.CodeQueries.CodeQueriesSet.Controller.CreateQuery(q.IsActive, q.QueryString,
q.DisplayStatInReport, q.DisplayListInReport, q.DisplaySelectionViewInReport, q.IsCriticalRule));
}
newQueries.Add(prj.CodeQueries.CodeQueriesSet.Controller.CreateQuery(originalQuery.IsActive, query, originalQuery.DisplayStatInReport, originalQuery.DisplayListInReport, originalQuery.DisplaySelectionViewInReport, originalQuery.IsCriticalRule));
var newGroup = prj.CodeQueries.CodeQueriesSet.Controller.CreateGroup(justMyCodeGroup.Name,
justMyCodeGroup.IsActive, justMyCodeGroup.ShownInReport, newQueries, new List<IGroup>());
prj.CodeQueries.CodeQueriesSet.RemoveGroup(justMyCodeGroup);
prj.CodeQueries.CodeQueriesSet.AddGroup(newGroup);
Right now, RemoveGroup throws exception:
this group of groups doesn't contain groupToRemove.
Update 2:
And I also wonder, why does this code return false ?
var justMyCodeGroup = prj.CodeQueries.CodeQueriesSet.ChildGroups.Single(x => x.Name.Contains("JustMyCode"));
prj.CodeQueries.CodeQueriesSet.ContainsGroup(justMyCodeGroup)
Refer to the PowerTools source file:
$NDependInstallDir$\NDepend.PowerTools.SourceCode\CQL2CQLinq\CQL2CQLinqPowerTool.cs
This PowerTools convert code queries written with old CQL syntax into code queries written with new CQLinq syntax, hence it loads the queries set from a project, update CQL queries, and then save the new queries set in the project.
The queriesController is gathered this way...
var queriesSet = project.CodeQueries.CodeQueriesSet;
var queriesController = queriesSet.Controller;
... and then used this way to modify the queries set:
queriesController.DoUpdateQueryObject(query, newQuery);

Send a mail automatically in an thunderbird addon

I work on a thunderbird addon and a need to send a mail written in by the addon and not by the user.
I try to do this with that but is doesn't work :
var am = Components.classes["#mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager);
var cf = Components.classes["#mozilla.org/messengercompose/composefields;1"].createInstance(Components.interfaces.nsIMsgCompFields);
cf.from = "somebody#somewhere.com";
cf.to = "somebodyelse#somewhere.com";
cf.subject = "test";
cf.body = "just a test\r\n";
var params = Components.classes["#mozilla.org/messengercompose/composeparams;1"].createInstance(Components.interfaces.nsIMsgComposeParams);
params.composeFields = cf;
var msgSend = Components.classes["#mozilla.org/messengercompose/send;1"].createInstance(Components.interfaces.nsIMsgSend);
var msgCompose = Components.classes["#mozilla.org/messengercompose/compose;1"].createInstance(Components.interfaces.nsIMsgCompose);
msgCompose.compFields = cf;
msgCompose.initialize(window,params); //[Exception... "Could not convert JavaScript argument arg 0 [nsIMsgCompose.initialize]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: *****" data: no]
msgCompose.SendMsg(msgSend.nsMsgDeliverNow, am.defaultAccount.defaultIdentity, am.defaultAccount.key, null, null);
Anyone know where is my mistake or a simple method to do that ?
Thanks
Sending an email from an addon is a hauntingly complex task. Fortunately, libraries exist, namely in the form of thunderbird-stdlib. See https://github.com/protz/thunderbird-stdlib/blob/master/send.js#L228 for the implementation of the sendMessage function, https://github.com/protz/GMail-Conversation-View/blob/master/content/stub.compose-ui.js#L879 for an example of how to use the function.