Exemplo n.º 1
0
    public static IEnumerable <XAttribute> SerializeProperties(this IData data)
    {
        var list = new List <XAttribute>();

        if (data != null)
        {
            foreach (var property in data.DataSourceId.InterfaceType.GetProperties())
            {
                var    name  = property.Name;
                var    value = property.GetValue(data, null);
                string label = null;

                if (property.Name == nameof(ITask.TaskType))
                {
                    label = SR.GetString(LocalizationFile, "Task." + value);
                }

                if (property.Name == nameof(IActivity.ActivityType))
                {
                    label = SR.GetString(LocalizationFile, "Activity." + value);
                }

                if (value != null)
                {
                    list.Add(new XAttribute(name, value.ToString()));
                }

                if (label != null)
                {
                    list.Add(new XAttribute("Label", label));
                }
            }
        }
        return(list);
    }
Exemplo n.º 2
0
        public override IEnumerable <ElementAction> GetActions()
        {
            var result = new List <ElementAction>();

            Type type = WorkflowFacade.GetWorkflowType("Composite.Plugins.Elements.ElementProviders.PageTemplateElementProvider.EditXmlPageTemplateWorkflow");

            result.Add(new ElementAction(new ActionHandle(new WorkflowActionToken(type, new[] { PermissionType.Edit })))
            {
                VisualData = new ActionVisualizedData
                {
                    Label          = SR.GetString("Composite.Plugins.PageTemplateElementProvider", "PageTemplateElementProvider.EditXmlTemplate"),
                    ToolTip        = SR.GetString("Composite.Plugins.PageTemplateElementProvider", "PageTemplateElementProvider.EditXmlTemplateToolTip"),
                    Icon           = PageTemplateElementProvider.EditTemplate,
                    Disabled       = false,
                    ActionLocation = new ActionLocation
                    {
                        ActionType  = ActionType.Edit,
                        IsInFolder  = false,
                        IsInToolbar = true,
                        ActionGroup = PrimaryActionGroup
                    }
                }
            });

            type = WorkflowFacade.GetWorkflowType("Composite.Plugins.Elements.ElementProviders.PageTemplateElementProvider.DeletePageTemplateWorkflow");

            result.Add(new ElementAction(new ActionHandle(new WorkflowActionToken(type, new[] { PermissionType.Delete })))
            {
                VisualData = new ActionVisualizedData
                {
                    Label          = SR.GetString("Composite.Plugins.PageTemplateElementProvider", "PageTemplateElementProvider.DeleteTemplate"),
                    ToolTip        = SR.GetString("Composite.Plugins.PageTemplateElementProvider", "PageTemplateElementProvider.DeleteTemplateToolTip"),
                    Icon           = DeleteTemplate,
                    Disabled       = false,
                    ActionLocation = new ActionLocation
                    {
                        ActionType  = ActionType.Delete,
                        IsInFolder  = false,
                        IsInToolbar = true,
                        ActionGroup = PrimaryActionGroup
                    }
                }
            });

            return(result);
        }
        public IEnumerable <Element> GetRoots(SearchToken searchToken)
        {
            Element element = new Element(_context.CreateElementHandle(new PageTemplateRootEntityToken()));

            bool hasChildren = PageTemplateFacade.GetPageTemplates().Any();

            element.VisualData = new ElementVisualizedData
            {
                Label       = SR.GetString("Composite.Plugins.PageTemplateElementProvider", "PageTemplateElementProvider.RootLabel"),
                ToolTip     = SR.GetString("Composite.Plugins.PageTemplateElementProvider", "PageTemplateElementProvider.RootLabelToolTip"),
                HasChildren = hasChildren,
                Icon        = PageTemplateElementProvider.RootClosed,
                OpenedIcon  = PageTemplateElementProvider.RootOpen
            };

            const string addTemplateWorkflowType = "Composite.Plugins.Elements.ElementProviders.PageTemplateElementProvider.AddNewPageTemplateWorkflow";

            element.AddWorkflowAction(addTemplateWorkflowType, new[] { PermissionType.Add },
                                      new ActionVisualizedData
            {
                Label          = SR.GetString("Composite.Plugins.PageTemplateElementProvider", "PageTemplateElementProvider.AddTemplate"),
                ToolTip        = SR.GetString("Composite.Plugins.PageTemplateElementProvider", "PageTemplateElementProvider.AddTemplateToolTip"),
                Icon           = PageTemplateElementProvider.AddTemplate,
                Disabled       = false,
                ActionLocation = new ActionLocation
                {
                    ActionType  = ActionType.Add,
                    IsInFolder  = false,
                    IsInToolbar = true,
                    ActionGroup = PrimaryActionGroup
                }
            });

            foreach (var pageTemplateProviderName in PageTemplateProviderRegistry.ProviderNames)
            {
                var provider = PageTemplateProviderPluginFacade.GetProvider(pageTemplateProviderName);

                Verify.IsNotNull(provider, "Failed to get provider by name '{0}'", pageTemplateProviderName);

                IEnumerable <ElementAction> actions = provider.GetRootActions();

                element.AddAction(actions);
            }

            return(new [] { element });
        }
Exemplo n.º 4
0
    void GenerateXlsDocument(IQueryable <IGrouping <ITask, IActivity> > activities)
    {
        var workbook  = new Workbook();
        var worksheet = new Worksheet("Sheet1")
        {
            GenerateXmlMap = true
        };

        workbook.Worksheets.Add(worksheet);

        Func <string, Type, Column> column = (label, type) =>
                                             new Column(SR.GetString(LocalizationFile, label), type);

        var columns = new List <Column>
        {
            column("Table.HeadingTime", typeof(DateTime)),
            column("Table.HeadingUser", typeof(string)),
            column("Table.HeadingTask", typeof(string)),
            column("Table.HeadingActivity", typeof(string))
        };

        worksheet.Columns.AddRange(columns);

        foreach (var item in activities.OrderByDescending(a => a.Key.StartTime).ToList())
        {
            var task = item.Key;

            var subactivities = item.Where(d => d != null).OrderByDescending(d => d.ActivityTime);
            if (!subactivities.Any())
            {
                worksheet.AddRow(task.StartTime, task.Username,
                                 SR.GetString(LocalizationFile, "Task." + task.TaskType), string.Empty);
            }

            foreach (var activity in subactivities)
            {
                worksheet.AddRow(activity.ActivityTime, task.Username,
                                 SR.GetString(LocalizationFile, "Task." + task.TaskType),
                                 SR.GetString(LocalizationFile, "Activity." + activity.ActivityType));
            }
        }

        workbook.WriteToResponse(Context, string.Format("VersioningReport-{0:yyyy-MM-dd-HH-mm}.xls", DateTime.Now));
    }
Exemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var tasks = new[] { "Add", "Edit", "SendToDraft", "SendForPublication", "Publish", "Unpublish", "Rollback", "Delete" };
                LogType.DataSource = new[] { new ListItem {
                                                 Text = SR.GetString(LocalizationFileName, "Filter.Task.All"), Value = "All"
                                             } }
                .Concat(tasks.Select(t => new ListItem {
                    Text = GetTaskLabel(t), Value = t
                })).ToList();
                LogType.DataTextField  = "Text";
                LogType.DataValueField = "Value";
                LogType.DataBind();

                DataType.DataSource = new[] { new ListItem {
                                                  Text = SR.GetString(LocalizationFileName, "Filter.Type.All"), Value = "All"
                                              } }
                .Concat(TargetDataSourceFacade.GetTargetTypes()
                        .Select(d => new ListItem {
                    Text = d.GetShortLabel(), Value = TypeManager.SerializeType(d)
                })).ToList();
                DataType.DataTextField  = "Text";
                DataType.DataValueField = "Value";
                DataType.DataBind();

                Refresh(sender, e);
            }


            string eventTarget = HttpContext.Current.Request.Form["__EVENTTARGET"];

            if (eventTarget == "ToDateSelectorInput")
            {
                ToDateWidgetPlaceHolder.Visible   = !ToDateWidgetPlaceHolder.Visible;
                FromDateWidgetPlaceHolder.Visible = false;
            }
            else if (eventTarget == "FromDateSelectorInput")
            {
                FromDateWidgetPlaceHolder.Visible = !FromDateWidgetPlaceHolder.Visible;
                ToDateWidgetPlaceHolder.Visible   = false;
            }
        }
Exemplo n.º 6
0
 private static string GetActivityLabel(string activity)
 {
     return(SR.GetString(LocalizationFileName, "Activity." + activity));
 }
Exemplo n.º 7
0
 private static string GetTaskLabel(string task)
 {
     return(SR.GetString(LocalizationFileName, "Task." + task));
 }
Exemplo n.º 8
0
        protected void Page_PreRender(object sender, EventArgs e)
        {
            var pageNumber = GetPageNumber();
            var pageSize   = GetPageSize();

            using (var connection = new DataConnection())
            {
                Expression <Func <ITask, bool> >       taskFilter   = t => true;
                Expression <Func <ITaskTarget, bool> > targetFilter = t => true;

                if (!string.IsNullOrWhiteSpace(Username.Text))
                {
                    taskFilter = taskFilter.And(d => d.Username.Contains(Username.Text));
                }
                if (LogType.SelectedValue != "All" && !string.IsNullOrWhiteSpace(LogType.SelectedValue))
                {
                    taskFilter = taskFilter.And(d => d.TaskType == LogType.SelectedValue);
                }
                if (DataType.SelectedValue != "All" && !string.IsNullOrWhiteSpace(DataType.SelectedValue))
                {
                    targetFilter = targetFilter.And(d => d.TargetDataSourceId.Contains(string.Format(@"_interfaceType_='{0}'", DataType.SelectedValue.Replace(".", @"\."))));
                }

                var activities = from t in connection.Get <ITask>().Where(taskFilter)
                                 join tt in connection.Get <ITaskTarget>().Where(targetFilter) on t.TaskTargetId equals tt.Id
                                 join a in connection.Get <IActivity>() on t.Id equals a.TaskId into ats
                                 from at in ats.DefaultIfEmpty()
                                 select new
                {
                    Time = at == null ? t.StartTime : at.ActivityTime,
                    t.Username,
                    t.TaskType,
                    ActivityType = at == null ? null : at.ActivityType,
                    t.CultureName,
                    TaskTarget = tt,
                    Activity   = at
                };

                var from = FromDateWidget.SelectedDate;
                var to   = ToDateWidget.SelectedDate;
                activities = activities.Where(d => d.Time >= from && d.Time < to.AddDays(1));


                activities = activities.Where(item => !(item.ActivityType == null &&
                                                        new[] { "edit", "add", "rollback", "delete" }.Contains(item.TaskType.ToLower())))
                             .OrderByDescending(d => d.Time);

                switch (SortColumn)
                {
                case Column.Time:
                    activities = SortDirection == SortDirection.Ascending
                                                        ? activities.OrderBy(d => d.Time)
                                                        : activities.OrderByDescending(d => d.Time);
                    break;

                case Column.User:
                    activities = SortDirection == SortDirection.Ascending
                                                        ? activities.OrderBy(d => d.Username)
                                                        : activities.OrderByDescending(d => d.Username);
                    break;

                case Column.Task:
                    activities = SortDirection == SortDirection.Ascending
                                                        ? activities.OrderBy(d => d.TaskType)
                                                        : activities.OrderByDescending(d => d.TaskType);
                    break;
                }



                string eventTarget = Request.Form["__EVENTTARGET"];
                if (eventTarget == "export")
                {
                    var workbook  = new Workbook();
                    var worksheet = new Worksheet("Sheet1")
                    {
                        GenerateXmlMap = true
                    };
                    workbook.Worksheets.Add(worksheet);
                    Func <string, Type, XlsColumn> column = (label, type) =>
                                                            new XlsColumn(SR.GetString(LocalizationFileName, label), type);

                    var columns = new List <XlsColumn>
                    {
                        column("Table.HeadingTime", typeof(DateTime)),
                        column("Table.HeadingUser", typeof(string)),
                        column("Table.HeadingTask", typeof(string)),
                        column("Table.HeadingActivity", typeof(string)),
                        column("Table.HeadingTitle", typeof(string)),
                        column("Table.HeadingType", typeof(string))
                    };


                    if (IsMultiLocale)
                    {
                        columns.Add(new XlsColumn(SR.GetString("Composite.Plugins.XsltBasedFunction", "EditXsltFunction.LabelActiveLocales"), typeof(string)));
                    }

                    worksheet.Columns.AddRange(columns);

                    foreach (var item in activities)
                    {
                        var parameters = new object[]
                        {
                            item.Time,
                            item.Username ?? string.Empty,
                            item.TaskType != null?GetTaskLabel(item.TaskType) : string.Empty,
                                item.ActivityType != null?GetActivityLabel(item.ActivityType) : string.Empty,
                                    GetTitle(item.TaskTarget),
                                    GetTargetType(item.TaskTarget)
                        };

                        if (IsMultiLocale)
                        {
                            parameters = parameters.Concat(new object[] { GetCulture(item.CultureName) }).ToArray();
                        }

                        worksheet.AddRow(parameters);
                    }

                    workbook.WriteToResponse(Context, string.Format("ContentModificationLog-{0:yyyy-MM-dd-HH-mm}.xls", DateTime.Now));
                    return;
                }

                activities = activities.Skip(pageSize * (pageNumber - 1)).Take(pageSize + 1);

                PrevPage.Attributes["client_isdisabled"] = (pageNumber == 1).ToString().ToLower();
                NextPage.Attributes["client_isdisabled"] = (activities.Count() <= pageSize).ToString().ToLower();


                var result = activities.Take(pageSize).ToList();
                LogHolder.DataSource = result.Select(d =>
                                                     new
                {
                    d.Time,
                    d.Username,
                    d.ActivityType,
                    ActivityLabel = string.IsNullOrEmpty(d.ActivityType) ? "" : GetActivityLabel(d.ActivityType),
                    d.TaskType,
                    TaskLabel   = GetTaskLabel(d.TaskType),
                    Title       = GetTitle(d.TaskTarget),
                    EntityToken = GetEntityToken(d.TaskTarget),
                    TargetType  = GetTargetType(d.TaskTarget),
                    d.CultureName,
                    RestoreAction = GetRestoreAction(d.Activity)
                }).ToList();
                LogHolder.DataBind();
            }

            SetPageNumber(pageNumber);
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        var compareId   = new Guid(Request["compare"]);
        var compareToId = new Guid(Request["compareTo"]);

        var compareData   = DataFacade.GetData <IDataChanges>(d => d.ActivityId == compareId).ToList();
        var compareToData = DataFacade.GetData <IDataChanges>(d => d.ActivityId == compareToId).ToList();


        var compareReport = new XElement("CompareReport");

        var targetIds = compareData.Select(d => d.TargetId).Union(compareToData.Select(d => d.TargetId));

        Func <IEnumerable <IDataChanges>, Guid, XElement> getXml = (data, targetId) =>
                                                                   XElement.Parse(data.Where(d => d.TargetId == targetId).Select(d => d.SerializedData).FirstOrDefault()
                                                                                  ?? "<Data />");

        foreach (var targetId in targetIds)
        {
            var compareXml   = getXml(compareData, targetId);
            var compareToXml = getXml(compareToData, targetId);

            Guid?pageId = ExtractPageId(compareXml) ?? ExtractPageId(compareToXml);

            var helper = new DataTypeHelper(targetId, pageId);

            var Data = new XElement("Data", new XAttribute("caption", helper.GetCaption()));



            var attributeNames = compareXml.Attributes().Select(a => a.Name.LocalName)
                                 .Union(compareToXml.Attributes().Select(a => a.Name.LocalName))
                                 .Except(helper.GetKeyPropertyNames());

            foreach (var attributeName in attributeNames)
            {
                var compareField   = compareXml.Attribute(attributeName);
                var compareToField = compareToXml.Attribute(attributeName);

                var property = new XElement("Property",
                                            new XAttribute("Label", helper.GetFieldLabel(attributeName)),
                                            new XAttribute("Equals", helper.EqualsValueAttributes(compareField, compareToField)),
                                            new XAttribute("IsMarkup", ismarkupystify(helper.GetValue(compareField))),
                                            new XElement("Compare", stringelingify(helper.GetValue(compareField))),
                                            new XElement("CompareTo", stringelingify(helper.GetValue(compareToField)))
                                            );

                Data.Add(property);
            }

            compareReport.Add(Data);
        }

        var compareTable = new XElement("compareTable");

        var sb  = new StringBuilder();
        var xws = new XmlWriterSettings()
        {
            OmitXmlDeclaration = true
        };

        using (var writer = XmlWriter.Create(sb, xws))
        {
            var settings = new XsltSettings(false, true);

            var xslTransform = new XslCompiledTransform();
            xslTransform.Load(
                Server.MapPath(Path.Combine(Page.TemplateSourceDirectory, "compare.xslt")),
                settings,
                new XmlUrlResolver()
                );
            xslTransform.Transform(compareReport.CreateReader(), writer);
        }

        Holder.Controls.Add(new LiteralControl(sb.ToString()));

        string eventTarget = Request.Form["__EVENTTARGET"];

        if (eventTarget == "export")
        {
            var workbook  = new Workbook();
            var worksheet = new Worksheet("Sheet1")
            {
                GenerateXmlMap = true
            };
            workbook.Worksheets.Add(worksheet);
            var columns = new List <Column>()
            {
                new Column(string.Empty, typeof(string)),
                new Column(SR.GetString("Composite.Versioning.ContentVersioning", "Table.HeadingNew"), typeof(string)),
                new Column(SR.GetString("Composite.Versioning.ContentVersioning", "Table.HeadingOld"), typeof(string))
            };

            worksheet.Columns.AddRange(columns);

            foreach (var data in compareReport.Elements("Data"))
            {
                worksheet.AddRow(data.Attribute("caption").Value, string.Empty, string.Empty);

                foreach (var property in data.Elements("Property"))
                {
                    var      equals   = property.Attribute("Equals").Value == "true";
                    var      label    = property.Attribute("Label").Value;
                    var      newvalue = property.Element("Compare").Value;
                    var      oldvalue = property.Element("CompareTo").Value;
                    DateTime date;
                    if (DateTime.TryParse(newvalue, out date))
                    {
                        newvalue = date.ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    if (DateTime.TryParse(oldvalue, out date))
                    {
                        oldvalue = date.ToString("yyyy-MM-dd HH:mm:ss");
                    }

                    worksheet.AddBoldRow(!equals, label, newvalue, oldvalue);
                }

                worksheet.AddRow(string.Empty, string.Empty, string.Empty);
            }

            workbook.WriteToResponse(Context, string.Format("VersioningReport-{0:yyyy-MM-dd-HH-mm}.xls", DateTime.Now));
            return;
        }
    }
 private static string GetResourceString(string key)
 {
     return(SR.GetString("Composite.Plugins.PageTemplateElementProvider", key));
 }