C# Winforms Cefsharp cache path is to big - c#

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.

Related

WPF C# How to play local .swf file with a Control that still reacts to flow?

I'm trying to play a .swf file saved in the output folder, but the standard WebBrowser doesn't react to the flow of the document. It doesn't get cut off when it reaches the top of a Scrollviewer and that's a problem. I tried CefSharp, but I can only figure out how to play .swf files from the web. Are there any Controls that can play local .swf files and react with the flow.
EDIT:
Here's the code I used with CefSharp to load the .swf files. Basically, it loads a blank HTML file and then runs some JavaScript on it to create the correct Flash object with the correct path. This works for websites, but I need to run a local .swf file and that won't work (probably because CefSharp runs on Chromium and therefore has certain security settings that don't allow files from the computer to be accessed like that.)
if (TotalChecklistBrowser[itemNum].IsBrowserInitialized)
{
TotalChecklistBrowser[itemNum].Load(#"blank.html");
TotalChecklistBrowser[itemNum].FrameLoadEnd += (origin, args) =>
{
if (args.Frame.IsMain)
{
args.Frame.ExecuteJavaScriptAsync("document.body.innerHTML = \"\"; document.documentElement.style.overflow = \"hidden\"; document.body.style.margin = \"0\"; var obj = document.createElement(\"object\"); obj.width = \"260\"; obj.height = \"180\"; var param = document.createElement(\"param\"); param.id = \"item01\"; param.name = \"movie\"; param.value = \"" + BrowserTitles[itemNum].Replace(#"\", "/") + "\"; var embed = document.createElement(\"embed\"); embed.id = \"item02\"; embed.src = \"" + BrowserTitles[itemNum].Replace(#"\", "/") + "\"; embed.width = \"260\"; embed.height = \"180\"; document.body.appendChild(obj); obj.appendChild(param); obj.appendChild(embed); ");
}
};
}

Programatically target default document library for file upload in SP16

I made a C# application for uploading files to SharePoint. So far it Works as intended, on all document libraries except the default one. Everytime it throws an exception : List 'Documents' does not exist at site with URL 'http://...'
I've tried with "Shared Documents" as well, but same result. Does the default library have some internal name I'm not aware of?
The code for uploading is as follows:
// Get the SharePoint context
ClientContext context = new ClientContext(domain);
// Open the web
var web = context.Web;
String[] files = System.IO.File.ReadAllLines(args[0]);
foreach (String file in files)
{
// Create the new file
var newFile = new FileCreationInformation
{
Content = System.IO.File.ReadAllBytes(file),
Url = Path.GetFileName(file),
Overwrite = true
};
// Get a reference to the document library
var docs = web.Lists.GetByTitle(library);
var uploadFile = docs.RootFolder.Files.Add(newFile);
// Upload the document
context.Load(uploadFile);
}
First of all, it is much safer to get list by url, not title.
using (ClientContext context = new ClientContext("https://sharepoint.domain.com"))
{
context.Load(context.Web, w => w.ServerRelativeUrl);
context.ExecuteQuery();
List list = context.Web.GetList($"{context.Web.ServerRelativeUrl.TrimEnd('/')}/Shared Documents");
}
Also don't forget to dispose the object context.
Check enabled alternate languages (Site settings > Site Administration > Language settings). You may have more enabled languages and the default one could be different then you expect. Each language holds its own list name.

Google drive API V3, trying to change the ownership of files other than docs sheets and slides

I am using google API for google drive, V3 with C# dot net. When trying to change the ownership from my service account to a 'regular' drive account (so it is within the same domain) of files other than docs, sheets and slides (like .zip or even .pdf) I get an error saying that:
Error: Bad Request. User message: "You can't yet change the owner of this item. (We're working on it.).
I guess this has something to do with the fact that docs, sheets and slides are not taken into account in the storage quota.
(1) Does this have a workaround? (Trying to change the file name to .doc before uploading it causes auto file conversion of the file and it is useless after that).
(2) Does this also happen on a paid account?
(3) Is Google team really 'working on it' as it states in the error message?
UPDATE:
This is the code I am using:
public string UploadFileToDrive(string FilePath, string ParentID)
{
try
{
Google.Apis.Drive.v3.Data.File body = new Google.Apis.Drive.v3.Data.File();
string fileNameNoPath = System.IO.Path.GetFileName(FilePath);
body.Name = "NewFile.ASC"; // some file names such as zip are not acceptable by google drive api
//body.MimeType = GoogleDriveMimeTypes.GetGenericMimeTypeString();
if (ParentID != null)
{
body.Parents = new List<string>();
body.Parents.Add(ParentID);
}
byte[] byteArray = System.IO.File.ReadAllBytes(FilePath);
System.IO.MemoryStream Ustream = new System.IO.MemoryStream(byteArray);
var requestU = _CurrentDriveService.Files.Create(body, Ustream, "");
requestU.Upload();
var uploadedFileID = requestU.ResponseBody.Id;
body.Name = fileNameNoPath;
//body.MimeType = GoogleDriveMimeTypes.GetGenericMimeTypeString();
FilesResource.CopyRequest cr = new FilesResource.CopyRequest(_CurrentDriveService, body, uploadedFileID);
var newFile = cr.Execute();
var NewFileNameID = newFile.Id;
DeleteFileFromDrive(uploadedFileID);
{
Permission p = new Permission();
p.Role = "reader";
p.Type = "anyone";
PermissionsResource.CreateRequest cc = new PermissionsResource.CreateRequest(_CurrentDriveService, p, NewFileNameID);
cc.Execute();
}
// you can comment out the next block if using Auth client
//
{
// make main account the owner in order to take its size quota in main account not google service.
Permission p = new Permission();
p.Role = "owner";
p.Type = "user";
p.EmailAddress = "vizfilesender#gmail.com";
PermissionsResource.CreateRequest cc = new PermissionsResource.CreateRequest(_CurrentDriveService, p, NewFileNameID);
cc.TransferOwnership = true; // acknowledge transfer of ownership - must be set to "true" in order for role to change to "owner"
cc.Execute();
}
return NewFileNameID;
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
return "";
}
}
With this code I can upload all files, change permissions for sharing, but I can't change ownership back to the google drive account.
I finally found the answer. I need to impersonate to another user.
var initializer = new ServiceAccountCredential.Initializer("blablablabla#blabla.iam.gserviceaccount.com")
{
Scopes = scope,
User = "emailToImpersonate#domain"
};
var credential = new ServiceAccountCredential(initializer.FromPrivateKey("-----BEGIN PRIVATE KEY-----\n-----END PRIVATE KEY-----\n"));
var driveService = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName
});
Also, make sure you give the google service domain wide delegation as shown here:
https://developers.google.com/drive/v2/web/delegation
and let up to 10 minutes for the change to take effect.
This is the workaround I have been searching for.

Hide share option from Google doc

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

Using different proxy for each GeckoFx Instances

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().

Categories