Esempio n. 1
0
        /// <summary>
        /// Retrieves order for export and calls the IExportOrderService for each one
        /// </summary>
        /// <returns>A status message to be stored in the database log and visible from admin mode</returns>
        public override string Execute()
        {
            PrincipalInfo.CurrentPrincipal = PrincipalInfo.CreatePrincipal("admin");
            //Call OnStatusChanged to periodically notify progress of job for manually started jobs
            OnStatusChanged("Starting looking for orders to export.");

            Stopwatch tmr = Stopwatch.StartNew();
            List <ExportOrderInformation> results = new List <ExportOrderInformation>();
            List <PurchaseOrder>          orders  = GetOrdersToExport();

            tmr.Stop();

            _log.Debug("Found {0} orders to export in {1}ms", orders.Count, tmr.ElapsedMilliseconds);


            if (_stopSignaled)
            {
                return("Job was stopped");
            }

            IExportOrderService service = ServiceLocator.Current.GetInstance <IExportOrderService>();

            foreach (PurchaseOrder purchaseOrder in orders)
            {
                if (_stopSignaled)
                {
                    return("Job was stopped");
                }
                OnStatusChanged(string.Format("Exporting order: {0}", purchaseOrder.TrackingNumber));

                results.Add(ExportOrder(purchaseOrder, service));
            }

            return(string.Format("Exported {0} orders", results.Count));
        }
        /// <summary>
        /// After the page is imported
        /// </summary>
        public void DataImporter_ContentImported(DataImporter dataImported, ContentImportedEventArgs e)
        {
            PageData page = null;

            if (!ContentReference.IsNullOrEmpty(e.ContentLink))
            {
                page = DataFactory.Instance.Get <PageData>(e.ContentLink).CreateWritableClone();
            }

            if (page == null)
            {
                return;
            }

            page["PageSaved"]              = _originalValues.PageSaved;
            page["PageChanged"]            = _originalValues.PageChanged;
            page["PageChangedBy"]          = _originalValues.PageChangedBy;
            page["PageCreatedBy"]          = _originalValues.PageCreatedBy;
            page["PageChangedOnPublish"]   = true;
            PrincipalInfo.CurrentPrincipal = PrincipalInfo.CreatePrincipal(_originalValues.PageChangedBy);
            try {
                global::EPiServer.BaseLibrary.Context.Current["PageSaveDB:PageSaved"] = true;
                DataFactory.Instance.Save(page, SaveAction.ForceCurrentVersion | SaveAction.Publish
                                          | SaveAction.SkipValidation,
                                          AccessLevel.NoAccess);
            }
            finally {
                global::EPiServer.BaseLibrary.Context.Current["PageSaveDB:PageSaved"] = null;
            }

            MigrationHook.Invoke(new AfterPageImportEvent(e), Log);
        }
Esempio n. 3
0
        private void TransformPage(PageData sourcePage, bool clearPropertyValues = true)
        {
            MigrationHook.Invoke(new BeforePageTransformEvent(sourcePage), Logger);

            _currentConvertablePageData.Properties = sourcePage.Property;
            _currentConvertablePageData.TypeName   = sourcePage.PageTypeName;

            var pTRepo         = ServiceLocator.Current.GetInstance <PageTypeRepository>();
            var sourcePageType = pTRepo.Load(sourcePage.PageTypeID);
            var targetPageType = pTRepo.Load(_mapper.GetTargetPageType(sourcePage));

            string result;

            //Convert The Page
            if (clearPropertyValues)
            {
                var keys       = new List <KeyValuePair <int, int> >();
                var properties = sourcePage.Property.Select(p => p.PropertyDefinitionID).Where(p => p > 0);
                foreach (var propertyId in properties)
                {
                    keys.Add(new KeyValuePair <int, int>(propertyId, 0));
                }

                //Convert The Page
                result = PageTypeConverter.Convert(sourcePage.PageLink, sourcePageType, targetPageType,
                                                   keys, false, false, _repo);
            }
            else
            {
                result = PageTypeConverter.Convert(sourcePage.PageLink, sourcePageType, targetPageType,
                                                   new List <KeyValuePair <int, int> >(), false, false, _repo);
            }
            Logger.Log(result);

            var transformedPage = _repo.Get <PageData>(sourcePage.PageLink).CreateWritableClone();

            _mapper.SetPropertyValues(transformedPage, _currentConvertablePageData);

            transformedPage.URLSegment = UrlSegment.GetUrlFriendlySegment(transformedPage.URLSegment);
            var oldPrincipal = PrincipalInfo.CurrentPrincipal;

            try {
                PrincipalInfo.CurrentPrincipal =
                    PrincipalInfo.CreatePrincipal(sourcePage.ChangedBy);
                global::EPiServer.BaseLibrary.Context.Current["PageSaveDB:PageSaved"] = true;
                var savedPage = _repo.Save(transformedPage,
                                           SaveAction.ForceCurrentVersion | SaveAction.Publish | SaveAction.SkipValidation,
                                           AccessLevel.NoAccess);

                MigrationHook.Invoke(new AfterPageTransformEvent(savedPage), Logger);
            }
            finally {
                global::EPiServer.BaseLibrary.Context.Current["PageSaveDB:PageSaved"] = null;
                PrincipalInfo.CurrentPrincipal = oldPrincipal;
            }
        }
Esempio n. 4
0
        private static void AddCurrentUserToEpiLogin(string userName)
        {
            if (string.IsNullOrEmpty(userName))
            {
                return;
            }

            PrincipalInfo.CurrentPrincipal = PrincipalInfo.CreatePrincipal(userName);
            SetAuthCookie(userName, false);
        }
Esempio n. 5
0
        /// <summary>
        /// Ladda alla noder med data från filstrukturen
        /// </summary>
        /// <param name="context">Den HttpContext appen körs i</param>
        /// <param name="dirId">GUID för rotkatalogen</param>
        private FileTreeInfo Load(HttpContext context, string dirId)
        {
            //Hämta epi användare.
            var username          = context.User.Identity.Name;
            var epiUser           = PrincipalInfo.CreatePrincipal(username);
            var contentRepository = ServiceLocator.Current.GetInstance <IContentRepository>();
            var folder            = contentRepository.Get <ContentFolder>(ContentReference.Parse(dirId));

            var rootNode = new FileTreeInfo
            {
                id       = "root",
                parentId = "",
                name     = "roten",
                size     = 0,
                link     = "",
                type     = "root",
                children = new List <FileTreeInfo>()

                           //folder = true,
                           //folderPath = "",
                           //key = "0",
                           //path = "",
                           //title = "rooten",
            };

            var includedRootNode = new FileTreeInfo
            {
                id       = dirId.ToString(CultureInfo.InvariantCulture),
                type     = "dir",
                name     = folder.Name,
                parentId = rootNode.id,
                size     = 0,
                link     = folder.Name,
                children = new List <FileTreeInfo>()

                           //key = dirId.ToString(CultureInfo.InvariantCulture),
                           //folder = true,
                           //title = folder.Name,
                           //path = folder.Name,
                           //folderPath = folder.Name + "/",
                           //edit = getRightsJson(folder, AccessLevel.Edit),
                           //delete = getRightsJson(folder, AccessLevel.Delete),
                           //contentreference = folder.ContentLink.ToString(),
                           //typeofmedia = "folder",
            };

            rootNode.children.Add(includedRootNode);
            LoadRecursiveFromMedia(folder, includedRootNode, epiUser, dirId);
            return(rootNode);
        }
Esempio n. 6
0
        /// <summary>
        /// Login user to CMS
        /// </summary>
        private void Login()
        {
            if (User.Identity.IsAuthenticated)
            {
                return;
            }

            PrincipalInfo.CurrentPrincipal = PrincipalInfo.CreatePrincipal(UserName);

            if (FormsSettings.IsFormsAuthentication)
            {
                FormsAuthentication.SetAuthCookie(UserName, false);
            }
        }
Esempio n. 7
0
 /// <summary>
 /// Gets principal from username
 /// </summary>
 /// <param name="username"></param>
 /// <returns></returns>
 public static IPrincipal GetUser(string username) => PrincipalInfo.CreatePrincipal(username);