I would like to set ISpProperties for an ISpRecognizer instanance.
ISpProperties list have a list of properties I would like to modify, specifically SPPROP_RESPONSE_SPEED. But I don't know how to do this syntaxly.
CComPtr<ISpRecognizer> m_cpRecognizer; // object type
HRESULT hr = S_OK;
hr = m_cpRecognizer.CoCreateInstance(CLSID_SpInprocRecognizer); // create an instance
Now how can I now use ISpProperties to modify m_cpRecognizer properties now. Specifically modify SPPROP_RESPONSE_SPEED property.
Thanks
Hope this will work
m_cpRecognizer->SetPropertyNum(SPPROP_RESPONSE_SPEED,600);
this will set response time to 600ms.
Related
I am trying to create a WCF service without knowing its type/interface at runtime. To do this, I use ChannelFactory. ChannelFactory is a generic class so I need to use Type.MakeGenericType. The type I pass to MakeGenericType is from a list of interfaces I previously gathered with reflection by searching some assemblies.
Ultimately, I call MethodInfo.Invoke to create the object. The object is created just fine, but I cannot cast it to the proper interface. Upon casting, I receive the following error:
"Unable to cast transparent proxy to type 'Tssc.Services.MyType.IMyType'"
After some experimenting, I have found that the interface/type passed to MakeGenericType seems to be the problem. If I substitute the interface in my list with the actual interface, then everything works fine. I have combed through the two objects and cannot see a difference. When I modify the code to produce both types, comparing them with Equals returns false. It is unclear to me whether Equals is just checking that they are referring to the same object (not) or thety are checking all properties, etc.
Could this have something to do with how I gathered my interfaces (Reflection, saving in a list...)? A comparison of the objects seems to indicate they are equivalent. I printed all properties for both objects and they are the same. Do I need to dig deeper? If so, into where?
// createService() method
//*** tried both of these interfaces, only 2nd works - but they seem to be identical
//Type t = interfaces[i]; // get type from list created above - doesn't work
Type t = typeof(Tssc.Services.MyType.IMyType); // actual type - works OK
// create ChannelFactory type with my type parameter (t)
Type factoryType = typeof(ChannelFactory<>);
factoryType = factoryType.MakeGenericType(new Type[] { t });
// create ChannelFactory<> object with two-param ctor
BasicHttpBinding binding = new BasicHttpBinding();
string address = "blah blah blah";
var factory = Activator.CreateInstance(factoryType, new object[] { binding, address });
// get overload of ChannelFactory<>.CreateChannel with no parameters
MethodInfo method = factoryType.GetMethod("CreateChannel", new Type[] { });
return method.Invoke(factory, null);
//--------------- code that calls code above and uses its return
object ob = createService();
//*** this cast fails
Tssc.Services.MyType.IMyType service = (Tssc.Services.MyType.IMyType)ob;
Ok, I understand whats happening here - the problem is relating to loading the same assembly being effectively loaded twice - once via a reference, and once via the assembly load command. What you need to do is change the place where you load your assembly, and check to see if it already exists in the current AppDomain, like this maybe:
Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetName().Name.Equals("ClassLibrary1Name"));
if (assembly == null)
{
assembly = System.Reflection.Assembly.LoadFile("path to your assembly");
}
//do your work here
This way if the assembly is already loaded into memory, it'll use that one.
Ektron 8.0.1 SP1
I am using SmartForms and Content Types to read (and hopefully write) data. I can read data but now I am attempting to write a new record similar to the following.
ContentTypeManager<member> contentTypeManager = new ContentTypeManager<member>();
ContentType<member> newmem = new ContentType<member>();
newmem.SmartForm.details.field1 = "Chuck"; // This line throws 'Object reference not set to an instance of an object.' error
newmem.SmartForm.details.field2 = "Norris";
contentTypeManager.Update(newmem);
I get the error "Object reference not set to an instance of an object." for that first assignment line. What am I missing?
I am having trouble finding good documentation on ContentTypes for 8.0.1 now that the Ektron website has been redesigned.
Thx.
Thanks for clarifying, to ADD content to a folder that has a smartform assigned to it, the basic code block should get you started: (Note: the Html attribute of the content is simply the xml matched to the schema you created)
Ektron.Cms.Framework.Content.ContentManager cmanager = new Cms.Framework.Content.ContentManager();
Ektron.Cms.ContentData cdata = new ContentData();
cdata.FolderId = 0;
cdata.XmlConfiguration.Id = 0; //SMARTFORM ID HERE
cdata.Html = "<root><field1>field1 value</field1><field2>field2 value</field2></root>";
cmanager.Add(cdata);
You could update ContentTypes.cs to include an Add method. Just copy the Update method and change contentManager.Update to contentManager.Add.
public void Add(ContentType<T> contentType)
{
Initialize();
contentType.Content.Html = Ektron.Cms.EkXml.Serialize(typeof(T), contentType.SmartForm);
contentManager.Add(contentType.Content);
}
Unfortunately, contentManager.Add returns void. Ideally it should return the new content ID.
It's kind of hard to explain what I'm searching for but my example should clarify it.
I have next code:
var schedule = ScheduleUtil.CreateScheduleDto(user, user);
Expect.Call(() => _scheduleRepository.Save(schedule));
Now, what I want to do is when this Save call is made, the schedule.id property should be set to another value (1 for instance).
I do not want to mock schedule. Can this be done? The Save method doesn't return a value, so that's not a possiblity, but I do want the object schedule to be modified.
UPDATE: Maybe a small example will clarify what I exactly want.
Say there's a class with a method Save:
public void Create(Entity entity)
{
//entity is saved to database
//entity.id is updated with the created id in database
}
So, before the create, entity.id is -1, after the create it is > 0.
Now, there's a service that uses this Create. Code contracts on this service method say that before it is called, the entity must have an id equal to -1, after it is called it must have an id > 0 (preconditions and postconditions).
So, what I need is something like this:
var entity = new Entity(); //id == -1
Expect.Call(() => _instance.Create(entity);
//Now the entity.id should be a random number > 0. This is what I need, to have Rhino Mocks update the id of entity to a given integer. Is this possible?
No. If you're not mocking the _scheduleRepository, Rhino Mocks doesn't know about it. Why don't you want to mock the _scheduleRepository?
EDIT: Ok, now I see what you want to do. Use the "WhenCalled" extension method to define code to be executed when Rhino.Mocks intercepts the call. Something like this should work:
_scheduleRepository.Expect(s => s.Save(schedule)).WhenCalled(a => ((Schedule) a.Arguments[0]).Id = 1);
Now. I so confuse when use any classes. What is best practice approach to use them?
Example
I have a UserClass name User that have 2 attributes UserName and Password
when I use I will create new object like this
UserClass userObject = new UserClass();
this is my question that I so confuse to use
If i want to call Method name "Login" what is appropriate way to use them?
Between
1 Set Value to Attribute of Object Like this
userObject.UserName = "user";
userObject.Password = "password";
if (userObject.Login())
{
//Do Something After Login
}
else
{
//Show Something when Error
}
2 Send Value as parameter
if (userObject.Login("user","password"))
{
//Do Something After Login
}
else
{
//Show Something when Error
}
From above
What is appropriate approach to use and apply to any classes?
Thank you very much for your guidance _/\_
P.S I practice to be better Programmer
Use a property to store information that belongs to the object. (eg, a Username)
Use a parameter to pass information to a single method which doesn't have to do with the rest of the object.
I try to call skype instance by COM on F#.
A aim is get mood message.
test.fs
// Import skype4com Api
open SKYPE4COMLib
type SKYPE4COM =
new() = new SKYPE4COM()
let GetMood =
let aSkype = new SKYPE4COM
mood <- aSkype.CurrentUserProfile.MoodText
mood
But when build(before too),error occur.
Incomplete structured construct at or before this point in expression
Thanks in advance.
this is next version what I think.
test01.fs
// Import skype4com Api
open SKYPE4COMLib
let GetMood =
let aSkype = new SKYPE4COMLib() // line 1
mood <- aSkype.CurrentUserProfile.MoodText // line 2
mood // line 3
error message(when building).
line in 1:error FS0039: The type 'SKYPE4COMLib' is not defined
line in 2:error FS0039: The value or constructor 'mood' is not defined
line in 3:error FS0039: The value or constructor 'mood' is not defined
also like that...
Your code has several issues. First of all, your constructor for the SKYPE4COM class appears to be recursive (?!), which is going to cause a stack overflow if you try to create an instance. Secondly, the error that you're receiving is because you are using the new operator, but you haven't completed the call to the constructor (i.e. you need to apply the constructor using parentheses: let aSkype = new SKYPE4COM()). Even then, though, you've got another issue because your type doesn't expose a CurrentUserProfile property, so your code still won't work.
Try something like this:
open SKYPE4COMLib
let getMood() =
SkypeClass().CurrentUserProfile.MoodText
Consider using a Type Extension to add a member to an already existing type:
open SKYPE4COMLib
type SKYPE4COMLib with
member this.GetMood() =
aSkype.CurrentUserProfile.MoodText
This would allow you to access GetMood as if it were a member function defined on the SKYPE4COMLib type:
let x = new SKYPE4COMLib()
printfn "%A" (x.GetMood())