Exemple #1
0
        public UpdateNode(Request request, String url, Double version, String dir)
        {
            if (request == null) {
                Logger.log(Logger.TYPE.ERROR, "Provided a null request to UpdateNode");
            }
            this.request = request;

            if (url == null) {
                Logger.log(Logger.TYPE.ERROR, "Provided a null url to UpdateNode");
            }
            this.url = url;

            if (version < 0.1) {
                Logger.log(Logger.TYPE.ERROR, "Provided an invalid version to UpdateNode");
            }
            this.version = version;

            this.dir = dir != null ? dir : "";
        }
Exemple #2
0
        static Response WrapInLauncher(Request req)
        {
            LauncherPage launcher = Self.GET<LauncherPage>("/launcher");
            launcher.uri = req.Uri;

            // First check if a workspace already exists for the app that registered the uri.
            LayoutInfo workspace = null;
            string appName = req.HandlerAppName;
            for (var i = 0; i < launcher.workspaces.Count; i++) {
                var existingWs = (launcher.workspaces[i] as LayoutInfo);
                if (existingWs == null) continue;

                if (existingWs.AppName.Equals(appName, StringComparison.InvariantCultureIgnoreCase)) {
                    workspace = existingWs;
                    break;
                }
            }

            if (workspace == null) {
                workspace = new LayoutInfo() { AppName = appName };
                launcher.workspaces.Add(workspace);
            }
            workspace.ActiveWorkspace = true;

            // Call proxied request
            Response resp = Self.CallUsingExternalRequest(req, () => { return workspace; });
            return launcher;
        }
Exemple #3
0
        static Json OnJsonMerge(Request request, string callingAppName, IEnumerable<Json> partialJsons)
        {
            bool returnNewSibling = false;
            LayoutInfo layoutInfo = null;
            Layout layout;
            string html = null;
            string partialUrl;
            var publicViewModel = (Session.Current != null) ? Session.Current.PublicViewModel : null;

            // First look for any responses already added. The same set of siblings can be merged
            // several times due to different URI's are on the same level in the viewmodel.
            foreach (Json partialJson in partialJsons) {
                if (partialJson == publicViewModel)
                    return null;

                if (partialJson is LayoutInfo) {
                    if (layoutInfo == null) {
                        layoutInfo = (LayoutInfo)partialJson; // Reusing first existing instance
                        layoutInfo.AppsResponded.Clear();
                    } else {
                        // Workaround for merged siblings containing more than one sibling
                        // from the same app.
                        ((LayoutInfo)partialJson).ActiveWorkspace = layoutInfo.ActiveWorkspace;
                    }
                }
            }

            if (layoutInfo == null) {
                returnNewSibling = true;
                layoutInfo = new LayoutInfo();
            }

            foreach (Json partialJson in partialJsons) {
                var appItem = layoutInfo.AppsResponded.Add();
                appItem.StringValue = partialJson.GetAppName();

                partialUrl = partialJson.GetHtmlPartialUrl();
                if (!string.IsNullOrEmpty(partialUrl)) {
                    if (html != null)
                        html += "&";
                    html += partialJson.GetAppName() + "=" + partialUrl;

                    if (callingAppName.Equals(partialJson.GetAppName(), StringComparison.CurrentCultureIgnoreCase)) {
                        layoutInfo.PartialId = partialUrl;
                    }
                }
            }

            layoutInfo.AppName = callingAppName;
            layoutInfo.Path = request.Uri;
            if (!string.IsNullOrEmpty(html))
                layoutInfo.MergedHtml = StarcounterConstants.HtmlMergerPrefix + html;

            layout = Db.SQL<Layout>("SELECT l FROM Starcounter.Layout l WHERE l.Key=?", layoutInfo.PartialId).First;
            if (layout != null)
                layoutInfo.Layout = layout.Value;

            if (returnNewSibling)
                return layoutInfo;

            // We used an existing instance. We dont want to add it as a sibling again.
            return null;
        }
Exemple #4
0
 public void setRequest(Request request)
 {
     this.request = request;
 }