|
How's it going? Made any progress? I now have two different algorithms that seem to do what you describe; neither is recursive.
|
|
|
|
|
I think this is related to Egyptian Fractions[^].
I would start with 1/64 - 1/64 - ... - 1/64 - 1/64 (64 times) and loop thru grouping two adjoing equal numbers, to the one above it (i.e., double). To avoid repeats, store what you have in an array and rotate each sequence n - 1 times adding only the unique sequences, and do the same for the reverse sequences adding them to your array.
Vertically shown:
1/4 | Same 3 below |
1/4 | 1/4 | 1/4 | 1/2 | |
1/4 | 1/4 | 1/2 | 1/4 | 1/2 |
1/4 | 1/2 | 1/4 | 1/4 | 1/2 | 1
Out of all permutations with 4, you only have 4 generating sequences and the rest are generated through rotating and reversing.
modified 4-Oct-14 11:29am.
|
|
|
|
|
Another thing to look into is Euler's Integer Partition.
For 1, there's 1 sequence.
For 1/2, there's 2 sequences.
For 1/4, there's 6 sequences.
For 1/8, there's 56 sequences.
Maybe there's a rule[^] out there.
8C8 = 1
1/8
1/8
1/8
1/8
1/8
1/8
1/8
1/8
7C6,1 = 7
1/4 1/8 1/8 1/8 1/8 1/8 1/8
1/8 1/4 1/8 1/8 1/8 1/8 1/8
1/8 1/8 1/4 1/8 1/8 1/8 1/8
1/8 1/8 1/8 1/4 1/8 1/8 1/8
1/8 1/8 1/8 1/8 1/4 1/8 1/8
1/8 1/8 1/8 1/8 1/8 1/4 1/8
1/8 1/8 1/8 1/8 1/8 1/8 1/4
6C4,2 = 15
1/4 1/8 1/8 1/8 1/8 1/4 1/4 1/4 1/4 1/8 1/8 1/8 1/8 1/8 1/8
1/4 1/4 1/8 1/8 1/8 1/8 1/8 1/8 1/8 1/4 1/4 1/4 1/8 1/8 1/8
1/8 1/4 1/4 1/8 1/8 1/4 1/8 1/8 1/8 1/8 1/8 1/8 1/4 1/4 1/8
1/8 1/8 1/4 1/4 1/8 1/8 1/4 1/8 1/8 1/4 1/8 1/8 1/8 1/8 1/4
1/8 1/8 1/8 1/4 1/4 1/8 1/8 1/4 1/8 1/8 1/4 1/8 1/4 1/8 1/8
1/8 1/8 1/8 1/8 1/4 1/8 1/8 1/8 1/4 1/8 1/8 1/4 1/8 1/4 1/4
5C3,2 = 10
1/4
1/4
1/4
1/8
1/8
4C4 = 1
1/4
1/4
1/4
1/4
5C4,1 = 5
1/2
1/8
1/8
1/8
1/8
4C2,1,1 = 12
1/2
1/4
1/8
1/8
3C2,1 = 3
1/2
1/4
1/4
2C2 = 1
1/2
1/2
1C1 = 1
1
modified 4-Oct-14 11:37am.
|
|
|
|
|
General solution for generating unique sequences (in increasing order or decreasing denominators) (e.g., {(1/4, 1/4, 1/2)}):
Let S1 = {(1)} and S2 = {(1/2, 1/2)} ∪ S0.
Then S2n = The set of every element in S2n-1 beginning with 1/2n-1 and ending with 1/2k concatenated with every set element in S2n-1 greater than or equal to 1/2k and every element fraction gets halved ∪ S2n-1.
If we omit the first underlined condition, we wouldn't be able to use the union of the previous set as a shortcut. If we omit the second underlined condition, we won't get the uniqueness and we won't get every permutation either.
So S4 = [ {(1/2, 1/2), (1/2, 1/2)} & {(1/2, 1/2), (1)} ] / 2 ∪ S2 = {(1/4, 1/4, 1/4, 1/4), (1/4, 1/4, 1/2)} ∪ S2.
This will not generate (1/4, 1/2, 1/4) or (1/2, 1/4, 1/4), etc.
And, thus, S8 = {(1/4, 1/4, 1/4, 1/4) concatenated with each set in S4 then halved, and (1/4, 1/4, 1/2) concatenated with each of the two sets in {(1/2, 1/2), (1)} and halved, and all of S4 once more}.
To get the count of them, you'd need to count all the permutations.
16C16 16 16's
15C14,1 14 16's 1 8's
14C12,2 12 16's 2 8's
13C12,1 12 16's 1 4's
13C10,3 10 16's 3 8's
12C10,1,1 10 16's 1 8's 1 4's
12C8,4 8 16's 4 8's
11C8,2,1 8 16's 2 8's 1 4's
10C8,2 8 16's 2 4's
9C8,1 8 16's 1 2's
11C6,5 6 16's 5 8's
10C6,3,1 6 16's 3 8's 1 4's
9C6,1,2 6 16's 1 8's 2 4's
8C6,1,1 6 16's 1 8's 1 2's
10C4,6 4 16's 6 8's
9C4,4,1 4 16's 4 8's 1 4's
8C4,2,2 4 16's 2 8's 2 4's
7C4,2,1 4 16's 2 8's 1 2's
7C4,3 4 16's 3 4's
6C4,1,1 4 16's 1 4's 1 2's
9C2,7 2 16's 7 8's
8C2,5,1 2 16's 5 8's 1 4's
7C2,3,2 2 16's 3 8's 2 4's
6C2,3,1 2 16's 3 8's 1 2's
6C2,1,3 2 16's 1 8's 3 4's
5C2,1,1,1 2 16's 1 8's 1 4's 1 2's
8C8 8 8's
7C6,1 6 8's 1 4's
6C4,2 4 8's 2 4's
5C4,1 4 8's 1 2's
5C2,3 2 8's 3 4's
4C2,1,1 2 8's 1 4's 1 2's
4C4 4 4's
3C2,1 2 4's 1 2's
2C2 2 2's
1C1 1 1's
Count(S1) =1
Count(S2) =2
Count(S4) =6
Count(S8) =56
Count(S16)=5272
Generating the count for 32 and 64 is not all that difficult manually or programmatically. Would rather do it manually myself. Generating every permutation is still an interesting exercise.
modified 26-Oct-14 14:33pm.
|
|
|
|
|
Hi,
I found lots of post with same question but none of them match with what I want to do.
I have a usercontrol with nothing special in it. I want to be able to add only button in it.
How do I prevent my usercontrol adding other stuff then Button ?
I have override the OnControlAdded event but this event is activate after the control is added. I want to prevent which mean block before it is added to the controls collection.
Is it possible ?
Regards,
|
|
|
|
|
You need to be more specific about what it is you are trying to "block:"
1. are you speaking of a design-time scenario where other developers add instances of your UserControl to a Form, and then add other Controls to it ?
2. or, are you speaking of the UserControl at run-time, when some action by the user triggers the creation of a new Control and the adding of that Control to the instance of the UserControl ?
Exactly what is it you have no control over now in terms of other Controls being added to your UserControl ?
« I had therefore to remove knowledge, in order to make room for belief » Immanuel Kant
|
|
|
|
|
Hi BillWoodruff,
Let's say I want to do this in a design-time scenario.
I add my usercontrol to the form and I want to prevent other programmer to add control in it.
[Designer(typeof(MyControlDesigner))]
public partial class GroupInput : UserControl
{
private Color _BorderColor = Color.Black;
[Category("Appearance")]
[Description("Set the border color")]
[Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public Color BorderColor
{
get { return _BorderColor; }
set {
_BorderColor = value;this.Refresh();
}
}
public GroupInput()
{
SetStyle(ControlStyles.ResizeRedraw, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle, this._BorderColor, ButtonBorderStyle.Solid);
}
}
internal class MyControlDesigner : ParentControlDesigner
{
private const int glyphSize = 6;
private const int hitBoundSize = glyphSize + 4;
private GroupInput _groupInput = null;
public override void Initialize(IComponent component)
{
base.Initialize(component);
_groupInput = (GroupInput)component;
}
public override void InitializeNewComponent(IDictionary defaultValues)
{
base.InitializeNewComponent(defaultValues);
PropertyDescriptor colorPropDesc =
TypeDescriptor.GetProperties(Component)["BorderColor"];
if (colorPropDesc != null &&
colorPropDesc.PropertyType == typeof(Color) &&
!colorPropDesc.IsReadOnly &&
colorPropDesc.IsBrowsable)
{
colorPropDesc.SetValue(Component, Color.LightBlue);
}
}
protected override void OnPaintAdornments(System.Windows.Forms.PaintEventArgs pe)
{
_groupInput = (GroupInput)Component;
base.OnPaintAdornments(pe);
ControlPaint.DrawBorder(pe.Graphics, _groupInput.ClientRectangle, _groupInput.BorderColor, ButtonBorderStyle.Solid);
}
}
|
|
|
|
|
Let me do a little reality check and make sure we are talking about the same thing
1. you created your UserControl by creating a new WindowsFormsControlLibrary Project whose compiled output is a Class Library (dll)
2. the way you expect users of your UserControl to use it at design-time in their projects is by setting a reference to it in the Project/References, then installing it in the ToolBox in the usual way, and then drag-dropping it on to a Form from the ToolBox.
3. all this is working fine now ... you've tested this.
4. you understand that any Control drag-dropped from the ToolBox, and dropped inside the bounds of an instance of your UserControl on some other user's Form, will never be added to your UserControl's Control Collection. In fact there is a way to modify your UserControl to allow other Controls to be added by drag-drop at design-time, but I assume that's not of interest to you right now.
If all this is correct, then the only way a user could add new Controls to the instance of your UserControl, would be in code, and in your code you can add an EventHandler for 'ControlAdded:
private void UserControl1_ControlAdded(object sender, ControlEventArgs e)
{
Control controlAdded = e.Control;
if (e.Control.GetType() != typeof (Button))
{
this.Controls.Remove(controlAdded);
MessageBox.Show("bad add: UC Controls count = " + this.Controls.Count.ToString());
}
} To reverse the addition of any Control whose Type is not 'Button.
I don't like this technique ... it's a smelly hack ... but, it does work; I'd like to see a better way to do this where any Control could be prevented from being added to the UserControl.
My hope is that the questions asked here, and the brief code example, will, at least, lead to your clarifying exactly what you want to achieve ... since I'm still not sure I understand that fully
« I had therefore to remove knowledge, in order to make room for belief » Immanuel Kant
|
|
|
|
|
Thank you,
Like you said, it's a smelly hack but it does work.
Regards,
Philippe
|
|
|
|
|
I'm glad you found my response useful in some way, Philippe. If you find a better way to achieve this, I'd appreciate a message.
thanks, Bill
« I had therefore to remove knowledge, in order to make room for belief » Immanuel Kant
|
|
|
|
|
suppose my wcf has many end point with different binding.so when user / client add service ref from VS IDE at then multiple endpoint related data expose & added in client config file at client side.
Can we design service in such a way as a result only one endpoint related address will be revealed at client side?
Suppose I have one service with HTTP & TCP related endpoint and I want when external customer will add our service from their VS IDE then they will see our HTTP endpoint address not TCP. So guide me how could I do this? How to design service end config file for my requirement?
here i am attaching a small sample code for multiple endpoint related in config file.
<services>
<service behaviorConfiguration="MulContractService" name="MyWCFLibrary.MultipleContract">
<clear />
<endpoint binding="basicHttpBinding" bindingConfiguration="MulContractBasicBinding"
name="MulContractBasicEndPoint" contract="MyWCFLibrary.IMultipleContract"
listenUriMode="Explicit">
<identity>
<dns value="localhost" />
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<endpoint address="test1" binding="wsHttpBinding" bindingConfiguration="MulContractWsHttpBinding"
name="MulContractWsHttp" contract="MyWCFLibrary.IByeWorld"
listenUriMode="Explicit">
<identity>
<dns value="localhost" />
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<endpoint address="test1" binding="wsHttpBinding" bindingConfiguration="MulContractWsHttpBinding"
name="MulContractWsHttp" contract="MyWCFLibrary.IHelloWorld"
listenUriMode="Explicit">
<identity>
<dns value="localhost" />
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<endpoint address="net.tcp://localhost:8733/Design_Time_Addresses/MyWCFLibrary/MultipleContract/"
binding="netTcpBinding" bindingConfiguration="MulContractTCPBinding"
name="MulContractTCPEndPoint" contract="MyWCFLibrary.IMultipleContract" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/MyWCFLibrary/MultipleContract/" />
</baseAddresses>
</host>
</service>
</services>
tbhattacharjee
|
|
|
|
|
|
Why does your service have TCP bindings if you don't want clients of the service to consume them? Surely it would be easier to not define them at all, than to define them then hide them afterwards?
If you need different bindings for development, production etc then it would be easier to have multiple bindings defined - development bindings, production bindings etc.
In your development config you would define the bindings you require for development and testing. In your production config you define those you want for production (and therefore your external users). Your development config defines the HTTP and TCP bindings, whilst your production config only defines your production bindings.
The web.config allows you to separate the various sections to external files for just these purposes e.g. you can store all your connection strings in a separate file as follows.
<connectionStrings configSource="connectionstrings.dev.config" />
You can do the same for your bindings.
<bindings configSource="bindings.dev.config" />
<bindings configSource="bindings.production.config" />
In your development environment you would use the bindings.dev.config and in your production environment you would use the bindings.production.config (which omits the TCP bindings).
|
|
|
|
|
thanks for answer. i am new in wcf so can u please give a small full example of wcf for my situation with sample code and config code to better understand.
tbhattacharjee
|
|
|
|
|
Basically in your web.config set the configSource for the bindings section so that you specify a different file for development and live.
Your development web.config
<bindings configSource="bindings.dev.config" />
Your deployed (live) web.config
<bindings configSource="bindings.live.config" />
That's it. This is not really related to WCF, as it's more related to understanding how to construct a web.config for different environments.
|
|
|
|
|
can you please redirect me to any similar kind of article which discuss everything in details with sample code. thanks
tbhattacharjee
|
|
|
|
|
Just change your web.config file as I have suggested and you should be fine.
Where you see this....
<bindings>
change it to this....
<bindings configSource="bindings.dev.config" />
Then you need to create a new file called bindings.dev.config that holds your bindings config values for development and bindings.live.config for your live config values.
So the steps are.
1. Amend your web config file and change the binding section as described above.
2. Create two new files called bindings.dev.config and bindings.live.config
3. In your development web.config specify the bindings.dev.config
4. In your live web.config specify the bindings.live.config
|
|
|
|
|
I am be an error importing the Excel2007: "Not a legal OleAut date", you see my code below:
[CODE]
public static void ImportToSql(string excelfilepath)
{
string ssqltable = "TABHD";
string myexceldataquery = "SELECT * FROM [dbo_TABHD]";
try
{
string sexcelconnectionstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source =" + excelfilepath + "; Extended Properties=\"Excel 12.0; HDR=Yes; IMEX=2\"";
string ssqlconnectionstring = @"server = itfriend;Database=HD;integrated security = true";
//execute a query to erase any previous data from our destination table
string sclearsql = "delete " + ssqltable;
//INSERTING IT.INSTEAD I WANT TO UPDATE TABLE DATA"
SqlConnection sqlconn = new SqlConnection(ssqlconnectionstring);
OleDbConnection oledbconn = new OleDbConnection(sexcelconnectionstring);
OleDbCommand oledbcmd = new OleDbCommand(myexceldataquery, oledbconn);
oledbconn.Open();
OleDbDataReader dr = oledbcmd.ExecuteReader();
SqlBulkCopy bulkcopy = new SqlBulkCopy(ssqlconnectionstring);
bulkcopy.DestinationTableName = ssqltable;
bulkcopy.WriteToServer(dr); // Eror in here: "Not a legal OleAut date"
Console.WriteLine(".xlsx file imported succssessfully into database.", bulkcopy.NotifyAfter);
oledbconn.Close();
}
catch (Exception ex)
{
//handle exception
MessageBox.Show(ex.Message.ToString(), "Warning !");
}
}
[/CODE]
|
|
|
|
|
|
1) i like to know what is binary Serialization and when people use binary Serialization ?
2) what is the default Serialization type?
3) how many type of Serialization exist?
4) what is basic difference between xml serialization & SOAP serialization ?
i will be happy if someone discuss all my points in details with patience. thanks
tbhattacharjee
|
|
|
|
|
You're not looking for a discussion, but answers.
1) Serialization is the process of converting an object into a stream of bits.
2) There is no default
3) There's binary, xml and soap in the framework, but more have been added by the community.
4) formatting.
MSDN - Serialization[^]
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
|
Hi,
I have Sage Peachtree 2012. I can see the API folder in C:\Program Files (x86)\Sage\Peachtree but there are no documentation available.
Anyone tried to work on the integration to read / write into Sage Peachtree with C#?
How to get started with it?
Thanks,
Jassim
Technology News @ www.JassimRahma.com
|
|
|
|
|
Googling using the following certainly seems to suggest that documentation can be found.
peachtree api documentation
|
|
|
|
|