MaxDrillthroughRecords on IOLEDBConnection resets after changing Connection - c#

I'm working with an IOLEDBConnection object, and changing the MaxDrillthoughRecords field works as expected. However, I also need to change the Connection field of the IOLEDBConnection and when I do this then the MaxDrillthroughRecords field gets set to 1000. I don't want this to happen.
IOLEDBConnection oleConnection = connection.OLEDBConnection;
try
{
this.SetMaxDrillthroughRecords();
var a = oleConnection.MaxDrillthroughRecords; // MaxDrillthroughRecords is 5 here.
oleConnection.Connection = new object[] { connection.ConnectionString };
a = oleConnection.MaxDrillthroughRecords; // MaxDrillthroughRecords is 1000 here.
}
finally { Marshal.ReleaseComObject(oleConnection); }
I tried to use Reflector to view the code in the Microsoft.Office.Interop.Excel assembly but was strangely unable to locate the interface. Is there some subtle behavior I'm missing here? Thanks for any help.

Related

Azure.Messaging.EventGrid vs Azure.EventGrid IotHubDeviceTelemetryEventData missing Constructor?

I am attempting to use the newer Azure.Messaging.EventGrid over the traditional Azure.EventGrid. I am getting hung up on my unit tests attempting to create object of type IotHubDeviceTelemetryEventData(). In the older library, I was able to create this no problem using the following convention.
return new object[]
{
new
{
id = "73813f6e-4d43-eb85-d6f1-f2b6a0657731",
topic = "testTopic",
data = new IotHubDeviceTelemetryEventData <-- New Up the object (no problem!)
{
Body = body} <-- Body has a setter. Great!
,
eventType = "Microsoft.Devices.DeviceTelemetry",
subject = "devices/b82bfa90fb/gw-uplink",
dataVersion = "1.0"
}
With the latest offering however, all of this is removed for some reason.
Old documentation with constructor etc (https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.eventgrid.models.iothubdevicetelemetryeventdata.-ctor?view=azure-dotnet
New documentation with no constructor, no setter on the body (DeviceTelemetry is sealed) etc:
https://learn.microsoft.com/en-us/dotnet/api/azure.messaging.eventgrid.systemevents.iothubdevicetelemetryeventdata?view=azure-dotnet
Anyone run into this? I would like to get off the old but I have existing unit tests that logically create TelemetryEventData and send to the function. I see no way of unit testing this ? I have tried mocking IotHubDeviceTelemetryEventData with
_mockHubTelemEventData.setup(c => c.Body).Returns(foo)
but this as well throws me an error of no setter on Body.
Super frustrating.
Other attempts have included creating EventGridEvent() but this as well is missing core functionality as the EventGridEvent.parse won't find any object of type Body.
EventGridEvent[] egEvents = EventGridEvent.ParseMany(BinaryData.FromStream(req.Body));
Mocking code you don't own comes with downsides, and you just one of them. But that's not why you're here. If you want to create instances of IotHubDeviceTelemetryEventData, you can try creating them as JSON and deserialize them. Give this a shot:
using System.Text.Json;
using Azure.Messaging.EventGrid.SystemEvents;
var json = #"
{
""body"":
{
""property"": { ""foo"": ""bar"" }
}
}
";
var eventData = JsonSerializer.Deserialize<IotHubDeviceTelemetryEventData>(json);

Property read only error when setting the label location for the axes - Infragistics

I am building the xamdatachart axes in the code behind as below:
NumericYAxis yAxis = new NumericYAxis() { IsInverted=true, MajorStrokeThickness= 0 };
NumericYAxis yAxis_right = new NumericYAxis() { IsInverted = false, MajorStrokeThickness = 0 };
To set yAxis's location to OutsideLeft and yAxis_right's location to OutsideRight, I added following part:
yAxis.MinimumValue = 0;
yAxis.Title = "Depth";
yAxis.LabelSettings.Location = AxisLabelsLocation.OutsideLeft;
yAxis_right.MinimumValue = 0;
yAxis_right.Title = "Net Production";
yAxis_right.LabelSettings.Location = AxisLabelsLocation.OutsideRight;
But get error as
"Cannot set a property on object 'Infragistics.Controls.Charts.AxisLabelSettings' because it is in a read-only state."
Any insights on why it happens?
I found this link useful from their website and I did follow the same but I get above error.
The error is being thrown because some property in LabelSettings is read-only aka get-only property. From your code, only Location property is being assigned so i would believe that property doesn't have a public set, causing an error when you try.
I searched for NumericYAxis class and found this:
http://help.infragistics.com/Help/Doc/wpf/2012.1/clr4.0/html/InfragisticsWPF4.Controls.Charts.XamDataChart.v12.1~Infragistics.Controls.Charts.AxisLabelSettings~LocationProperty.html
So Location is both a Dependency property (and this is static read-only) and a also the name of a member property (with get and set). When you type yAxis_right.LabelSettings.Location only one suggestion appears in Visual Studio?
Apparently this is a known issue in Xamdatachart.
here is the Infragistics's response and workaround to it.
This is essentially due to the AxisLabelSettings object being frozen, and so it gets placed in a read-only state. The workaround to this issue is to create a new AxisLabelSettings object and assign it to your axes' LabelSettings property. You can use the following code for this:
AxisLabelSettings settings = new AxisLabelSettings() { Location = AxisLabelsLocation.OutsideRight };
yAxis.LabelSettings = settings;

How to get Redmine Rest Api Issue with any parameters?

I am getting Redmine Issue with parameters.
I tried:
var rmMan = new RedmineManager(RedmineHost, RedmineKey);
rmMan.GetObjectList<Issue>(new NameValueCollection { { "parent_id", "1111" } }).Where(i=>i.Tracker.Name == "MyTrackerName");
How can I overcome this?
I want to get "Issue" object, found in the parameters without specifying Id. For example on the tracker.
GetObjectList wont do any filtering unless you specify the parameters. It will get all objects of type Issue (in your case). Adding the Where clause does the filtering after you've selected everything. I'm not sure that your NameValueCollection using parent_id will do anything either and redmine-net-api has terrible documentation.
Try this:
var parameters = new NameValueCollection
{
{ "parent_id", "1111" },
{ "tracker", "MyTrackerName" },
}
var rmMan = new RedmineManager(RedmineHost, RedmineKey);
var issues = rmMan.GetObjectList<Issue>(parameters);
Again, since the redmine-net-api documentation is very bad, this is kind of a shot in the dark.
I've forked the repository on GitHub and I'm going to try to generate the XMLDoc comments for the library in the next few days. Hopefully it'll get released with the next version.

AccessViolationException when accessing the Above, Below, Suffix, and Prefix properties of a Dimension

In Revit 2013 I have tool that I'm making that copies dimensions from one drafting view to another. I've got it to properly create a new version of a dimension including the Curve, DimensionType, and References but I'm having trouble with the properties Above, Below, Prefix, and Suffix. They copy just fine if at least one of them has a value. However, if none of them have a value then it will throw an AccessViolationException when I try to access them. I have tried to catch that exception but it bubbles up and it crashes Revit (I'm assuming it's caused by native code that fails).
How can I check to see if these properties have any value when I do my copying without triggering this AccessViolationException?
Autodesk Discussion Group Question
The DimensionData class is my own used for storing the dimension information so that it can be used to create the dimension in a separate document.
private IEnumerable<DimensionData> GetDimensionDataSet(Document document,
View view)
{
if (document == null)
throw new ArgumentNullException("document");
if (view == null)
throw new ArgumentNullException("view");
List<DimensionData> dimensionDataSet = new List<DimensionData>();
FilteredElementCollector dimensionCollector =
new FilteredElementCollector(document, view.Id);
dimensionCollector.OfClass(typeof(Dimension));
foreach (Dimension oldDimension in dimensionCollector)
{
Line oldDimensionLine = (Line)oldDimension.Curve;
string dimensionTypeName = oldDimension.DimensionType.Name;
List<ElementId> oldReferences = new List<ElementId>();
foreach (Reference oldReference in oldDimension.References)
oldReferences.Add(oldReference.ElementId);
DimensionData dimensionData;
try
{
string prefix = oldDimension.Prefix;
dimensionData = new DimensionData(oldDimensionLine,
oldReferences,
dimensionTypeName,
prefix,
oldDimension.Suffix,
oldDimension.Above,
oldDimension.Below);
}
catch (AccessViolationException)
{
dimensionData = new DimensionData(oldDimensionLine,
oldReferences, dimensionTypeName);
}
dimensionDataSet.Add(dimensionData);
}
return dimensionDataSet;
}
Regarding transactions: As far as I'm aware, you are only required to be inside a transaction when you are making any sort of CHANGE (modifications, deletions, additions). If all you are doing is collecting dimension information, you would not need a transaction, but when you use that information to create new dimensions in another document, that code would have to be inside a transaction. I have had a number of programs under development which did not yet modify the document but simply collected parameter settings and posted them to a TaskDialog.Show(). These programs worked fine, and I don't see anything in your code that actually modifies your model, so that doesn't seem to be your issue.
It seems like I bug.
Can you post the issue to the ADN Support?
The solution I can suggest is to use Parameters of the Dimension element instead of Dimension class properties.
For example, you can get Suffix and Prefix by following code
var suffixParameter =
oldDimension.get_Parameter(BuiltInParameter.SPOT_SLOPE_SUFFIX);
string suffix = null;
if (suffixParameter != null)
{
suffix = suffixParameter.AsString();
}
var prefixParameter =
oldDimension.get_Parameter(BuiltInParameter.SPOT_SLOPE_PREFIX);
string prefix = null;
if (prefixParameter != null)
{
prefix = prefixParameter.AsString();
}
Unfortunatelly, I don't tell you how to get Above and Below Properties via parameters, because I don't have a project to test. But you can easily determine parameters using BuiltInParameter Checker
Hope it helps.

Sharepoint Client Object Model setting ModifiedBy field

I am trying to update the "ModifiedBy" field in a Sharepoint discussion board using the Client Object Model. By changing the "Editor" and "Author" fields, I can change the "ModifiedBy" that appears on the list view. However, once you click on a discussion post, the "ModifiedBy" field that appears there (the one with the picture above it) does not reflect the changes. After experimenting, I discovered that the field I need to change to correct this is called "MyEditor". Unfortunately, this field is read-only.
In the code below, I try to change the read-only settings of the field to false. When I look at the MyEditor field in Visual Studio's debugger after the ExecuteQuery() line at the bottom of the first block, it shows that the ReadOnlyField value has in fact been set to false.
sharepointContext.Load(discussionList);
sharepointContext.ExecuteQuery();
var fields = discussionList.Fields;
sharepointContext.Load(fields);
sharepointContext.ExecuteQuery();
var field = fields.GetByInternalNameOrTitle("MyEditor");
field.ReadOnlyField = false;
field.Update();
sharepointContext.Load(field);
sharepointContext.ExecuteQuery();
The code above executes with no problems. The problem comes with this next block:
//...Code to initialize discussionItem...
discussionItem["MyEditor"] = 0;
discussionItem["Editor"] = 0;
discussionItem["Author"] = 0;
discussionItem["Body"] = "Testing";
discussionItem["Title"] = "Hello Worlds";
discussionItem.Update();
sharepointContext.Load(discussionItem);
sharepointContext.ExecuteQuery();
When the code reaches the ExecuteQuery() at the bottom of the second block, it throws a ServerException with the following message:
Invalid data has been used to update the list item.
The field you are trying to update may be read only.
To make sure that the MyEditor field was the one causing the exception to be thrown, I commented out the line where I set it and ran the code again. Everything worked fine. I don't understand what is wrong, can someone help me?
In case someone needs to find the user by name, it goes like this:
private static FieldUserValue GetUser(ClientContext clientContext, string userName)
{
var userValue = new FieldUserValue();
var newUser = clientContext.Web.EnsureUser(userName);
clientContext.Load(newUser);
clientContext.ExecuteQuery();
userValue.LookupId = newUser.Id;
return userValue;
}
The returned value can be set via item["Author"]
ModifiedBy and CreadtedBy calculated automatically from Author and Editor you need to change only Author and Editor fields like this:
using (var clientContext = new ClientContext(#"http://server"))
{
var web = clientContext.Web;
var lst = web.Lists.GetByTitle("Discus");
var item = lst.GetItemById(2);
item["Author"] = 3;
item["Editor"] = 2;
item.Update();
clientContext.ExecuteQuery();
Console.WriteLine("done");
}

Categories