I am developing a windows store app that allows a User to place points on a map and load them from a server. I have this working fine but I need to include more properties than the standard Pushpin class allows (rating / description / user).
Because Pushpin is sealed, I cannot add these fields and use my own object in place of Pushpin. I tried over the past couple of hours to compose my own PointOfInterest class with a Pushpin object inside it however, this approach fails in a number of areas (When I place a point on a map, I want to retrieve more details than just name / tag and have no way of getting a reference back to the original object.)
If anybody has an idea of where to go from here I would like to hear from you !
If you need access to the private members of a sealed class then you are out of luck.
Best you can do is proxy (which you already seem to be doing by including it as a member). Also called faking it :)
Related
I'm practicing C# and have only been learning for about a month. I have a question that maybe is a bit on the beginner side so I hope someone doesn't mind answering for me.
I have a class called yourCharacter. In this class sits all the information for someone's character. I want to give the user the ability to create a new character so I've created a method/function to do so. My question is, can I place a function within yourCharacter that creates a List of yourCharacter. Is this doable? Is it bad form to do it this way? Should I be creating this list in my Main class and then calling a function within the main class to do this?
I hope my question is clear enough, please let me know if you need further detail. The only reason I want to do this is because in my head it makes more sense to group my methods/functions with the class it is manipulating and or working with.
class yourCharacter{
//insert a bunch of variables here
public static void newChar(){
List newCharacter = new List<yourCharacter>();
}
}
What you have there is doable for sure.
A class can contain itself as a member. This might make sense in some scenario, but think about yours and see whether it applies. In your case it seems as if you're trying to have a mechanism to group characters - but it's not a good way to do it. Why? Read on...
Say you had a box. This box contained another box inside... that box could contain another box inside...
So in that case, if I made a class which represents this kind of box it might make sense to add that class into itself.
Making a class like that represents a system in reality where a box contains other boxes.
What system are you trying to abstract, so that it is useful that a character contains other characters?
I can think of something: let's imagine a character in your game can swallow other characters and they'll live inside his tummy...
If you want to group them - you'd likely want to use another class which represents the system under which your characters are grouped like this:
Say your game has an adventure party! The adventure party can invite other people to join and they go questing together. Let's say this adventure party has a leader which decides who can join and who can't. You still probably wouldn't make a character which contains other characters... you would rather create a class called "AdventureGroup" with a list of "ordinary" party members and a leader, you would assign a string which represents the "group nickname", and all other kinds of things which represent the group as an entity. Something like that... you get the jist.
I need to change the layer mask during runtime in order to select different objects depending on the context.
From my understanding this should be done in the InputSystemProfile by editing the Pointers property:
CoreServices.InputSystem.InputSystemProfile.PointerProfile.PointingRaycastLayerMasks
But the field is read-only, and I can't find another way to edit it, other than manually in the editor.
Btw I'm using an editable profile for the input system.
In HTK this was achieved by assigning a value to:
GazeManager.Instance.RaycastLayerMasks
Any suggestions?
For the returned field PointingRaycastLayerMasks, it is an instance of reference type LayerMask[]. Therefore, although you cannot change the value of the reference itself, it is possible to change the data that belongs to that referenced object.
So, you can change Layer Mask with the following code:
//Uncheck [PostProcessing],[Spatial Awareness]
CoreServices.InputSystem.InputSystemProfile.PointerProfile.PointingRaycastLayerMasks[0].value = 19;
If you have questions about how to use LayerMasks in Unity, please see here: How do I use layermasks?
you could change the pointers layer mask by overriding it
All the pointers can by found here: CoreServices.InputSystem.DetectedInputSources
and in each one you can do:
ptr.PrioritizedLayerMasksOverride
Hope this helps
Our database includes 4,000,000 records (sql server) and it's physical size is 550 MB .
Entities in database are related each other as graph style. When i load an entity from db with 5 level depth there is a problem (all records are loaded).
Is there any mechanism like Entity Framework( Include("MyProperty.ItsProperty"))
What is the best Types for using with db4O databases?
Is there any issue for Guid, Generic Collections?
Is there any best practise for WebApplication with db4o? Session Containers+EmbeddedDb4ODb or Client/ServerDb4O?
Thx for help..
Thx for good explanation. But i want to give my exact problem as a sample:
I have three entities: (N-N relationship. B is an intersection Entity. Concept:Graph)
class A
{
public B[] BList;
public int Number;
public R R;
}
class B
{
public A A;
public C C;
public D D;
public int Number;
}
class C
{
public B[] BList;
public E E;
public F F;
public int Number;
}
I want to query dbContext.A.Include("BList.C.BList.A").Include("BList.C.E.G").Where(....)
I want to get :A.BList.C.BList.A.R
But I dont want to get :A.R
I want to get :A.BList.C.E.G
But I dont want to get :A.BList.C.F
I want to get :A.BList.C.E.G
But I dont want get :A.BList.D
Note:this requirements can change a query to another query
Extra question is there any possibility to load
A.BList[#Number<120].C.BList.A[#Number>100] Super syntax :)
Activation: As you said db4o uses it's activation-mechanism to control which objects are loaded. To prevent that to many objects are loaded there are different strategies.
Lower the global default activation-depth: configuration.Common.ActivationDepth = 2 Then use the strategies below to activate objects on need.
Use class-specific activation configuration like cascading activation, minimum and maximun activation-depth etc.
Activate objects explicit on demand: container.Activate(theObject,5)
However all these stuff is rather painful on complex object graphs. The only strategy to get away from that pain is transparent activation. Create an attribute like TransparentlyActivated. Use this attribute to mark your stored classes. Then use the db4otool to enhance your classes. Add the db4otool-command to the Post-Build events in Visual Studio: Like 'PathTo\Db4oTool.exe -ta -debug -by-attribute:YourNamespace.TransparentlyActivated $(TargetPath)
Guid, Generic Collections:
No (in Version 7.12 or 8.0). However if you store your own structs: Those are handled very poorly by db4o
WebApplication: I recommend an embedded-container, and then a session-container for each request.
Update for extended question part
To your case. For such complex activation schema I would use transparent activation.
I assume you are using properties and not public fields in your real scenario, otherwise transparent persistence doesn't work.
The transparent activation basically loads an object in the moment a method/property is called the first. So when you access the property A.R then A itself it loaded, but not the referenced objects. I just go through a few of you access patterns to show what I mean:
Getting 'A.BList.C.BList.A.R'
A is loaded when you access A.BList. The BList array is filled with unactivate objects
You keep navigating further to BList.C. At this moment the BList object is loaded
Then you access C.BList. db4o loads the C-object
And so on and so forth.
So when you get 'A.BList.C.BList.A.R' then 'A.R' isn't loaded
A unloaded object is represented by an 'empty'-shell object, which has all values set to null or the default value. Arrays are always fully loaded, but first filled with unactivated objects.
Note that theres no real query syntax to do some kind of elaborate load requests. You load your start object and then pull stuff in as you need it.
I also need to mention that this kind of access will perform terrible over the network with db4o.
Yet another hint. If you want to do elaborate work on a graph-structure, you also should take a look at graph databases, like Neo4J or Sones Graph DB
I need to bind labels or items in a toolstrip to variables in Design Mode.
I don't use the buit-in resources not the settings, so the section Data is not useful. I am taking the values out from an XML that I map to a class.
I know there are many programs like:
http://www.jollans.com/tiki/tiki-index.php?page=MultilangVsNetQuickTourForms
but they work with compiled resx. I want to use not compiled XML.
I know that programatically i can do it, i create a method (for example, UpdateUI()), and there I assign the new values like this:
this.tsBtn.Text=Class.Texts.tsBtnText;
I would like something i could do from Design Mode or a more optimized way than the current one. Is there any Custom Control out there or Extension?
Aleksandar's response is one way to accomplish this, but in the long run it's going to be very time consuming and won't really provide much benefit. The bigger question that should be asked is why do you not want to use the tools and features built-in to .NET and Visual Studio or at least use a commercial third-party tool? It sounds like you are spending (have spent?) a lot of time to solve a problem that has already been solved.
Try with inheriting basic win controls and override OnPaint method. Example bellow is a button that has his text set on paint depending on value contained in his Tag property (let suppose that you will use Tag property to set the key that will be used to read matching resource). Then you can find some way to read all cache resource strings from xml files (e.g. fictional MyGlobalResources class.
public class LocalizedButton : Button
{
protected override void OnPaint(PaintEventArgs pevent)
{
base.OnPaint(pevent);
this.Text = MyGlobalResources.GetItem(this.Tag.ToString());
}
}
You can use satellite assemblies for localization and generate them using your XML file as a source for the translated entities.
more about satellites http://msdn.microsoft.com/en-us/library/21a15yht(VS.71).aspx
sure it's not from design mode, but there's no way to do it this way with your restrictions.
I am trying to use a business object that I am passing to the report.rdlc. The properties in my object are not directly exposed. The properties I require are embedded within another object inside the top level object. As this is a WCF project I can't control what goes on at the server end. I am just able to request these objects or Insert/Update/Delete their info from the database. It is done in this way as the back end can use multiple flavors of database.
Here is what I can see after adding my business object as a DataSource:
-BusinessObject
-CustomerInfo
-ClientName
-ColumnName
-DisplayName
-FieldName
-IsNull
-KeyColumn
-SenondKeyColumn
-StringValue
-ClientID
-ColumnName
-DisplayName
-FieldName
-IntValue
-IsNull
-KeyColumn
-SenondKeyColumn
+ClientAddress
+Instrument
+Telephone
etc etc
I need to be able to display, for example, the ClientName.StringValue field.
If I drag the field I want onto the report I get:
=First(Fields!StringValue.Value)
This doesn't display anything when the report is run, I assume because it can't qualify what StringValue it is talking about and there could be many.
If I try dragging the ClientName object I get:
=First(Fields!ContactName.Value)
However this gives:
#ERROR
When the report is run.
I would have thought you could use:
=First(Fields!ClientName.StringValue.Value)
but this won't even let me build.
The problem was that the info wasn't at the root level. I worked it out though.
=First(Fields!ClientName.Value.StringValue, "BusinessObject_CustomerInfo")
I've got a pretty good grip of the ReportViewer component now cheers.
If you set the data source to the CustomerInfo instance (or list) returned from the service it should work. The ReportViewer control can be a little complicated when you start dealing with object hierarchies, but you don't have to do anything crazy or special if all the information is at the root level.