Ejemplo n.º 1
0
        protected override void ProcessRecord()
        {
            LogErrors(() =>
            {
                if (!CheckSessionCanDoInteractiveAction())
                {
                    return;
                }

                object content;
                InputObject = InputObject.BaseObject();

                switch (InputObject)
                {
                case Stream inputObject:
                    {
                        using (var stream = inputObject)
                        {
                            var bytes = new byte[stream.Length];
                            stream.Seek(0, SeekOrigin.Begin);
                            stream.Read(bytes, 0, (int)stream.Length);
                            content = bytes;
                        }

                        break;
                    }

                case FileInfo _:
                case string _:
                case byte[] _:
                    content = InputObject;
                    break;

                case string[] strings:
                    content = strings.ToList().Aggregate((accumulated, next) =>
                                                         accumulated + "\n" + next);
                    break;

                default:
                    WriteError(typeof(FormatException), "InputObject must be of type string, string[], byte[], Stream or FileInfo",
                               ErrorIds.InvalidItemType, ErrorCategory.InvalidType, InputObject, true);
                    WriteObject(false);
                    return;
                }

                if (!ServiceAuthorizationManager.IsUserAuthorized(WebServiceSettings.ServiceHandleDownload, Sitecore.Context.User.Name))
                {
                    WriteError(typeof(FormatException), "Handle Download Service is disabled or user is not authorized.",
                               ErrorIds.InsufficientSecurityRights, ErrorCategory.PermissionDenied, InputObject, true);
                    WriteObject(false);
                    return;
                }

                LogErrors(() =>
                {
                    WriteObject(true);
                    PutMessage(new OutDownloadMessage(content, Name, ContentType));
                });
            });
        }
Ejemplo n.º 2
0
        protected override void ProcessRecord()
        {
            Item currentItem = InputObject.BaseObject() as Item;

            var ruleContext = new RuleContext
            {
                Item = currentItem
            };

            WriteObject(!rules.Rules.Any() || rules.Rules.Any(rule => rule.Evaluate(ruleContext)));
        }
Ejemplo n.º 3
0
        protected override void ProcessRecord()
        {
            LogErrors(() =>
            {
                if (!CheckSessionCanDoInteractiveAction())
                {
                    return;
                }


                object content;
                InputObject = InputObject.BaseObject();

                if (InputObject is Stream)
                {
                    using (var stream = InputObject as Stream)
                    {
                        byte[] bytes = new byte[stream.Length];
                        stream.Seek(0, SeekOrigin.Begin);
                        stream.Read(bytes, 0, (int)stream.Length);
                        content = bytes;
                    }
                }
                else if (InputObject is string)
                {
                    content = InputObject;
                }
                else if (InputObject is string[])
                {
                    content = (InputObject as string[]).ToList().Aggregate((accumulated, next) =>
                                                                           accumulated + "\n" + next);
                }
                else if (InputObject is byte[])
                {
                    content = InputObject;
                }
                else
                {
                    WriteError(typeof(FormatException), "InputObject must be of type string, strings[], Stream byte[]",
                               ErrorIds.InvalidItemType, ErrorCategory.InvalidType, InputObject, true);
                    return;
                }

                LogErrors(() =>
                {
                    PutMessage(new OutDownloadMessage(content, Name, ContentType));
                });
            });
        }
Ejemplo n.º 4
0
        protected override void BeginProcessing()
        {
            Item currentItem = InputObject.BaseObject() as Item;

            string ruleDatabaseName = RuleDatabase;

            if (!string.IsNullOrEmpty(ruleDatabaseName))
            {
                ruleDatabaseName = currentItem != null
                    ? currentItem.Database.Name
                    : ApplicationSettings.RulesDb;
            }

            Database ruleDatabase = Factory.GetDatabase(ruleDatabaseName);

            rules = RuleFactory.ParseRules <RuleContext>(ruleDatabase, Rule);
        }
        protected override void ProcessRecord()
        {
            LogErrors(() =>
            {
                if (!CheckSessionCanDoInteractiveAction())
                {
                    return;
                }


                object content;
                InputObject = InputObject.BaseObject();

                if (InputObject is Stream)
                {
                    using (var stream = InputObject as Stream)
                    {
                        byte[] bytes = new byte[stream.Length];
                        stream.Seek(0, SeekOrigin.Begin);
                        stream.Read(bytes, 0, (int)stream.Length);
                        content = bytes;
                    }
                }
                else if (InputObject is FileInfo)
                {
                    content = InputObject;
                }
                else if (InputObject is string)
                {
                    content = InputObject;
                }
                else if (InputObject is string[])
                {
                    content = (InputObject as string[]).ToList().Aggregate((accumulated, next) =>
                                                                           accumulated + "\n" + next);
                }
                else if (InputObject is byte[])
                {
                    content = InputObject;
                }
                else
                {
                    WriteError(typeof(FormatException), "InputObject must be of type string, strings[], Stream byte[]",
                               ErrorIds.InvalidItemType, ErrorCategory.InvalidType, InputObject, true);
                    WriteObject(false);
                    return;
                }

                if (!WebServiceSettings.ServiceEnabledHandleDownload ||
                    !ServiceAuthorizationManager.IsUserAuthorized(WebServiceSettings.ServiceHandleDownload,
                                                                  Sitecore.Context.User.Name, false))
                {
                    WriteError(typeof(FormatException), "Handle Download Service is disabled or user is not authorized.",
                               ErrorIds.InsufficientSecurityRights, ErrorCategory.PermissionDenied, InputObject, true);
                    WriteObject(false);
                    return;
                }

                LogErrors(() =>
                {
                    WriteObject(true);
                    PutMessage(new OutDownloadMessage(content, Name, ContentType));
                });
            });
        }