Exemple #1
0
        internal void Save()
        {
            if (!DataService.Key.Equals(_DataServiceStrategy))
            {
                Bootstrapper.SetDataStrategy(DataService.Key);
                Settings.DataService    = _DataService;
                Tasks.DataService       = _DataService;
                Paths.DataService       = _DataService;
                Mimes.DataService       = _DataService;
                Content.DataService     = _DataService;
                Credentials.DataService = _DataService;
                Indexer.DataService     = _DataService;
                Chronos.DataService     = _DataService;
                Mimes.DataService       = _DataService;
                Schema.DataService      = _DataService;
                Mimes.SaveWorkspace();
            }
            if (Content.CanSaveWorkspace())
            {
                Content.SetPreferences();
                Content.SaveWorkspace();
            }

            if (Schema.CanSaveWorkspace())
            {
                Schema.SetPreferences();
                Schema.SaveWorkspace();
            }
            if (Indexer.CanSaveWorkspace())
            {
                Indexer.SaveWorkspace();
            }

            if (Tasks.CanSaveWorkspace())
            {
                Tasks.SetPreferences();
                Tasks.SaveWorkspace();
            }
            if (_Chronos != null && _Chronos.CanSaveWorkspace())
            {
                _Chronos.SaveWorkspace();
            }
            if (Styx != null && Styx.CanSaveWorkspace())
            {
                Styx.SaveWorkspace();
            }
            // must be last so that preferences are persisted
            if (Settings.CanSaveWorkspace())
            {
                Settings.SaveWorkspace();
            }
        }
Exemple #2
0
        private void Import()
        {
            int                totalfiles  = 0;
            int                foundfiles  = 0;
            List <string>      orphanfiles = new List <string>();
            List <ContentItem> list        = new List <ContentItem>();
            var                xdoc        = XDocument.Load(@"c:\data\snippets.xml", LoadOptions.None);

            foreach (XElement el in xdoc.Descendants("ContentItem"))
            {
                ContentItem item = new ContentItem()
                {
                    Language = AppConstants.Languages.English
                };

                item.Id = el.Attribute("id").Value;
                var display = el.Element("Title");
                if (display != null)
                {
                    item.Display = display.Value;
                }
                else
                {
                }

                item.Body = el.Element("Text").Value;
                string mime = el.Attribute("mime").Value;
                if (cp.ContainsKey(mime))
                {
                    item.Mime = cp[mime];
                    if (mime == "text/snippet" || mime == "resource/url" || mime == "text/credential")
                    {
                    }
                    else // file based
                    {
                        totalfiles++;
                        string   filepath = Path.Combine(@"c:\data\content.directory", item.Body);
                        FileInfo info     = new FileInfo(filepath);
                        if (info.Exists)
                        {
                            foundfiles++;
                            if (ContentManager.TryInload(info, out string filename))
                            {
                                var found = Mimes.FirstOrDefault(x => x.Extension.Equals(info.Extension, StringComparison.OrdinalIgnoreCase));
                                if (found != null)
                                {
                                    item.Mime = found.Id;
                                }
                                else
                                {
                                    item.Mime = info.Extension.TrimStart('.').ToLower();
                                }
                                item.Body = filename;
                                item.Properties.Add(new Property()
                                {
                                    Name  = $"{AppConstants.Tags.Prefix}-{AppConstants.Tags.Extension}",
                                    Value = item.Mime
                                });
                            }
                        }
                        else
                        {
                            orphanfiles.Add(item.Body);
                        }
                    }
                }
                else
                {
                }

                List <string> tags = new List <string>();
                foreach (var tag in el.Descendants("Tag"))
                {
                    string id  = tag.Attribute("id").Value;
                    string key = tag.Attribute("key").Value;

                    if (!exc.Contains(id))
                    {
                        if (tag.HasElements)
                        {
                            key = $"{key}:{tag.Element("Value").Value}";
                        }
                        tags.Add(key);
                    }
                    else if (id.Equals("28211d7a-a54c-413b-bbc2-0ad6363edc0e")) // created
                    {
                        if (tag.HasElements && DateTime.TryParse(tag.Element("Value").Value, out DateTime created))
                        {
                            item.Properties.Add(new Property()
                            {
                                Name  = $"{AppConstants.Tags.Prefix}-{AppConstants.Tags.CreatedAt}",
                                Value = created
                            });
                        }
                    }
                    else if (id.Equals("21574fd9-0c7b-4342-9074-5974baf598be")) // created by
                    {
                        if (tag.HasElements)
                        {
                            item.Properties.Add(new Property()
                            {
                                Name  = $"{AppConstants.Tags.Prefix}-{AppConstants.Tags.CreatedBy}",
                                Value = tag.Element("Value").Value
                            });
                        }
                    }
                    else if (id.Equals("2bdd1d41-59c3-4ff2-b15e-889f5f881219")) // updated
                    {
                        if (tag.HasElements && DateTime.TryParse(tag.Element("Value").Value, out DateTime updated))
                        {
                            item.Properties.Add(new Property()
                            {
                                Name  = $"{AppConstants.Tags.Prefix}-{AppConstants.Tags.ModifiedAt}",
                                Value = updated
                            });
                        }
                    }
                }
                item.Properties.Add(new Property()
                {
                    Name  = $"{AppConstants.Tags.Prefix}-{AppConstants.Tags.Domain}",
                    Value = Settings.SelectedDomain.Id
                });

                item.Properties.AddRange(Resolver.Resolve(tags));

                list.Add(item);
            }
            list.ForEach(x => {
                model.Items.Add(x);
            });
        }