Beispiel #1
0
        internal static int GetAppIdFromGuidName(int zoneId, string appName, bool alsoCheckFolderName = false)
        {
            var baseCache = (BaseCache)DataSource.GetCache(Eav.Constants.DefaultZoneId, Eav.Constants.MetaDataAppId);
            // ReSharper disable once UnusedVariable
            var dummy = baseCache.CacheTimestamp;

            if (String.IsNullOrEmpty(appName))
            {
                return(0);
            }

            var appId = baseCache.ZoneApps[zoneId].Apps
                        .Where(p => p.Value == appName).Select(p => p.Key).FirstOrDefault();

            // optionally check folder names
            if (appId == 0 && alsoCheckFolderName)
            {
                var nameLower = appName.ToLower();
                foreach (var p in baseCache.ZoneApps[zoneId].Apps)
                {
                    var mds         = DataSource.GetMetaDataSource(zoneId, p.Key);
                    var appMetaData = mds
                                      .GetMetadata(SystemRuntime.MetadataType(Eav.Constants.AppAssignmentName), p.Key,
                                                   AppConstants.TypeAppConfig)
                                      .FirstOrDefault();
                    var folder = appMetaData?.GetBestValue("Folder").ToString();
                    if (!String.IsNullOrEmpty(folder) && folder.ToLower() == nameLower)
                    {
                        return(p.Key);
                    }
                }
            }
            return(appId > 0 ? appId : Settings.DataIsMissingInDb);
        }
Beispiel #2
0
        internal static int GetAppIdFromGuidName(int zoneId, string appName, bool alsoCheckFolderName = false)
        {
            // ToDo: Fix issue in EAV (cache is only ensured when a CacheItem-Property is accessed like LastRefresh)
            var baseCache = ((BaseCache)DataSource.GetCache(Constants.DefaultZoneId, Constants.MetaDataAppId));
            // ReSharper disable once UnusedVariable
            var dummy = baseCache.CacheLastRefresh;

            if (IsNullOrEmpty(appName))
            {
                return(0);
            }

            var appId = baseCache.ZoneApps[zoneId].Apps
                        .Where(p => p.Value == appName).Select(p => p.Key).FirstOrDefault();

            // optionally check folder names
            if (appId == 0 && alsoCheckFolderName)
            {
                var nameLower = appName.ToLower();
                foreach (var p in baseCache.ZoneApps[zoneId].Apps)
                {
                    var mds         = DataSource.GetMetaDataSource(zoneId, p.Key);
                    var appMetaData = mds
                                      .GetMetadata(SystemRuntime.MetadataType(Constants.AppAssignmentName), p.Key,
                                                   AppConstants.AttributeSetStaticNameApps)
                                      .FirstOrDefault();
                    string folder = appMetaData?.GetBestValue("Folder").ToString();
                    if (!IsNullOrEmpty(folder) && folder.ToLower() == nameLower)
                    {
                        return(p.Key);
                    }
                }
            }
            return(appId > 0 ? appId : Settings.DataIsMissingInDb);
        }
Beispiel #3
0
        public static IApp Init(this App app, IServiceProvider sp, int appId, ILog log, bool showDrafts = false)
        {
            var appIdentity  = new AppIdentity(SystemRuntime.ZoneIdOfApp(appId), appId);
            var confProvider = sp.Build <AppConfigDelegate>().Init(log);

            return(app.Init(confProvider, appIdentity, log, showDrafts));
        }
Beispiel #4
0
        public static IApp Init(this App app, int appId, ILog log, IBlock optionalBlock = null, bool showDrafts = false)
        {
            var appIdentity = new AppIdentity(SystemRuntime.ZoneIdOfApp(appId), appId);

            if (optionalBlock == null)
            {
                return(app.Init(appIdentity, log, showDrafts));
            }
            var buildConfig = ConfigurationProvider.Build(optionalBlock, true);

            return(app.Init(appIdentity, buildConfig, false, log));
        }
Beispiel #5
0
        public static IApp Init(this App app, IServiceProvider sp, int appId, ILog log, IBlock optionalBlock = null, bool showDrafts = false)
        {
            var appIdentity  = new AppIdentity(SystemRuntime.ZoneIdOfApp(appId), appId);
            var confProvider = sp.Build <AppConfigDelegate>().Init(log);

            if (optionalBlock == null)
            {
                return(app.Init(confProvider, appIdentity, log, showDrafts));
            }
            var buildConfig = confProvider.Build(optionalBlock);

            return(app.Init(appIdentity, buildConfig, log));
        }
Beispiel #6
0
        public void ShouldBeAbleToBuyRandomProduct()
        {
            // Open brand menu
            PageBase currentPage = new HomePage(_driver);

            ManufacturerPage manufacturerPage = null;
            ProductPage      productPage      = null;

            for (int i = 0; i < 50; i++)
            {
                currentPage = manufacturerPage = OpenRandomManufacturerPage(currentPage);

                if (!manufacturerPage.HasProducts)
                {
                    manufacturerPage = null;
                    continue;
                }

                productPage = OpenRandomProductPage(manufacturerPage);

                if (!productPage.CanAddProductToCart)
                {
                    productPage = null;
                    continue;
                }

                break;
            }

            if (manufacturerPage == null || productPage == null)
            {
                throw new Exception("Could not find available manufacturer and product");
            }

            var orderPage = OrderProductOnProductPage(productPage);

            Assert.AreEqual("Оформление заказа", orderPage.Title);
            Assert.AreEqual("Оформление заказа", orderPage.Header.GetInnerHtml());

            PopulateOrderForm(orderPage);

            if (!SystemRuntime.IsDebug())
            {
                ExcuteOrderOnOrderPage(orderPage);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Assign all kinds of metadata / resources / settings (App-Mode only)
        /// </summary>
        private void InitializeResourcesSettingsAndMetadata(bool allowSideEffects)
        {
            Log.Add($"init app resources allowSE:{allowSideEffects}");
            _env = new Environment.DnnEnvironment(Log);

            if (allowSideEffects)
            {
                // if it's a real App (not content/default), do more
                AppManagement.EnsureAppIsConfigured(ZoneId, AppId, parentLog: Log); // make sure additional settings etc. exist
            }
            // Get app-describing entity
            var appAssignmentId = SystemRuntime.GetMetadataType(Eav.Constants.AppAssignmentName);
            var mds             = DataSource.GetMetaDataSource(ZoneId, AppId);
            var appMetaData     = mds
                                  .GetAssignedEntities(appAssignmentId, AppId,
                                                       SexyContent.Settings.AttributeSetStaticNameApps)
                                  .FirstOrDefault();
            var appResources = mds
                               .GetAssignedEntities(appAssignmentId, AppId,
                                                    SexyContent.Settings.AttributeSetStaticNameAppResources)
                               .FirstOrDefault();
            var appSettings = mds
                              .GetAssignedEntities(appAssignmentId, AppId,
                                                   SexyContent.Settings.AttributeSetStaticNameAppSettings)
                              .FirstOrDefault();

            dynamic appMetaDataDynamic = appMetaData != null
                ? new DynamicEntity(appMetaData, new[] { Thread.CurrentThread.CurrentCulture.Name }, null)
                : null;

            Name          = appMetaDataDynamic?.DisplayName ?? "Error";
            Folder        = appMetaDataDynamic?.Folder ?? "Error";
            Configuration = appMetaDataDynamic;
            Resources     = appResources != null
                ? new DynamicEntity(appResources, new[] { Thread.CurrentThread.CurrentCulture.Name }, null)
                : null;
            Settings = appResources != null
                ? new DynamicEntity(appSettings, new[] { Thread.CurrentThread.CurrentCulture.Name }, null)
                : null;
            Hidden = appMetaDataDynamic?.Hidden ?? false;
        }
Beispiel #8
0
        private XmlExporter GenerateExportXml(bool includeContentGroups, bool resetAppGuid)
        {
            // Get Export XML
            var attributeSets = new AppRuntime(_zoneId, _appId).ContentTypes.FromScope(includeAttributeTypes: true);

            attributeSets = attributeSets.Where(a => !((IContentTypeShareable)a).AlwaysShareConfiguration);

            var attributeSetIds = attributeSets.Select(p => p.ContentTypeId.ToString()).ToArray();
            var templateTypeId  = SystemRuntime.GetMetadataType(Settings.TemplateContentType);
            var entities        =
                DataSource.GetInitialDataSource(_zoneId, _appId).Out["Default"].List.Where(
                    e => e.Value.Metadata.TargetType != templateTypeId &&
                    e.Value.Metadata.TargetType != Constants.MetadataForAttribute).ToList();

            if (!includeContentGroups)
            {
                entities = entities.Where(p => p.Value.Type.StaticName != _sexycontentContentgroupName).ToList();
            }

            var entityIds = entities
                            .Select(e => e.Value.EntityId.ToString()).ToArray();

            var xmlExport = Factory.Resolve <XmlExporter>()
                            .Init(_zoneId, _appId, true, attributeSetIds, entityIds);

            // var xmlExport = Factory.Container.Resolve<XmlExporter>(new ParameterOverrides { { "zoneId", _zoneId }, { "appId", _appId}, {"appExport", true}, { "contentTypeIds", attributeSetIds }, {"entityIds", entityIds} });
            // new ToSxcXmlExporter(_zoneId, _appId, true, attributeSetIds, entityIds);

            #region reset App Guid if necessary

            if (resetAppGuid)
            {
                var root    = xmlExport.ExportXDocument; //.Root;
                var appGuid = root.XPathSelectElement("/SexyContent/Header/App").Attribute("Guid");
                appGuid.Value = _blankGuid;
            }
            return(xmlExport);

            #endregion
        }
Beispiel #9
0
        public void ShouldBeAbleToMakePhoneCallRequestFromHomePage()
        {
            var page = new HomePage(_driver);

            var phoneCallPopup = page.OpenPhoneCallPopup();

            phoneCallPopup.NameImput.SendKeys("Владимир Владимирович");
            phoneCallPopup.PhoneInput.SendKeys("89312853680");
            phoneCallPopup.CommentInput.SendKeys("Я хочу проконсультироваться по поводу нужной мне модели");
            phoneCallPopup.TermCheckbox.Click();

            if (!SystemRuntime.IsDebug())
            {
                phoneCallPopup.SubmitButton.Click();

                Assert.IsEmpty(phoneCallPopup.GetErrorMessages());

                _wait.Until(
                    ExpectedConditions.ElementExists(By.CssSelector("div#popup-call-phone-wrapper>div.popup-center>p")),
                    "Popup with successfull phone call request was not displayed");
            }

            phoneCallPopup.ClosePopup();
        }
Beispiel #10
0
        /// <summary>
        /// Create app-describing entity for configuration and add Settings and Resources Content Type
        /// </summary>
        internal static void EnsureAppIsConfigured(int zoneId, int appId, Log parentLog, string appName = null)
        {
            var appAssignment = SystemRuntime.MetadataType(Constants.AppAssignmentName);
            var scope         = Settings.AttributeSetScopeApps;
            var mds           = DataSource.GetMetaDataSource(zoneId, appId);
            var appMetaData   = mds.GetMetadata(appAssignment, appId, Settings.AttributeSetStaticNameApps).FirstOrDefault();
            var appResources  = mds.GetMetadata(appAssignment, appId, Settings.AttributeSetStaticNameAppResources).FirstOrDefault();
            var appSettings   = mds.GetMetadata(appAssignment, appId, Settings.AttributeSetStaticNameAppSettings).FirstOrDefault();

            // Get appName from cache - stop if it's a "Default" app
            var eavAppName = new ZoneRuntime(zoneId, parentLog).GetName(appId);// State.GetAppName(zoneId, appId);

            if (eavAppName == Eav.Constants.DefaultAppName)
            {
                return;
            }

            var appMan = new AppManager(zoneId, appId);

            if (appMetaData == null)
            {
                appMan.MetadataEnsureTypeAndSingleEntity(scope,
                                                         Settings.AttributeSetStaticNameApps,
                                                         "App Metadata",
                                                         appAssignment,
                                                         new Dictionary <string, object>()
                {
                    { "DisplayName", IsNullOrEmpty(appName) ? eavAppName : appName },
                    { "Folder", IsNullOrEmpty(appName) ? eavAppName : RemoveIllegalCharsFromPath(appName) },
                    { "AllowTokenTemplates", "False" },
                    { "AllowRazorTemplates", "False" },
                    { "Version", "00.00.01" },
                    { "OriginalId", "" }
                });
            }


            // Add new (empty) ContentType for Settings
            if (appSettings == null)
            {
                appMan.MetadataEnsureTypeAndSingleEntity(scope,
                                                         Settings.AttributeSetStaticNameAppSettings,
                                                         "Stores settings for an app",
                                                         appAssignment,
                                                         null);
            }

            // add new (empty) ContentType for Resources
            if (appResources == null)
            {
                appMan.MetadataEnsureTypeAndSingleEntity(scope,
                                                         Settings.AttributeSetStaticNameAppResources,
                                                         "Stores resources like translations for an app",
                                                         appAssignment,
                                                         null);
            }

            if (appMetaData == null || appSettings == null || appResources == null)
            {
                SystemManager.Purge(zoneId, appId);
            }
        }
Beispiel #11
0
        public dynamic GetManyForEditing([FromBody] List <ItemIdentifier> items, int appId)
        {
            var wrapLog = Log.Call("GetManyForEditing", $"get many a#{appId}, items⋮{items.Count}");

            // before we start, we have to convert the indexes into something more useful, because
            // otherwise in content-list scenarios we don't have the type
            var appForSecurityChecks = App.LightWithoutData(new DnnTenant(PortalSettings), SystemRuntime.ZoneIdOfApp(appId), appId, Log);

            items = new SaveHelpers.ContentGroupList(SxcInstance, Log).ConvertListIndexToId(items, appForSecurityChecks);

            // to do full security check, we'll have to see what content-type is requested
            var permCheck = new MultiPermissionsTypes(SxcInstance, appId, items, Log);

            if (!permCheck.EnsureAll(GrantSets.WriteSomething, out var exception))
            {
                throw exception;
            }

            var list = new EntityApi(appId, Log).GetEntitiesForEditing(appId, items);

            // Reformat to the Entity-WithLanguage setup
            var listAsEwH = list.Select(p => new BundleWithHeader <EntityWithLanguages>
            {
                Header = p.Header,
                Entity = p.Entity != null
                    ? EntityWithLanguages.Build(appId, p.Entity)
                    : null
            }).ToList();

            // 2018-09-26 2dm
            // if we're giving items which already exist, then we must verify that edit/read is allowed.
            // important, this code is shared/duplicated in the UiController.Load
            if (list.Any(set => set.Entity != null))
            {
                if (!permCheck.EnsureAll(GrantSets.ReadSomething, out exception))
                {
                    throw exception;
                }
            }

            wrapLog($"will return items⋮{list.Count}");
            return(listAsEwH);
        }
Beispiel #12
0
 public MultiPermissionsApp(IBlockBuilder blockBuilder, int appId, ILog parentLog) :
     this(blockBuilder, SystemRuntime.ZoneIdOfApp(appId), appId, parentLog)
 {
 }
Beispiel #13
0
        /// <summary>
        /// Returns an EAV import entity
        /// </summary>
        /// <param name="entityNode">The xml-Element of the entity to import</param>
        /// <param name="assignmentObjectTypeId">assignmentObjectTypeId</param>
        /// <returns></returns>
        private IEntity GetImportEntity(XElement entityNode, int assignmentObjectTypeId)
        {
            #region retrieve optional metadata keys in the import - must happen before we apply corrections like AppId
            Guid?keyGuid   = null;
            var  maybeGuid = entityNode.Attribute(XmlConstants.KeyGuid);
            if (maybeGuid != null)
            {
                keyGuid = Guid.Parse(maybeGuid.Value);
            }
            int?keyNumber   = null;
            var maybeNumber = entityNode.Attribute(XmlConstants.KeyNumber);
            if (maybeNumber != null)
            {
                keyNumber = int.Parse(maybeNumber.Value);
            }

            var keyString = entityNode.Attribute(XmlConstants.KeyString)?.Value;
            #endregion

            #region check if the xml has an own assignment object type (then we wouldn't use the default)
            switch (entityNode.Attribute(XmlConstants.KeyTargetType)?.Value)
            {
            // Special case: App AttributeSets must be assigned to the current app
            case XmlConstants.App:
                keyNumber = AppId;
                assignmentObjectTypeId = SystemRuntime.GetMetadataType(Constants.AppAssignmentName);
                break;

            case XmlConstants.Entity:
            case "Data Pipeline":     // 2dm: this was an old value, 2017-08-11 this was still used in the old Employees directory app v. 1.02
                assignmentObjectTypeId = Constants.MetadataForEntity;
                break;

            case XmlConstants.ContentType:
                assignmentObjectTypeId = Constants.MetadataForContentType;
                break;

            case XmlConstants.CmsObject:
                assignmentObjectTypeId = Constants.MetadataForContentType;

                if (keyString == null)
                {
                    throw new Exception("found cms object, but couldn't find metadata-key of type string, will abort");
                }
                var newKey = GetMappedLink(keyString);
                if (newKey != null)
                {
                    keyString = newKey;
                }
                break;
            }
            #endregion


            // Special case #2: Corrent values of Template-Describing entities, and resolve files

            foreach (var sourceValue in entityNode.Elements(XmlConstants.ValueNode))
            {
                var sourceValueString = sourceValue.Attribute(XmlConstants.ValueAttr).Value;

                // Correct FileId in Hyperlink fields (takes XML data that lists files)
                if (!String.IsNullOrEmpty(sourceValueString) && sourceValue.Attribute(XmlConstants.EntityTypeAttribute).Value == XmlConstants.ValueTypeLink)
                {
                    string newValue = GetMappedLink(sourceValueString);
                    if (newValue != null)
                    {
                        sourceValue.Attribute(XmlConstants.ValueAttr).SetValue(newValue);
                    }
                }
            }

            var importEntity = _xmlBuilder.BuildEntityFromXml(entityNode, /*_targetDimensions, _sourceDimensions, _sourceDefaultDimensionId, DefaultLanguage,*/ new Metadata
            {
                TargetType = assignmentObjectTypeId,
                KeyNumber  = keyNumber,
                KeyGuid    = keyGuid,
                KeyString  = keyString
            });

            return(importEntity);
        }
Beispiel #14
0
 public MultiPermissionsApp(SxcInstance sxcInstance, int appId, Log parentLog) :
     this(sxcInstance, SystemRuntime.ZoneIdOfApp(appId), appId, parentLog)
 {
 }