/// <summary>
        /// Initializes a new instance of the <see cref="GridDesignerMain" /> class.
        /// </summary>
        /// <param name="databaseUri">The database Uri.</param>
        /// <param name="currentLayoutTypeValue">The current layout type value.</param>
        /// <param name="numberOfCell">The number of cell.</param>
        /// <param name="cellAttributes">The cell attributes.</param>
        public GridDesignerMain([NotNull] DatabaseUri databaseUri, [CanBeNull] string currentLayoutTypeValue, int numberOfCell, [NotNull] string cellAttributes)
        {
            InitializeComponent();
            this.InitializeDialog();

            Site.RequestCompleted completed = delegate(string response)
            {
                LayoutType currentLayoutType = null;
                var        layoutTypes       = new List <LayoutType>();

                var root = response.ToXElement();
                if (root != null)
                {
                    foreach (var element in root.Elements())
                    {
                        var layoutType = GetLayoutTypeFromItem(element);
                        if (layoutType != null)
                        {
                            layoutTypes.Add(layoutType);
                            if (layoutType.Name.Equals(currentLayoutTypeValue))
                            {
                                currentLayoutType = layoutType;
                            }
                        }
                    }
                }

                InitializeGridDesigner(layoutTypes, currentLayoutType, numberOfCell, cellAttributes);
            };

            databaseUri.Site.Execute("Layouts.GetGridDesignerLayouts", completed, databaseUri.DatabaseName.Name);
        }
        public IEnumerable <IItem> GetItems(DatabaseUri databaseUri)
        {
            Assert.ArgumentNotNull(databaseUri, nameof(databaseUri));

            var activeTree = ActiveContext.ActiveContentTree;

            if (activeTree == null)
            {
                return(Enumerable.Empty <IItem>());
            }

            var selectedItem = activeTree.ContentTreeView.SelectedItem as ItemTreeViewItem;

            if (selectedItem == null)
            {
                return(Enumerable.Empty <IItem>());
            }

            if (selectedItem.Item.ItemUri.DatabaseUri != databaseUri)
            {
                return(Enumerable.Empty <IItem>());
            }

            return(new List <IItem>()
            {
                selectedItem
            });
        }
        protected override void Execute(DatabaseUri databaseUri, ExecuteCompleted callback)
        {
            Debug.ArgumentNotNull(databaseUri, nameof(databaseUri));
            Debug.ArgumentNotNull(callback, nameof(callback));

            databaseUri.Site.DataService.RevertDatabase(databaseUri, callback);
        }
        public override bool CanExecute(DatabaseUri databaseUri, BuildSourceField field)
        {
            Assert.ArgumentNotNull(databaseUri, nameof(databaseUri));
            Assert.ArgumentNotNull(field, nameof(field));

            return(databaseUri.Site.IsSitecoreVersion(SitecoreVersion.Version70));
        }
        public void Initialize([NotNull] DatabaseUri databaseUri, [NotNull] string caption)
        {
            Assert.ArgumentNotNull(databaseUri, nameof(databaseUri));
            Assert.ArgumentNotNull(caption, nameof(caption));

            RecycleBinViewer.Initialize("recyclebin", Resources.RecycleBinPane_RecycleBinPane_Recycle_Bin, databaseUri);
        }
        public override DataSourceString Execute(DatabaseUri databaseUri, BuildSourceField field, DataSourceString dataSource)
        {
            Assert.ArgumentNotNull(databaseUri, nameof(databaseUri));
            Assert.ArgumentNotNull(field, nameof(field));
            Assert.ArgumentNotNull(dataSource, nameof(dataSource));

            var itemId = new ItemId(DatabaseTreeViewItem.RootItemGuid);

            var value = dataSource["datasource"];

            if (!string.IsNullOrEmpty(value))
            {
                Guid guid;
                if (Guid.TryParse(value, out guid))
                {
                    itemId = new ItemId(guid);
                }
            }

            var itemUri = new ItemUri(databaseUri, itemId);

            var dialog = new SelectItemDialog();

            dialog.Initialize(Resources.Browse, itemUri);
            if (AppHost.Shell.ShowDialog(dialog) != true)
            {
                return(null);
            }

            dataSource.Path          = string.Empty;
            dataSource["datasource"] = dialog.SelectedItemUri.ItemId.ToString();

            return(dataSource);
        }
        public override DataSourceString Execute(DatabaseUri databaseUri, BuildSourceField field, DataSourceString dataSource)
        {
            Assert.ArgumentNotNull(databaseUri, nameof(databaseUri));
            Assert.ArgumentNotNull(field, nameof(field));
            Assert.ArgumentNotNull(dataSource, nameof(dataSource));

            var bindMode = dataSource["bindmode"] ?? string.Empty;

            var dialog = new BindModeDialog(bindMode);

            if (AppHost.Shell.ShowDialog(dialog) != true)
            {
                return(null);
            }

            bindMode = dialog.BindMode;

            SetDataSource(dataSource);
            if (string.IsNullOrEmpty(bindMode))
            {
                dataSource.Remove("bindmode");
            }
            else
            {
                dataSource["bindmode"] = bindMode;
            }

            return(dataSource);
        }
        public IEnumerable <IItem> GetItems(DatabaseUri databaseUri)
        {
            Assert.ArgumentNotNull(databaseUri, nameof(databaseUri));

            journal = new StringJournal("SelectItem", databaseUri.ToString())
            {
                Max = 8,
                RemoveDuplicates = true
            };

            foreach (var entry in journal.GetHistory())
            {
                var parts = entry.Split('^');
                if (parts.Length != 2)
                {
                    continue;
                }

                ItemUri itemUri;
                if (!ItemUri.TryParse(parts[1], out itemUri))
                {
                    continue;
                }

                var name = parts[0];

                yield return(new HistoryEntry(itemUri, name));
            }
        }
Example #9
0
        protected virtual ItemHeader GetItemHeader([NotNull] XmlNode child, [NotNull] DatabaseUri databaseUri)
        {
            Debug.ArgumentNotNull(child, nameof(child));
            Debug.ArgumentNotNull(databaseUri, nameof(databaseUri));

            return(WebServiceMethods.GetItemHeader.Call(child, databaseUri));
        }
        public override void Execute(object parameter)
        {
            var context = parameter as CommandViewerContext;

            if (context == null)
            {
                return;
            }

            var selectedItem = context.CommandViewer.CommandsList.SelectedItem as CommandViewer.CommandDescriptor;

            if (selectedItem == null)
            {
                return;
            }

            var databaseUri = new DatabaseUri(context.CommandViewer.Context.Site, new DatabaseName("core"));

            var queryAnalyzer = AppHost.Windows.Factory.OpenQueryAnalyzer(databaseUri);

            if (queryAnalyzer == null)
            {
                Trace.TraceError("Could not open query analyzer");
                return;
            }

            var script = string.Format("use core;\nselect * from //*[@Click='{0}' or @Message='{0}'];\nuse master;\nselect * from //*[@Click='{0}' or @Message='{0}']", selectedItem.Name);

            queryAnalyzer.SetScript(script);
            queryAnalyzer.Execute();
        }
        public override DataSourceString Execute(DatabaseUri databaseUri, BuildSourceField field, DataSourceString dataSource)
        {
            Assert.ArgumentNotNull(databaseUri, nameof(databaseUri));
            Assert.ArgumentNotNull(field, nameof(field));
            Assert.ArgumentNotNull(dataSource, nameof(dataSource));

            var query = dataSource.Path;

            if (query.StartsWith(@"query:", StringComparison.InvariantCultureIgnoreCase))
            {
                query = query.Mid(6);
            }

            var dialog = new BuildQueryDialog(query, CustomValidationType.Query);

            dialog.Title = "Build Query";
            if (AppHost.Shell.ShowDialog(dialog) != true)
            {
                return(null);
            }

            dataSource.Path = @"query:" + dialog.Text;
            dataSource.Parameters.Clear();

            return(dataSource);
        }
        public static IEnumerable <TemplateHeader> GetTemplates([NotNull] DatabaseUri databaseUri)
        {
            Assert.ArgumentNotNull(databaseUri, nameof(databaseUri));

            var list = AppHost.Settings.Get(ControlsTemplateSelectorRecent, GetStorageKey(databaseUri), string.Empty) as string;

            if (string.IsNullOrEmpty(list))
            {
                return(Enumerable.Empty <TemplateHeader>());
            }

            var result = new List <TemplateHeader>();

            var items = list.Split('|');

            foreach (var item in items)
            {
                var parts = item.Split('^');

                var name   = parts[0];
                var itemId = new ItemId(new Guid(parts[1]));
                var path   = parts[2];

                var templateUri = new ItemUri(databaseUri, itemId);

                var template = new TemplateHeader(templateUri, name, string.Empty, path, Resources.Recent, false);

                result.Add(template);
            }

            return(result);
        }
Example #13
0
        private static void GetRootItem([NotNull] XmlNode child, [NotNull] Field field)
        {
            Assert.ArgumentNotNull(child, nameof(child));
            Assert.ArgumentNotNull(field, nameof(field));

            var root = child.SelectSingleNode(@"root/item");

            if (root == null)
            {
                return;
            }

            var databaseUri = field.FieldUris.First().ItemVersionUri.ItemUri.DatabaseUri;

            var urlString = new UrlString(field.Source);

            var databaseName = urlString[@"databasename"];

            if (!string.IsNullOrEmpty(databaseName))
            {
                databaseUri = new DatabaseUri(databaseUri.Site, new DatabaseName(databaseName));
            }

            field.Root = GetItemHeader.Call(root, databaseUri);
        }
        public override bool CanExecute(DatabaseUri databaseUri, BuildSourceField field)
        {
            Assert.ArgumentNotNull(databaseUri, nameof(databaseUri));
            Assert.ArgumentNotNull(field, nameof(field));

            if (string.Compare(field.Type, @"tree list", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                return(false);
            }

            if (string.Compare(field.Type, @"treelist", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                return(false);
            }

            if (string.Compare(field.Type, @"treelistex", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                return(false);
            }

            if (string.Compare(field.Type, @"droptree", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                return(false);
            }

            if (string.Compare(field.Type, @"reference", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                return(false);
            }

            return(true);
        }
        public override void GetTemplatesAsync(DatabaseUri databaseUri, GetItemsCompleted <TemplateHeader> getTemplatesCallback)
        {
            Assert.ArgumentNotNull(databaseUri, nameof(databaseUri));
            Assert.ArgumentNotNull(getTemplatesCallback, nameof(getTemplatesCallback));

            getTemplatesCallback(Enumerable.Empty <TemplateHeader>());
        }
        public override IEnumerable <ItemPath> GetItemPath(DatabaseUri databaseUri, string itemPath)
        {
            Assert.ArgumentNotNull(databaseUri, nameof(databaseUri));
            Assert.ArgumentNotNull(itemPath, nameof(itemPath));

            return(Enumerable.Empty <ItemPath>());
        }
        public override DataSourceString Execute(DatabaseUri databaseUri, BuildSourceField field, DataSourceString dataSource)
        {
            Assert.ArgumentNotNull(databaseUri, nameof(databaseUri));
            Assert.ArgumentNotNull(field, nameof(field));
            Assert.ArgumentNotNull(dataSource, nameof(dataSource));

            var dialog = new SelectDatabaseDialog
            {
                SelectedDatabaseUri = databaseUri
            };

            if (!dialog.ShowDialog())
            {
                return(null);
            }

            var d = dialog.SelectedDatabaseUri;

            if (d == DatabaseUri.Empty)
            {
                return(null);
            }

            SetDataSource(dataSource);
            dataSource["databasename"] = d.DatabaseName.ToString();

            return(dataSource);
        }
Example #18
0
        private void Execute([NotNull] Site site, [NotNull] DatabaseUri databaseUri)
        {
            Debug.ArgumentNotNull(site, nameof(site));
            Debug.ArgumentNotNull(databaseUri, nameof(databaseUri));

            AppHost.Windows.Factory.OpenManagementViewer(site.Name, new DatabaseManagementContext(databaseUri), HistoryViewer.ItemName);
        }
        public void Initialize([NotNull] DatabaseUri databaseUri)
        {
            Assert.ArgumentNotNull(databaseUri, nameof(databaseUri));

            DatabaseUri  = databaseUri;
            Pane.Caption = string.Format(@"XPath Builder [{0}/{1}]", databaseUri.DatabaseName, databaseUri.Site.Name);
        }
Example #20
0
        public override bool CanExecute(DatabaseUri databaseUri, BuildSourceField field)
        {
            Assert.ArgumentNotNull(databaseUri, nameof(databaseUri));
            Assert.ArgumentNotNull(field, nameof(field));

            return(string.Compare(field.Type, @"rules", StringComparison.InvariantCultureIgnoreCase) == 0);
        }
Example #21
0
        public virtual bool CanExecute(DatabaseUri databaseUri, [NotNull] BuildSourceField field)
        {
            Assert.ArgumentNotNull(databaseUri, nameof(databaseUri));
            Assert.ArgumentNotNull(field, nameof(field));

            return(true);
        }
Example #22
0
        private void HandleActiveDatabaseChanged([NotNull] object sender, [NotNull] DatabaseUri databaseUri)
        {
            Debug.ArgumentNotNull(sender, nameof(sender));
            Debug.ArgumentNotNull(databaseUri, nameof(databaseUri));

            ItemHeader.IsActive = databaseUri.Site == Site;
        }
        public AdvancedPublishDialog([NotNull] DatabaseUri databaseUri)
        {
            Assert.ArgumentNotNull(databaseUri, nameof(databaseUri));

            InitializeComponent();
            this.InitializeDialog();

            AllLanguages.IsChecked = true;
            AllTargets.IsChecked   = true;

            DatabaseUri = databaseUri;

            JobViewer.IsChecked = AppHost.Settings.Options.ShowJobViewer;

            LoadProfiles();

            if (!profiles.Any())
            {
                var profile = new PublishProfile
                {
                    Name = "Default"
                };
                profiles.Add(profile);
            }

            RenderProfiles();

            LoadPublishInformation();

            RelatedItems.Visibility = databaseUri.Site.IsSitecoreVersion(Constants.Versions.Version72) ? Visibility.Visible : Visibility.Collapsed;

            EnableButtons();
        }
Example #24
0
        public RenderingItem([CanBeNull] IRenderingContainer renderingContainer, [NotNull] DatabaseUri databaseUri, [NotNull] XElement element, bool isDuplicate) : this(renderingContainer, databaseUri, element)
        {
            Assert.ArgumentNotNull(databaseUri, nameof(databaseUri));
            Assert.ArgumentNotNull(element, nameof(element));

            hasParameters = isDuplicate;
            if (!isDuplicate)
            {
                return;
            }

            UniqueId = Guid.NewGuid().ToString("B").ToUpperInvariant();

            var idProperty = DynamicProperties.FirstOrDefault(p => string.Compare(p.Name, @"id", StringComparison.InvariantCultureIgnoreCase) == 0);

            if (idProperty != null)
            {
                var n = idProperty.Value as string;
                if (!string.IsNullOrEmpty(n))
                {
                    n = n.TrimEnd('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
                }
                else
                {
                    n = Name;
                }

                disableRenaming  = true;
                idProperty.Value = GetNewControlId(n.GetSafeCodeIdentifier());
                disableRenaming  = false;
            }
        }
Example #25
0
        private void NavigateCloneSource([NotNull] object sender, [NotNull] EventArgs e)
        {
            Debug.ArgumentNotNull(sender, nameof(sender));
            Debug.ArgumentNotNull(e, nameof(e));

            if (ContentEditor.ContentModel.IsEmpty)
            {
                return;
            }

            var item = ContentEditor.ContentModel.FirstItem;

            var source = item.Source;

            if (string.IsNullOrEmpty(source))
            {
                return;
            }

            var parts       = source.Split('|');
            var databaseUri = new DatabaseUri(item.ItemUri.Site, new DatabaseName(parts[0]));
            var itemId      = new ItemId(new Guid(parts[1]));

            var itemUri = new ItemUri(databaseUri, itemId);

            AppHost.OpenContentEditor(new ItemVersionUri(itemUri, LanguageManager.CurrentLanguage, Data.Version.Latest));
        }
Example #26
0
        private void Save([NotNull] DatabaseUri databaseUri, [NotNull] Template template)
        {
            Debug.ArgumentNotNull(databaseUri, nameof(databaseUri));
            Debug.ArgumentNotNull(template, nameof(template));

            var writer = new StringWriter();
            var output = new XmlTextWriter(writer);

            output.Formatting = Formatting.Indented;

            var templateName = template.Name;
            var templateId   = template.TemplateItemId.ToString();

            output.WriteStartElement(@"template");

            output.WriteAttributeString(@"name", templateName);
            output.WriteAttributeString(@"id", templateId);
            output.WriteAttributeString(@"icon", template.Icon);
            output.WriteAttributeString(@"basetemplates", template.BaseTemplates);
            output.WriteAttributeString(@"parentpath", template.ParentPath);

            foreach (var templateSection in template.Sections)
            {
                var templateSectionName = templateSection.Name;
                var templateSectionId   = templateSection.TemplateSectionItemId.ToString();

                output.WriteStartElement(@"section");

                output.WriteAttributeString(@"name", templateSectionName);
                output.WriteAttributeString(@"id", templateSectionId);

                foreach (var field in templateSection.Fields)
                {
                    var fieldName = field.Name;
                    var fieldId   = field.TemplateFieldItemId.ToString();

                    output.WriteStartElement(@"field");

                    output.WriteAttributeString(@"id", fieldId);
                    output.WriteAttributeString(@"name", fieldName);
                    output.WriteAttributeString(@"type", field.Type);
                    output.WriteAttributeString(@"source", field.Source);
                    output.WriteAttributeString(@"shared", field.Shared ? "1" : "0");
                    output.WriteAttributeString(@"unversioned", field.Unversioned ? @"1" : "0");
                    output.WriteAttributeString(@"title", field.Title);
                    output.WriteAttributeString(@"validatorbar", field.ValidatorBar);

                    output.WriteEndElement();
                }

                output.WriteEndElement();
            }

            output.WriteEndElement();

            GetValueCompleted <string> completed = delegate { };

            databaseUri.Site.DataService.SaveTemplateXml(writer.ToString(), databaseUri, completed);
        }
Example #27
0
        protected virtual void Register([NotNull] Site site, [NotNull] List <EnvDTE.ProjectItem> items)
        {
            Debug.ArgumentNotNull(site, nameof(site));
            Debug.ArgumentNotNull(items, nameof(items));

            var databaseUri = new DatabaseUri(site, new DatabaseName("master"));

            var dialog = new SelectItemDialog();

            dialog.Initialize(DialogTitle, databaseUri, DefaultItemPath);

            if (AppHost.Shell.ShowDialog(dialog) != true)
            {
                return;
            }

            var     selectedItemUri = dialog.SelectedItemUri;
            ItemUri templateUri;

            Guid guid;

            if (Guid.TryParse(TemplateItemPath, out guid))
            {
                templateUri = new ItemUri(databaseUri, new ItemId(guid));
            }
            else
            {
                templateUri = new ItemUri(databaseUri, IdManager.GetItemId(TemplateItemPath));
            }

            var item = items.FirstOrDefault();

            if (item == null)
            {
                return;
            }

            var project = ProjectManager.GetProject(item);

            if (project == null)
            {
                return;
            }

            var itemUris = CreateItems(project, items, selectedItemUri, templateUri);
            var itemUri  = itemUris.FirstOrDefault();

            if (itemUri == null)
            {
                return;
            }

            if (AppHost.CurrentContentTree != null)
            {
                AppHost.CurrentContentTree.Locate(itemUri);
            }

            AppHost.OpenContentEditor(itemUri);
        }
Example #28
0
        public static void GetFieldTypes([NotNull] this DataService dataService, [NotNull] DatabaseUri databaseUri, [NotNull] GetFieldTypesCompleted callback)
        {
            Assert.ArgumentNotNull(dataService, nameof(dataService));
            Assert.ArgumentNotNull(databaseUri, nameof(databaseUri));
            Assert.ArgumentNotNull(callback, nameof(callback));

            ExecuteCompleted c = delegate(string response, ExecuteResult executeResult)
            {
                if (!DataService.HandleExecute(response, executeResult))
                {
                    callback(Enumerable.Empty <FieldTypeHeader>(), Enumerable.Empty <FieldValidationHeader>());
                    return;
                }

                var root = Parse(response);
                if (root == null)
                {
                    callback(Enumerable.Empty <FieldTypeHeader>(), Enumerable.Empty <FieldValidationHeader>());
                    return;
                }

                var fieldTypes = new List <FieldTypeHeader>();

                var fieldTypesElement = root.Element(@"fieldtypes");
                if (fieldTypesElement != null)
                {
                    foreach (var element in fieldTypesElement.Elements())
                    {
                        var item = new FieldTypeHeader(new ItemUri(databaseUri, new ItemId(new Guid(element.GetAttributeValue("id")))), element.GetAttributeValue("name"), element.GetAttributeValue("icon"), element.GetAttributeValue("path"), element.GetAttributeValue("section"));

                        fieldTypes.Add(item);
                    }
                }

                fieldTypes.Sort(new FieldTypeHeaderComparer());

                var validations = new List <FieldValidationHeader>();

                var validationsElement = root.Element(@"validations");
                if (validationsElement != null)
                {
                    foreach (var element in validationsElement.Elements())
                    {
                        var item = new FieldValidationHeader
                        {
                            Name    = element.GetAttributeValue("name"),
                            Section = element.GetAttributeValue("section"),
                            ItemUri = new ItemUri(databaseUri, new ItemId(new Guid(element.GetAttributeValue("id"))))
                        };

                        validations.Add(item);
                    }
                }

                callback(fieldTypes, validations);
            };

            dataService.ExecuteAsync("Templates.GetFieldTypes", c, databaseUri.DatabaseName.ToString());
        }
        public void Initialize([NotNull] DatabaseUri databaseUri, [NotNull] List <ItemId> selectedItems)
        {
            Assert.ArgumentNotNull(databaseUri, nameof(databaseUri));
            Assert.ArgumentNotNull(selectedItems, nameof(selectedItems));

            ValidatorPicker.Initialize(databaseUri, selectedItems);
            SelectedItems = selectedItems;
        }
        public void Initialize([NotNull] DatabaseUri databaseUri, [NotNull] string dataSource, [NotNull] RuleModel ruleModel)
        {
            Assert.ArgumentNotNull(databaseUri, nameof(databaseUri));
            Assert.ArgumentNotNull(dataSource, nameof(dataSource));
            Assert.ArgumentNotNull(ruleModel, nameof(ruleModel));

            Editor.Initialize(databaseUri, dataSource, ruleModel);
        }
Example #31
0
 public void Constructor()
 {
     DatabaseUri dbUri = new DatabaseUri("mysql://*****:*****@localhost:3306/mydb");
     Assert.AreEqual("mysql",     dbUri.DatabaseType);
     Assert.AreEqual("root",      dbUri.Username);
     Assert.AreEqual("secret",    dbUri.Password);
     Assert.AreEqual("localhost", dbUri.Host);
     Assert.AreEqual(3306,        dbUri.Port);
     Assert.AreEqual("mydb",      dbUri.DatabaseName);
 }