Пример #1
0
 public IDefaultHttpAction CreateDefaultAction(IHttpActionContext context, NodeHead targetNode, NodeHead appNode)
 {
     return new DefaultHttpAction
     {
         Context = context,
         TargetNode = targetNode,
         AppNode = appNode
     };
 }
Пример #2
0
 private bool IsApplication(NodeHead appNode)
 {
     var type = TypeHandler.GetType(appNode.GetNodeType().ClassName);
     //if (typeof(Page).IsAssignableFrom(type))
     //    return true;
     //if (typeof(IHttpHandler).IsAssignableFrom(type))
     //    return true;
     return typeof(Application).IsAssignableFrom(type);
 }
Пример #3
0
 public IRemapHttpAction CreateRemapAction(IHttpActionContext context, NodeHead targetNode, NodeHead appNode, NodeHead httpHandlerNode)
 {
     return new RemapHttpAction
     {
         Context = context,
         TargetNode = targetNode,
         AppNode = appNode,
         HttpHandlerNode = httpHandlerNode
     };
 }
Пример #4
0
 public IRewriteHttpAction CreateRewriteAction(IHttpActionContext context, NodeHead targetNode, NodeHead appNode, string path)
 {
     return new RewriteHttpAction
     {
         Context = context,
         TargetNode = targetNode,
         AppNode = appNode,
         Path = path
     };
 }
Пример #5
0
 public IRedirectHttpAction CreateRedirectAction(IHttpActionContext context, NodeHead targetNode, NodeHead appNode, string targetUrl, bool permanent, bool endResponse)
 {
     return new RedirectHttpAction
     {
         Context = context,
         TargetNode = targetNode,
         AppNode = appNode,
         TargetUrl = targetUrl,
         Permanent = permanent,
         EndResponse = endResponse,
     };
 }
Пример #6
0
 public IRewriteHttpAction CreateRewriteAction(IHttpActionContext context, NodeHead targetNode, NodeHead appNode, string filePath, string pathInfo, string queryString)
 {
     return new RewriteHttpAction
     {
         Context = context,
         TargetNode = targetNode,
         AppNode = appNode,
         FilePath = filePath,
         PathInfo = pathInfo,
         QueryString = queryString
     };
 }
Пример #7
0
        // ====================================================================== Get NodeHead

        internal static NodeHead GetNodeHead(int nodeId)
        {
            if (!CanExistInDatabase(nodeId))
            {
                return(null);
            }

            string   idKey = CreateNodeHeadIdCacheKey(nodeId);
            NodeHead item  = (NodeHead)DistributedApplication.Cache.Get(idKey);

            if (item == null)
            {
                item = DataProvider.Current.LoadNodeHead(nodeId);
                if (item != null)
                {
                    CacheNodeHead(item, idKey, CreateNodeHeadPathCacheKey(item.Path));
                }
            }

            return(item);
        }
Пример #8
0
        internal static NodeHead GetNodeHead(string path)
        {
            if (!CanExistInDatabase(path))
            {
                return(null);
            }

            string   pathKey = CreateNodeHeadPathCacheKey(path);
            NodeHead item    = (NodeHead)DistributedApplication.Cache.Get(pathKey);

            if (item == null)
            {
                Debug.WriteLine("#GetNodeHead from db: " + path);
                item = DataProvider.Current.LoadNodeHead(path);
                if (item != null)
                {
                    CacheNodeHead(item, CreateNodeHeadIdCacheKey(item.Id), pathKey);
                }
            }
            return(item);
        }
Пример #9
0
        private static IHttpAction GetExternalPageAction(IHttpActionFactory factory, PortalContext portalContext, NodeHead contextNode, string actionName, string appNodePath)
        {
            if (contextNode == null)
                return null;
            if (actionName != null)
                return null;
            if (appNodePath != null)
                return null;

            string outerUrl = null;
            AccessProvider.ChangeToSystemAccount();
            try
            {
                Page page = Node.LoadNode(contextNode.Id) as Page;
                if (page != null)
                    if (Convert.ToBoolean((page["IsExternal"])))
                        outerUrl = page.GetProperty<string>("OuterUrl");
            }
            finally
            {
                AccessProvider.RestoreOriginalUser();
            }
            if (outerUrl != null)
                return factory.CreateRedirectAction(portalContext, contextNode, null, outerUrl, false, true);
            return null;
        }
Пример #10
0
 private static IHttpAction GetExternalResourceAction(IHttpActionFactory factory, PortalContext portalContext, NodeHead contextNode)
 {
     if (contextNode == null)
     {
         return factory.CreateDefaultAction(portalContext, contextNode, null);
         //return CreateApplication(actionContext, contextNode, null, new RewriteApp { TargetPath = actionContext.RequestedUrl });
     }
     return null;
 }
Пример #11
0
 private static IHttpAction GetSmartUrlAction(IHttpActionFactory factory, PortalContext portalContext, NodeHead contextNode)
 {
     string smartUrl = GetSmartUrl(portalContext);
     if (smartUrl != null)
         return factory.CreateRedirectAction(portalContext, contextNode, null, smartUrl, false, true);
     return null;
 }
Пример #12
0
        private static Node LoadContextNode(NodeHead head, string versionRequest)
        {
            Node node = null;
            if (head == null)
                return null;

            //we need to user system account here during startup
            //because authentication occurs after this
            var changeToSystem = (User.Current.Id == RepositoryConfiguration.StartupUserId);

            try
            {
                if (changeToSystem)
                    AccessProvider.ChangeToSystemAccount();

                if (String.IsNullOrEmpty(versionRequest))
                {
                    node = Node.LoadNode(head.Id);
                }
                else
                {
                    VersionNumber version;
                    if (VersionNumber.TryParse(versionRequest, out version))
                        node = Node.LoadNode(head.Id, version);
                }
            }
            finally
            {
                if (changeToSystem)
                    AccessProvider.RestoreOriginalUser();
            }

            return node;
        }
Пример #13
0
 public static bool IsApplicationNode(NodeHead nodeHead)
 {
     return IsApplicationNodeType(nodeHead.GetNodeType());
 }
Пример #14
0
        //---------------------------------------------------------------------

        private static NodeHead FindApplication(NodeHead requestedNodeHead, string actionName, string appNodePath, string device)
        {
            if (appNodePath != null)
                return NodeHead.Get(appNodePath);
            if (String.IsNullOrEmpty(actionName))
                actionName = "Browse";

            Content content;

            using (new SystemAccount())
            {
                content = Content.Load(requestedNodeHead.Id);

                // self dispatch
                var genericContent = content.ContentHandler as GenericContent;
                if (genericContent != null)
                {
                    var selfDispatchApp = genericContent.GetApplication(actionName);
                    if (selfDispatchApp != null)
                        return selfDispatchApp;
                }

                //bool appExists;
                //var specificappname = String.Join("-", new string[] { actionName, device });
                //var app = ApplicationStorage.Instance.GetApplication(specificappname, content, out appExists);

                //if (!appExists)
                //    app = ApplicationStorage.Instance.GetApplication(actionName, content, out appExists);

                //if (!string.IsNullOrEmpty(actionName) && !appExists)
                //{
                //    throw new UnknownActionException(string.Format("Action '{0}' does not exist", actionName), actionName);
                //}
                bool appExists;
                var app = ApplicationStorage.Instance.GetApplication(actionName, content, out appExists, device);

                if (!string.IsNullOrEmpty(actionName) && !appExists)
                    throw new UnknownActionException(string.Format("Action '{0}' does not exist", actionName), actionName);

                return app != null ? NodeHead.Get(app.Id) : null;
            }
        }
Пример #15
0
 private static IHttpAction GetIHttpHandlerAction(IHttpActionFactory factory, PortalContext portalContext, NodeHead contextNode, NodeHead handlerNode)
 {
     var nodeType = handlerNode.GetNodeType();
     Type appType = TypeHandler.GetType(nodeType.ClassName);
     if (typeof(IHttpHandler).IsAssignableFrom(appType))
         return factory.CreateRemapAction(portalContext, contextNode, null, handlerNode);
     return null;
 }
Пример #16
0
        //---------------------------------------------------------------------

        private static string GetRewritePath(NodeHead appNodeHead, PortalContext portalContext)
        {
            if (!String.IsNullOrEmpty(portalContext.QueryStringNodePropertyName))
                return appNodeHead.Path;
            
            NodeType contextNodeType = appNodeHead.GetNodeType();

            if (contextNodeType.IsInstaceOfOrDerivedFrom("Page"))
                return appNodeHead.Path + PortalContext.InRepositoryPageSuffix;
            //else if (contextNodeType.IsInstaceOfOrDerivedFrom("GenericContent") && !contextNodeType.IsInstaceOfOrDerivedFrom("File"))
            //    return appNodeHead.Path + PortalContext.InRepositoryPageSuffix;
            else if (contextNodeType.IsInstaceOfOrDerivedFrom("Site"))
                throw new NotSupportedException("/*!!!*/");

            return appNodeHead.Path;
        }
Пример #17
0
 private static string GetVersionHistoryString(NodeHead head)
 {
     return String.Join(" ", (from version in head.Versions
                              select version.VersionNumber.ToString()).ToArray());
 }
Пример #18
0
        private static bool SaveNodeDataTransactional(Node node, NodeSaveSettings settings, IIndexPopulator populator, string originalPath, string newPath)
        {
            IndexDocumentData indexDocument = null;
            bool hasBinary = false;

            var data      = node.Data;
            var isNewNode = data.Id == 0;
            NodeDataParticipant participant = null;
            var isLocalTransaction          = !TransactionScope.IsActive;

            if (isLocalTransaction)
            {
                TransactionScope.Begin();
            }
            Logger.WriteVerbose("Transaction: " + TransactionScope.CurrentId + " SAVING " + node.Id + ", " + node.Path);

            try
            {
                //-- collect data for populator
                var populatorData = populator.BeginPopulateNode(node, settings, originalPath, newPath);

                data.CreateSnapshotData();

                participant = new NodeDataParticipant {
                    Data = data, Settings = settings, IsNewNode = isNewNode
                };

                TransactionScope.Participate(participant);

                int lastMajorVersionId, lastMinorVersionId;
                DataProvider.Current.SaveNodeData(data, settings, out lastMajorVersionId, out lastMinorVersionId);

                //-- here we re-create the node head to insert it into the cache and refresh the version info);
                if (lastMajorVersionId > 0 || lastMinorVersionId > 0)
                {
                    var head = NodeHead.CreateFromNode(node, lastMinorVersionId, lastMajorVersionId);
                    if (MustCache(node.NodeType))
                    {
                        //-- participate cache items
                        var idKey        = CreateNodeHeadIdCacheKey(head.Id);
                        var participant2 = new InsertCacheParticipant {
                            CacheKey = idKey
                        };
                        TransactionScope.Participate(participant2);
                        var pathKey      = CreateNodeHeadPathCacheKey(head.Path);
                        var participant3 = new InsertCacheParticipant {
                            CacheKey = pathKey
                        };
                        TransactionScope.Participate(participant3);

                        CacheNodeHead(head, idKey, pathKey);
                    }

                    node.RefreshVersionInfo(head);

                    if (!settings.DeletableVersionIds.Contains(node.VersionId))
                    {
                        // Elevation: we need to create the index document with full
                        // control to avoid field access errors (indexing must be independent
                        // from the current users permissions).
                        using (new SystemAccount())
                        {
                            indexDocument = SaveIndexDocument(node, true, out hasBinary);
                        }
                    }
                }

                if (isLocalTransaction)
                {
                    TransactionScope.Commit();
                }

                //-- populate
                using (new SystemAccount())
                    populator.CommitPopulateNode(populatorData, indexDocument);

                if (indexDocument != null && hasBinary)
                {
                    using (new SystemAccount())
                    {
                        indexDocument = SaveIndexDocument(node, indexDocument);
                        populator.FinalizeTextExtracting(populatorData, indexDocument);
                    }
                }
            }
            catch (NodeIsOutOfDateException)
            {
                RemoveFromCache(participant);
                throw;
            }
            catch (System.Data.Common.DbException dbe)
            {
                Logger.WriteException(new Exception(string.Format("Error saving node. Id: {0}, Path: {1}", node.Id, node.Path), dbe));

                if (isLocalTransaction && IsDeadlockException(dbe))
                {
                    return(false);
                }
                throw SavingExceptionHelper(data, dbe);
            }
            catch (Exception e)
            {
                Logger.WriteException(new Exception(string.Format("Error saving node. Id: {0}, Path: {1}", node.Id, node.Path), e));

                var ee = SavingExceptionHelper(data, e);
                if (ee == e)
                {
                    throw;
                }
                else
                {
                    throw ee;
                }
            }
            finally
            {
                if (isLocalTransaction && TransactionScope.IsActive)
                {
                    TransactionScope.Rollback();
                }
            }
            return(true);
        }
Пример #19
0
        private void Initialize(HttpContext context, PortalContextInitInfo initInfo)
        {
            _ownerHttpContext = context;
            // use absolute uri to clone. requesturi.tostring messes up encoded parts, like backurl
            _originalUri = new Uri(initInfo.RequestUri.AbsoluteUri.ToString()); // clone
            _isWebdavRequest = initInfo.IsWebdavRequest;
            _isOfficeProtocolRequest = initInfo.IsOfficeProtocolRequest;
            _basicAuthHeaders = initInfo.BasicAuthHeaders;

            _site = initInfo.RequestedSite;
            _siteUrl = initInfo.SiteUrl;
            _siteRelativePath = initInfo.SiteRelativePath;
            _repositoryPath = initInfo.RepositoryPath;

            _actionName = initInfo.ActionName;
            _appNodePath = initInfo.AppNodePath;
            _contextNodePath = initInfo.ContextNodePath;
            _versionRequest = initInfo.VersionRequest;

            _deviceName = initInfo.DeviceName;

            if (_contextNodePath == null)
            {
                _contextNodeHead = initInfo.RequestedNodeHead;
            }
            else
            {
                _contextNodeHead = NodeHead.Get(initInfo.ContextNodePath);
                _appNodePath = initInfo.RequestedNodeHead.Path;
            }

            //if (_siteUrl != null)
            //    _authenticationMode = _site.UrlList[siteUrl];
            _authenticationMode = GetCurrentAuthenticationMode();

            if (_contextNodeHead != null /*_isRequestedResourceExistInRepository*/)
            {
                _nodeType = initInfo.RequestedNodeHead.GetNodeType();
                _nodeId = initInfo.RequestedNodeHead.Id;
            }

            //_queryStringNodePropertyName = HttpContext.Current.Request.QueryString[QUERYSTRING_NODEPROPERTY_KEY];
            _queryStringNodePropertyName = context.Request.QueryString[QUERYSTRING_NODEPROPERTY_KEY];
            if (_queryStringNodePropertyName != null)
                _queryStringNodePropertyName = _queryStringNodePropertyName.Replace('$', '#');

            BinaryHandlerRequestedNodeHead = initInfo.BinaryHandlerRequestedNodeHead;
        }
Пример #20
0
 private static void AssertAppmodelelements(NodeHead requestedNodeHead, string actionName, string appNodePath, string contextNodePath)
 {
     var paramCount = (actionName == null ? 0 : 1) + (appNodePath == null ? 0 : 1) + (contextNodePath == null ? 0 : 1);
     if (paramCount > 1)
         throw new InvalidOperationException("More than one Application model parameters are not applicable.");
     if (contextNodePath != null && !IsApplicationNode(requestedNodeHead))
         throw new InvalidOperationException("Requested node is not an application.");
 }
Пример #21
0
        private static IHttpAction GetWebdavAction(IHttpActionFactory factory, PortalContext portalContext, NodeHead contextNode)
        {
            if (!portalContext.IsWebdavRequest)
                return null;

            return GetIHttpHandlerAction(factory, portalContext, contextNode, typeof(SenseNet.Services.WebDav.WebDavHandler));
        }
Пример #22
0
 internal static bool HasPreviewPermission(NodeHead nodeHead)
 {
     return(Current != null && Current.HasPreviewPermission(nodeHead));
 }
Пример #23
0
 private static IHttpAction GetIHttpHandlerAction(IHttpActionFactory factory, PortalContext portalContext, NodeHead contextNode, Type httpHandlerType)
 {
     return factory.CreateRemapAction(portalContext, contextNode, null, httpHandlerType);
 }
Пример #24
0
 internal static void CacheNodeHead(NodeHead head, string idKey, string pathKey)
 {
     var dependencyForPathKey = CacheDependencyFactory.CreateNodeHeadDependency(head);
     var dependencyForIdKey = CacheDependencyFactory.CreateNodeHeadDependency(head);
     DistributedApplication.Cache.Insert(idKey, head, dependencyForIdKey);
     DistributedApplication.Cache.Insert(pathKey, head, dependencyForPathKey);
 }
Пример #25
0
 private static IHttpAction GetDefaultContextAction(IHttpActionFactory factory, PortalContext portalContext, NodeHead contextNode, string actionName, string appNodePath)
 {
     if (String.IsNullOrEmpty(actionName) && String.IsNullOrEmpty(appNodePath))
     {
         if(!String.IsNullOrEmpty(portalContext.QueryStringNodePropertyName))
             return factory.CreateDownloadAction(portalContext, contextNode, null, GetRewritePath(contextNode, portalContext), portalContext.QueryStringNodePropertyName);
         var nodeType = contextNode.GetNodeType();
         if (nodeType.IsInstaceOfOrDerivedFrom("Page"))
             return factory.CreateRewriteAction(portalContext, contextNode, null, GetRewritePath(contextNode, portalContext));
         if (nodeType.IsInstaceOfOrDerivedFrom("File"))
             return factory.CreateDownloadAction(portalContext, contextNode, null, GetRewritePath(contextNode, portalContext), PortalContext.DefaultNodePropertyName);
     }
     return null;
 }
Пример #26
0
        internal static NodeToken[] GetNodeData(NodeHead[] headArray, int[] versionIdArray)
        {
            var tokens = new List<NodeToken>();
            var tokensToLoad = new List<NodeToken>();
            for (var i = 0; i < headArray.Length; i++)
            {
                var head = headArray[i];
                var versionId = versionIdArray[i];

                int listId = head.ContentListId;
                int listTypeId = head.ContentListTypeId;

                NodeToken token = new NodeToken(head.Id, head.NodeTypeId, listId, listTypeId, versionId, null);
                token.NodeHead = head;
                tokens.Add(token);

                //--

                var cacheKey = GenerateNodeDataVersionIdCacheKey(versionId);
                var nodeData = DistributedApplication.Cache.Get(cacheKey) as NodeData;

                if (nodeData == null)
                    tokensToLoad.Add(token);
                else
                    token.NodeData = nodeData;
            }
            if (tokensToLoad.Count > 0)
            {
                DataProvider.Current.LoadNodeData(tokensToLoad);
                foreach (var token in tokensToLoad)
                {
                    var nodeData = token.NodeData;
                    if (nodeData != null) //-- lost version
                        CacheNodeData(nodeData);
                }
            }
            return tokens.ToArray();
        }
Пример #27
0
        private static IHttpAction CreateActionPrivate(IHttpActionContext actionContext, IHttpActionFactory actionFactory, NodeHead requestedNode, string requestedActionName, string requestedApplicationNodePath, string requestedDevice)
        {
            IHttpAction action = null;

            var factory = actionFactory ?? actionContext.GetActionFactory();
            var contextNode = requestedNode ?? actionContext.GetRequestedNode();
            var actionName = requestedActionName ?? actionContext.RequestedActionName;
            var appNodePath = requestedApplicationNodePath ?? actionContext.RequestedApplicationNodePath;
            var portalContext = (PortalContext)actionContext;

            //================================================= #1: preconditions

            action = GetFirstRunAction(factory, portalContext, contextNode);
            if (action != null)
                return action;

            // webdav request?
            action = GetWebdavAction(factory, portalContext, contextNode);
            if (action != null)
                return action;

            /*
            //---- Uncomment and recompile to support *.SVC on IIS5.1
            action = (GetIIS5SVCRequestAction(portalContext, httpContext));
            if (action != null)
                return action;
            */

            //----------------------------------------------- forward to start page if context is a Site

            action = GetSiteStartPageAction(factory, portalContext, contextNode);
            if (action != null)
                return action;

            //----------------------------------------------- smart url

            action = GetSmartUrlAction(factory, portalContext, contextNode);
            if (action != null)
                return action;

            //----------------------------------------------- outer resource

            action = GetExternalResourceAction(factory, portalContext, contextNode);
            if (action != null)
                return action;

            //----------------------------------------------- context is external page

            action = GetExternalPageAction(factory, portalContext, contextNode, actionName, appNodePath);
            if (action != null)
                return action;

            //----------------------------------------------- context is IHttpHandlerNode

            if (string.IsNullOrEmpty(actionName))
            {
                action = GetIHttpHandlerAction(factory, portalContext, contextNode, contextNode);
                if (action != null)
                    return action;
            }

            //----------------------------------------------- default context action

            action = GetDefaultContextAction(factory, portalContext, contextNode, actionName, appNodePath);
            if (action != null)
                return action;

            //================================================= #2: FindApplication(node, action);

            var appNode = FindApplication(contextNode, actionName, appNodePath, actionContext.DeviceName);
            if (appNode == null)
                return factory.CreateRewriteAction(actionContext, contextNode, null, GetRewritePath(contextNode, portalContext));

            portalContext.BackwardCompatibility_SetPageRepositoryPath(appNode.Path);

            //-----------------------------------------------

            //TODO: appNode external page check?

            //----------------------------------------------- AppNode is IHttpHandlerNode 

            action = GetIHttpHandlerAction(factory, portalContext, contextNode, appNode);
            if (action != null)
                return action;

            //----------------------------------------------- page and site

            return factory.CreateRewriteAction(actionContext, contextNode, appNode, GetRewritePath(appNode, portalContext));
        }
Пример #28
0
 public IDownloadHttpAction CreateDownloadAction(IHttpActionContext context, NodeHead targetNode, NodeHead appNode, string path, string binaryPropertyName)
 {
     return new DownloadHttpAction
     {
         Context = context,
         TargetNode = targetNode,
         AppNode = appNode,
         Path = path,
         BinaryPropertyName = binaryPropertyName
     };
 }
Пример #29
0
        private static Exception SaveNodeDataTransactional(Node node, NodeSaveSettings settings, IIndexPopulator populator, string originalPath, string newPath)
        {
            IndexDocumentData indexDocument = null;
            bool hasBinary = false;

            var data      = node.Data;
            var isNewNode = data.Id == 0;
            NodeDataParticipant participant = null;

            var msg = "Saving Node#" + node.Id + ", " + node.ParentPath + "/" + node.Name;
            var isLocalTransaction = !TransactionScope.IsActive;

            using (var op = SnTrace.Database.StartOperation(msg))
            {
                if (isLocalTransaction)
                {
                    TransactionScope.Begin();
                }

                try
                {
                    // collect data for populator
                    var populatorData = populator.BeginPopulateNode(node, settings, originalPath, newPath);

                    data.CreateSnapshotData();

                    participant = new NodeDataParticipant {
                        Data = data, Settings = settings, IsNewNode = isNewNode
                    };

                    TransactionScope.Participate(participant);

                    if (settings.NodeHead != null)
                    {
                        settings.LastMajorVersionIdBefore = settings.NodeHead.LastMajorVersionId;
                        settings.LastMinorVersionIdBefore = settings.NodeHead.LastMinorVersionId;
                    }

                    int lastMajorVersionId, lastMinorVersionId;
                    DataProvider.Current.SaveNodeData(data, settings, out lastMajorVersionId, out lastMinorVersionId);

                    settings.LastMajorVersionIdAfter = lastMajorVersionId;
                    settings.LastMinorVersionIdAfter = lastMinorVersionId;

                    // here we re-create the node head to insert it into the cache and refresh the version info);
                    if (lastMajorVersionId > 0 || lastMinorVersionId > 0)
                    {
                        var head = NodeHead.CreateFromNode(node, lastMinorVersionId, lastMajorVersionId);
                        if (MustCache(node.NodeType))
                        {
                            // participate cache items
                            var idKey        = CreateNodeHeadIdCacheKey(head.Id);
                            var participant2 = new InsertCacheParticipant {
                                CacheKey = idKey
                            };
                            TransactionScope.Participate(participant2);
                            var pathKey      = CreateNodeHeadPathCacheKey(head.Path);
                            var participant3 = new InsertCacheParticipant {
                                CacheKey = pathKey
                            };
                            TransactionScope.Participate(participant3);

                            CacheNodeHead(head, idKey, pathKey);
                        }

                        node.RefreshVersionInfo(head);

                        if (!settings.DeletableVersionIds.Contains(node.VersionId))
                        {
                            // Elevation: we need to create the index document with full
                            // control to avoid field access errors (indexing must be independent
                            // from the current users permissions).
                            using (new SystemAccount())
                            {
                                indexDocument = SaveIndexDocument(node, true, isNewNode, out hasBinary);
                            }
                        }
                    }

                    if (isLocalTransaction)
                    {
                        TransactionScope.Commit();
                    }

                    // populate index only if it is enabled on this content (e.g. preview images will be skipped)
                    using (var op2 = SnTrace.Index.StartOperation("Indexing node"))
                    {
                        if (node.IsIndexingEnabled)
                        {
                            using (new SystemAccount())
                                populator.CommitPopulateNode(populatorData, indexDocument);
                        }

                        if (indexDocument != null && hasBinary)
                        {
                            using (new SystemAccount())
                            {
                                indexDocument = SaveIndexDocument(node, indexDocument);
                                populator.FinalizeTextExtracting(populatorData, indexDocument);
                            }
                        }
                        op2.Successful = true;
                    }
                }
                catch (NodeIsOutOfDateException)
                {
                    RemoveFromCache(participant);
                    throw;
                }
                catch (System.Data.Common.DbException dbe)
                {
                    if (isLocalTransaction && IsDeadlockException(dbe))
                    {
                        return(dbe);
                    }
                    throw SavingExceptionHelper(data, dbe);
                }
                catch (Exception e)
                {
                    var ee = SavingExceptionHelper(data, e);
                    if (ee == e)
                    {
                        throw;
                    }
                    else
                    {
                        throw ee;
                    }
                }
                finally
                {
                    if (isLocalTransaction && TransactionScope.IsActive)
                    {
                        TransactionScope.Rollback();
                    }
                }
                op.Successful = true;
            }
            return(null);
        }
Пример #30
0
        private static IHttpAction GetFirstRunAction(IHttpActionFactory factory, PortalContext portalContext, NodeHead contextNode)
        {
            //TODO: this is for WebPI first time execution, not really side by side friendly reconsideration needed.
            if (portalContext.Site == null)
            {
                Uri uri = portalContext.OwnerHttpContext.Request.Url;
                string uriPath = uri.GetComponents(UriComponents.Path, UriFormat.Unescaped);
                string installTest = Path.Combine(uri.Authority, "/install/").ToLower();
                string lowerUrl = uri.ToString().ToLower();

                if (!lowerUrl.EndsWith("/default.aspx") &&
                    !lowerUrl.EndsWith("/config.aspx") &&
                    lowerUrl.IndexOf(installTest) < 0 &&
                    !uriPath.EndsWith(".axd"))
                {
                    var appName = HttpRuntime.AppDomainAppVirtualPath;
                    if (!appName.EndsWith("/"))
                        appName = appName + "/";

                    return factory.CreateRedirectAction(portalContext, contextNode, null, 
                        appName + "IISConfig/Config.aspx", false, false);
                }
            }
            return null;
        }
Пример #31
0
        internal static void CacheNodeHead(NodeHead nodeHead)
        {
            if (nodeHead == null)
                throw new ArgumentNullException("nodeHead");

            var idKey = CreateNodeHeadIdCacheKey(nodeHead.Id);
            var item = (NodeHead)DistributedApplication.Cache.Get(idKey);

            if (item != null)
                return;

            CacheNodeHead(nodeHead, idKey, CreateNodeHeadPathCacheKey(nodeHead.Path));
        }
Пример #32
0
        private static IHttpAction GetIIS5SVCRequestAction(IHttpActionFactory factory, PortalContext portalContext, NodeHead contextNode)
        {
            // Rewrite path (create PathInfo) if service called on IIS5
            var httpContext = portalContext.OwnerHttpContext;
            const int XP_MAJOR_VERSION_NUMBER = 5;
            if (httpContext.Request.Path.Contains(".svc") && Environment.OSVersion.Version.Major == XP_MAJOR_VERSION_NUMBER)
            {
                string filePath, pathInfo, queryString;
                string originalPath = httpContext.Request.Path;

                string[] uriElements = System.Text.RegularExpressions.Regex.Split(originalPath, @".svc/");

                filePath = uriElements[0];
                if (!filePath.EndsWith(".svc", StringComparison.InvariantCultureIgnoreCase))
                    filePath = string.Concat(filePath, ".svc");

                pathInfo = uriElements.Length > 1 ? uriElements[1] : String.Empty;
                string qs = httpContext.Request.Url.Query;
                queryString = string.IsNullOrEmpty(qs) ? string.Empty : qs.Substring(1);

                httpContext.RewritePath(filePath, pathInfo, queryString);

                return factory.CreateRewriteAction(portalContext, contextNode, null, filePath, pathInfo, queryString);
            }
            return null;
        }
Пример #33
0
        //====================================================================== Get NodeData

        internal static NodeToken GetNodeData(NodeHead head, int versionId)
        {
            int listId = head.ContentListId;
            int listTypeId = head.ContentListTypeId;

            var cacheKey = GenerateNodeDataVersionIdCacheKey(versionId);
            var nodeData = DistributedApplication.Cache.Get(cacheKey) as NodeData;

            NodeToken token = new NodeToken(head.Id, head.NodeTypeId, listId, listTypeId, versionId, null);
            token.NodeHead = head;
            if (nodeData == null)
            {
                DataProvider.Current.LoadNodeData(new NodeToken[] { token });
                nodeData = token.NodeData;
                if (nodeData != null) //-- lost version
                    CacheNodeData(nodeData, cacheKey);
            }
            else
            {
                token.NodeData = nodeData;
            }
            return token;
        }
Пример #34
0
        private static IHttpAction GetSiteStartPageAction(IHttpActionFactory factory, PortalContext portalContext, NodeHead contextNode)
        {
            if (contextNode == null)
                return null;
            if (!contextNode.GetNodeType().IsInstaceOfOrDerivedFrom("Site"))
                return null;
            //var startPage = portalContext.Site.StartPage;
            Page startPage = null;

            using (new SystemAccount())
            {
                var contextSite = Node.Load<Site>(contextNode.Id);
                if (contextSite != null && (portalContext.ActionName == null || portalContext.ActionName.ToLower() == "browse"))
                    startPage = contextSite.StartPage;
                if (startPage == null)
                    return null;
            }

            var relPath = startPage.Path.Replace(portalContext.Site.Path, "");
            return factory.CreateRedirectAction(portalContext, contextNode, null, relPath, false, true);
        }
Пример #35
0
 private Node LoadNode(NodeHead head, VersionNumber version)
 {
     var nodeAcc = new PrivateType(typeof(Node));
     var node = (Node)nodeAcc.InvokeStatic("LoadNode", head, version);
     return node;
 }
Пример #36
0
        private static bool SaveNodeDataTransactional(Node node, NodeSaveSettings settings, out IndexDocumentData indexDocument)
        {
            indexDocument = null;

            var data               = node.Data;
            var isNewNode          = data.Id == 0;
            var isLocalTransaction = !TransactionScope.IsActive;

            if (isLocalTransaction)
            {
                TransactionScope.Begin();
            }
            try
            {
                data.CreateSnapshotData();
                var participant = new NodeDataParticipant {
                    Data = data, Settings = settings, IsNewNode = isNewNode
                };
                TransactionScope.Participate(participant);

                int lastMajorVersionId, lastMinorVersionId;
                DataProvider.Current.SaveNodeData(data, settings, out lastMajorVersionId, out lastMinorVersionId);

                //-- here we re-create the node head to insert it into the cache and refresh the version info
                if (lastMajorVersionId > 0 || lastMinorVersionId > 0)
                {
                    var head = NodeHead.CreateFromNode(node, lastMinorVersionId, lastMajorVersionId);
                    if (MustCache(node.NodeType))
                    {
                        //-- participate cache items
                        var idKey        = CreateNodeHeadIdCacheKey(head.Id);
                        var participant2 = new InsertCacheParticipant {
                            CacheKey = idKey
                        };
                        TransactionScope.Participate(participant2);
                        var pathKey      = CreateNodeHeadPathCacheKey(head.Path);
                        var participant3 = new InsertCacheParticipant {
                            CacheKey = pathKey
                        };
                        TransactionScope.Participate(participant3);

                        CacheNodeHead(head, idKey, pathKey);
                    }

                    node.RefreshVersionInfo(head);

                    if (!settings.DeletableVersionIds.Contains(node.VersionId))
                    {
                        indexDocument = SaveIndexDocument(node);
                    }
                }

                if (isLocalTransaction)
                {
                    TransactionScope.Commit();
                }
            }
            catch (System.Data.Common.DbException dbe)
            {
                if (isLocalTransaction && IsDeadlockException(dbe))
                {
                    return(false);
                }
                throw SavingExceptionHelper(data, dbe);
            }
            catch (Exception e)
            {
                var ee = SavingExceptionHelper(data, e);
                if (ee == e)
                {
                    throw;
                }
                else
                {
                    throw ee;
                }
            }
            finally
            {
                if (isLocalTransaction && TransactionScope.IsActive)
                {
                    TransactionScope.Rollback();
                }
            }
            return(true);
        }