Does anyone know how to pass the sfx settings for the SevenZipSfx class located at http://sevenzipsharp.codeplex.com/. I need to specify what file to run, etc. I just took one of the samples e.g
;!#Install#!UTF-8!
RunProgram="setup.exe /s"
GUIMode="2"
;!#InstallEnd#!
and set it via the sfx.ModuleFileName property but its fails with null exception when I call the
sfx.MakeSfx(#"C:\a.7z", #"C:\test.exe"); inside the GetSettingsStream(...) as the settings.key is null
I don't think this is the correct way but can't seem to locate where its reading the settings from. I don't want to hard code this in the source.
Related
The attribute [CallerFilePath] seems to do what I need to do:
How to find path to .cs file by its type in C#
...but I would like to be able to avoid having to add this new prop to every type that I want to check:
public string SourceFilePath { get; } = Helper.GetCallerFilePath();
What I have tried:
Adding this method at runtime does not seem to be an option.
Using it in a base class does not seem to work either (it returns the
path of the base class).
My guess is that this is somehow feasible, because an exception is able to give you this kind of info (from any given type).
What I really want to do in my particular case is: I have a set of cs files that can be identified via their implemented interface, and I want to know their location in the file structure of the project.
So in this case I don't need to know the file location of any given type, but it would be my preferred approach if that's possible.
I am writing a hookscript for TortoiseSVN using C# and SharpSvn.
It needs to get a list of external files/dirs that have been modified. I am using the method SvnClient.Status() that recursively returns SvnStatusEventArgs objects. These objects have the properties LocalContentStatus, LocalNodeStatus, LocalPropertyStatus and LocalTextStatus. I know that i have to use these properties to determine what I am dealing with (an external link, a modified file, ...) but I don't know what these properties exactly mean.
Correct me if I'm wrong, but I think LocalTextStatus is some kind of display name of the status and LocalPropertyStatus is the status of the path's properties (e.g. svn:externals or svn:needs-lock).
Thank you
ContentStatus refers to the status of the file contents. For example if you have modified a file, its ContentStatus would be modified. ContentStatus for a folder is not used and either none or not set.
PropertyStatus refers to the properties of the file or folder.
NodeStatus refers to the file or folder itself. For example status like added, deleted would show up here, but of course not a status like modified
I have a class which is being serialized/deserialized which works fine on most machines, but doesn't work on others (I have not been able to discern the difference, though on the boxes that present an issue I see other issues which have hints of "security/permission" issue [specifically my app can create a folder, but then can't write files to it... weird, but not the main issue]).
The error I get is:
Unable to generate a temporary class (result=1).
error CS0200: Property or indexer 'Namespace.Object.ParentOrganizations' cannot be assigned to -- it is read only
The following is the property:
public List<long> ParentOrganizations
{
get
{
return m_OrganizationIDs;
}
internal set
{
m_OrganizationIDs = value;
}
}
And if I change the "set" to public it does work, but I want to know why I have to do this on only a few specific boxes... so I can help assess why this and the other weird issues are occurring. I figure fixing a single weird issue at a time in my app is more of a hassle (and likely wrong) versus finding and resolving a system configuration issue.
UPDATE: Giving localMachine\Everyone full permissions to the executing folder resolves this issue as well, but is not a good long-term solution.
Assuming you are using one of the Common serializers, you are facing the problem that the serializer self is simply not able to set the ParentOrganizations property because the internal access modifier limit the access to all callers that are not inside the same Assembly then the property is. This causes the serializer ( that is located in an other asseambly ) to throw this exception because he is not allowed to access the property.
I have an application and I'm using MEF to compose it. I want to know if it is possible to update the Metadata information of the parts after they were imported.
The reason to do this is the following: I display the imported parts' name and an typeof(int) property in a ListBox, and they are not loaded until the corresponding ListBoxItem is selected (pretty standard). Now I want to update the Metadata info of one part when some event raises, so the displayed info in the ListBox is somethind like "[Part name] ([new number])".
I'm importing the metadata as an Interface that defines it's info, but when I set the int property to be editable (with a set accesor) I receive the following execption at composition time:
"The MetadataView 'myMetadataInterface' is invalid
because property 'myInt' has a property set method."
Is there ANY way to achieve this? Or is the metadata ALWAYS read only once the part is created?
I know this question looks weird, but it doesn't make it any less difficult and therefore interesting ;-)
EDIT (based on Lee's answer, in order to keep people to the core of the question)
I just want to know if it is possible to update a Metadata property after the part is composed, but before it is actually loaded (HasValue == false). Don't worry about filtering or finding the part.
I added a property to the export inteface, which is meant only to be represented in the UI and to be updated, this property has no other function and the parts are not filtered by it.
Thanks
Metadata filtering and DefaultValueAttribute
When you specifiy a metadata view, an implicit filtering will occur to
match only those exports which contain the metadata properties defined
in the view. You can specify on the metadata view that a property is
not required, by using the
System.ComponentModel.DefaultValueAttribute. Below you can see where
we have specified a default value of false on IsSecure. This means if
a part exports IMessageSender, but does not supply IsSecure metadata,
then it will still be matched.
citation
Short Version (EDITED in after question edit).
You shouldn't ever need to update metadata at runtime. If you have some data that should be updated and belongs to a mef part, you need to choose to either have it be updated by recompiling, or store that data in a flexible storage outside of the dll. There's no way to store the change you made in the dll without recompiling, so this is a flawed design.
Previous post.
Altering values on the view would by lying about the components loaded. Sure the metadata is just an interface to an object that returns initialized values; sure you can technically update those values, but that's not the purpose of metadata.
You wouldn't be changing the Name field of an instance of Type. Why not? Because it's metadata. Updating metadata at runtime would imply that the nature of the instance of real data is somehow modified.
This line of code, if possible, wouldn't introduce the Triple type.
typeof(Double).Name = "Triple";
var IGotATriple = new Triple();
If you want to alter values, you need to just make another object with that information and bind to that. Metadata is compiled in. If you change it after a part is loaded, it doesn't change anything in the part's source, so you'd be lying. (unless you're going to have access to the source-code and you change it there and recompile).
Let's look at an example:
[Export(typeof(IPart))]
[ExportMetadata("Part Name","Gearbox")]
[ExportMetadata("Part Number","123")]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class GearBoxPart : Part { public double GearRatio ... }
Now, let's assume that you had a UI that showed available parts and their numbers. Now, the manufacturer changes the part number for whatever reason and you want to update it. If this is possible, you might want to consider storing part number in a manifest or database instead. Alternatively you'd have to recompile every time a part number changes.
Recompile is possible. You have a controller UI that does the above, but instead of updating the metadata, you submit a request to rebuild the part's codefile. The request would be handled by parsing the codefile, replacing the part number, then sending off for a batch recompile and redistribute the new dll. That's a lot of work for nothing IMO.
So, you setup a database. Then you change the object metadata to this.
[ExportMetadata("OurCompanyNamePartNumber","123")]
Then you have a database/manifest/xml that maps your unique permanent static part number that your company devises to the current part number. Modifications in your control UI update the database/manifest/xml.
<PartMap>
<PartMapEntry OurCompanyNamePartNumber="123" ManufacturerPartNumber="456"/>
...
</PartMap>
Then the end-user UI does lookups for the part by manufacturer part number, and the mef code looks in the PartMap to get the mef part number.
I have an Windows Forms application VS 2008 - C#, that uses app.config.
In execution time, in Menu option of my application, I want editing values of app.config, save it and restart application.
any sample source code, any good patterns and practices ??
edit:
in MSDN Forums, Jean Paul VA:
Create an test windows forms application and add an app.config into it.
Add reference to System.confguration
Add a key named "font" in appSettings with value "Verdana"
Place a button on form and on click of it add the modification code.
System.Configuration.Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
configuration.AppSettings.Settings.Remove("font");
configuration.AppSettings.Settings.Add("font", "Calibri");
configuration.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
what you think about it ?
I don't think you can actually write to the configuration file at runtime - it may well be read-only, however, there may be a way around this by re-writing the file (with proper alterations as required) and essentially replacing the existing one, then, further, restarting the application to load the new values (I highly doubt this is desirable and personally would not try to instrument this malarkey).
You may also just consider storing application settings in the settings file which are easily manipulated in this way.
To use settings, first let's assume you have a Settings.settings file (if not then create one: Add Item->Settings File), then we have a setting configured named MyUnicornsName; In order to make a change and persist it you can simply do as follows:
Settings.Default.MyUnicornsName = "Lucifers Spawn";
Settings.Default.Save();
Similarly, to read a setting:
ATextDisplayControl.Text = Settings.Default.MyUnicornsName
In case you don't know, Visual Studio will open the settings editor when you open/double click the settings file in the IDE; using this interface you can add and edit your initial settings and their values, and string is not the only supported value, all primitives can be used, and, as far as I know, any serializable value too.
Is there any reason you can't use the usual auto-gen'd Properties.Settings to store the changing data in a settings file instead? One great thing is that you know what you're changing so you don't even have to restart the application!
Using Settings in C#
Runtime access of settings is as easy as:
this.BackColor = Properties.Settings.Default.myColor;
(There is no good pattern for modifing app.config itself simply b/c it's designed to be readonly in that context, with expert-user settings.)
Use the Project->Properties->Settings for these kinds of things.
well actually the Properties in the App.config are ReadOnly so u cant do it.
But there's a trick............................
In the Settings.cs file create a Function or method that is public so that it can be available with Properties.settings
and write the following code..
public void ChangeProperty(string propertyname, string value)
{
this[propertyname] = value;
}
remember to pass the exact string of the property name to the method. or better create a Writeonly Property for the setting.
update
here is a code for setting as a property, i am taking a connection string as an example, bet it can be anything. remember the property stored is of Object type so you can create property specific to that..
public string MyCustomConnectionstring
{
set
{
//replace the string with your connection string otr what ever setting you want to change
this["myConnectionString"] = value;
}
}
Now you can easily use this Property to change the ConnectionString at run time...