示例#1
0
        static void Init()
        {
            string contentRootPath = Directory.GetParent(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath)).FullName;
            string logPath         = Path.Combine(contentRootPath, @"App_Data\WebDav\Logs");

            logger.LogFile        = Path.Combine(logPath, "WebDAVlog.txt");
            logger.IsDebugEnabled = debugLoggingEnabled;

            webDavEngine = new DavEngineAsync
            {
                Logger = logger

                         // Use idented responses if debug logging is enabled.
                , OutputXmlFormatting = true
            };

            /// This license lile is used to activate:
            ///  - IT Hit WebDAV Server Engine for .NET
            ///  - IT Hit iCalendar and vCard Library if used in a project
            string license = File.ReadAllText(Path.Combine(contentRootPath, "License.lic"));

            webDavEngine.License = license;

            /// This license file is used to activate G Suite Documents Editing for IT Hit WebDAV Server
            string gSuiteLicense = File.Exists(Path.Combine(contentRootPath, "GSuiteLicense.lic")) ? File.ReadAllText(Path.Combine(contentRootPath, "GSuiteLicense.lic")) : string.Empty;

            if (!string.IsNullOrEmpty(gSuiteLicense))
            {
                gSuiteEngine = new GSuiteEngineAsync(googleServiceAccountID, googleServicePrivateKey, googleNotificationsRelativeUrl)
                {
                    License = gSuiteLicense,
                    Logger  = logger
                };
            }

            // Set custom handler to process GET and HEAD requests to folders and display
            // info about how to connect to server. We are using the same custom handler
            // class (but different instances) here to process both GET and HEAD because
            // these requests are very similar. Some WebDAV clients may fail to connect if HEAD
            // request is not processed.
            MyCustomGetHandler handlerGet  = new MyCustomGetHandler(contentRootPath);
            MyCustomGetHandler handlerHead = new MyCustomGetHandler(contentRootPath);

            handlerGet.OriginalHandler  = webDavEngine.RegisterMethodHandler("GET", handlerGet);
            handlerHead.OriginalHandler = webDavEngine.RegisterMethodHandler("HEAD", handlerHead);
            string attrStoragePath = (ConfigurationManager.AppSettings["AttrStoragePath"] ?? string.Empty).TrimEnd(Path.DirectorySeparatorChar);

            if (!string.IsNullOrEmpty(attrStoragePath))
            {
                FileSystemInfoExtension.UseFileSystemAttribute(new FileSystemExtendedAttribute(attrStoragePath, repositoryPath));
            }
            else if (!(new DirectoryInfo(repositoryPath).IsExtendedAttributesSupported()))
            {
                var tempPath = Path.Combine(Path.GetTempPath(), System.Reflection.Assembly.GetExecutingAssembly().GetName().Name);
                FileSystemInfoExtension.UseFileSystemAttribute(new FileSystemExtendedAttribute(tempPath, repositoryPath));
            }
        }
示例#2
0
        /// <summary>
        /// Enables processing of HTTP Web requests.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpContext"/> object that provides references to the
        /// intrinsic server objects (for example, Request, Response, Session, and Server) used to service
        /// HTTP requests.
        /// </param>
        public override async Task ProcessRequestAsync(HttpContext context)
        {
            DavEngineAsync webDavEngine = getOrInitializeWebDavEngine(context);

            context.Response.BufferOutput = false;
            DavContext        ntfsDavContext = new DavContext(context);
            GSuiteEngineAsync gSuiteEngine   = getOrInitializeGSuiteEngine(context);
            await webDavEngine.RunAsync(ntfsDavContext);

            if (gSuiteEngine != null)
            {
                await gSuiteEngine.RunAsync(ContextConverter.ConvertToGSuiteContext(ntfsDavContext));
            }
        }
示例#3
0
        static void Init()
        {
            string contentRootPath = Directory.GetParent(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath)).FullName;
            string logPath         = Path.Combine(contentRootPath, @"App_Data\WebDav\Logs");

            logger.LogFile        = Path.Combine(logPath, "WebDAVlog.txt");
            logger.IsDebugEnabled = debugLoggingEnabled;

            webDavEngine = new DavEngineAsync
            {
                Logger = logger

                         // Use idented responses if debug logging is enabled.
                , OutputXmlFormatting = true
            };

            /// This license lile is used to activate:
            ///  - IT Hit WebDAV Server Engine for .NET
            ///  - IT Hit iCalendar and vCard Library if used in a project
            string license = File.ReadAllText(Path.Combine(contentRootPath, "License.lic"));

            webDavEngine.License = license;

            /// This license file is used to activate G Suite Documents Editing for IT Hit WebDAV Server
            string gSuiteLicense = File.ReadAllText(Path.Combine(contentRootPath, "GSuiteLicense.lic"));

            gSuiteEngine = new GSuiteEngineAsync(googleServiceAccountID, googleServicePrivateKey)
            {
                License = gSuiteLicense,
                Logger  = logger
            };

            // Set custom handler to process GET and HEAD requests to folders and display
            // info about how to connect to server. We are using the same custom handler
            // class (but different instances) here to process both GET and HEAD because
            // these requests are very similar. Some WebDAV clients may fail to connect if HEAD
            // request is not processed.
            MyCustomGetHandler handlerGet  = new MyCustomGetHandler(contentRootPath);
            MyCustomGetHandler handlerHead = new MyCustomGetHandler(contentRootPath);

            handlerGet.OriginalHandler  = webDavEngine.RegisterMethodHandler("GET", handlerGet);
            handlerHead.OriginalHandler = webDavEngine.RegisterMethodHandler("HEAD", handlerHead);
        }
示例#4
0
        /// <summary>
        /// Initializes or gets engine singleton.
        /// </summary>
        /// <param name="context">Instance of <see cref="HttpContext"/>.</param>
        /// <returns>Instance of <see cref="GSuiteEngineAsync"/>.</returns>
        private GSuiteEngineAsync getOrInitializeGSuiteEngine(HttpContext context)
        {
            //we don't use any double check lock pattern here because nothing wrong
            //is going to happen if we created occasionally several engines.
            const string ENGINE_KEY = "$GSuiteEngine$";

            if (string.IsNullOrEmpty(googleServiceAccountID) || string.IsNullOrEmpty(googleServicePrivateKey))
            {
                return(null);
            }

            if (context.Application[ENGINE_KEY] == null)
            {
                var gSuiteEngine = new GSuiteEngineAsync(googleServiceAccountID, googleServicePrivateKey, googleNotificationsRelativeUrl)
                {
                    License = gSuiteLicense,
                    Logger  = WebDAVServer.FileSystemStorage.AspNet.Logger.Instance
                };

                context.Application[ENGINE_KEY] = gSuiteEngine;
            }

            return((GSuiteEngineAsync)context.Application[ENGINE_KEY]);
        }