p4java client setRoot not working - perforce

Using p4java to sync files on various machines, so I'm using IClient.setRoot() to change the root accordingly. But IClient.setRoot() doesn't actually change the root in the client object.I looked in the debugger right after the setRoot() call
Here's my code after connecting to the server.
client is an IClient and p4Server is an IServer.
the prop functions are simply pulling properties entries for workspace and root dir
What am I missing to make setRoot() work. Thanks!
client = p4Server.getClient(prop.getString("perforce.workspace"));
if (client == null) {
logger.error("Failed to fetch workspace: {}", prop.getString("perforce.workspace"));
} else {
File p4Dir = new File(prop.getPath("perforce.scripts.dest"));
if (!p4Dir.exists()) {
p4Dir.mkdirs();
}
client.setRoot(p4Dir.getPath());
logger.debug("Setting p4sync dest root to: {}",p4Dir.getPath() );
p4Server.setCurrentClient(client);

You must update the client on the server - the setCurrentClient() does not do this.
client.setRoot(p4Dir.getPath());
logger.debug("Setting p4sync dest root to: {}",p4Dir.getPath() );
client.update();
p4Server.setCurrentClient(client);

Related

Not able to write image in shared folder in IIS

I have developed an module to save image in windows shared location
my code works fine development machine in VS 2015 and IIS express.
But when i deploy the code in my IIS sever(IIS 8) and set my appppol.
When it checks the directory exists or no it fails and does not save the image.
in share path. I have tried accessing the shared path from server I am able to open it without issues
I have applied logs to check but it fails that directory does not exit
Sharepath ex:\atse-bs-13450.abc.xyz.com\Sharefolder\PhotoImages
My app pool is set to ApplicationPoolIdentity
public void WriteImage(string Location, string base64Image)
{
try
{
// Check if directory exist
if (Directory.Exists(Location))
{
//location value is set in appSettings;
//"\\atse-bs-13450.abc.xyz.com\Sharefolder\PhotoImages\"
string strImagePath = Location;
// Check file exist in location
if (!File.Exists(Location))
{
if (!string.IsNullOrEmpty(base64Image))
{
using (FileStream stream = new FileStream(strImagePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
{
BinaryWriter writer = new BinaryWriter(stream);
writer.Write(Base64String2Blob(base64Image));
}
}
}
else
{
strBlobLogMessage = "image file could not be stored on shared location , Share path location : ";
PathNotFound(strBlobLogMessage);
}
}
else
{
strBlobLogMessage = "image file could not be stored on shared location as path does not exists , Share path location : ";
PathNotFound(strBlobLogMessage);
}
}
catch (Exception ex)
{
throw ex;
}
}
Two options
Create a user account and then assign that user account read and write access on shared location. Then you can set the Application Pool Identity to Custom account and then set it to newly created user account.
Since your app pool is using Application Pool Identity, there will be user account with name IIS AppPool\{Applicaiton Pool name} e.g. for DefaultAppPool the user account is IIS AppPool\DefaultAppPool so you can allow read/write access to shared directory to Applicaiton Pool user

Unable to resolve sync conflict when using Azure Mobile Client - error keeps coming back

I'm using a Node.JS backend on Azure with Easy Tables. The table contains the required columns to support offline syncing.
While testing the sync process I noticed that conflicts keep coming back even though I'm resolving them.
My test:
Pull table content from Azure to iOS and Android device
Change a record on iOS but don't sync back to Azure
Change the same record on Android and sync
Now sync iOS
As expected, the conflict is detected correctly and I catch a MobileServicePushFailedException. I am then resolving the error by replacing the local item with the server item:
localItem.AzureVersion = serverItem.AzureVersion;
await result.UpdateOperationAsync(JObject.FromObject (localItem));
However, the next time I sync, the same item fails again with the same error.
The AzureVersion property is declared like this:
[Version]
public string AzureVersion { get; set; }
What exactly is result.UpdateOperationAsync() doing? Does it update my local database? Do I have to do it manually?
And also: am I supposed to trigger an explicit PushAsync() afterwards?
EDIT:
I changed the property from AzureVersion to Version and it works. I noticed that the serverItem's AzureVersion property was NULL even though the JSON contained it. Bug in Json.Net or in the Azure Mobile Client?
You should be using something like the following:
public async Task SyncAsync()
{
ReadOnlyCollection<MobileServiceTableOperationError> syncErrors = null;
try
{
await this.client.SyncContext.PushAsync();
await this.todoTable.PullAsync(
//The first parameter is a query name that is used internally by the client SDK to implement incremental sync.
//Use a different query name for each unique query in your program
"allTodoItems",
this.todoTable.CreateQuery());
}
catch (MobileServicePushFailedException exc)
{
if (exc.PushResult != null)
{
syncErrors = exc.PushResult.Errors;
}
}
// Simple error/conflict handling. A real application would handle the various errors like network conditions,
// server conflicts and others via the IMobileServiceSyncHandler.
if (syncErrors != null)
{
foreach (var error in syncErrors)
{
if (error.OperationKind == MobileServiceTableOperationKind.Update && error.Result != null)
{
//Update failed, reverting to server's copy.
await error.CancelAndUpdateItemAsync(error.Result);
}
else
{
// Discard local change.
await error.CancelAndDiscardItemAsync();
}
Debug.WriteLine(#"Error executing sync operation. Item: {0} ({1}). Operation discarded.", error.TableName, error.Item["id"]);
}
}
}
Note the CancelAndUpdateItemAsync(), which updates the item to the server copy or CancelAndDiscardItemAsync(), which accepts the local item. These are the important things for you.
This code came from the official HOWTO docs here: https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-dotnet-how-to-use-client-library/##offlinesync

Azure Schema Extensions in Graph Client

Whatever I tried I cannot set an extension property on a User object, here is a reproducible piece of code:
public async Task CleanTest(string extName)
{
ExtensionProperty ep = new ExtensionProperty
{
Name = extName,
DataType = "String",
TargetObjects = { "User" }
};
App app = (App)(await _client.Applications.Where(a => a.AppId == _managementAppClientId).ExecuteSingleAsync());
app.ExtensionProperties.Add(ep);
await app.UpdateAsync();
GraphUser user = (GraphUser)(await _client.Users.Where(u => u.UserPrincipalName.Equals("email")).ExecuteSingleAsync());
string propName = FormatExtensionPropertyName(extName); //formats properly as extesion_xxx_name
user.SetExtendedProperty(propName, "testvalue");
//user.SetExtendedProperty(extName, "testvalue");
await user.UpdateAsync(); // fails here
}
user.UpdateAsync() according to Fiddler doesn't even go out and application fails with an exception:
"The property 'extension_e206e28ff36244b19bc56c01160b9cf0_UserEEEqdbtgd3ixx2' does not exist on type 'Microsoft.Azure.ActiveDirectory.GraphClient.Internal.User'. Make sure to only use property names that are defined by the type."
This issue is also being tracked here:
https://github.com/Azure-Samples/active-directory-dotnet-graphapi-console/issues/28
I've got an alternative workaround for this bug, for those that want to use the version 5.7 OData libraries rather than redirecting to the v5.6.4 versions.
Add a request pipeline configuration handler.
// initialize in the usual way
ActiveDirectoryClient activeDirectoryClient =
AuthenticationHelper.GetActiveDirectoryClientAsApplication();
// after initialization add a handler to the request pipline configuration.
activeDirectoryClient.Context
.Configurations.RequestPipeline
.OnMessageWriterSettingsCreated(UndeclaredPropertyHandler);
In the handler, change the ODataUndeclaredPropertyBehaviorKinds value on the writer settings to SupportUndeclaredValueProperty.
private static void UndeclaredPropertyHandler(MessageWriterSettingsArgs args)
{
var field = args.Settings.GetType().GetField("settings",
BindingFlags.NonPublic | BindingFlags.Instance);
var settingsObject = field?.GetValue(args.Settings);
var settings = settingsObject as ODataMessageWriterSettings;
if (settings != null)
{
settings.UndeclaredPropertyBehaviorKinds =
ODataUndeclaredPropertyBehaviorKinds.SupportUndeclaredValueProperty;
}
}
Just in case you still looking for solution to this problem or someone else is facing the same issue:
I got similar issue and it looks like, at least for me, the problem was in latest version of "Microsoft.Data.Services.Client" package - 5.7.0 (or in one of it dependencies). When I downgraded to previous version - 5.6.4 it worked as a charm.
I had same symptoms - updating of extended property was failing even w/o any request is made (also used Fiddler)
Hope it helps!
Artem Liman

log4net web plugin location of log file

I have a windows forms application that runs in two different modes desktop mode and web plugin mode. I'm trying to put the log files using log4net in the same place. but when it is running as a web plugin my log file get put into the temporary internet folder of the users app data folder.
Code:
Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
if (Uri.TryCreate(uri, "log4net.config", out uri))
{
log4net.Config.XmlConfigurator.Configure(new FileInfo(uri.LocalPath));
}
_configured = true;
if (Utilities.WebPlugin)
{
var logNetHierarchy = (log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository();
foreach (var iAppender in logNetHierarchy.Root.Appenders)
{
if (iAppender is FileAppender)
{
var fileAppender = (FileAppender)iAppender;
fileAppender.File = #"C:\Users\" + Environment.UserName + #"\Company\Viewer\Web\log.xml";
fileAppender.ActivateOptions();
}
}
}
I would like to get them in the same place without including some kind of script.
stuartd was right soon as I put the site into trusted sites it worked perfectly.

Connect to FTP server and download file from FTP to local machine

I need to know a way to connect to a FTP site and i am unable to find an example to do the program using C#.
I need to write the code where i could connect, and download files from the FTP server without using third party component.
How can i do this ? Help.
There is FtpWebRequest class in .Net 4
http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx
There are examples at the end. Here is a sample taken from msdn:
public static bool DisplayFileFromServer(Uri serverUri)
{
// The serverUri parameter should start with the ftp:// scheme.
if (serverUri.Scheme != Uri.UriSchemeFtp)
{
return false;
}
// Get the object used to communicate with the server.
WebClient request = new WebClient();
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential ("anonymous","janeDoe#contoso.com");
try
{
byte [] newFileData = request.DownloadData (serverUri.ToString());
string fileString = System.Text.Encoding.UTF8.GetString(newFileData);
Console.WriteLine(fileString);
}
catch (WebException e)
{
Console.WriteLine(e.ToString());
}
return true;
}
This isn't specifically a question as such.
You need to use the socket classes within the .NET framework:
MSDN - System.Net.Sockets
A good example I've previously used is:
www.dreamincode.net - Create an ftp class library

Resources