How to get Perforce (P4Api.net) Workspace Path - c#

var P4USER = p4Config.P4USER;
var P4PORT = p4Config.P4PORT;
var P4CLIENT = p4Config.P4CLIENT;
var P4PASSWD = p4Config.P4PASSWD;
Perforce.P4.Server srv = new Perforce.P4.Server(new ServerAddress(P4PORT));
Perforce.P4.Repository p4 = new Perforce.P4.Repository(srv);
p4.Connection.UserName = P4USER;
p4.Connection.SetClient(P4CLIENT);
p4.Connection.Connect(new Perforce.P4.Options());
p4.Connection.Login(P4PASSWD);
I using P4Api.net and login done. but how can I get my worksapce path ?

I found solution , so I answer by my self.
string P4CLIENT = "YourWorkSpaceName";
Client c = p4.GetClient(P4CLIENT);
//here
Console.WriteLine(c.Root);

Related

How to create a folder on shared drive in Google Drive using C#

I would like to create a new folder on another shared drive using c#, everything works on my drive only.
I use this code.
var fileMetadata = new Google.Apis.Drive.v3.Data.File()
{
Name = folderName,
MimeType = "application/vnd.google-apps.folder",
Parents = new List<string>() { folderTargetID },
};
// Create a new folder on drive.
var request = service.Files.Create(fileMetadata);
request.Fields = "id";
var folderInfo = request.Execute();
please help me, thanks.
After i add some code, finally works fine.
// File metadata
var fileMetadata = new Google.Apis.Drive.v3.Data.File()
{
Name = folderName,
MimeType = "application/vnd.google-apps.folder",
Parents = new List<string>() { folderTargetID },
};
// Create a new folder on drive.
var request = service.Files.Create(fileMetadata);
request.SupportsAllDrives = true;
request.SupportsTeamDrives = true;
request.Fields = "id";
var folderInfo = request.Execute();

XML reading - Deserialize vs XElement.Load

my question is fairly simple, which method should I use and why for parsing XML files?
Right now I have function for that:
return new EdiFile
{
SPPLR_MAILBOX = xmlDoc.Element("SPPLR_MAILBOX").Value,
MESSAGE_ID = xmlDoc.Element("MESSAGE_ID").Value,
ATTRIBUTE05 = xmlDoc.Element("ATTRIBUTE05").Value,
Levels0 = (from a in xmlDoc.Element("LEVELS0").Elements("LEVEL0")
select new Level0
{
PLT_NUM = a.Element("PLT_NUM").Value,
PLT_LABEL_ID = a.Element("PLT_LABEL_ID").Value,
BOX_QTY = a.Element("BOX_QTY").Value,
PLT_WEIGHT = a.Element("PLT_WEIGTH").Value,
PLT_DIMENSION = a.Element("PLT_DIMENSION").Value,
PLT_CHEM = a.Element("PLT_CHEM").Value,
PLT_NOT_STACK = a.Element("PLT_NOT_STACK").Value,
PLT_NOTE = a.Element("PLT_NOTE").Value,
ATTRIBUTE01 = a.Element("ATTRIBUTE01").Value,
ATTRIBUTE02 = a.Element("ATTRIBUTE02").Value,
ATTRIBUTE03 = a.Element("ATTRIBUTE03").Value,
ATTRIBUTE04 = a.Element("ATTRIBUTE04").Value,
ATTRIBUTE05 = a.Element("ATTRIBUTE05").Value,
Levels1 = (from b in a.Element("LEVELS1").Elements("LEVEL1")
select new Level1
{
BOX_NUM = b.Element("BOX_NUM").Value,
BOX_LABEL_ID = b.Element("BOX_LABEL_ID").Value,
Items = (from c in b.Element("ITEMS").Elements("ITEM")
select new Item
{
SPPLR_ITEM = c.Element("SPPLR_ITEM").Value,
CUST_ITEM = c.Element("CUST_ITEM").Value,
ATTRIBUTE01 = c.Element("ATTRIBUTE01").Value,
ATTRIBUTE02 = c.Element("ATTRIBUTE02").Value,
ATTRIBUTE03 = c.Element("ATTRIBUTE03").Value,
ATTRIBUTE04 = c.Element("ATTRIBUTE04").Value,
ATTRIBUTE05 = c.Element("ATTRIBUTE05").Value,
Lots = (from d in c.Element("LOTS").Elements("LOT")
select new Lot
{
LOT_NUM = d.Element("LOT_NUM").Value,
LOT_LABEL_ID = d.Element("LOT_LABEL_ID").Value,
LOT_NOTE = d.Element("LOT_NOTE").Value,
LOT_EXP_DATE = d.Element("LOT_EXP_DATE").Value,
QTY = d.Element("QTY").Value,
UOM = d.Element("UOM").Value,
ATTRIBUTE01 = d.Element("ATTRIBUTE01").Value,
ATTRIBUTE02 = d.Element("ATTRIBUTE02").Value,
ATTRIBUTE03 = d.Element("ATTRIBUTE03").Value,
ATTRIBUTE04 = d.Element("ATTRIBUTE04").Value,
ATTRIBUTE05 = d.Element("ATTRIBUTE05").Value
}).ToList()
}).ToList()
}).ToList()
}).ToList()
};
But should I use deserialize? I learnt about serialization yesterday.
I cant really find any source explaining my method, vs deserialization.
Can someone get me any insight please?
Your method is more performance and flexie, because you have control on processing xml file. Serialization is using reflection and it is less performance.

Adding attributes for faceting with Algolia C#

I have an attribute that I'd like to add for faceting: ApprovalFL. When I add the facet in the Algolia dashboard, it works fine until I have to reindex which ends up deleting my facets in the dashboard for some reason. I was thinking, maybe adding the attribute in my code would resolve that. I found the documentation about this step here: https://www.algolia.com/doc/api-reference/api-parameters/attributesForFaceting/
Here's the C# example they provide:
index.SetSettings(
JObject.Parse(#"{""attributesForFaceting"":[""author"",""filterOnly(category)"",""searchable(publisher)""]}")
);
If I understand correctly, this code needs to go in my backend reindexing code (found in my AdminController.cs):
public async Task<ActionResult> ReIndexData()
{
var algoliaArtistModels = Tools.BuildAlgoliaArtistModels(EntityDataAccess.GetAllAccountInfoes());
var algoliaUnaffiliatedArtistModels = Tools.BuildAlgoliaArtistModels(EntityDataAccess.GetAllUnaffiliatedAccountInfo());
var algoliaSongModels = Tools.BuildAlgoliaSongModels(EntityDataAccess.GetAllAcceptedSongs());
var artistIndexHelper = HttpContext.Application.Get("ArtistIndexHelper") as IndexHelper<ArtistAlgoliaModel>;
var unaffiliatedArtistIndexHelper = HttpContext.Application.Get("UnaffiliatedArtist") as IndexHelper<ArtistAlgoliaModel>;
var songIndexHelper = HttpContext.Application.Get("SongIndexHelper") as IndexHelper<SongAlgoliaModel>;
await artistIndexHelper.OverwriteIndexAsync(algoliaArtistModels);
await unaffiliatedArtistIndexHelper.OverwriteIndexAsync(algoliaUnaffiliatedArtistModels);
await songIndexHelper.OverwriteIndexAsync(algoliaSongModels);
return View("AlgoliaReIndexData");
}
However, I don't think I put index.setSettings in this block of code, what is the best way to set this attribute for faceting in my backend code? The ApprovalFL attribute is stored in my Song indices.
Possibly it should go somewhere here in my Tools.cs?
public static SongAlgoliaModel BuildAlgoliaSongModel(Song song)
{
var model = new SongAlgoliaModel();
var album = EntityDataAccess.GetAlbumByID(song.AlbumID);
model.AccountImageURL = album.AccountInfo.ImageURL;
model.AccountInfoID = album.AccountInfoID;
model.AccountType = album.AccountInfo.CreatorFL == true ? "Creator" : "Artist";
model.AlbumID = song.AlbumID;
model.AlbumName = album.AlbumName;
model.ApprovalFL = song.ApprovalFL;
model.Artist = album.AccountInfo.DisplayName;
model.BPM = song.BPM;
model.Duration = song.Duration;
model.FeaturedArtist = song.Artist;
model.FreeFL = album.FreeFL;
model.ImageURL = album.ImageURL;
model.iTunesURL = album.iTunesURL;
model.LabelName = album.LabelName;
model.LicenseFL = album.LicenseFL;
model.SongID = song.SongID;
model.Title = song.Title;
model.UploadDate = song.UploadDate;
model.URL = song.URL;
model.UserID = album.AccountInfo.UserID;
return model;
}
public static List<SongAlgoliaModel> BuildAlgoliaSongModels(AccountInfo accountInfo)
{
var list = new List<SongAlgoliaModel>();
var songs = EntityDataAccess.GetSongsByUserID(accountInfo.UserID).Where(x => x.ApprovalFL == true).ToList();
foreach(var item in songs)
{
var model = new SongAlgoliaModel();
model.AccountImageURL = item.Album.AccountInfo.ImageURL;
model.AccountInfoID = item.Album.AccountInfoID;
model.AccountType = item.Album.AccountInfo.CreatorFL == true ? "Creator" : "Artist";
model.AlbumID = item.AlbumID;
model.AlbumName = item.Album.AlbumName;
model.ApprovalFL = item.ApprovalFL;
model.Artist = item.Album.AccountInfo.DisplayName;
model.BPM = item.BPM;
model.Duration = item.Duration;
model.FeaturedArtist = item.Artist;
model.FreeFL = item.Album.FreeFL;
model.ImageURL = item.Album.ImageURL;
model.iTunesURL = item.Album.iTunesURL;
model.LabelName = item.Album.LabelName;
model.LicenseFL = item.Album.LicenseFL;
model.SongID = item.SongID;
model.Title = item.Title;
model.UploadDate = item.UploadDate;
model.URL = item.URL;
model.UserID = item.Album.AccountInfo.UserID;
list.Add(model);
}
return list;
}
OK for those using C# .NET it's as simple as adding it to your Global.asax.cs for example for me:
var songIndexHelper = new IndexHelper<SongAlgoliaModel>(algoliaClient, "Song", "SongID");
songIndexHelper.SetSettings(JObject.Parse(#"{""attributesForFaceting"":[""ApprovalFL""]}"));
Why do you have to re-index by the way? Best practice is to set up your index only initially.

How to get internal & external url data using Mozscape API?

I am using C# wrapper for SEOmoz API. The internal/external data which is displayed in open site explorer. How to get this data using this API?
var moz = new Mozscape() { MozAccessId = "xxxxxx-xxxxxxxx", MozSecretKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", MozApiType = MozAPI.URL_METRICS };
var url = moz.CreateMozAPIUrl("webmetro.com", MozAPI.URL_METRICS, 1);
var results = moz.GetUrlMetrics(url);
Mozscape Link Metrics is used for internal and external data.
To get Internal Data.
var moz = new Mozscape() { MozAccessId = MozAccessID, MozSecretKey = MozSecretKEY, MozApiType = MozAPI.LINK_SCAPE };
var url = moz.CreateMozAPIUrl_LinkMetrics(DomainName, MozAPI.LINK_SCAPE, 1, Scope.page_to_domain);
var FullIntUrl = url + "&Filter=internal&Sort=page_authority&SourceCols=103079217573&TargetCols=4&Limit=1000";
var Intr = moz.GetLinkMetrics(FullIntUrl);
To get External data.
var FullExtUrl = url + "&Filter=external&Sort=page_authority&SourceCols=103079217573&TargetCols=4&Limit=1000";
var Extr = moz.GetLinkMetrics(FullExtUrl);

UPS API - LabelLinksIndicator - Object Reference not set to an instance of an object

Below is some code for generating a UPS shipping label. It is based on the .net sample provided in the UPS developer kit. My problem is with the line highlighted in bold below. It throws and error as follows "System.NullReferenceException: Object reference not set to an instance of an object.".
What I know is this LabelLinksIndicator is required if you want the UPS API to return a link to a label. Otherwise it returns details on the shipment but no label. The relevant section of the UPS documentation is at the bottom of my question.
What do I need to do to overcome this error? It is not clear to me from the documentation what value I should be passing for LabelLinksIndicator. I've tried passing a 1, true and and an empty string. Same error in every case. The error message seems to indicate that there is an object I need to instantiate that I am not currently. However, I can't figure out what to instantiate. The available information on the web and on UPS.com is unfortunately sparse.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Foo.Web.UPSWebReference;
namespace Foo.Web.Auth
{
public partial class UPS : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["id"] != null)
{
try
{
ShipService shpSvc = new ShipService();
ShipmentRequest shipmentRequest = new ShipmentRequest();
UPSSecurity upss = new UPSSecurity();
UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken();
upssSvcAccessToken.AccessLicenseNumber = "foo";
upss.ServiceAccessToken = upssSvcAccessToken;
UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken();
upssUsrNameToken.Username = "foo";
upssUsrNameToken.Password = "foo";
upss.UsernameToken = upssUsrNameToken;
shpSvc.UPSSecurityValue = upss;
RequestType request = new RequestType();
String[] requestOption = { "nonvalidate" };
request.RequestOption = requestOption;
shipmentRequest.Request = request;
ShipmentType shipment = new ShipmentType();
shipment.Description = "Ship webservice example";
ReturnServiceType rtn = new ReturnServiceType();
rtn.Code = "8";
rtn.Description = "Description";
ShipperType shipper = new ShipperType();
shipper.ShipperNumber = "foo";
PaymentInfoType paymentInfo = new PaymentInfoType();
ShipmentChargeType shpmentCharge = new ShipmentChargeType();
BillShipperType billShipper = new BillShipperType();
billShipper.AccountNumber = "foo";
shpmentCharge.BillShipper = billShipper;
shpmentCharge.Type = "01";
ShipmentChargeType[] shpmentChargeArray = { shpmentCharge };
paymentInfo.ShipmentCharge = shpmentChargeArray;
shipment.PaymentInformation = paymentInfo;
foo.Web.UPSWebReference.ShipAddressType shipperAddress = new foo.Web.UPSWebReference.ShipAddressType();
String[] addressLine = { "301 166th Street" };
shipperAddress.AddressLine = addressLine;
shipperAddress.City = "Jersey City";
shipperAddress.PostalCode = "07310";
shipperAddress.StateProvinceCode = "NJ";
shipperAddress.CountryCode = "US";
shipperAddress.AddressLine = addressLine;
shipper.Address = shipperAddress;
shipper.Name = "ABC Associates";
shipper.AttentionName = "ABC Associates";
ShipPhoneType shipperPhone = new ShipPhoneType();
shipperPhone.Number = "1234567890";
shipper.Phone = shipperPhone;
shipment.Shipper = shipper;
ShipFromType shipFrom = new ShipFromType();
foo.Web.UPSWebReference.ShipAddressType shipFromAddress = new foo.Web.UPSWebReference.ShipAddressType();
String[] shipFromAddressLine = { "100 82nd Street" };
shipFromAddress.AddressLine = addressLine;
shipFromAddress.City = "New York";
shipFromAddress.PostalCode = "10024";
shipFromAddress.StateProvinceCode = "NY";
shipFromAddress.CountryCode = "US";
shipFrom.Address = shipFromAddress;
shipFrom.AttentionName = "Mr.ABC";
shipFrom.Name = "ABC Associates";
shipment.ShipFrom = shipFrom;
ShipToType shipTo = new ShipToType();
ShipToAddressType shipToAddress = new ShipToAddressType();
String[] addressLine1 = { "Some Street" };
shipToAddress.AddressLine = addressLine1;
shipToAddress.City = "Roswell";
shipToAddress.PostalCode = "30076";
shipToAddress.StateProvinceCode = "GA";
shipToAddress.CountryCode = "US";
shipTo.Address = shipToAddress;
shipTo.Address.ResidentialAddressIndicator = "1"; //dan
shipTo.AttentionName = "DEF";
shipTo.Name = "DEF Associates";
ShipPhoneType shipToPhone = new ShipPhoneType();
shipToPhone.Number = "1234567890";
shipTo.Phone = shipToPhone;
shipment.ShipTo = shipTo;
ServiceType service = new ServiceType();
service.Code = "03";
service.Description = "Ground";
shipment.Service = service;
PackageType package = new PackageType();
package.Description = "Deliver to Warehouse";
PackageWeightType packageWeight = new PackageWeightType();
packageWeight.Weight = "10";
ShipUnitOfMeasurementType uom = new ShipUnitOfMeasurementType();
uom.Code = "LBS";
packageWeight.UnitOfMeasurement = uom;
package.PackageWeight = packageWeight;
PackagingType packType = new PackagingType();
packType.Code = "02";
package.Packaging = packType;
PackageType[] pkgArray = { package };
shipment.Package = pkgArray;
LabelSpecificationType labelSpec = new LabelSpecificationType();
LabelImageFormatType labelImageFormat = new LabelImageFormatType();
labelImageFormat.Code = "GIF";
labelSpec.LabelImageFormat = labelImageFormat;
string userAgent = Request.UserAgent;
labelSpec.HTTPUserAgent = userAgent;
shipmentRequest.LabelSpecification = labelSpec;
**shipmentRequest.Shipment.ShipmentServiceOptions.LabelDelivery.LabelLinksIndicator = "1";**
shipmentRequest.Shipment = shipment;
System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
ShipmentResponse shipmentResponse = shpSvc.ProcessShipment(shipmentRequest);
Response.Redirect(shipmentResponse.ShipmentResults.LabelURL.ToString());
I figured out what the problem was. I needed first to new-up an instance of
ShipmentTypeShipmentServiceOptions shipServOpt = new ShipmentTypeServiceOptions();
and
LabelDeliveryType labelDel = new LabelDeliveryType();
Then set the LabelLinksIndicator element
labeldel.LabelLinksIndicator = "";
Then assign the options to my shipment instance
shipment.ShipmentServiceOptions = shipServOpt;
Note, ShipmentServiceOptionsType is NOT the same as ShipmentTypeServiceOptions. This tripped me up for a while.
Dear UPS, if you are reading this please consider improving upon your documentation and providing a more complete set of code examples.
shipmentRequest.Shipment appears to be null, since you aren't assigning anything to it until the next line. So, you can't do shipmentRequest.Shipment.ANYTHING. Switch them around, so that you have
shipmentRequest.Shipment = shipment;
shipmentRequest.Shipment.ShipmentServiceOptions.LabelDelivery.LabelLinksIndicator = "1";
The element needs to get passed as <LabelLinksIndicator/> in the XML. In your sample you'd be sending it as <LabelLinksIndicator>1</LabelLinksIndicator> which is invalid.

Categories

Resources