public GetXmlOrXmbFileResult TryGetXmlOrXmbFile(ContentStorage loc, GameDirectory gameDir, string filename, out FileInfo file,
                                                        string ext = null)
        {
            Contract.Requires(!string.IsNullOrEmpty(filename));
            file = null;

            if (TryGetFile(loc, gameDir, filename, out file, ext))
            {
                return(GetXmlOrXmbFileResult.Xml);
            }

            if (ext.IsNotNullOrEmpty())
            {
                filename += ext;
            }

            filename += Xmb.XmbFile.kFileExt;

            // purposely don't pass ext through in the XMB round
            bool xmb_found = loc == ContentStorage.UpdateOrGame
                                ? TryGetFileFromUpdateOrGame(gameDir, filename, out file, ext: null)
                                : TryGetFileImpl(loc, gameDir, filename, out file, ext: null);

            if (xmb_found)
            {
                return(GetXmlOrXmbFileResult.Xmb);
            }

            return(GetXmlOrXmbFileResult.FileNotFound);
        }
示例#2
0
        public void Relink(
            [Argument("site", "s", Description = "The root http address of the website copy.")]
            string site,
            [Argument("from", "f", Description = "The original link you want to change.")]
            string sourceLink,
            [Argument("target", "t", Description = "The new link you want to use instead.")]
            string targetLink)
        {
            Uri sourceUri = new Uri(sourceLink, UriKind.Absolute);
            Uri targetUri = new Uri(targetLink, UriKind.Absolute);

            using (ContentStorage storage = new ContentStorage(StoragePath(site), false))
            {
                ContentParser parser = new ContentParser(storage, new Uri(site, UriKind.Absolute));
                parser.RewriteUri += u =>
                {
                    if (sourceUri == u)
                    {
                        return(targetUri);
                    }
                    return(u);
                };
                parser.ProcessAll();
            }
        }
示例#3
0
        public void RelinkEx(
            [Argument("site", "s", Description = "The root http address of the website copy.")]
            string site,
            [Argument("expression", "e", Description = "A regular expression to match against the links.")]
            string expression,
            [Argument("target", "t", Description = "The new link, use {0} to insert matched capture groups by ordinal.")]
            string targetLink)
        {
            Regex exp = new Regex(expression, RegexOptions.Singleline);

            using (ContentStorage storage = new ContentStorage(StoragePath(site), false))
            {
                ContentParser parser = new ContentParser(storage, new Uri(site, UriKind.Absolute));
                parser.RewriteUri += u =>
                {
                    Match match = exp.Match(u.OriginalString);
                    if (match.Success)
                    {
                        string newLink =
                            String.Format(
                                targetLink,
                                match.Groups.Cast <Group>()
                                .Select(g => g.Value)
                                .Cast <object>().ToArray()
                                );
                        return(new Uri(newLink, UriKind.Absolute));
                    }
                    return(u);
                };
                parser.ProcessAll();
            }
        }
示例#4
0
        public async Task <ActionResult> ContentAttach(int announcementApplicationId, string contentId)
        {
            if (string.IsNullOrWhiteSpace(contentId))
            {
                throw new ChalkableApiException("Invalid param. ContentId is missing");
            }
            var content = ContentStorage.GetStorage().GetContentById(contentId);

            if (content == null)
            {
                throw new ChalkableApiException("Content not found");
            }
            PrepareBaseData(announcementApplicationId);
            var updateAnnAppMeta = Connector.Announcement.UpdateAnnouncementApplicationMeta(announcementApplicationId, content.Text, content.ImageUrl, content.Description);

            var ids           = defaultAbIds.Select(Guid.Parse).ToList();
            var standardsTask = Connector.Standards.GetStandardsByIds(ids);
            var relationsTask = Connector.Standards.GetListOfStandardRelations(ids);



            return(View("Attach", DefaultJsonViewData.Create(new
            {
                Content = content,
                Standards = await standardsTask,
                Relations = await relationsTask,
                UpdatedAnnAppMeate = await updateAnnAppMeta,
            })));
        }
示例#5
0
        public string GetAbsoluteDirectory(ContentStorage loc, GameDirectory gameDir)
        {
            string root = GetContentLocation(loc);
            string dir  = GetDirectory(gameDir);

            return(Path.Combine(root, dir));
        }
示例#6
0
 public ContentResponse(ContentStorage content, Uri uri)
 {
     _content = content;
     _status  = HttpStatusCode.InternalServerError;
     _record  = ContentRecord.DefaultInstance;
     try
     {
         string path = uri.NormalizedPathAndQuery();
         if (_content.TryGetValue(path, out _record))
         {
             if (_record.HasContentRedirect)
             {
                 _status = HttpStatusCode.Redirect;
             }
             else
             {
                 _status = HttpStatusCode.OK;
             }
         }
         else
         {
             _record = ContentRecord.DefaultInstance;
             _status = HttpStatusCode.NotFound;
             Log.Warning("404 - {0}", path);
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex, "Exception on {0}", uri);
     }
 }
        public void Search(
            [Argument("site", "s", Description = "The root http address of the website copy.")]
            string site,
            [Argument("term", "t", Description = "The expression to search for, see http://lucene.apache.org/java/2_4_0/queryparsersyntax.html.")]
            string term,
            [Argument("newest", "n", DefaultValue = false, Description = "Order the results by date rather than by best match.")]
            bool newest)
        {
            int limit = 50;

            using (ContentStorage store = new ContentStorage(StoragePath(site), true))
            {
                int total, count = 0;
                foreach (var result in store.Search(term, 0, limit, newest, out total))
                {
                    Console.WriteLine(" {0,3}%  {1,-25}  {2:yyyy-MM-dd}  \"{3}\"", result.Ranking, result.Uri, result.Modified, result.Title);
                    count++;
                }

                if (count == total)
                {
                    Console.WriteLine("[{0} total]", count);
                }
                else
                {
                    Console.WriteLine("[{0} of {1} total]", count, total);
                }
            }
        }
示例#8
0
 public void Remove(
     [Argument("page", "p", Description = "The full http address of the page you want to remove.")]
     string url)
 {
     using (ContentStorage store = new ContentStorage(StoragePath(url), false))
         store.Remove(new Uri(url, UriKind.Absolute).NormalizedPathAndQuery());
 }
示例#9
0
        public void Rename(
            [Argument("page", "p", Description = "The full http address of the page to move the source content to.")]
            string targetLink,
            [Argument("source", "s", Description = "The full http address of the page you want to move.")]
            string sourceLink,
            [Argument("redirect", "r", DefaultValue = true, Description = "True to insert a redirect after moving the content.")]
            bool redirect)
        {
            Uri targetUri = new Uri(targetLink, UriKind.Absolute);
            Uri sourceUri = new Uri(sourceLink, UriKind.Absolute);

            Check.Assert <InvalidOperationException>(sourceUri.IsSameHost(targetUri), "The source and target should be in the same site.");

            using (ContentStorage store = new ContentStorage(StoragePath(sourceLink), false))
            {
                store.Rename(sourceUri.NormalizedPathAndQuery(), targetUri.NormalizedPathAndQuery());
                if (redirect)
                {
                    DateTime time = DateTime.Now;
                    ContentRecord.Builder builder = store.New(sourceUri.NormalizedPathAndQuery(), time);
                    builder
                    .SetHttpStatus((uint)HttpStatusCode.Redirect)
                    .SetContentRedirect(targetUri.NormalizedPathAndQuery())
                    ;
                    store.Add(builder.ContentUri, builder.Build());
                }
            }
        }
示例#10
0
        protected void Init(IDatabaseFileProviderService databaseFileProviderService, ContentStorage storage)
        {
            Storage?.RemoveDisposeBy(this);

            Storage      = storage;
            fileProvider = databaseFileProviderService.FileProvider;

            Storage.DisposeBy(this);
        }
示例#11
0
 public Game(string title = "TestGameApp") : base(title, WindowSizePresets.HD)
 {
     this.SetBackgroundColor(Color.Black);
     cs  = new ContentStorage("testassets");
     gc1 = new ContentStorage("gamecontent1");
     //config = new GameConfig("Configs", "TestConfig");
     cs.ContentStorageCreated += Cs_ContentStorageCreated;
     cs.ContentLoading        += Cs_ContentLoading;
 }
示例#12
0
        public IEnumerable <string> GetFiles(ContentStorage loc, GameDirectory gameDir, string searchPattern)
        {
            Contract.Requires(loc != ContentStorage.UpdateOrGame, "Must iterate storages separately");
            Contract.Requires(!string.IsNullOrEmpty(searchPattern));

            string dir = GetAbsoluteDirectory(loc, gameDir);

            return(Directory.GetFiles(dir, searchPattern));
        }
示例#13
0
        protected void Init(ContentStorage storage)
        {
            Storage?.RemoveDisposeBy(this);

            Storage      = storage;
            FileProvider = ContentManager.FileProvider;

            Storage?.DisposeBy(this);
        }
示例#14
0
 public void MakeSearchTemplate(
     [Argument("site", "s", Description = "The root http address of the website copy.")]
     string site)
 {
     using (ContentStorage store = new ContentStorage(StoragePath(site), false))
     {
         SearchTemplateBuilder builder = new SearchTemplateBuilder(store, new Uri(site, UriKind.Absolute));
         builder.RebuildTemplate();
     }
 }
        public bool TryGetFile(ContentStorage loc, GameDirectory gameDir, string filename, out FileInfo file,
                               string ext = null)
        {
            Contract.Requires(!string.IsNullOrEmpty(filename));
            file = null;

            return(loc == ContentStorage.UpdateOrGame
                                ? TryGetFileFromUpdateOrGame(gameDir, filename, out file, ext)
                                : TryGetFileImpl(loc, gameDir, filename, out file, ext));
        }
示例#16
0
        public SiteConverter(string storagePath, string baseUri)
        {
            RebaseLinks = true;
            _baseUri    = new Uri(baseUri, UriKind.Absolute);
            HttpCloneConfig config = Config.ReadConfig(_baseUri, storagePath);

            _mime        = new MimeInfoMap(_baseUri, storagePath);
            CleanupRegex = new Regex(config.BadNameCharsExpression ?? @"[^\w]+", RegexOptions.IgnoreCase | RegexOptions.Singleline);
            _content     = new ContentStorage(storagePath, true);
        }
示例#17
0
        public void Import(
            [Argument("page", "p", Description = "The full http address of the page to save the source content to.")]
            string targetLink,
            [Argument("source", "s", Description = "The full http address of the page you want to import.")]
            string sourceLink,
            [Argument("recursive", "r", DefaultValue = false, Description = "True to recursivly import all links within the same domain.")]
            bool recursive,
            [Argument("noprompt", "q", DefaultValue = false, Description = "True to stop prompt for confirmation before overwriting content.")]
            bool noPrompt
            )
        {
            Uri targetUri = new Uri(targetLink, UriKind.Absolute);

            using (TempDirectory tempFolder = new TempDirectory())
                using (ContentStorage writer = new ContentStorage(StoragePath(targetLink), false))
                {
                    bool exists = writer.ContainsKey(targetUri.NormalizedPathAndQuery());
                    if (exists)
                    {
                        if (!noPrompt && !new ConfirmPrompt().Continue("Overwrite " + targetUri.NormalizedPathAndQuery()))
                        {
                            return;
                        }
                    }

                    Uri sourceUri = new Uri(sourceLink, UriKind.Absolute);
                    using (SiteCollector index = new SiteCollector(tempFolder.TempPath, sourceLink))
                    {
                        index.NoDefaultPages       = true;
                        index.UpdateSearchTemplate = false;
                        if (recursive)
                        {
                            index.CrawlSite();
                        }
                        else
                        {
                            index.AddUrlsFound = false;
                            index.CrawlPage(sourceUri.NormalizedPathAndQuery());
                        }
                    }

                    using (SiteConverter index = new SiteConverter(tempFolder.TempPath, sourceLink))
                    {
                        index.Overwrite = true;
                        index.ConvertTo(targetLink, writer);
                    }

                    if (exists)
                    {
                        writer.Remove(targetUri.NormalizedPathAndQuery());
                    }
                    writer.Rename(sourceUri.NormalizedPathAndQuery(), targetUri.NormalizedPathAndQuery());
                }
        }
示例#18
0
 public void TestExampleSite()
 {
     SetupW3Example();
     using (ContentStorage store = new ContentStorage(W3ExampleDirectory, true))
     {
         foreach (string url in KnownLinks)
         {
             Assert.IsTrue(store.ContainsKey(url));
         }
     }
 }
示例#19
0
 private void VerifyLinks(string directory, IEnumerable <string> knownLinks)
 {
     using (ContentStorage store = new ContentStorage(directory, true))
     {
         foreach (string url in knownLinks)
         {
             Assert.IsTrue(store.ContainsKey(url), "missing link " + url);
         }
         Assert.AreEqual(knownLinks.Count(), store.Count, "incorrect total links");
     }
 }
示例#20
0
        public WcfHttpHost(ContentStorage storage, int port)
        {
            _uri     = new Uri(String.Format("http://localhost:{0}/", port));
            _handler = new SimpleHttpHandler(storage);

            _host = new WebServiceHost(this);
            ServiceEndpoint pages = _host.AddServiceEndpoint(GetType(), new WebHttpBinding(), _uri);

            pages.Behaviors.Add(new WebHttpBehavior());
            _host.Open();
        }
示例#21
0
        public string GetContentLocation(ContentStorage location)
        {
            switch (location)
            {
            case ContentStorage.Game: return(RootDirectory);

            case ContentStorage.Update:
                return(UpdateDirectoryIsValid ? UpdateDirectory : RootDirectory);

            default: throw new NotImplementedException();
            }
        }
示例#22
0
        protected override PaginatedList <ApplicationContent> GetApplicationContents(IList <StandardInfo> standardInfos, int?start, int?count)
        {
            start = start ?? 0;
            count = count ?? int.MaxValue;

            var standards = Task.Run(() => PrepareCommonCores(standardInfos)).Result;

            var userEmail = Task.Run(() => GetCurrentUser(null)).Result.Email;

            var res = ContentStorage.GetStorage().GetContents().OrderBy(x => x.ContentId).ToList();

            return(new PaginatedList <ApplicationContent>(res, start.Value, count.Value));
        }
示例#23
0
 public void Like(
     [Argument("page", "p", Description = "The http address of the web page.")]
     string url)
 {
     using (ContentStorage store = new ContentStorage(StoragePath(url), true))
     {
         Uri uri = new Uri(url, UriKind.Absolute);
         foreach (var result in store.Similar(uri.NormalizedPathAndQuery(), 10, false))
         {
             Console.WriteLine(" {0,3}%  {1,-25}  {2:yyyy-MM-dd}  \"{3}\"", result.Ranking, result.Uri, result.Modified, result.Title);
         }
     }
 }
示例#24
0
        internal void Init(IDatabaseFileProviderService databaseFileProviderService, [NotNull] ContentStorage storage, ref ImageDescription imageDescription)
        {
            if (imageDescription.Depth != 1)
            {
                throw new ContentStreamingException("Texture streaming supports only 2D textures and 2D texture arrays.", storage);
            }

            Init(databaseFileProviderService, storage);
            texture.FullQualitySize = new Size3(imageDescription.Width, imageDescription.Height, imageDescription.Depth);
            description             = imageDescription;
            residentMips            = 0;
            CacheMipMaps();
        }
        public IEnumerable <string> GetFiles(ContentStorage loc, GameDirectory gameDir, string searchPattern)
        {
            Contract.Requires(loc != ContentStorage.UpdateOrGame, "Must iterate storages separately");
            Contract.Requires(!string.IsNullOrEmpty(searchPattern));

            string dir = GetAbsoluteDirectory(loc, gameDir);

            if (!Directory.Exists(dir))
            {
                throw new DirectoryNotFoundException(dir);
            }

            return(Directory.EnumerateFiles(dir, searchPattern));
        }
示例#26
0
 private int CountLinks(string directory, Predicate <Uri> test)
 {
     using (ContentStorage store = new ContentStorage(directory, true))
     {
         int           counter = 0;
         ContentParser parser  = new ContentParser(store, W3ExampleUrl);
         parser.VisitUri += u => { if (test(u))
                                   {
                                       counter++;
                                   }
         };
         parser.ProcessAll();
         return(counter);
     }
 }
示例#27
0
        bool TryGetFileImpl(ContentStorage loc, GameDirectory gameDir, string filename, out FileInfo file, string ext = null)
        {
            file = null;

            string root      = GetContentLocation(loc);
            string dir       = GetDirectory(gameDir);
            string file_path = Path.Combine(root, dir, filename);

            if (!string.IsNullOrEmpty(ext))
            {
                file_path += ext;
            }

            return((file = new FileInfo(file_path)).Exists);
        }
示例#28
0
 public void CopySite(
     [Argument("site", "s", Description = "The root http address of the website to copy.")]
     string original,
     [Argument("target", "t", Description = "The root http address of the destination website.")]
     string target,
     [Argument("overwrite", "y", DefaultValue = false, Description = "True to overwrite any existing content.")]
     bool overwrite)
 {
     using (SiteConverter index = new SiteConverter(StoragePath(original), original))
     using (ContentStorage writer = new ContentStorage(StoragePath(target), false))
     {
         index.Overwrite = overwrite;
         index.ConvertTo(target, writer);
     }
 }
示例#29
0
        public ContentState(ContentStorage content)
        {
            //_executionLock = new SimpleReadWriteLocking();
            _executionLock = IgnoreLocking.Instance;
            _rsaKeyPair    = ReadKeyFile();
            _content       = content ?? ReadCurrent();

            _channel = new IpcEventChannel(Path.Combine(Settings.RegistryPath, "IISChannel"),
                                           BitConverter.ToString(Hash.MD5(Encoding.UTF8.GetBytes(StoragePath)).ToArray()));

            _channel.OnError += (o, e) => Log.Error(e.GetException());
            _channel[Events.ContentUpdate].OnEvent += OnContentUpdated;
            _channel[Events.CompletionAck].OnEvent += (o, e) => { };
            _channel.StartListening();
        }
示例#30
0
        public SitePublisher(string storagePath, string site)
        {
            _storagePath = storagePath;
            _siteUri     = new Uri(site, UriKind.Absolute);
            _content     = new ContentStorage(storagePath, true);

            _keyfile = Path.Combine(storagePath, "client-publishing.key");
            if (File.Exists(_keyfile))
            {
                _rsaKeyPair = new RSAKeyPair(_keyfile, true);
                // we publish on the hash of both client and server keys so that if the handler is invoked there is already
                // a high-probability that the keyset will match.
                _publishUri = "/api/publish/" + Safe64Encoding.EncodeBytes(_rsaKeyPair.KeyPairHash.ToArray()) + "/";
            }
        }