private void ReadFeatures() { features = new List <IFeature>(); extend = new Envelope(); var lineNumber = 1; string line = ""; try { using (var fileStream = File.OpenRead(Path)) using (var streamReader = new StreamReader(fileStream)) using (CultureUtils.SwitchToInvariantCulture()) { do { do // skip empty, comment & name lines { line = streamReader.ReadLine(); lineNumber++; } while (string.IsNullOrEmpty(line) || line.StartsWith("*")); var sizeLine = streamReader.ReadLine(); lineNumber++; var sizeSplit = Split(sizeLine); var numCoordinates = int.Parse(sizeSplit[0]); var coordinates = new List <Coordinate>(); for (var i = 0; i < numCoordinates; i++) { var coordinateLine = streamReader.ReadLine(); lineNumber++; var coordinateSplit = Split(coordinateLine); var x = double.Parse(coordinateSplit[0]); var y = double.Parse(coordinateSplit[1]); if (Math.Abs(x - 999.999) < 0.00001 && Math.Abs(y - 999.999) < 0.00001) //coordinate split; new feature { AddFeature(features, coordinates, extend); coordinates.Clear(); } else { coordinates.Add(new Coordinate(x, y)); } } AddFeature(features, coordinates, extend); line = streamReader.ReadLine(); lineNumber++; // read (skip) feature name } while (line != null); } } catch (Exception e) { log.ErrorFormat("Error parsing ldb file, line {0}: {1}. Error: {2}", lineNumber, line, e.Message); } }
private static void EnsureTypeConsistency(TypeSymbol type, object value) { if (type == BuiltinTypes.Bool && value is bool) { return; } if (type == BuiltinTypes.Int && value is int) { return; } if (type == BuiltinTypes.Double && value is double) { return; } if (type == BuiltinTypes.String && value is string) { return; } if (type == BuiltinTypes.Void && value is int i && i == 0) { return; } using (CultureUtils.InvariantCulture()) throw new InvalidOperationException($"Unexpected literal '{value ?? ""}' for type {type.Name}"); }
public void English() { CultureUtils.SetCultureForThisThread("en-US"); var actual = "{0}".FormatEx(0.123); var expected = "0.123"; Assert.AreEqual(expected, actual); }
public void Default() { CultureUtils.SetDefaultCultureForThisThread(); var actual = "{0}".FormatEx(0.123); var expected = "0.123"; Assert.AreEqual(expected, actual); }
public void German() { CultureUtils.SetCultureForThisThread("de-DE"); var actual = "{0}".FormatEx(0.123); var expected = "0,123"; Assert.AreEqual(expected, actual); }
/// <summary> /// Occurs as the first event in the HTTP pipeline chain of execution when ASP.NET responds to a request. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Application_BeginRequest(object sender, EventArgs e) { // set preferred culture based on Accept-Language header if (sender is HttpApplication app && app.Context?.Request?.Headers != null) { Thread.CurrentThread.CurrentCulture = CultureUtils.GetCultureFromHeader(app.Context.Request.Headers["Accept-Language"]) ?? Thread.CurrentThread.CurrentCulture; } }
/// <inheritdoc /> protected override async Task <ExecutionResult <string> > ExecuteCoreAsync(Activity activity, string arguments) { CultureInfo clientCulture = CultureUtils.GetCultureInfoOrDefault(activity.Locale); ExecutionResult <string> result = string.IsNullOrWhiteSpace(arguments) ? await ExecuteWithNoArgumentsAsync(activity, clientCulture) : await ExecuteWithArguments(activity, arguments, clientCulture); return(result); }
public void SetUp() { CultureUtils.SetDefaultCultureForThisThread(); _now = DateTimeOffset.MinValue; _dateUtils = Mock.Of <IDateUtils>(); Mock.Get(_dateUtils).Setup(u => u.Now).Returns(() => _now); _dirTmp = CreateTempDir(); _sut = Create(Log("a.log")); }
public AssemblyNameReference(string name, string culture, Version version) { if (name == null) { throw new ArgumentNullException("name"); } if (culture == null || !CultureUtils.IsValid(culture)) { throw new ArgumentException("culture is either null or non valid"); } m_name = name; m_culture = culture; m_version = version; m_hashAlgo = AssemblyHashAlgorithm.None; }
public override void DeployModel(object modelHost, DefinitionBase model) { var definition = model.WithAssertAndCast <RootWebDefinition>("model", value => value.RequireNotNull()); var spObject = GetCurrentObject(modelHost, definition); var assert = ServiceFactory.AssertService .NewAssert(definition, spObject) .ShouldNotBeNull(spObject); // temporarily switch culture to allow setting of the properties Title and Description for multi-language scenarios CultureUtils.WithCulture(spObject.UICulture, () => { if (string.IsNullOrEmpty(definition.Title)) { assert.SkipProperty(m => m.Title, "Title is null or empty"); } else { assert.ShouldBeEqual(m => m.Title, o => o.Title); } if (string.IsNullOrEmpty(definition.Description)) { assert.SkipProperty(m => m.Description, "Description is null or empty"); } else { assert.ShouldBeEqual(m => m.Description, o => o.Description); } }); assert.ShouldBeEqual((p, s, d) => { var isValid = d.IsRootWeb; return(new PropertyValidationResult { Tag = p.Tag, Src = null, Dst = null, IsValid = isValid, Message = "Checking if IsRootWeb == TRUE" }); }); }
public override void DeployModel(object modelHost, DefinitionBase model) { var definition = model.WithAssertAndCast <RootWebDefinition>("model", value => value.RequireNotNull()); var currentObject = GetCurrentObject(modelHost, definition); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = currentObject, ObjectType = typeof(SPWeb), ObjectDefinition = definition, ModelHost = modelHost }); // temporarily switch culture to allow setting of the properties Title and Description for multi-language scenarios CultureUtils.WithCulture(currentObject.UICulture, () => { if (!string.IsNullOrEmpty(definition.Title)) { currentObject.Title = definition.Title; } if (!string.IsNullOrEmpty(definition.Description)) { currentObject.Description = definition.Description; } }); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = currentObject, ObjectType = typeof(SPWeb), ObjectDefinition = definition, ModelHost = modelHost }); currentObject.Update(); }
/// <summary> /// Parses the command line arguments. Format of the /// arguments are -option <option arg> /// </summary> /// <param name="args">Args to parse</param> private static void parseCommandLine(string[] args) { var parseState = ParseState.Next; for (int index = 0; index < args.Length; index++) { switch (args[index].ToLower().Trim()) { case "-form": case "/form": case "-f": case "/f": parseState = ParseState.Form; break; case "-culture": case "/culture": parseState = ParseState.Culture; break; } switch (parseState) { case ParseState.Form: args[index] = args[index].Trim(); if (!isOption(args[index])) { _formName = args[index].Trim(); } break; case ParseState.Culture: if (!isOption(args[index])) { CultureUtils.SetCulture(args[index].Trim()); } break; } } }
public Boolean SetUILanguage() { UInt16 lcid; try { lcid = Culture.IsCultureEquals(CultureInfo.InvariantCulture) ? Default.LCID16() : Culture.LCID16(); } catch (Exception) { lcid = Default.LCID16(); } if (CultureUtils.SetUILanguage(lcid)) { return(true); } Default.SetUILanguage(); return(false); }
/// <summary> /// Set culture for the request. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Application_PreRequestHandlerExecute(object sender, EventArgs e) { CultureUtils.SetCulture(WeavyContext.Current.User); }
public void Setup() { CultureUtils.SetDefaultCultureForThisThread(); }
public Boolean Update(Int32 lcid) { return(Update(CultureUtils.GetCultureInfo(lcid))); }
private static void MapProperties(SPWeb web, WebDefinition webModel) { // temporarily switch culture to allow setting of the properties Title and Description for multi-language scenarios CultureUtils.WithCulture(web.UICulture, () => { if (!string.IsNullOrEmpty(webModel.Title)) { web.Title = webModel.Title; } if (!string.IsNullOrEmpty(webModel.Description)) { web.Description = webModel.Description; } }); if (webModel.LCID > 0) { web.Locale = new CultureInfo((int)webModel.LCID); } if (!string.IsNullOrEmpty(webModel.AlternateCssUrl)) { web.AlternateCssUrl = webModel.AlternateCssUrl; } if (!string.IsNullOrEmpty(webModel.SiteLogoUrl)) { web.SiteLogoUrl = webModel.SiteLogoUrl; } #if !NET35 if (webModel.IndexedPropertyKeys.Any()) { foreach (var indexedProperty in webModel.IndexedPropertyKeys) { // indexed prop should exist in the prop bag // otherwise it won't be saved by SharePoint (ILSpy / Refletor to see the logic) // http://rwcchen.blogspot.com.au/2014/06/sharepoint-2013-indexed-property-keys.html var propName = indexedProperty.Name; var propValue = string.IsNullOrEmpty(indexedProperty.Value) ? string.Empty : indexedProperty.Value; if (web.AllProperties.ContainsKey(propName)) { web.AllProperties[propName] = propValue; } else { web.AllProperties.Add(propName, propValue); } if (!web.IndexedPropertyKeys.Contains(propName)) { web.IndexedPropertyKeys.Add(propName); } } } #endif }
protected override void MapObject(SPList currentObject, ListDefinition definition) { var list = currentObject; // temporarily switch culture to allow setting of the properties Title and Description for multi-language scenarios CultureUtils.WithCulture(currentObject.ParentWeb.UICulture, () => { list.Title = definition.Title; // SPBug, again & again, must not be null list.Description = definition.Description ?? string.Empty; }); list.ContentTypesEnabled = definition.ContentTypesEnabled; if (!string.IsNullOrEmpty(definition.DraftVersionVisibility)) { var draftOption = (DraftVisibilityType)Enum.Parse(typeof(DraftVisibilityType), definition.DraftVersionVisibility); list.DraftVersionVisibility = draftOption; } // IRM if (definition.IrmEnabled.HasValue) { list.IrmEnabled = definition.IrmEnabled.Value; } if (definition.IrmExpire.HasValue) { list.IrmExpire = definition.IrmExpire.Value; } if (definition.IrmReject.HasValue) { list.IrmReject = definition.IrmReject.Value; } // the rest if (definition.EnableAttachments.HasValue) { list.EnableAttachments = definition.EnableAttachments.Value; } if (definition.EnableFolderCreation.HasValue) { list.EnableFolderCreation = definition.EnableFolderCreation.Value; } if (definition.EnableMinorVersions.HasValue) { list.EnableMinorVersions = definition.EnableMinorVersions.Value; } if (definition.EnableModeration.HasValue) { list.EnableModeration = definition.EnableModeration.Value; } if (definition.EnableVersioning.HasValue) { list.EnableVersioning = definition.EnableVersioning.Value; } if (definition.ForceCheckout.HasValue) { list.ForceCheckout = definition.ForceCheckout.Value; } if (definition.Hidden.HasValue) { list.Hidden = definition.Hidden.Value; } if (definition.NoCrawl.HasValue) { list.NoCrawl = definition.NoCrawl.Value; } if (definition.OnQuickLaunch.HasValue) { list.OnQuickLaunch = definition.OnQuickLaunch.Value; } if (definition.MajorVersionLimit.HasValue) { list.MajorVersionLimit = definition.MajorVersionLimit.Value; } if (definition.MajorWithMinorVersionsLimit.HasValue) { list.MajorWithMinorVersionsLimit = definition.MajorWithMinorVersionsLimit.Value; } if (definition.NavigateForFormsPages.HasValue) { list.NavigateForFormsPages = definition.NavigateForFormsPages.Value; } if (definition.EnableAssignToEmail.HasValue) { list.EnableAssignToEmail = definition.EnableAssignToEmail.Value; } if (definition.DisableGridEditing.HasValue) { list.DisableGridEditing = definition.DisableGridEditing.Value; } #if !NET35 if (definition.IndexedRootFolderPropertyKeys.Any()) { foreach (var indexedProperty in definition.IndexedRootFolderPropertyKeys) { // indexed prop should exist in the prop bag // otherwise it won't be saved by SharePoint (ILSpy / Refletor to see the logic) // http://rwcchen.blogspot.com.au/2014/06/sharepoint-2013-indexed-property-keys.html var propName = indexedProperty.Name; var propValue = string.IsNullOrEmpty(indexedProperty.Value) ? string.Empty : indexedProperty.Value; if (list.RootFolder.Properties.ContainsKey(propName)) { list.RootFolder.Properties[propName] = propValue; } else { list.RootFolder.Properties.Add(propName, propValue); } if (!list.IndexedRootFolderPropertyKeys.Contains(propName)) { list.IndexedRootFolderPropertyKeys.Add(propName); } } } #endif if (definition.WriteSecurity.HasValue) { list.WriteSecurity = definition.WriteSecurity.Value; } if (definition.ReadSecurity.HasValue) { list.ReadSecurity = definition.ReadSecurity.Value; } var docLibrary = list as SPDocumentLibrary; if (docLibrary != null) { if (!string.IsNullOrEmpty(definition.DocumentTemplateUrl)) { var urlValue = definition.DocumentTemplateUrl; urlValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext { Value = urlValue, Context = list.ParentWeb }).Value; if (!urlValue.StartsWith("/") && !urlValue.StartsWith("http:") && !urlValue.StartsWith("https:")) { urlValue = "/" + urlValue; } docLibrary.DocumentTemplateUrl = urlValue; } } ProcessLocalization(list, definition); }
public void LoggerTestBaseSetup() { CultureUtils.SetDefaultCultureForThisThread(); Log = new LineLogger(); }
public override void DeployModel(object modelHost, DefinitionBase model) { var webModelHost = modelHost.WithAssertAndCast <WebModelHost>("modelHost", value => value.RequireNotNull()); var web = webModelHost.HostWeb; var definition = model.WithAssertAndCast <ListDefinition>("model", value => value.RequireNotNull()); #pragma warning disable 618 var spObject = web.GetList(SPUrlUtility.CombineUrl(web.ServerRelativeUrl, definition.GetListUrl())); #pragma warning restore 618 var assert = ServiceFactory.AssertService.NewAssert(model, definition, spObject); // temporarily switch culture to allow getting of the properties Title and Description for multi-language scenarios CultureUtils.WithCulture(spObject.ParentWeb.UICulture, () => { assert .ShouldBeEqual(m => m.Title, o => o.Title) //.ShouldBeEqual(m => m.Hidden, o => o.Hidden) //.ShouldBeEqual(m => m.Description, o => o.Description) //.ShouldBeEqual(m => m.IrmEnabled, o => o.IrmEnabled) //.ShouldBeEqual(m => m.IrmExpire, o => o.IrmExpire) //.ShouldBeEqual(m => m.IrmReject, o => o.IrmReject) //.ShouldBeEndOf(m => m.GetListUrl(), m => m.Url, o => o.GetServerRelativeUrl(), o => o.GetServerRelativeUrl()) .ShouldBeEqual(m => m.ContentTypesEnabled, o => o.ContentTypesEnabled); if (!string.IsNullOrEmpty(definition.Description)) { assert.ShouldBeEqual(m => m.Description, o => o.Description); } else { assert.SkipProperty(m => m.Description); } }); if (definition.NavigateForFormsPages.HasValue) { assert.ShouldBeEqual(m => m.NavigateForFormsPages, o => o.NavigateForFormsPages); } else { assert.SkipProperty(m => m.NavigateForFormsPages, "NavigateForFormsPages is null or empty"); } if (definition.WriteSecurity.HasValue) { assert.ShouldBeEqual(m => m.WriteSecurity, o => o.WriteSecurity); } else { assert.SkipProperty(m => m.WriteSecurity, "WriteSecurity is null or empty"); } if (!string.IsNullOrEmpty(definition.DraftVersionVisibility)) { var draftOption = (DraftVisibilityType)Enum.Parse(typeof(DraftVisibilityType), definition.DraftVersionVisibility); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.DraftVersionVisibility); var dstProp = d.GetExpressionValue(m => m.DraftVersionVisibility); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = draftOption == (DraftVisibilityType)dstProp.Value }); }); } else { assert.SkipProperty(m => m.DraftVersionVisibility, "Skipping from validation. DraftVersionVisibility IS NULL"); } #pragma warning disable 618 if (!string.IsNullOrEmpty(definition.Url)) { assert.ShouldBeEndOf(m => m.GetListUrl(), m => m.Url, o => o.GetServerRelativeUrl(), o => o.GetServerRelativeUrl()); } else { assert.SkipProperty(m => m.Url, "Skipping from validation. Url IS NULL"); } #pragma warning restore 618 if (!string.IsNullOrEmpty(definition.CustomUrl)) { assert.ShouldBeEndOf(m => m.CustomUrl, o => o.GetServerRelativeUrl()); } else { assert.SkipProperty(m => m.CustomUrl, "Skipping from validation. CustomUrl IS NULL"); } // common if (definition.EnableAttachments.HasValue) { assert.ShouldBeEqual(m => m.EnableAttachments, o => o.EnableAttachments); } else { assert.SkipProperty(m => m.EnableAttachments, "Skipping from validation. EnableAttachments IS NULL"); } if (definition.EnableFolderCreation.HasValue) { assert.ShouldBeEqual(m => m.EnableFolderCreation, o => o.EnableFolderCreation); } else { assert.SkipProperty(m => m.EnableFolderCreation, "Skipping from validation. EnableFolderCreation IS NULL"); } if (definition.EnableMinorVersions.HasValue) { assert.ShouldBeEqual(m => m.EnableMinorVersions, o => o.EnableMinorVersions); } else { assert.SkipProperty(m => m.EnableMinorVersions, "Skipping from validation. EnableMinorVersions IS NULL"); } if (definition.EnableModeration.HasValue) { assert.ShouldBeEqual(m => m.EnableModeration, o => o.EnableModeration); } else { assert.SkipProperty(m => m.EnableModeration, "Skipping from validation. EnableModeration IS NULL"); } if (definition.EnableVersioning.HasValue) { assert.ShouldBeEqual(m => m.EnableVersioning, o => o.EnableVersioning); } else { assert.SkipProperty(m => m.EnableVersioning, "Skipping from validation. EnableVersioning IS NULL"); } if (definition.ForceCheckout.HasValue) { assert.ShouldBeEqual(m => m.ForceCheckout, o => o.ForceCheckout); } else { assert.SkipProperty(m => m.ForceCheckout, "Skipping from validation. ForceCheckout IS NULL"); } if (definition.Hidden.HasValue) { assert.ShouldBeEqual(m => m.Hidden, o => o.Hidden); } else { assert.SkipProperty(m => m.Hidden, "Skipping from validation. Hidden IS NULL"); } if (definition.NoCrawl.HasValue) { assert.ShouldBeEqual(m => m.NoCrawl, o => o.NoCrawl); } else { assert.SkipProperty(m => m.NoCrawl, "Skipping from validation. NoCrawl IS NULL"); } if (definition.OnQuickLaunch.HasValue) { assert.ShouldBeEqual(m => m.OnQuickLaunch, o => o.OnQuickLaunch); } else { assert.SkipProperty(m => m.OnQuickLaunch, "Skipping from validation. OnQuickLaunch IS NULL"); } // IRM if (definition.IrmEnabled.HasValue) { assert.ShouldBeEqual(m => m.IrmEnabled, o => o.IrmEnabled); } else { assert.SkipProperty(m => m.IrmEnabled, "Skipping from validation. IrmEnabled IS NULL"); } if (definition.IrmExpire.HasValue) { assert.ShouldBeEqual(m => m.IrmExpire, o => o.IrmExpire); } else { assert.SkipProperty(m => m.IrmExpire, "Skipping from validation. IrmExpire IS NULL"); } if (definition.IrmReject.HasValue) { assert.ShouldBeEqual(m => m.IrmReject, o => o.IrmReject); } else { assert.SkipProperty(m => m.IrmReject, "Skipping from validation. IrmReject IS NULL"); } if (definition.TemplateType > 0) { assert .ShouldBeEqual(m => m.TemplateType, o => (int)o.BaseTemplate) .SkipProperty(m => m.TemplateName, "Skipping from validation. TemplateType should be == 0"); } else { assert .SkipProperty(m => m.TemplateType, "Skipping from validation. TemplateName should be empty"); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.TemplateName); var listTemplate = ResolveListTemplate(web, definition); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = (spObject.TemplateFeatureId == listTemplate.FeatureId) && ((int)spObject.BaseTemplate == (int)listTemplate.Type) }); }); } if (definition.MajorVersionLimit.HasValue) { assert.ShouldBeEqual(m => m.MajorVersionLimit, o => o.MajorVersionLimit); } else { assert.SkipProperty(m => m.MajorVersionLimit, "Skipping from validation. MajorVersionLimit IS NULL"); } if (definition.MajorWithMinorVersionsLimit.HasValue) { assert.ShouldBeEqual(m => m.MajorWithMinorVersionsLimit, o => o.MajorWithMinorVersionsLimit); } else { assert.SkipProperty(m => m.MajorWithMinorVersionsLimit, "Skipping from validation. MajorWithMinorVersionsLimit IS NULL"); } if (definition.IndexedRootFolderPropertyKeys.Any()) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.IndexedRootFolderPropertyKeys); // Search if any indexPropertyKey from definition is not in WebModel var differentKeys = s.IndexedRootFolderPropertyKeys.Select(o => o.Name) .Except(d.IndexedRootFolderPropertyKeys); var isValid = !differentKeys.Any(); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.IndexedRootFolderPropertyKeys, "IndexedRootFolderPropertyKeys is NULL or empty. Skipping."); } // template url if (string.IsNullOrEmpty(definition.DocumentTemplateUrl) || !(spObject is SPDocumentLibrary)) { assert.SkipProperty(m => m.DocumentTemplateUrl, "Skipping DocumentTemplateUrl or list is not a document library. Skipping."); } else { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.DocumentTemplateUrl); var dstProp = (spObject as SPDocumentLibrary).DocumentTemplateUrl; var srcUrl = srcProp.Value as string; var dstUrl = dstProp; if (!dstUrl.StartsWith("/")) { dstUrl = "/" + dstUrl; } if (!srcUrl.StartsWith("/")) { srcUrl = "/" + srcUrl; } srcUrl = srcUrl.ToLower(); dstUrl = dstUrl.ToLower(); bool isValid; if (s.DocumentTemplateUrl.Contains("~sitecollection")) { var siteCollectionUrl = web.Site.ServerRelativeUrl == "/" ? string.Empty : web.Site.ServerRelativeUrl; isValid = srcUrl .Replace("~sitecollection", siteCollectionUrl) .Replace("//", "/") == dstUrl; } else if (s.DocumentTemplateUrl.Contains("~site")) { var siteCollectionUrl = web.ServerRelativeUrl == "/" ? string.Empty : web.ServerRelativeUrl; isValid = srcUrl .Replace("~site", siteCollectionUrl) .Replace("//", "/") == dstUrl; } else { isValid = dstUrl.EndsWith(srcUrl); } return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } // localization if (definition.TitleResource.Any()) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.TitleResource); var isValid = true; foreach (var userResource in s.TitleResource) { var culture = LocalizationService.GetUserResourceCultureInfo(userResource); var value = d.TitleResource.GetValueForUICulture(culture); isValid = userResource.Value == value; if (!isValid) { break; } } return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.TitleResource, "TitleResource is NULL or empty. Skipping."); } if (definition.DescriptionResource.Any()) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.DescriptionResource); var isValid = true; foreach (var userResource in s.DescriptionResource) { var culture = LocalizationService.GetUserResourceCultureInfo(userResource); var value = d.DescriptionResource.GetValueForUICulture(culture); isValid = userResource.Value == value; if (!isValid) { break; } } return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.DescriptionResource, "DescriptionResource is NULL or empty. Skipping."); } }
public static MFilesDocument UpdateSlave(DocumentsContext ctx, MFilesDocument masterDoc, MFilesDocument targetDoc, ObjectVersionWrapper sourceDoc, IDictionary <string, VaultDetails> vaultDetails, string thumbnailsUrlPattern) { if (sourceDoc.Guid != masterDoc.Guid) { targetDoc.Guid = sourceDoc.Guid; targetDoc.ModifiedDate = sourceDoc.ModifiedDate; targetDoc.CreatedDate = sourceDoc.CreatedDate; } else { targetDoc = masterDoc; } var doc = masterDoc.Document; Debug.Assert(doc != null); string languageCode; // TODO: should be in configuration or don't use CultureUtils // or we need to update language in M-Files if (sourceDoc.Language == "Portugese") { languageCode = "pt"; } else if (sourceDoc.Language == "Azeri") { languageCode = "az"; } else { languageCode = CultureUtils.GetLangTwoLetterCode(sourceDoc.Language); } if (languageCode == null) { ClassLogger.Warn( $"Could not find language code for {sourceDoc.Language} (Document {sourceDoc.UnNumber})"); return(null); } var title = doc.Titles.FirstOrDefault(t => t.Language == languageCode && t.Document == doc); if (title == null || title.MFilesDocument == targetDoc) { if (title == null) { title = new Title { MFilesDocument = targetDoc }; doc.Titles.Add(title); } title.Document = doc; title.Language = languageCode; title.LanguageFull = sourceDoc.Language; title.MFilesDocument = targetDoc; title.Value = sourceDoc.Title; } var descirpiton = doc.Descriptions.FirstOrDefault(t => t.Language == languageCode && t.Document == doc); if (descirpiton == null || descirpiton.MFilesDocument == targetDoc) { if (descirpiton == null) { descirpiton = new Description(); doc.Descriptions.Add(descirpiton); } descirpiton.Document = doc; descirpiton.Language = languageCode; descirpiton.LanguageFull = sourceDoc.Language; descirpiton.MFilesDocument = targetDoc; descirpiton.Value = sourceDoc.Description; } var file = sourceDoc.File; var repositoryUrl = vaultDetails[sourceDoc.VaultName].Url ?? ""; var targetFile = ctx.Files.FirstOrDefault(f => f.FileId == targetDoc.Guid); if (targetFile == null) { targetFile = new File(); doc.Files.Add(targetFile); } targetFile.Document = doc; targetFile.MFilesDocument = targetDoc; targetFile.Language = languageCode; targetFile.LanguageFull = sourceDoc.Language; targetFile.Name = file.Name; targetFile.Extension = file.Extension.ToLower(); targetFile.Size = file.Size; targetFile.MimeType = Mime.Lookup(file.Name + "." + file.Extension.ToLower()); targetFile.Url = file.GetUrl(repositoryUrl); targetFile.ThumbnailUrl = thumbnailsUrlPattern.Replace("{vault}", sourceDoc.VaultName) .Replace("{file}", $"{targetFile.Name}.{targetFile.Extension}"); using (var trans = ctx.Database.BeginTransaction()) { try { ctx.SaveChanges(); trans.Commit(); } catch (Exception ex) { trans.Rollback(); ClassLogger.Error(ex); throw; } } return(targetDoc); }
public override void DeployModel(object modelHost, DefinitionBase model) { var definition = model.WithAssertAndCast <WebDefinition>("model", value => value.RequireNotNull()); SPWeb parentWeb = null; if (modelHost is SiteModelHost) { parentWeb = (modelHost as SiteModelHost).HostSite.RootWeb; } if (modelHost is WebModelHost) { parentWeb = (modelHost as WebModelHost).HostWeb; } var spObject = GetWeb(parentWeb, definition); var assert = ServiceFactory.AssertService .NewAssert(definition, spObject) .ShouldBeEqual(m => m.LCID, o => o.GetLCID()); //.ShouldBeEqual(m => m.WebTemplate, o => o.GetWebTemplate()) // temporarily switch culture to allow setting of the properties Title and Description for multi-language scenarios CultureUtils.WithCulture(spObject.UICulture, () => { assert.ShouldBeEqual(m => m.Title, o => o.Title) .ShouldBeEqual(m => m.UseUniquePermission, o => o.HasUniqueRoleAssignments); }); if (!string.IsNullOrEmpty(definition.WebTemplate)) { assert.ShouldBeEqual(m => m.WebTemplate, o => o.GetWebTemplate()); assert.SkipProperty(m => m.CustomWebTemplate); } else { // no sense to chek custom web template assert.SkipProperty(m => m.WebTemplate); assert.SkipProperty(m => m.CustomWebTemplate); } if (!string.IsNullOrEmpty(definition.AlternateCssUrl)) { assert.ShouldBeEndOf(m => m.AlternateCssUrl, o => o.AlternateCssUrl); } else { assert.SkipProperty(m => m.AlternateCssUrl); } if (!string.IsNullOrEmpty(definition.SiteLogoUrl)) { assert.ShouldBeEndOf(m => m.SiteLogoUrl, o => o.SiteLogoUrl); } else { assert.SkipProperty(m => m.SiteLogoUrl); } if (!string.IsNullOrEmpty(definition.Description)) { assert.ShouldBeEqual(m => m.Description, o => o.Description); } else { assert.SkipProperty(m => m.Description); } assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.Url); var dstProp = d.GetExpressionValue(ct => ct.Url); var srcUrl = s.Url; var dstUrl = d.Url; srcUrl = UrlUtility.RemoveStartingSlash(srcUrl); var dstSubUrl = dstUrl.Replace(parentWeb.Url + "/", string.Empty); var isValid = srcUrl.ToUpper() == dstSubUrl.ToUpper(); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); // localization if (definition.TitleResource.Any()) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.TitleResource); var isValid = true; foreach (var userResource in s.TitleResource) { var culture = LocalizationService.GetUserResourceCultureInfo(userResource); var value = d.TitleResource.GetValueForUICulture(culture); isValid = userResource.Value == value; if (!isValid) { break; } } return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.TitleResource, "TitleResource is NULL or empty. Skipping."); } if (definition.DescriptionResource.Any()) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.DescriptionResource); var isValid = true; foreach (var userResource in s.DescriptionResource) { var culture = LocalizationService.GetUserResourceCultureInfo(userResource); var value = d.DescriptionResource.GetValueForUICulture(culture); isValid = userResource.Value == value; if (!isValid) { break; } } return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.DescriptionResource, "DescriptionResource is NULL or empty. Skipping."); } if (definition.IndexedPropertyKeys.Any()) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.IndexedPropertyKeys); // Search if any indexPropertyKey from definition is not in WebModel var differentKeys = s.IndexedPropertyKeys.Select(o => o.Name) .Except(d.IndexedPropertyKeys); var isValid = !differentKeys.Any(); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.IndexedPropertyKeys, "IndexedPropertyKeys is NULL or empty. Skipping."); } // O365 props assert.SkipProperty(m => m.MembersCanShare, "Skipping O365 prop"); assert.SkipProperty(m => m.RequestAccessEmail, "Skipping O365 prop"); }
/// <summary> /// Parses the command line arguments. Format of the /// arguments are -option <option arg> /// </summary> /// <param name="args">Args to parse</param> private static void parseCommandLine(string[] args) { var parseState = ParseState.Next; for (int index = 0; index < args.Length; index++) { switch (args[index].ToLower().Trim()) { case "-user": case "/user": parseState = ParseState.Username; break; case "-profile": case "/profile": parseState = ParseState.Profile; break; case "-panelconfig": case "/panelconfig": parseState = ParseState.PanelConfig; break; case "-culture": case "/culture": parseState = ParseState.Culture; break; } switch (parseState) { case ParseState.Profile: args[index] = args[index].Trim(); if (!isOption(args[index])) { _profile = args[index].Trim(); } break; case ParseState.Username: if (!isOption(args[index])) { _userName = args[index].Trim(); } break; case ParseState.PanelConfig: if (!isOption(args[index])) { _panelConfig = args[index].Trim(); } break; case ParseState.Culture: if (!isOption(args[index])) { CultureUtils.SetCulture(args[index].Trim()); } break; } } }