public void UpdateServiceEndpoint(string primaryKey, string namespaceAddress, string sharedAccessKey, string serviceNamespace) { Logger.Trace(CultureInfo.InvariantCulture, TraceMessageHelper.EnteredMethod, SystemTypeName, MethodBase.GetCurrentMethod().Name); if (string.IsNullOrWhiteSpace(primaryKey)) { throw new ArgumentNullException(nameof(primaryKey)); } Logger.Info(CultureInfo.InvariantCulture, "Primary key: {0}.", primaryKey); bool isValidGuid = Guid.TryParse(primaryKey, out Guid key); if (!isValidGuid) { throw new ArgumentException("Primary key argument is invalid."); } if (string.IsNullOrWhiteSpace(namespaceAddress)) { throw new ArgumentNullException(nameof(namespaceAddress)); } Logger.Info(CultureInfo.InvariantCulture, "Namespace address: {0}.", namespaceAddress); if (string.IsNullOrWhiteSpace(sharedAccessKey)) { throw new ArgumentNullException(nameof(sharedAccessKey)); } if (string.IsNullOrWhiteSpace(serviceNamespace)) { throw new ArgumentNullException(nameof(serviceNamespace)); } Logger.Info(CultureInfo.InvariantCulture, "Service namespace: {0}.", serviceNamespace); ServiceEndpoint serviceEndpoint = CrmService.GetServiceEndpoint(key); if (serviceEndpoint == null) { throw new EntityNotFoundException("Service endpoint not found."); } OrganizationServiceContext.ClearChanges(); ServiceEndpoint se = new ServiceEndpoint { ServiceEndpointId = serviceEndpoint.Id, ContentTypeOfTheMessage = ServiceEndpointMessageFormat.Json, NamespaceAddress = namespaceAddress, //SASKey = sharedAccessKey, //TO-DO ServiceNamespace = serviceNamespace }; OrganizationServiceContext.Attach(se); OrganizationServiceContext.UpdateObject(se); CrmService.SaveChanges(OrganizationServiceContext, SaveChangesOptions.None); Logger.Trace(CultureInfo.InvariantCulture, TraceMessageHelper.ExitingMethod, SystemTypeName, MethodBase.GetCurrentMethod().Name); }
private void UpdateOrganizationSettings(string replaceString, string blockedAttachments) { Logger.Trace(CultureInfo.InvariantCulture, TraceMessageHelper.EnteredMethod, SystemTypeName, MethodBase.GetCurrentMethod().Name); if (string.IsNullOrWhiteSpace(blockedAttachments)) { throw new ArgumentNullException(nameof(blockedAttachments)); } Logger.Info(CultureInfo.InvariantCulture, "Updating blocked attachments."); Organization organizationSettings = CrmService.GetOrganizationSettings(); if (organizationSettings == null) { throw new EntityNotFoundException("No organization record can be found in the system."); } OrganizationServiceContext.ClearChanges(); Organization updatedOrganizationSettings = new Organization { Id = organizationSettings.Id, BlockAttachments = blockedAttachments.Replace(replaceString, string.Empty), }; OrganizationServiceContext.Attach(updatedOrganizationSettings); OrganizationServiceContext.UpdateObject(updatedOrganizationSettings); CrmService.SaveChanges(OrganizationServiceContext, SaveChangesOptions.None); Thread.Sleep(60000); Logger.Info(CultureInfo.InvariantCulture, "Blocked attachments updated to: {0}.", updatedOrganizationSettings.BlockAttachments); Logger.Trace(CultureInfo.InvariantCulture, TraceMessageHelper.ExitingMethod, SystemTypeName, MethodBase.GetCurrentMethod().Name); }
public void UpdateOrganizationSettings(Organization organization) { Logger.Trace(CultureInfo.InvariantCulture, TraceMessageHelper.EnteredMethod, SystemTypeName, MethodBase.GetCurrentMethod().Name); if (organization == null) { throw new ArgumentNullException(nameof(organization)); } Organization organizationSettings = CrmService.GetOrganizationSettings(); if (organizationSettings == null) { throw new EntityNotFoundException("No organization record can be found in the system."); } OrganizationServiceContext.ClearChanges(); //TO-DO: this is in experimental mode Organization updatedOrganizationSettings = new Organization { Id = organizationSettings.Id, //BlockAttachments = organization.BlockAttachments, OrganizationName = organization.OrganizationName }; OrganizationServiceContext.Attach(updatedOrganizationSettings); OrganizationServiceContext.UpdateObject(updatedOrganizationSettings); CrmService.SaveChanges(OrganizationServiceContext, SaveChangesOptions.None); //Logger.Info(CultureInfo.InvariantCulture, "Blocked attachments updated to: {0}.", updatedOrganizationSettings.BlockAttachments); Logger.Trace(CultureInfo.InvariantCulture, TraceMessageHelper.ExitingMethod, SystemTypeName, MethodBase.GetCurrentMethod().Name); }
public void UpdateWebFiles(string inputPath, string websitePrimaryKey, string blockedAttachments) { Logger.Trace(CultureInfo.InvariantCulture, TraceMessageHelper.EnteredMethod, SystemTypeName, MethodBase.GetCurrentMethod().Name); if (string.IsNullOrWhiteSpace(inputPath)) { throw new ArgumentNullException(nameof(inputPath)); } Logger.Info(CultureInfo.InvariantCulture, "Input path: {0}.", inputPath); if (!Directory.Exists(Path.GetDirectoryName(inputPath))) { throw new FileNotFoundException("The input file path does not exist."); } if (string.IsNullOrWhiteSpace(websitePrimaryKey)) { throw new ArgumentNullException(nameof(websitePrimaryKey)); } Logger.Info(CultureInfo.InvariantCulture, "Web site primary key: {0}.", websitePrimaryKey); bool isValid = Guid.TryParse(websitePrimaryKey, out Guid websiteId); if (!isValid) { throw new ArgumentException("The web site primary key is not valid"); } IList <FileInfo> files = new List <FileInfo>(); EnumerateFiles(inputPath, files); UpdateOrganizationSettings("js;", blockedAttachments); IList <WebFile> webFiles = CrmService.GetWebsiteFiles(websiteId); OrganizationServiceContext.ClearChanges(); foreach (FileInfo file in files) { Logger.Info(CultureInfo.InvariantCulture, "Processing file {0}.", file.FullName); WebFile webFile = webFiles.SingleOrDefault(x => x.Name.ToUpperInvariant().Equals(file.Name.ToUpperInvariant())); if (webFile == null) { Logger.Warn(CultureInfo.InvariantCulture, "There is no portal web file entity for the file {0}.", file.Name); continue; } Note annotation = CrmService.GetAnnotations(webFile.Id).OrderByDescending(x => x.CreatedOn).FirstOrDefault(); if (annotation == null) { Logger.Info(CultureInfo.InvariantCulture, "A new annotation {0} will be created.", file.Name); annotation = new Note { Document = Convert.ToBase64String(File.ReadAllBytes(file.FullName)), FileName = file.Name, IsDocument = true, MimeType = MimeMapping.GetMimeMapping(file.Name), ObjectType = webFile.LogicalName, Regarding = new EntityReference(webFile.LogicalName, webFile.Id), }; OrganizationServiceContext.AddObject(annotation); } else if (!annotation.Document.Equals(Convert.ToBase64String(File.ReadAllBytes(file.FullName)))) { Logger.Info(CultureInfo.InvariantCulture, "The annotation {0} will be updated.", file.Name); annotation = new Note { AnnotationId = annotation.Id, Document = Convert.ToBase64String(File.ReadAllBytes(file.FullName)) }; OrganizationServiceContext.Attach(annotation); OrganizationServiceContext.UpdateObject(annotation); } } CrmService.SaveChanges(OrganizationServiceContext, SaveChangesOptions.None); UpdateOrganizationSettings("nothing really", blockedAttachments); Logger.Trace(CultureInfo.InvariantCulture, TraceMessageHelper.ExitingMethod, SystemTypeName, MethodBase.GetCurrentMethod().Name); }
public void UpdateWebTemplates(string inputPath, string websitePrimaryKey) { Logger.Trace(CultureInfo.InvariantCulture, TraceMessageHelper.EnteredMethod, SystemTypeName, MethodBase.GetCurrentMethod().Name); if (string.IsNullOrWhiteSpace(inputPath)) { throw new ArgumentNullException(nameof(inputPath)); } Logger.Info(CultureInfo.InvariantCulture, "Input path: {0}.", inputPath); if (!Directory.Exists(Path.GetDirectoryName(inputPath))) { throw new FileNotFoundException("The input file path does not exist."); } if (string.IsNullOrWhiteSpace(websitePrimaryKey)) { throw new ArgumentNullException(nameof(websitePrimaryKey)); } Logger.Info(CultureInfo.InvariantCulture, "Web site primary key: {0}.", websitePrimaryKey); bool isValid = Guid.TryParse(websitePrimaryKey, out Guid websiteId); if (!isValid) { throw new ArgumentException("The web site primary key is not valid"); } IList <FileInfo> files = new List <FileInfo>(); EnumerateFiles(inputPath, files); IList <WebTemplate> webTemplates = CrmService.GetWebTemplates(websiteId); OrganizationServiceContext.ClearChanges(); foreach (FileInfo file in files) { Logger.Info(CultureInfo.InvariantCulture, "Processing file {0}.", file.FullName); string fileName = file.Name.ToUpperInvariant().Replace(".HTML", string.Empty); WebTemplate webTemplate = webTemplates.SingleOrDefault(x => x.Name.ToUpperInvariant().Equals(fileName)); if (webTemplate == null) { Logger.Warn(CultureInfo.InvariantCulture, "There is no portal web template entity for the file {0}.", file.Name); continue; } string source = File.ReadAllText(file.FullName); if (source.Equals(webTemplate.Source)) { continue; } var updatedWebTemplate = new WebTemplate { Id = webTemplate.Id, Source = source }; OrganizationServiceContext.Attach(updatedWebTemplate); OrganizationServiceContext.UpdateObject(updatedWebTemplate); } CrmService.SaveChanges(OrganizationServiceContext, SaveChangesOptions.None); Logger.Trace(CultureInfo.InvariantCulture, TraceMessageHelper.ExitingMethod, SystemTypeName, MethodBase.GetCurrentMethod().Name); }