Ejemplo n.º 1
0
        public Stream TestMe()
        {
            if (WebOperationContext.Current == null)
            {
                throw new InvalidOperationException("This service operation is intended to be invoked only by REST clients.");
            }

            //If this call fails, ensure that the Service Application is started, and then do an IISReset (Yoda Says: !!Important, the last part, it is.)
            BaristaServiceClient client = new BaristaServiceClient(SPServiceContext.Current);

            var request = BrewRequest.CreateServiceApplicationRequestFromHttpRequest(HttpContext.Current.Request);

            request.ScriptEngineFactory = "Barista.SharePoint.SPBaristaJurassicScriptEngineFactory, Barista.SharePoint, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a2d8064cb9226f52";
            request.Code = "6*7";

            var result = client.Eval(request);

            var setHeaders = true;

            if (WebOperationContext.Current != null)
            {
                result.ModifyOutgoingWebResponse(WebOperationContext.Current.OutgoingResponse);
                setHeaders = false;
            }

            result.ModifyHttpResponse(HttpContext.Current.Response, setHeaders);

            var resultStream = new MemoryStream(result.Content);

            return(resultStream);
        }
Ejemplo n.º 2
0
        protected override void CreateChildControls()
        {
            if (String.IsNullOrEmpty(Code))
            {
                return;
            }

            if (String.IsNullOrEmpty(Code.Trim()))
            {
                return;
            }

            BaristaHelper.EnsureExecutionInTrustedLocation();

            string codePath;
            var    codeToExecute = Tamp(Code, out codePath);

            var client = new BaristaServiceClient(SPServiceContext.Current);

            var request = BrewRequest.CreateServiceApplicationRequestFromHttpRequest(HttpContext.Current.Request);

            request.ScriptEngineFactory = "Barista.SharePoint.SPBaristaJurassicScriptEngineFactory, Barista.SharePoint, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a2d8064cb9226f52";
            request.Code     = codeToExecute;
            request.CodePath = codePath;

            var headers = new Dictionary <string, IEnumerable <string> >
            {
                { "barista_instancemode", new[] { InstanceMode.ToString() } },
                { "barista_instancename", new[] { InstanceName } },
                { "barista_instanceabsoluteexpiration", new[] { InstanceAbsoluteExpiration.ToString() } },
                { "barista_instanceslidingexpiration", new[] { InstanceSlidingExpiration.ToString() } }
            };

            if (String.IsNullOrEmpty(InstanceInitializationCode) == false)
            {
                string filePath;
                request.InstanceInitializationCode     = Tamp(InstanceInitializationCode, out filePath);
                request.InstanceInitializationCodePath = filePath;
            }
            request.Headers = new BrewRequestHeaders(headers);
            request.SetExtendedPropertiesFromCurrentSPContext();

            var result     = client.Eval(request);
            var resultText = System.Text.Encoding.UTF8.GetString(result.Content);

            //TODO: Based on the content type of the result, emit the contents differently.
            var cntrl = new LiteralControl(resultText);

            Controls.Add(cntrl);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Brews a cup of coffee. E.g. Executes the specified script.
        /// </summary>
        /// <param name="code"></param>
        /// <param name="codePath"></param>
        private static void Brew(string code, string codePath)
        {
            var request = BrewRequest.CreateServiceApplicationRequestFromHttpRequest(HttpContext.Current.Request);

            request.ScriptEngineFactory = "Barista.SharePoint.SPBaristaJurassicScriptEngineFactory, Barista.SharePoint, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a2d8064cb9226f52";
            request.Code     = code;
            request.CodePath = codePath;

            if (String.IsNullOrEmpty(request.InstanceInitializationCode) == false)
            {
                string instanceInitializationCodePath;
                request.InstanceInitializationCode     = Tamp(request.InstanceInitializationCode, out instanceInitializationCodePath);
                request.InstanceInitializationCodePath = instanceInitializationCodePath;
            }

            Exec(request);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Pulls a shot of espresso. E.g. Executes the specified script and sets the appropriate values on the response object.
        /// </summary>
        /// <param name="code"></param>
        /// <param name="codePath"></param>
        /// <returns></returns>
        private static Stream Pull(string code, string codePath)
        {
            var request = BrewRequest.CreateServiceApplicationRequestFromHttpRequest(HttpContext.Current.Request);

            request.ScriptEngineFactory = "Barista.SharePoint.SPBaristaScriptEngineFactory, Barista.SharePoint, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a2d8064cb9226f52";
            request.Code     = code;
            request.CodePath = codePath;

            if (String.IsNullOrEmpty(request.InstanceInitializationCode) == false)
            {
                string instanceInitializationCodePath;
                request.InstanceInitializationCode     = Tamp(request.InstanceInitializationCode, out instanceInitializationCodePath);
                request.InstanceInitializationCodePath = instanceInitializationCodePath;
            }

            var result = Eval(request);

            var setHeader = true;

            if (WebOperationContext.Current != null)
            {
                result.ModifyOutgoingWebResponse(WebOperationContext.Current.OutgoingResponse);
                setHeader = false;
            }

            result.ModifyHttpResponse(HttpContext.Current.Response, setHeader);

            if (result.Content == null)
            {
                return(null);
            }

            var resultStream = new MemoryStream(result.Content);

            return(resultStream);
        }