Ejemplo n.º 1
0
        protected internal IMdContentProvider GetContentProvider()
        {
            // see if git is being used or just the file system
            // if the config has a value for gitUri then its git

            IMdContentProvider result = null;

            MdContentProviderType mdProviderType = fainting.goat.common.Config.GetContentProviderTypeFromConfig(this.Config);

            if (mdProviderType == MdContentProviderType.Git)
            {
                result = new GitMdContentProvier(
                    KernelManager.GetKernel().Get <GitHelper>(),
                    this.Config,
                    this.LocalRepoPath);
            }
            else if (mdProviderType == MdContentProviderType.FileSystem)
            {
                result = new FileSystemMdContentProvider();
            }
            else
            {
                string message = string.Format("Unknown MdContentProviderType [{0}]", mdProviderType);
                // TODO: Change provider type here
                throw new ApplicationException(message);
            }

            return(result);
        }
Ejemplo n.º 2
0
        public void StartAsyncTask(object workItemState)
        {
            IKernel         kernel     = KernelManager.GetKernel();
            IConfig         config     = kernel.Get <IConfig>();
            IPathHelper     pathHelper = kernel.Get <IPathHelper>();
            FullPathCleaner cleaner    = new FullPathCleaner(s => Context.Server.MapPath(s));

            string localPath    = cleaner.CleanPath(Context.Request.Url.AbsolutePath);
            string repoFilePath = pathHelper.ConvertMdUriToLocalPath(Context.Request.Url.AbsolutePath,
                                                                     s => cleaner.CleanPath(s));

            string fileToReturn = File.Exists(localPath) ? localPath : repoFilePath;

            // see if the file exists, if so we need to write it to the response
            if (File.Exists(fileToReturn))
            {
                var          objImage        = System.Drawing.Bitmap.FromFile(fileToReturn);
                MemoryStream objMemoryStream = new MemoryStream();
                objImage.Save(objMemoryStream, System.Drawing.Imaging.ImageFormat.Png);
                byte[] imageContent = new byte[objMemoryStream.Length];
                objMemoryStream.Position = 0;
                objMemoryStream.Read(imageContent, 0, (int)objMemoryStream.Length);
                Context.Response.ContentType = "image/png";
                Context.Response.BinaryWrite(imageContent);
            }
            else
            {
                Context.Response.StatusCode = 404;
            }

            Completed = true;
            Callback(this);
        }