Delete obsolete reported properties from Azure iot edge module Twin - c#

I am still rather inexperienced to Microsoft Azure iotedge (and stackoverflow - this being my first post) and how module twins work and have an issue regarding the deletion of obsolete properties from the reported part of my module twin.
I have migrated a couple of properties from one device to another within the module twin, however have not been able te remove the properties from the reported and I understand that setting them to null should do the trick (setting them to null and updating them in desired removes them only from the desired part of the twin). The obsolete properties are also not present in the module twin locally on the device
I have tried updating the reported - with a C# console app using the Microsoft.Azure package setting the obsolete properties to null - but this doesnt seem to work either.
await registryManager.UpdateTwinAsync(deviceId, moduleId, removeProperties, eTag);
with my string removeProperties being something like the following (updating desired using this route works like a charm)
{
{
"properties": {
"reported": {
"foo": {
"bar": null
}
}
}
}
Can Anybody suggest on a way to remove these properties?

You can't update the reported properties through the registry manager. However, it can be done using the device's identity. In the same way you wrote a console program to update the twin with the service SDK, you could do it with the device SDK (granted that the device is offline).
For instance if you have a file called twin.json:
{
"foo": {
"bar": null
}
}
You can update the reported properties like this:
var text = await File.ReadAllTextAsync("./twin.json");
var deviceClient = DeviceClient.CreateFromConnectionString("very-secret-connection-string");
var twinCollection = new TwinCollection(text);
await deviceClient.UpdateReportedPropertiesAsync(twinCollection);

Related

ASP.NET boilerplate localization

In ASP.NET Boilerplate I am changing language like
English
It works properly on my local machine, but not on test server.
Also when I'm clicking it locally, sometimes there is abp.message.error with null content.
I have a few questions about that:
1) What is this URL (/AbpLocalization...), looks lika a controller, but there is no such thing in my code?
2) How can I find and debug it?
3) What may happen on another server that crashes it (on test server clicking button reloads state, but does not change language)
Solved!
What caused the problem was the fact, that the database on test server did not have one table that was in local database, and what's more important: this table was included in model transferred through Entity Framework to database. After adding table to test server everything works fine.
ASP.NET Boilerplate is an application framework built from modules, one of them being Localization module. Since it's open source you can change default behaviors, although I should not recommend doing it without really good reason.
Localization is part of the core package and it's located here: GitHub
I recommend you to use documentation and configure it to your needs. You can find localization documentation here: documentation.
And lastly, you should check your running configuration in the test environment, which is possibly faulted in some way. Another reason for error may be an issue with your ABP version.
AbpLocalizationController is located here in source code
src/Abp.AspNetCore/AspNetCore/Mvc/Controllers/AbpLocalizationController.cs
And this is change culture code:
public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "")
{
if (!GlobalizationHelper.IsValidCultureCode(cultureName))
{
throw new AbpException("Unknown language: " + cultureName + ". It must be a valid culture!");
}
var cookieValue = CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(cultureName, cultureName));
Response.Cookies.Append(
CookieRequestCultureProvider.DefaultCookieName,
cookieValue,
new CookieOptions {Expires = Clock.Now.AddYears(2)}
);
if (AbpSession.UserId.HasValue)
{
SettingManager.ChangeSettingForUser(
AbpSession.ToUserIdentifier(),
LocalizationSettingNames.DefaultLanguage,
cultureName
);
}
if (Request.IsAjaxRequest())
{
return Json(new AjaxResponse());
}
if (!string.IsNullOrWhiteSpace(returnUrl) && AbpUrlHelper.IsLocalUrl(Request, returnUrl))
{
return Redirect(returnUrl);
}
return Redirect("/"); //TODO: Go to app root
}
https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.AspNetCore/AspNetCore/Mvc/Controllers/AbpLocalizationController.cs
If you want to debug this code, fork the project from github repo and add it to your solution. Replace your abp dll references with this local project references.
Meanwhile you didn't mention what the error say. To learn it check out website logs.

CRM 2015 SDK : The deserializer has no knowledge of any type that maps to this name

I am currently working with CRM 2015 SDK. I am simply trying to update a value in C# with this SDK. But for some reasons that I try to figure out, there is a trouble when I save my context.
There is the code :
foreach (KeyValuePair<string, Account> account in dicAccount)
{
//Calcul of url/login/date/key/customer values
string generatedUrl = Utilities.GenerateURL(url, login, date, key, customer);
account.Value.new_Link = generatedUrl;
if (!context.IsAttached(account.Value))
{
context.Attach(account.Value);
}
context.UpdateObject(account.Value);
}
SaveChangesResultCollection results = context.SaveChanges(SaveChangesOptions.ContinueOnError);
if (results != null)
{
foreach (SaveChangesResult result in results)
{
Type type = result.Request.GetType();
bool hasError = result.Error != null;
Entity entity = (Entity)result.Request.Parameters["Target"];
if (type == typeof(UpdateRequest))
{
if (hasError)
{
if (entity != null)
{
log.Error(result.Error.Message);
}
}
}
On my Dynamics entities, I have this :
[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("new_link")]
public string new_Link
{
get
{
return this.GetAttributeValue<string>("new_link");
}
set
{
this.OnPropertyChanging("new_link");
this.SetAttributeValue("new_link", value);
this.OnPropertyChanged("new_link");
}
}
Right now, I got this error printed by the LogError :
The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:request. The InnerException message was 'Error in line 1 position 12271. Element 'http://schemas.datacontract.org/2004/07/System.Collections.Generic:value' contains data from a type that maps to the name 'http://schemas.microsoft.com/xrm/7.1/Contracts:ConcurrencyBehavior'. The deserializer has no knowledge of any type that maps to this name. Consider changing the implementation of the ResolveName method on your DataContractResolver to return a non-null value for name 'ConcurrencyBehavior' and namespace 'http://schemas.microsoft.com/xrm/7.1/Contracts'.'. Please see InnerException for more details.
After few searchs, I found 2 possible causes :
Enable Proxy type : the fact is I have the code to do that. So this couldn't help me.
_serviceProxy.EnableProxyTypes();
Version of SDK : I saw some answers about the fact that the SDK version 7.0 can cause this problem. The fact is that I am using the version 7.1 and I also try with the latest 7.1.1. I use this DLL's : Microsoft.Xrm.Client, Microsoft.Xrm.Sdk, Microsoft.Crm.Sdk.Proxy
Type of this element : I also try with a basic string as datatype. There is still problem of serealization.
None of these ideas solve my problem and right now, I do'nt really know where I am suppose to look into to solve fix this problem.
Also the problem might be unknown types. It's important to enable proxy types on OrganizationServiceProxy. It solved my issue with similar error
using (OrganizationServiceProxy proxy = new OrganizationServiceProxy(organizationUri, null, credentials, null))
{
proxy.EnableProxyTypes();
}
Not 100% what the issue is but I would suggest trying the following to see if it helps.
Regenerate your proxy, it might be a case that your proxy is out of date which is why the deserializer has no knowledge of any type that maps to this name.
Try using late bound just to see if that works, help to narrow things down if there is a problem in the early bound code. For example:
Entity account = new Entity("account");
account.Id = new Guid("");
account["new_link"] = "your value";
service.Update(account);
Break point the code and see what values are being updated on the account objects, e.g. make sure another attribute doesn't have an odd value.
I will share my solution to this problem, when using own created WCF services, which are using generated models from CRM.
When referencing the WCF service in other project using VS 2017, there are some options in the Add Service Reference window: press "Advanced..." and uncheck Reuse types in referenced assemblies
Hope it helps someone.
I have solved this problem by updating the referece Microsoft.Xrm.Tooling.Connector
It turned out that I was using an older version which did not match with others SDK references, but it did not crash when building the program.
You can use NuGet to get that assembly.
This is the project's URL:
https://learn.microsoft.com/es-es/dotnet/api/microsoft.xrm.tooling.connector?view=dynamics-xrmtooling-ce-9

get application path in asp.net vnext

I've been trying to open a file in asp.net 5 and have not been having a lot of success.
In the past you used Server.MapPath or HostingEnvironment.ApplicationPhysicalPath. They are both gone in the OWIN based framework.
There is a HostingEnvironment class but it's in the System.Aspnet but it needs to be initialized by the hosting environment (it no longer has a static member for ApplicationPhysicalPath but I'm guessing the WebRoot member does that now. The problem is I can't find a reference to it anywhere.
I've also looked at Context.GetFeature<> but it doesn't seem to have any feature that would show the application path, just request and response related info. The code listing the features can be found here.
<snark>Is the ability to work with files a discontinued feature in ASP.NET?</snark>
There is also the possibility that I can't brain very well right now and missed something.
You can get it from the ApplicationBasePath property of Microsoft.Framework.Runtime.IApplicationEnvironment serivce.
Example: https://github.com/aspnet/Mvc/blob/9f1cb655f6bb1fa0ce1c1e3782c43a2d45ca4e37/test/WebSites/FilesWebSite/Controllers/DownloadFilesController.cs#L28
There are two approaches now:
using Microsoft.Extensions.PlatformAbstractions;
public Startup(IApplicationEnvironment appEnv)
{
// approach 1
var path01 = PlatformServices.Default.Application.ApplicationBasePath;
// approach 2
var path02 = appEnv.ApplicationBasePath;
}

SignalR ASPNetHost does not exist in the current context

I've downloaded the latest SignalR code (as of 04/04/12) from GitHub as it now compiles with MonoDevelop so I can use it on OS X.
But while testing the new version with the SignalR.Sample example listed on the Getting Started page, it fails with the following error:
The name 'AspNetHost' does not exist in the current context
This occurs in StockTicker.cs here:
private static dynamic GetClients()
{
return AspNetHost.DependencyResolver.Resolve<IConnectionManager>().GetClients<StockTickerHub>();
}
Can anyone explain what has become of AspNetHost?
Suggestions on how to get the SignalR.Sample compiling would be very welcome.
I had the same problem and found that this was deprecated in SignalR 0.5. Here is an article detailing the changes.
Specific to your item, the change is from this:
public void PerformLongRunningHubOperation()
{
var clients = AspNetHost.DependencyResolver.Resolve<IConnectionManager>().GetClients<MyHub>();
clients.notify("Hello world");
}
To this in 0.5:
public void PerformLongRunningHubOperation()
{
IHubContext context = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
context.Clients.notify("Hello world");
}
You're gonna need to read the code because the source isn't in sync with the docs. The docs are for the current release, not the actively developed.
Take a look at the asp.net sample to see the current API. It's not set in stone yet though.

PhluffyFotos does not work on Azure SDK 1.3

I have tried PhluffyFotos example on Azure SDK 1.2 and it works perfect. Today I have installed on another (clen) computer Azure SDK 1.3 and I have also want to try PhluffyFotos on it but it does not work. I have problem with this part:
if (!Roles.GetAllRoles().Contains("Administrator"))
{
Roles.CreateRole("Administrator");
}
It seems it somehow does not load the custom RoleProvider (TableStorageRoleProvider). Do you have any idea what it could be?
I get the following error: "The Role Manager feature has not been enabled.", because of the following exception "'System.Web.Security.Roles.ApplicationName' threw an exception of type 'System.Configuration.Provider.ProviderException'".
Can someone test this example and see what is the problem? http://phluffyfotos.codeplex.com/
Firsty I have the "SetConfigurationSettingPublisher" problem with this example, but I have successfully resole it.
EDIT:
I have look deeper into it and I am sure there are a problem with Role provider. Somehow the Roles class do not read config file. Have anyone any idea why?
I have the exact same problem with my own project. I verified with Fusion logs that the assembly which contains the custom providers dont even load. so it seems the problem is somehow related to the web.config settings being ignored.
To run PhluffyFotos example on Azure SKD 1.3 you have to the following:
Change reference Microsoft.WindowsAzure.StorageClient from 1.0 to 1.1
Move "GetConfigurationSettingValue" to the Global.asax "Application_Start" event.
Move Role related initialization to the Global.asax "Application_BeginRequest" event, but you have to ensure that it executes only once. Example:
private static object gate = new object();
private static bool initialized = false;
protected void Application_BeginRequest()
{
if (initialized)
{
return;
}
lock (gate)
{
if (!initialized)
{
// We need to check if this is the first launch of the app and pre-create
// the admin role and the first user to be admin (still needs to register).
if (!Roles.GetAllRoles().Contains("Administrator"))
{
Roles.CreateRole("Administrator");
}
if (!Roles.GetUsersInRole("Administrator").Any())
{
Roles.AddUserToRole(RoleEnvironment.GetConfigurationSettingValue("DefaultAdminRoleUser"), "Administrator");
}
initialized = true;
}
}
}
I posted a version of the code with the fixes suggested by Peter to rapidshare here:
http://rapidshare.com/files/434649379/PhluffyFotos.zip
For those who don't want to fuss around fixing the dependencies etc.
Cheers,
Daniel

Categories