|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestGeneric
{
class Program
{
static void Main(string[] args)
{
string myCar = "carA";
string myMoto = "motoB";
mPricer Pr = new mPricer(myCar,myMoto);
}
}
public class mPricer
{
double total;
public mPricer(string carId, string motoId)
{
Car c = (car) Activator.CreateInstance(myCar);
Moto m = (moto) Activator.CreateInstance(myMoto);
total = c.GetPrice() + m.GetCost();
}
public void ShowTotal()
{
Console.WriteLine(total);
}
}
public abstract class car { abstract public double GetPrice();}
public class carA : car { public override double GetPrice() { return 11; } }
public class carB : car { public override double GetPrice() { return 12; } }
public abstract class moto { abstract public double GetCost(); }
public class motoA : moto { public override double GetCost() { return 7; } }
public class motoB : moto { public override double GetCost() { return 6; } }
}
That, i think, should do it ... you don't need a generic class
Pedis ex oris
Quidquid latine dictum sit, altum sonatur
|
|
|
|
|
or better yet....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestGeneric
{
class Program
{
static void Main(string[] args)
{
string myCar = "carA";
string myMoto = "motoB";
Car c = (car) Activator.CreateInstance(myCar);
Moto m = (moto) Activator.CreateInstance(myMoto);
mPricer Pr = new mPricer(c,m);
}
}
public class mPricer
{
double total;
public mPricer(Car c, Moto m)
{
total = c.GetPrice() + m.GetCost();
}
public void ShowTotal()
{
Console.WriteLine(total);
}
}
public abstract class car { abstract public double GetPrice();}
public class carA : car { public override double GetPrice() { return 11; } }
public class carB : car { public override double GetPrice() { return 12; } }
public abstract class moto { abstract public double GetCost(); }
public class motoA : moto { public override double GetCost() { return 7; } }
public class motoB : moto { public override double GetCost() { return 6; } }
}
it helps to think about the interface exposed by a type ... regardless of which runtime car class you have you always want to call GetPrice ... we require that all car classes expose a getPrice method so this is either declared on the base class or interface. since this base class contains all the common functionality required it is sufficient for use throughout mPricer
generics would only be required if you wanted to expose the car/moto instances and didn't want to require a cast to their runtime types but, in an interface driven design you should probably ask yourself WHY you need the runtime type
Pedis ex oris
Quidquid latine dictum sit, altum sonatur
|
|
|
|
|
Oky thanks a lot.
The problem is that mPrice is a hudge class and I can not change it.
public class mPricer<T, G>
Contrains are:
input as string
ublic class mPricer<t, g="">
So I think is not possible to solve my problem without changing the class
|
|
|
|
|
aye, if you cant modify mPricer you are in the unfortunate situation of being stuck with someone elses shoddy design ... we've all been there and you have my sympathy.
Pedis ex oris
Quidquid latine dictum sit, altum sonatur
|
|
|
|
|
Well, if the class is broken and you can't change it, then you're pretty screwed. You should have mentioned this in the original question :P.
How much can you 'not change it'? Is this because you don't have the source, or because someone has told you you can't? If the latter, ignore them and don't tell them, and make the trivial change to call a factory instead of using new() directly.
|
|
|
|
|
Are you sure you can compile it?
Activator.CreateIstance() doesn't accept string
|
|
|
|
|
You might be right there, answering from memory doesn't always work.
Try
Type carType = Type.GetType("MyNamespace.Cars.Car");
Car car = (Car)Activator.CreateInstance(carType);
|
|
|
|
|
Thanks, really I was missing some reference in my project.
Thanks for your replay It is very usefull. I'm finding a solution using your path..
|
|
|
|
|
TBH, i just copied those lines from the OPs example without thinking, however there is an overload for createInstance that takes assembly name and type name as strings.. so i minor tweak
Pedis ex oris
Quidquid latine dictum sit, altum sonatur
|
|
|
|
|
Thanks it is usefull for me as starting point to study more
|
|
|
|
|
Hi all:
I installed TFS 2010 with minimum requirement by using advanced wizard. So the TFS server has only IIS, and MS SQL databases without reporting services, and SharePoint server. I installed it with success. I tried to create an team project using MS Studio 2010 without success. Then I installed team explorer from the same disk as TFS server, and tried to create it, also without success.
When I create a team project, I have to pick a template. I tried agile ... or cmmi ... for template from pick up list, both without success. I searcedh on the internet for quite sometime, I did not found anything that helps. And I guess it may be caused by the lack of these supporting appliances such as report services from SQl and Sharepoint server. I've been a programmer for last 20 years. I really could not figure out where to fix it.
The error is the following from the log.
Please help me since I've stuck here for awhile. I thank you in advanced
2012-02-14T09:56:32 | Module: Microsoft.ProjectCreationWizard.Build | Thread: 4 | <Permission allow="ViewBuildDefinition, ViewBuilds" identity="[$$PROJECTNAME$$]\Readers" />
2012-02-14T09:56:32 | Module: Microsoft.ProjectCreationWizard.Build | Thread: 4 | Allowing permission(s) ViewBuildDefinition, ViewBuilds to account [nirttest]\Readers.
2012-02-14T09:56:32 | Module: Microsoft.ProjectCreationWizard.Build | Thread: 4 | <Permission allow="ViewBuildDefinition, QueueBuilds, ViewBuilds, EditBuildQuality" identity="[$$PROJECTNAME$$]\Contributors" />
2012-02-14T09:56:32 | Module: Microsoft.ProjectCreationWizard.Build | Thread: 4 | Allowing permission(s) ViewBuildDefinition, QueueBuilds, ViewBuilds, EditBuildQuality to account [nirttest]\Contributors.
2012-02-14T09:56:32 | Module: Microsoft.ProjectCreationWizard.Build | Thread: 4 | <Permission allow="ViewBuildDefinition, EditBuildDefinition, DeleteBuildDefinition, QueueBuilds, ManageBuildQueue, StopBuilds, ViewBuilds, EditBuildQuality, RetainIndefinitely, DeleteBuilds, ManageBuildQualities, DestroyBuilds" identity="[$$PROJECTNAME$$]\Builders" />
2012-02-14T09:56:32 | Module: Microsoft.ProjectCreationWizard.Build | Thread: 4 | Allowing permission(s) ViewBuildDefinition, EditBuildDefinition, DeleteBuildDefinition, QueueBuilds, ManageBuildQueue, StopBuilds, ViewBuilds, EditBuildQuality, RetainIndefinitely, DeleteBuilds, ManageBuildQualities, DestroyBuilds to account [nirttest]\Builders.
2012-02-14T09:56:32 | Module: Microsoft.ProjectCreationWizard.Build | Thread: 4 | <Permission allow="ViewBuildDefinition, EditBuildDefinition, DeleteBuildDefinition, QueueBuilds, ManageBuildQueue, StopBuilds, ViewBuilds, EditBuildQuality, RetainIndefinitely, DeleteBuilds, ManageBuildQualities, DestroyBuilds" identity="[$$PROJECTNAME$$]\$$PROJECTADMINGROUP$$" />
2012-02-14T09:56:32 | Module: Microsoft.ProjectCreationWizard.Build | Thread: 4 | Allowing permission(s) ViewBuildDefinition, EditBuildDefinition, DeleteBuildDefinition, QueueBuilds, ManageBuildQueue, StopBuilds, ViewBuilds, EditBuildQuality, RetainIndefinitely, DeleteBuilds, ManageBuildQualities, DestroyBuilds to account [nirttest]\Project Administrators.
2012-02-14T09:56:32 | Module: Microsoft.ProjectCreationWizard.Build | Thread: 4 | <Permission allow="ViewBuildDefinition, EditBuildDefinition, DeleteBuildDefinition, QueueBuilds, ManageBuildQueue, StopBuilds, ViewBuilds, EditBuildQuality, RetainIndefinitely, DeleteBuilds, ManageBuildQualities, DestroyBuilds, OverrideBuildCheckInValidation" identity="$$COLLECTIONADMINGROUP$$" />
2012-02-14T09:56:32 | Module: Microsoft.ProjectCreationWizard.Build | Thread: 4 | Allowing permission(s) ViewBuildDefinition, EditBuildDefinition, DeleteBuildDefinition, QueueBuilds, ManageBuildQueue, StopBuilds, ViewBuilds, EditBuildQuality, RetainIndefinitely, DeleteBuilds, ManageBuildQualities, DestroyBuilds, OverrideBuildCheckInValidation to account vstfs:///Framework/IdentityDomain/98d85d64-370f-48b7-91ef-30ab8474bf6a\Project Collection Administrators.
---begin Exception entry---
Time: 2012-02-14T09:56:50
Module: Engine
Event Description: TF30162: Task "BuildTask" from Group "Build" failed
Exception Type: Microsoft.TeamFoundation.Client.PcwException
Exception Message: The file exists.
Exception Details:
Stack Trace:
at Microsoft.VisualStudio.TeamFoundation.Build.ProjectComponentCreator.ExecuteInternal(ProjectCreationContext context, XmlNode taskXml, Boolean validationOnly)
at Microsoft.VisualStudio.TeamFoundation.Build.ProjectComponentCreator.Execute(ProjectCreationContext context, XmlNode taskXml)
at Microsoft.VisualStudio.TeamFoundation.ProjectCreationEngine.TaskExecutor.PerformTask(IProjectComponentCreator componentCreator, ProjectCreationContext context, XmlNode taskXml)
at Microsoft.VisualStudio.TeamFoundation.ProjectCreationEngine.RunTask(Object taskObj)
-- Inner Exception --
Exception Message: The file exists.
(type BuildServerException)
Exception Stack Trace: at Microsoft.TeamFoundation.Client.TeamFoundationClientProxyBase.ProcessHttpResponse(HttpWebResponse response, Stream responseStream, WebException webException, XmlReader& xmlResponseReader)
at Microsoft.TeamFoundation.Client.TeamFoundationClientProxyBase.ExecWebServiceRequest(HttpWebRequest request, XmlWriter requestXml, String methodName, HttpWebResponse& response)
at Microsoft.TeamFoundation.Build.Client.BuildWebService.AddProcessTemplates(ProcessTemplate[] processTemplates)
at Microsoft.TeamFoundation.Build.Client.BuildServer.SaveProcessTemplates(IProcessTemplate[] processTemplates)
at Microsoft.VisualStudio.TeamFoundation.Build.ProjectComponentCreator.ExecuteInternal(ProjectCreationContext context, XmlNode taskXml, Boolean validationOnly)
Inner Exception Details:
Exception Message: The file exists.
(type SoapException)SoapException Details: <detail xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ExceptionMessage="The file exists.
" BaseExceptionName="System.IO.IOException" />
Exception Stack Trace:
--- end Exception entry ---
2012-02-14T09:56:50 | Module: Engine | Thread: 4 | TF30202: Task "" from Group "" will not be run because a prior task failed.
--------------------------------------------------
Thank you!
|
|
|
|
|
All,
This is a strange problem, I tried to find answer without success. The file I am tring to transmit is an xslx file.
I have the following piece of code that works fine when our employees/clients access our website from outside our network.
Response.ContentType = "application/vnd.ms-excel";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.AppendHeader("Content-Disposition", "attachment; filename=" + newFile.Name.Replace(" ","_"));
Response.AddHeader("Content-Length", new System.IO.FileInfo(newFile.FullName).Length.ToString());
Response.TransmitFile(newFile.FullName);
HttpContext.Current.ApplicationInstance.CompleteRequest();
But when someone within our local network/office accesses this website I get the following error, "Unable to download xxxx from xxxx.com. Unable to open this Internet site. The requested site is either unavailable or cannot be found. please try again later."
I tried different approaches like adding Response.Flush() and Response.End() etc., nothing worked so far, I appreciate any help with this.
This only happens with IE, works fine in Chrome and Firefox, if this helps.
modified 14-Feb-12 12:24pm.
|
|
|
|
|
Hi,
I try to use SMO for backup from my network server. But it's giving error like "Backup Failed for server "1.1.1.10"...
Anybody can point me that where I have a mistake...from the below code...?
Thanks
<pre>ServerConnection Conn1 = new ServerConnection("1.1.1.10", "admin", "xxxxxxxxxx");
Backup Mybackup = new Backup();
Server srv = new Server(Conn1);
srv.ConnectionContext.LoginSecure = false;
srv.ConnectionContext.Login = "admin";
srv.ConnectionContext.Password = "xxxxxxxxxx";
srv.ConnectionContext.Connect();
Mybackup.Action = BackupActionType.Database;
Mybackup.Database = "Invoice_Master";
Mybackup.Devices.Add(new BackupDeviceItem("C:\\Temp\\CHECK\\MyInvoices.bak", DeviceType.File));
Mybackup.BackupSetName = "For_Bills";
Mybackup.SqlBackup(srv);
|
|
|
|
|
Does Sql Server have write-rights on that specific path? In other words, can you backup to there using the Management Studio?
Bastard Programmer from Hell
|
|
|
|
|
Thanks Eddy...
Yes...Its a mapped drive path...
Also I manually use to take the backup daily by the following manner.
backup database Invoice_Master to disk="C:\MyPath\BackupName.bak"
|
|
|
|
|
Thanks Eddy...!
I got it, Thanks again!
|
|
|
|
|
Hi, I am new to InfoPath, and I am having an issue with a web-based form. I have a Rich Text Box that is in a repeating section that is
bound to an XHTML field. This is not in the main/default view, and the user can submit the form from the main/default view and from the
sub-view with this control in it. When the user adds more than one of these Rich Text Boxes to the form, the data that has been entered into
the field isn't always saved. I have, however, never seen the first time not be saved.
Scenario 1:
user enters text into the Rich Text Box. Then clicks the submit button. The text in the first Rich Text Box keeps the user entered text as
expected. The user then adds another field, enters text, and clicks submit. The form then saves, however, the newly entered text in the
Rich Text Box sometimes changes to "", and sometimes the text in the Rich Text Box stays as the newly entered text as expected
Scenario 2:
After clicking submit and the data stays as expected, the user then wants to change the value that is in the Rich Text Box. The user enters
new data in the Rich Text Box and presses submit. The form then saves, however, sometimes the text in the Rich Text Box changes back to
the data that was there previous to the user's changes, and sometimes the text stays as the newly entered text as expected.
This seems to be a random error. It sometimes happens on the second entered Rich Text Box and sometimes doesn't happen until the
4th or 5th. This error doesn't happen when debugging the form in infopath. The C# code I am using to debug this issue is on the submit
button clicked event.
XPathNavigator domNav = MainDataSource.CreateNavigator();
XPathNodeIterator rows = domNav.Select
("/my:myTipLead/fxintakerequest:IntakeRequest/fusionx:AnalystNotes/fusionx:AnalystNote/fusionx:NoteText"
, NamespaceManager);
while (rows.MoveNext())
{
EventLog.WriteEntry(ERROR_SOURCE, "node value = " + rows.Current.Value);
}
The event log show all of the times it acted as expected. When it fails to save the text entered, the event log has all of the previously entered Rich Text Box data and the newly entered Rich Text Box entry says "not value = ". I'm assuming that the text is never getting into the field. Any help would be much appreciated. Thank you!!
P.S. I know this isn't exactly a C# issue. I posted it in the SharePoint forums becuase we are using SharePoint to host our forms, and I was told that this was not a SharePoint issue. I'm not exactly sure where to post this question
|
|
|
|
|
Hello all,
how can i create textBox in C# with email autocomplate exactly like "outlook To field" ??
|
|
|
|
|
Subscribe to the text changed event of the text box. Filter your list of potential suggestions using the current Text property. Display a listbox filled with the suggestions below the text box. In the double click event of the list box, get the currently selected item, transfer that to the text box, and close (hide) the list box.
|
|
|
|
|
don't forget to temporarily prevent the text changed event firing when you set textbox to the selected value (by either -= the event handler and then += it back, or by using a bool flag). If you don't you'll get an infinite loop
Pedis ex oris
Quidquid latine dictum sit, altum sonatur
|
|
|
|
|
What technology are you targetting? Win Forms, WPF, Silverlight, ASP.NET?
The common thing for you to look at though, is that the text changes on every keypress (or on a paste operation), and this gives you something to filter your larger list on - and the results are displayed in some form of panel beneath the textbox.
|
|
|
|
|
|
If you're using WinForms, set AutoCompleteMode = Suggest , AutoCompleteSource = CustomSource and AutoCompleteCustomSource = (your list).
|
|
|
|
|
Hi I have created the usercontrol which is having autocomplete feature. It contains the controls combobox and listbox in the user control. I can't use the default autocompelete feature of the combobox or textbox due to some client's issue.
The user control is then implemented in the form which is having tablelayoutpanel control. But the issue is that the listbox is hiding in the tablelayoutpanel control.
I tried to set "Bring to front" of listbox/usercontrol. But could not solve the issue. Even I used setchildIndex but not useful.
Is there anything I can do to solve the issue?
|
|
|
|
|
have you tried setting the minimum size so that the control can't 'shrink' down so far as to hide its component controls?
Pedis ex oris
Quidquid latine dictum sit, altum sonatur
|
|
|
|
|