I'm Using Geckfx18.0 and xulrunner18.01. Since Geckofx share cookie and user preferences with others instance so I try to create a new profile directory to make them have unique setting but it seems to be no use. here is my code. Is there any problem with my code?
String profileDir = port.ToString();
string directory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Path.Combine("Geckofx", profileDir));
this.Text = directory.ToString();
if (!Directory.Exists(directory))
Directory.CreateDirectory(directory);
Gecko.Xpcom.ProfileDirectory = directory;
GeckoPreferences.User["network.proxy.type"] = 1;
GeckoPreferences.User["network.proxy.socks"] = "127.0.0.1";
GeckoPreferences.User["network.proxy.socks_port"] = port;
GeckoPreferences.User["network.proxy.socks_version"] = 5;
GeckoPreferences.User["general.useragent.override"] = ua;
Are you initializing the instance of Gecko before setting the ProfileDirectory?
Note that the XpCom.ProfileDirectory is a static property, so if you're trying to start each instance, keep in mind you may be undoing the path you set previously.
Additionally, rather than settings the preferences in code, you save your user preferences out to a file via GeckoPreferences.Save(). Then you can load them back in to support diferent users via GeckoPreferences.Load().
Related
I'm using this code to Init a CefSharp browser with a specific cache path(i have a specific cache path because my app use a lot of login options):
browser = new ChromiumWebBrowser("");
var requestContextSettings = new RequestContextSettings { CachePath = UsersManager.GetFullCachePath(userName) };
browser.RequestContext = new RequestContext(requestContextSettings, new CustomRequestContextHandler());
browser.Dock = DockStyle.Fill;
browser.FrameLoadEnd += webViewFrameLoadEnd;
browser.LoadError += getFromBrowser_LoadError;
BrowserPanel.Controls.Add(browser);
The issue here is that for every user the cache folder is taking something like 300 MB, There is an option to make a limitation on this folder? I only need it to save the cookies for the logins and O think it saves a lot of information that I don't need.
So I'm having a problem with automating my code to check-in files to TFS, and it's been driving me up the wall! Here is my code:
string location = AppDomain.CurrentDomain.BaseDirectory;
TfsTeamProjectCollection baseUserTpcConnection = new TfsTeamProjectCollection(uriToTeamProjectCollection);
IIdentityManagementService ims = baseUserTpcConnection.GetService<IIdentityManagementService>();
TeamFoundationIdentity identity = ims.ReadIdentity(IdentitySearchFactor.AccountName, #"PROD1\JR", MembershipQuery.None, ReadIdentityOptions.None);
TfsTeamProjectCollection impersonatedTpcConnection = new TfsTeamProjectCollection(uriToTeamProjectCollection, identity.Descriptor);
VersionControlServer sourceControl = impersonatedTpcConnection.GetService<VersionControlServer>();
Workspace workspace = sourceControl.CreateWorkspace("MyTempWorkspace", sourceControl.AuthorizedUser);
String topDir = null;
try
{
Directory.CreateDirectory(location + "TFS");
String localDir = location + "TFS";
workspace.Map("$/Automation/", localDir);
workspace.Get();
destinationFile = Path.Combine(localDir, Name + ".xml");
string SeconddestinationFile = Path.Combine(localDir, Name + ".ial");
bool check = sourceControl.ServerItemExists(destinationFile, ItemType.Any);
PendingChange[] pendingChanges;
File.Move(sourceFile, destinationFile);
File.Copy(destinationFile, sourceFile, true);
File.Move(SecondsourceFile, SeconddestinationFile);
File.Copy(SeconddestinationFile, SecondsourceFile, true);
if (check == false)
{
workspace.PendAdd(localDir,true);
pendingChanges = workspace.GetPendingChanges();
workspace.CheckIn(pendingChanges, Comments);
}
else
{
workspace.PendEdit(destinationFile);
pendingChanges = workspace.GetPendingChanges();
workspace.CheckIn(pendingChanges, Comments);
}
and the problem is that whenever it's NEW files (PendEdit works correctly when the files already exist in TFS) that my code is attempting to check in, and it runs through this code:
if (check == false)
{
workspace.PendAdd(localDir,true);
pendingChanges = workspace.GetPendingChanges();
workspace.CheckIn(pendingChanges, Comments);
}
The files, instead of being in the included changes in pending changes, are instead in the excluded changes like so:
and when the line that actually does the check-in runs, I'll get a "The array must contain at least one element" error, and the only way to fix it is to manually add those detected changes, and promote them to included changes, and I simply can't for the life of me figure out how to do that programatically though C#. If anyone has any guidance on what direction I should take for this, I would really appreciate it! Thank you!
Edit: I've also discovered another way to solve this by reconciling the folder, which also promotes the detected changes, but again the problem is I can't seem to figure out how to program that to do it automatically.
I know that running the visual studio developer command prompt, redirecting to the folder that this mapping is in, and the running "tf reconcile /promote" is one way, but I can only automate that as far as the /promote part, because that brings up a toolbox that a user would have to input into, which defeats the purpose of the automation. I'm at a loss.
Next Edit in response to TToni:
Next Edit in response to TToni:
I'm not entirely sure if I did this CreateWorkspaceParameters correctly (see picture 1), but this time it gave the same error, but the files were not even in the excluded portions. They just didn't show up anywhere in the pending changes (see picture 2).
Check this blog:
The workspace has a method GetPendingChangesWithCandidates, which actually gets all the “Excluded” changes. Code snippet is as below:
private void PendChangesAndCheckIn(string pathToWorkspace)
{
//Get Version Control Server object
VersionControlServer vs = collection.GetService(typeof
(VersionControlServer)) as VersionControlServer;
Workspace ws = vs.TryGetWorkspace(pathToWorkspace);
//Do Delete and Copy Actions to local path
//Create a item spec from the server Path
PendingChange[] candidateChanges = null;
string serverPath = ws.GetServerItemForLocalItem(pathToWorkspace);
List<ItemSpec> its = new List<ItemSpec>();
its.Add(new ItemSpec(serverPath, RecursionType.Full));
//get all candidate changes and promote them to included changes
ws.GetPendingChangesWithCandidates(its.ToArray(), true,
out candidateChanges);
foreach (var change in candidateChanges)
{
if (change.IsAdd)
{
ws.PendAdd(change.LocalItem);
}
else if (change.IsDelete)
{
ws.PendDelete(change.LocalItem);
}
}
//Check In all pending changes
ws.CheckIn(ws.GetPendingChanges(), "This is a comment");
}
I am uploading / creating file on Google Drive using .NET SDK for google drive api. Everything works fine and I can give permission to user as per my business logic like writer,reader,commenter or owner. But I want to hide the Share button from everybody except Owner as my business logic should decide which file should be shared with whom and when.
Here is the code for sharing the document:
try
{
Google.Apis.Drive.v2.Data.Permission permission = new Google.Apis.Drive.v2.Data.Permission();
switch (role)
{
case GoogleRoles.WRITER:
case GoogleRoles.READER:
case GoogleRoles.OWNER:
{
permission.Role = role;
permission.Value = userEmail;
permission.Type = "user";
break;
}
case GoogleRoles.COMMENTER:
{
permission.Role = GoogleRoles.READER; //Need to assign role before we assign the additional role of commenter.
List<String> additionalRoles = new List<string>();
additionalRoles.Add(GoogleRoles.COMMENTER);
permission.AdditionalRoles = additionalRoles;
permission.Type = "user";
permission.Value = userEmail;
break;
}
}
PermissionsResource.InsertRequest insertRequest = DriveService.Permissions.Insert(permission, fileId);
insertRequest.SendNotificationEmails = true;
insertRequest.Execute();
Where DriveService is an instance of service account. Any pointer would be a great help.
Unfortunately the Drive API doesn't yet support the feature of disabling sharing or disabling downloading. Please file a feature request here: https://code.google.com/a/google.com/p/apps-api-issues/issues/entry?template=Feature%20request&labels=Type-Enhancement,API-Drive
I had raised this as an enhancement, and got the response too. So in Google drive API its not part of permission but these are properties of file itself, so we need to set he properties instead of permissions like:
File.LabelsData labels = new File.LabelsData();
labels.Restricted = true;
File body = new File();
body.Labels = labels;
body.WritersCanShare = false;
It has solved the issue of Share but download issue is not solved it by above changes. More details about this can be found at https://developers.google.com/drive/v2/reference/files
I have made a Win Form and have a few controls like checkboxes, radio buttons etc. What I hope to happen is that the user will choose some settings e.g. tick the box to start the program on startup, then they can quit, when they open it again, how do I ensure that the choices that they made are saved? Thanks.
There are a few ways, but I'd recommend using the .NET user settings method to save their settings in the properties section of the application and reload and set them when they start the application again.
Here's an example:
Save Setting
Properties.Settings.Default.CheckboxChecked = true;
Properties.Settings.Default.Save();
Load Setting
checkBox.Checked = Properties.Settings.Default.CheckboxChecked;
I'd recommend giving them more meaningful names, however.
You can read more, with examples here: MSDN Using Application Settings and User Settings
This is also a nice tutorial on how to implement user settings from start to finish: C# - Saving User Settings - Easy way!
http://msdn.microsoft.com/en-us/library/aa730869%28v=vs.80%29.aspx Here is and Article how to use Settings in C# Application .
Where you can check ,if CheckBox is Checked with a Boolean etc.
Perhaps you’re looking for something like this:
Add this:
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
Then this to the program:
for_save info = new for_save();
string general_path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string path = general_path + "\\MyApplication";
BinaryFormatter serializer = new BinaryFormatter();
info.check = true;
info.radio = false;
//write
Directory.CreateDirectory(path);
Stream write_stream = File.Create(path + "\\MyFile.txt");
serializer.Serialize(write_stream, info);
write_stream.Close();
//read
Stream read_stream = File.OpenRead(path + "\\MyFile.txt");
for_save read_info = (for_save) serializer.Deserialize(read_stream);
read_stream.Close();
textBox1.Text = read_info.check.ToString() + read_info.radio.ToString();
And this class:
[Serializable()]
class for_save
{
public bool check;
public bool radio;
}
I believe I have been taking the right approach to this so far, but I would like to have a button start a video game on my computer.
So far, I have a button linking to a process:
void button2_Click(object sender, EventArgs e)
{
process1.Start();
}
this.process1.EnableRaisingEvents = true;
this.process1.StartInfo.Domain = "";
this.process1.StartInfo.FileName = "MBO\\marbleblast.exe";
this.process1.StartInfo.LoadUserProfile = false;
this.process1.StartInfo.Password = null;
this.process1.StartInfo.StandardErrorEncoding = null;
this.process1.StartInfo.StandardOutputEncoding = null;
this.process1.StartInfo.UserName = "";
this.process1.SynchronizingObject = this;
this.process1.Exited += new System.EventHandler(this.Process1Exited);
So, where-ever I place the EXE (the one I'm coding), it will launch the "marbleblast.exe" under the subfolder MBO relative to it's location.
It seems to be working and trying to launch the game, however, it says it cannot load files that are there. I tested the game without my launcher, and it worked. I believe it's trying to run the EXE, but not letting it use the other files inside of it's folder.
I'll give more details if needed.
How can I get the game to run normally?
try adding this
this.process1.StartInfo.WorkingDirectory= "MBO\\";
or something similar to set the Working Directory.
this.process1.StartInfo.WorkingDirectory= "MBO\";
There's sloppy programming in the game, it relies on the Environment.CurrentDirectory being set right. Which by default is the same directory as where the EXE is located. The upvoted answer repeats the mistake though. To make that statement actually fix the problem, you now rely on your CurrentDirectory being set right. If it is not set where you think it is then it still won't work.
The problem with the program's current directory is that it can be changed by software that you don't control. The classic example is OpenFileDialog with the RestoreDirectory property set to the default value of false. Etcetera.
Always program defensively and pass the full path name of files and directories. Like c:\mumble\foo.ext. To get that going, start with Assembly.GetEntryAssembly().Location, that's the path to your EXE. Then use the System.IO.Path class to generate path names from that. The correct always-works code is:
using System.IO;
using System.Reflection;
...
string myDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
string gameDir = Path.Combine(myDir, "MBO");
string gameExe = Path.Combine(gameDir, "marbleblast.exe");
process1.StartInfo.FileName = gameExe;
process1.StartInfo.WorkingDirectory = gameDir;
process1.SynchronizingObject = this;
process1.EnableRaisingEvents = true;
process1.Exited += new EventHandler(Process1Exited);
Set the WorkingDirectory property of the ProcessInfo to the correct directory.
I am Dobrakmato from MBForums. You simple need to add Working directory for Marble Blast.
this.process1.EnableRaisingEvents = true;
this.process1.StartInfo.Domain = "";
this.process1.StartInfo.FileName = "MBO\\marbleblast.exe";
this.process1.StartInfo.WorkingDirectory = "pathto marbleblast.exe directory";
this.process1.StartInfo.LoadUserProfile = false;
this.process1.StartInfo.Password = null;
this.process1.StartInfo.StandardErrorEncoding = null;
this.process1.StartInfo.StandardOutputEncoding = null;
this.process1.StartInfo.UserName = "";
this.process1.SynchronizingObject = this;
this.process1.Exited += new System.EventHandler(this.Process1Exited);