/// <summary>
        /// Takes an order. E.g. Asserts that the current web is valid, the user has read permissions on the current web, and the current web is a trusted location.
        /// </summary>
        public static void TakeOrder()
        {
            if (SPContext.Current == null || SPContext.Current.Web == null)
            {
                throw new InvalidOperationException("Cannot execute Barista: Barista must execute within the context of a SharePoint Web.");
            }

            if (SPContext.Current.Web.DoesUserHavePermissions(SPBasePermissions.Open) == false)
            {
                throw new InvalidOperationException("Cannot execute Barista: Access Denied - The current user does not have access to the current web.");
            }

            BaristaHelper.EnsureExecutionInTrustedLocation();
        }
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);
        }