|
Are you trying to get the assembly version?
If so, then it's trivial in C#:
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
My code will run inside DLL, and this needs to get probably(I am not sure) version of DLL
|
|
|
|
|
Try it: That's what GetExecutingAssembly does - returns the DLL if the code is in a DLL, and the EXE if it's still in the original app assembly.
There is another methods to get the EXE directly: Assembly.GetEntryAssembly[^]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
You can see my approach in response above to Richard, any comments?
var versInfo = FileVersionInfo.GetVersionInfo(dllPath);
return String.Format("{0}.{1}.{2}.{3}", versInfo.FileMajorPart, versInfo.FileMinorPart, versInfo.FileBuildPart, versInfo.FilePrivatePart);
modified 29-Oct-15 9:06am.
|
|
|
|
|
There is File version info and Assembly version info. The two are not the same.
The question is which one are you really looking for.
|
|
|
|
|
The one I am looking for is which is used in C++ code I showed
|
|
|
|
|
I have one app which freezes UI on StartWipeFile() function call..How to solve problem????plz help
try
{
var result = MsgBox.MsgGridVisbility("Alert",
"Do you want to continue for disk wipe ?", 2,
Config.MsgBoxFontColor, Config.MsgBoxHeaderBgColor, Config.MsgBoxHighlightedBtnColor,
Config.MsgBoxNormalBtnColor);
if (!result.Equals("2"))
{
BusyBar.IsBusy = false;
return;
}
this.Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart)delegate
{
BusyBar.IsBusy = true;
StartWipeFile();
});
}
finally
{
BusyBar.IsBusy = false;
}
}
private void StartWipeFile()
{
try
{
CreateFile(drivelist.SelectedValue.ToString());
wipe.WipeFile(fileName, Convert.ToInt32(Regex.Match(passlist.SelectedValue.ToString(), @"\d+").Value));
}
catch (Exception)
{
BusyBar.IsBusy = false;
}
finally
{
BusyBar.IsBusy = false;
}
}
public void CreateFile(string DriveNameSelectedValue)
{
try
{
char p = Convert.ToChar(DriveNameSelectedValue.Remove(1, 2).Cast<char>());
DriveManager.FormatDrive(p, "New Folder");
var disksize =
Convert.ToDouble(String.Format("{0 .00}",
AvailableFreeSpaceFormatted(DriveNameSelectedValue, DiskSizeUnit.Bytes)));
//var data = ConvertGigabytesTobytes(Convert.ToDouble(memorytxt.Text));
//var data = ConvertGigabytesTobytes(Convert.ToDouble(AvailableFreeSpaceFormatted(drivelist.SelectedItem.ToString(), DiskSizeUnit.GigaBytes)));
//string fileName = @"D:\\Text.txt";
fileName = @"" + DriveNameSelectedValue + "WXF1ENCR.txt";
if (File.Exists(fileName))
{
File.Delete(fileName);
}
var fs = new FileStream(fileName, FileMode.CreateNew);
// Create the writer for data.
var w = new BinaryWriter(fs);
// Write data to Test.data.
try
{
for (int i = 0; i < disksize; i++)
{
w.Write((byte) i);
}
}
catch (IOException)
{
//w.Close();
//fs.Close();
//return fileName;
//return Convert.ToString(0);
}
//w.Flush();
w.Close();
//fs.Flush();
fs.Close();
//return fileName;
}
catch (Exception ex)
{
MessageBox.Show((ex.Message));
}
}
|
|
|
|
|
If it's freezing the UI, then it's probably because the file wipe is taking a considerable amount of time - and because it's all being done in the same thread, the UI can't update until the long running task is complete.
Move your Wipe into a different thread and it should "unfreeze" the UI. Have a look at the BackgroundWorker class[^] - it's easy to use and provides event for progress reportign and task completion.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
1. You need to call StartWipeFile() on a different thread.
2. When posting, check that you don't mis-paste the code - such as showing & quot; etc.
3. Do a little debugging yourself - just clicking the "Break into debug" would have shown you the problem
Best,
John
|
|
|
|
|
Hello All exoperts,
below code which I saw in code project wi;l;l do a pivot of a data set where x,y,z axis are fixed, I just want to have 4 column to be used as y axis , can I do that ?
what I understood frpom the code,
y axis value is stored in a ;list
List<string> columnYValues = new List<string>();
and it was return at
foreach (string columnYValue in columnYValues)
{
//Creates a new Row
DataRow drReturn = returnTable.NewRow();
drReturn[0] = columnYValue;
can I return other y axis cpo;lumn in same way with in the same ;loop\.
///
/// Gets a Inverted DataTable
///
/// <param name="table" />Provided DataTable
/// <param name="columnX" />X Axis Column
/// <param name="columnY" />Y Axis Column
/// <param name="columnZ" />Z Axis Column (values)
/// <param name="columnsToIgnore" />Whether to ignore some column, it must be
/// provided here
public static DataTable GetInversedDataTable(DataTable table, string columnX,
string columnY, string columnZ, string nullValue, bool sumValues)
{
//Create a DataTable to Return
DataTable returnTable = new DataTable();
if (columnX == "")
columnX = table.Columns[0].ColumnName;
//Add a Column at the beginning of the table
returnTable.Columns.Add(columnY);
//Read all DISTINCT values from columnX Column in the provided DataTale
List<string> columnXValues = new List<string>();
foreach (DataRow dr in table.Rows)
{
string columnXTemp = dr[columnX].ToString();
if (!columnXValues.Contains(columnXTemp))
{
//Read each row value, if it's different from others provided, add to
//the list of values and creates a new Column with its value.
columnXValues.Add(columnXTemp);
returnTable.Columns.Add(columnXTemp);
}
}
//Verify if Y and Z Axis columns re provided
if (columnY != "" && columnZ != "")
{
//Read DISTINCT Values for Y Axis Column
List<string> columnYValues = new List<string>();
foreach (DataRow dr in table.Rows)
{
if (!columnYValues.Contains(dr[columnY].ToString()))
columnYValues.Add(dr[columnY].ToString());
}
//Loop all Column Y Distinct Value
foreach (string columnYValue in columnYValues)
{
//Creates a new Row
DataRow drReturn = returnTable.NewRow();
drReturn[0] = columnYValue;
//foreach column Y value, The rows are selected distincted
DataRow[] rows = table.Select(columnY + "='" + columnYValue + "'");
//Read each row to fill the DataTable
foreach (DataRow dr in rows)
{
string rowColumnTitle = dr[columnX].ToString();
//Read each column to fill the DataTable
foreach (DataColumn dc in returnTable.Columns)
{
if (dc.ColumnName == rowColumnTitle)
{
//If Sum of Values is True it try to perform a Sum
//If sum is not possible due to value types, the value
// displayed is the last one read
if (sumValues)
{
try
{
drReturn[rowColumnTitle] =
Convert.ToDecimal(drReturn[rowColumnTitle]) +
Convert.ToDecimal(dr[columnZ]);
}
catch
{
drReturn[rowColumnTitle] = dr[columnZ];
}
}
else
{
drReturn[rowColumnTitle] = dr[columnZ];
}
}
}
}
returnTable.Rows.Add(drReturn);
}
}
else
{
throw new Exception("The columns to perform inversion are not provided");
}
//if a nullValue is provided, fill the datable with it
if (nullValue != "")
{
foreach (DataRow dr in returnTable.Rows)
{
foreach (DataColumn dc in returnTable.Columns)
{
if (dr[dc.ColumnName].ToString() == "")
dr[dc.ColumnName] = nullValue;
}
}
}
return returnTable;
}
|
|
|
|
|
If you got the code from an article, then there is a "Add a Comment or Question" button at the bottom of that article, which causes an email to be sent to the author. They are then alerted that you wish to speak to them.
Posting this here relies on them "dropping by" and realising it is for them.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Member 12061647 wrote: below code which I saw in code project Please post your question in the forum at the end of the article so the author can help you.
|
|
|
|
|
I have a Hm-tr module and i want to observe it output in a box
I connect it to my pc and i want observe the data that has been received in my pc. it is important that the program writen with c# but if u have any other idea,tell me.
tnk a lot.
|
|
|
|
|
|
|
Context.InvokeAsynchronousTask(() =>
{
});
I have this code, its not getting called from the unit test project.
|
|
|
|
|
Well, without seeing the code for the unit test project, how do you expect anyone to give you any kind of usable answer?
|
|
|
|
|
Most likely the test finishes before the asynchronous task has a chance to execute.
You'll have to wait in the test for the completion of the asynchronous task. If you don't have a callback method that gets executed on completion you might just have to wait a few moments.
I usually use the ManualResetEvent with the WaitOne Method for such cases.
You can specify a timeout after which the execution should continue even if you don't receive a signal.
|
|
|
|
|
Thanks a lot
|
|
|
|
|
I am using WPF TestBlock control and activating a font which family id is Adolescence using Win32 API AddFontResource. This font is available on various document and also can be easily usable just adding the familyname on html web control. But for WPF TextBox it is not working just passing the family name.
I am using following code snippet.
<TextBlock Grid.Row="0" x:Name="SampleText" Text="{Binding
SampleText}" FontFamily="Adolescence" FontStyle="Normal"
FontSize="20"/>
I cannot put our fonts into windows font directory and also cannot add the directory path in FontFamily parameter and cannot add font into package.
I did googling a lot but could not found any solution. I also very curious to know why WPF is application is not able to detect Font while other application is able to detect the same.
Thanks in advance.
|
|
|
|
|
|
Some apps will "infer" a font based on a "name" and some properties; e.g. "Myriad Pro" and italic weight gives "Myriad Pro Italic", etc.
WPF needs the exact font name.
You should check the names of the fonts in the Control Panel "Fonts" app.
There are fonts (indicated with a little "stack" icon) that when clicked in Control Panel will yield other "sub-fonts" (which names one would use in WPF; besides the font properties).
|
|
|
|
|
<connectionstrings>
<add name="CostAllocationEntities2"
="" connectionstring="Data Source=PC210090\SQLEXPRESS;initial catalog=testdb1;Persist Security Info=True;User ID=sa;Password=password1$" providername="System.Data.SqlClient">
SqlConnection conn;
public SqlConnection openconn()
{
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CostAllocationEntities2"].ConnectionString);
try
{
if (conn.State == ConnectionState.Closed)
{<br />
conn.Open();
return conn;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Failed to Connect with Database.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return null;
}
return conn;
}
public void GetBackup(string strDBName)
{
if (string.IsNullOrEmpty(strDBName))
{
MessageBox.Show("Server Name & Database can not be Blank");
return;
}
else
{
string destinationPath = ConfigurationManager.AppSettings.Get("BackupDestinationPath");
BackupDeviceItem deviceItem = new BackupDeviceItem(destinationPath, DeviceType.File);
ServerConnection connection = new ServerConnection(ConfigurationManager.ConnectionStrings["CostAllocationEntities2"].ConnectionString);
Server sqlServer = new Server(connection);
Database db = sqlServer.Databases[strDBName];
Backup bkpDBFull = new Backup();
bkpDBFull.Action = BackupActionType.Database;
bkpDBFull.Database = strDBName;<br />
bkpDBFull.Devices.AddDevice(String.Format("{0}{1}-{2}.bak", destinationPath, strDBName, DateTime.Now.ToString("yyyy-MM-dd")), DeviceType.File);
bkpDBFull.BackupSetName = strDBName + " Backup";
bkpDBFull.BackupSetDescription = strDBName + "- Full Backup";
bkpDBFull.ExpirationDate = DateTime.Today.AddDays(10);<br />
bkpDBFull.Initialize = false;
bkpDBFull.SqlBackup(sqlServer);
MessageBox.Show("Backup Done");
}
}
On this line
Database db = sqlServer.Databases[strDBName];
I get an error:
Not allowed to change the 'ConnectionString' property. The connection's current state is connecting."
-- modified 28-Oct-15 2:27am.
|
|
|
|
|
|
Hello guys/gals,
Since a few months i have rather a real head desturbing issue :/
I have developed a plugin architecture that exists of a Host app and several plugins.
The host app basicly loads all the plugins availible, and allows any plugin to interact with the host, and vice versa.
Everything works fine when it comes to using methods/properties ect...accept for the events...
The events are used to send info to any asigned instance, including the plugins.
Whenever i assign the event inside plugin to recieve info from the host then i get the 'System.Reflection.TargetInvocationException'.
The exception is thrown whenever the host invokes the event that has been assigned from plugin instance.
Though i should mention that the event is used by the plugin AND the host.
They both should be revieving the plugin info...
I know ive used several events in a plugin system before, but that was the other way around.
The host was recieving info from plugin , witch works, just the other way arround seems to be a issue.
The Plugins are loaded by system.reflection as raw data and not as a file...
i did this because the plugins are stored in a custom container, compressed and encrypted.
Here is the manager interface (HOST):
public interface IPluginManager : IPluginBase
{
bool IsLoaded { get; }
Settings AppPreferences { get; }
ILogin Server { get; }
byte[] Signature { get; }
AppInfo[] Plugins { get; }
#region Events
event PluginRequestHandler PluginUpdate;
event PluginRequestHandler PluginInstall;
event PluginRequestHandler PluginRemove;
event PluginInstallHandler PluginsToInstall;
event PluginInstallHandler PluginsToUpdate;
event PluginInstallHandler PluginsToRemove;
event PluginHandler PluginActionChanged;
event PluginsHandler PluginsInstalled;
event PluginsHandler PluginsUpdated;
event PluginsHandler PluginsRemoved;
event EventHandler ManagerLoaded;
event EventHandler ManagerLoading;
event EventHandler ManagerDisposed;
#endregion
#region Methods
void LoadAsync();
void Dispose();
void RemovePluginAsync(AppInfo plugin);
bool RemovePlugin(AppInfo plugin);
void InstallPluginAsync(AppInfo plugin);
bool InstallPlugin(AppInfo plugin);
bool InstallNewPlugins();
void InstallNewPluginsAsync();
void MountPluginAsync(AppInfo info);
void UnmountPluginAsync(AppInfo info);
void EnableApp(AppInfo info);
void DisableApp(AppInfo info);
AppInfo[] GetOnlineApps();
#endregion
}
Here the code from plugin instance that init the Host event.
private void MainForm_Shown(object sender, EventArgs e)
{
if (Host != null && Host.PluginManager != null)
{
SCManager = Host.PluginManager;
SCManager.PluginActionChanged += X_PluginActionChanged;
Server = SCManager.Server;
if (Server == null)
{
var x = SCManager.Plugins.FirstOrDefault(t => t.Type == 1);
if (x != null)
SCManager.MountPluginAsync(x);
}
}
OnWindowShown(this);
}
Here is the Code that triggers the event:
protected virtual void OnPluginActionChanged(AppInfo info,PluginActionType action,Exception error = null,object param = null)
{
PluginHandler handler;
lock (_eventlock)
handler = _PluginActionChanged;
handler?.Invoke(this, info, action, error,param);
}
I really hope someone inhere can point me to the right direction, as i'm totally lost...
Thanks! and sorry for my bad english, let me know please if you guys/gals have any more question.
|
|
|
|