Exemple #1
0
        public LinkCache(BindingSession session)
        {
            int repCount = session.GetValue(SessionParameter.CacheSizeRepositories, CacheSizeRepositories);
            if (repCount < 1)
            {
                repCount = CacheSizeRepositories;
            }

            int typeCount = session.GetValue(SessionParameter.CacheSizeTypes, CacheSizeTypes);
            if (typeCount < 1)
            {
                typeCount = CacheSizeTypes;
            }

            int objCount = session.GetValue(SessionParameter.CacheSizeLinks, CacheSizeLinks);
            if (objCount < 1)
            {
                objCount = CacheSizeLinks;
            }

            string dictionaryLevelName = typeof(DictionaryCacheLevel).FullName;
            string lruLevelName = typeof(LruCacheLevel).FullName;
            string contentTypeLevelName = typeof(DictionaryCacheLevel).FullName;

            linkCache = new Cache("Link Cache");
            linkCache.Initialize(new string[] {
                dictionaryLevelName + " " + DictionaryCacheLevel.Capacity + "=" + repCount.ToString(), // repository
                lruLevelName + " " + LruCacheLevel.MaxEntries + "=" + objCount.ToString(), // id
                dictionaryLevelName + " " + DictionaryCacheLevel.Capacity + "=16", // rel
                contentTypeLevelName + " " + DictionaryCacheLevel.Capacity + "=3,"
                        + DictionaryCacheLevel.SingleValue + "=true" // type
        });

            typeLinkCache = new Cache("Type Link Cache");
            typeLinkCache.Initialize(new string[] {
                dictionaryLevelName + " " + DictionaryCacheLevel.Capacity + "=" + repCount.ToString(), // repository
                lruLevelName + " " + LruCacheLevel.MaxEntries + "=" + typeCount.ToString(), // id
                dictionaryLevelName + " " + DictionaryCacheLevel.Capacity + "=16", // rel
                contentTypeLevelName + " " + DictionaryCacheLevel.Capacity + "=3,"
                        + DictionaryCacheLevel.SingleValue + "=true"// type
        });

            collectionLinkCache = new Cache("Collection Link Cache");
            collectionLinkCache.Initialize(new string[] {
                dictionaryLevelName + " " + DictionaryCacheLevel.Capacity + "=" + repCount.ToString(), // repository
                dictionaryLevelName + " " + DictionaryCacheLevel.Capacity + "=8" // collection
        });

            templateCache = new Cache("URI Template Cache");
            templateCache.Initialize(new string[] {
                dictionaryLevelName + " " + DictionaryCacheLevel.Capacity + "=" + repCount.ToString(), // repository
                dictionaryLevelName + " " + DictionaryCacheLevel.Capacity + "=6" // type
        });

            repositoryLinkCache = new Cache("Repository Link Cache");
            repositoryLinkCache.Initialize(new string[] {
                dictionaryLevelName + " " + DictionaryCacheLevel.Capacity + "=" + repCount.ToString(), // repository
                dictionaryLevelName + " " + DictionaryCacheLevel.Capacity + "=6" // rel
        });
        }
Exemple #2
0
        private static Response Invoke(UrlBuilder url, String method, String contentType, Output writer, BindingSession session,
                                       int?offset, int?length, IDictionary <string, string> headers)
        {
            try
            {
                // log before connect
                if (DotCMISDebug.DotCMISSwitch.TraceInfo)
                {
                    Trace.WriteLine(method + " " + url);
                }

                // create connection
                HttpWebRequest conn = (HttpWebRequest)WebRequest.Create(url.Url);
                conn.Method    = method;
                conn.UserAgent = "Apache Chemistry DotCMIS";

                // timeouts
                int connectTimeout = session.GetValue(SessionParameter.ConnectTimeout, -2);
                if (connectTimeout >= -1)
                {
                    conn.Timeout = connectTimeout;
                }

                int readTimeout = session.GetValue(SessionParameter.ReadTimeout, -2);
                if (readTimeout >= -1)
                {
                    conn.ReadWriteTimeout = readTimeout;
                }

                // set content type
                if (contentType != null)
                {
                    conn.ContentType = contentType;
                }

                // set additional headers
                if (headers != null)
                {
                    foreach (KeyValuePair <string, string> header in headers)
                    {
                        conn.Headers.Add(header.Key, header.Value);
                    }
                }

                // authenticate
                IAuthenticationProvider authProvider = session.GetAuthenticationProvider();
                if (authProvider != null)
                {
                    conn.PreAuthenticate = true;
                    authProvider.Authenticate(conn);
                }

                // range
                if (offset != null && length != null)
                {
                    conn.AddRange(offset ?? 0, offset + length - 1 ?? 0);
                }
                else if (offset != null)
                {
                    conn.AddRange(offset ?? 0);
                }

                // compression
                string compressionFlag = session.GetValue(SessionParameter.Compression) as string;
                if (compressionFlag != null && compressionFlag.ToLower().Equals("true"))
                {
                    conn.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
                }

                // send data
                if (writer != null)
                {
                    conn.SendChunked = true;
                    Stream requestStream = conn.GetRequestStream();
                    writer(requestStream);
                    requestStream.Close();
                }

                // connect
                try
                {
                    HttpWebResponse response = (HttpWebResponse)conn.GetResponse();

                    if (authProvider != null)
                    {
                        authProvider.HandleResponse(response);
                    }

                    return(new Response(response));
                }
                catch (WebException we)
                {
                    return(new Response(we));
                }
            }
            catch (Exception e)
            {
                throw new CmisConnectionException("Cannot access " + url + ": " + e.Message, e);
            }
        }
Exemple #3
0
        private static Response Invoke(UrlBuilder url, String method, String contentType, Output writer, BindingSession session,
                long? offset, long? length, IDictionary<string, string> headers)
        {
            try
            {
                // log before connect
                if (DotCMISDebug.DotCMISSwitch.TraceInfo)
                {
                    Trace.WriteLine(method + " " + url);
                }

                // create connection           
                HttpWebRequest conn = (HttpWebRequest)WebRequest.Create(url.Url);
                conn.Method = method;
                conn.UserAgent = "Apache Chemistry DotCMIS";

                // timeouts
                int connectTimeout = session.GetValue(SessionParameter.ConnectTimeout, -2);
                if (connectTimeout >= -1)
                {
                    conn.Timeout = connectTimeout;
                }

                int readTimeout = session.GetValue(SessionParameter.ReadTimeout, -2);
                if (readTimeout >= -1)
                {
                    conn.ReadWriteTimeout = readTimeout;
                }

                // set content type
                if (contentType != null)
                {
                    conn.ContentType = contentType;
                }

                // set additional headers
                if (headers != null)
                {
                    foreach (KeyValuePair<string, string> header in headers)
                    {
                        conn.Headers.Add(header.Key, header.Value);
                    }
                }

                // authenticate
                IAuthenticationProvider authProvider = session.GetAuthenticationProvider();
                if (authProvider != null)
                {
                    conn.PreAuthenticate = true;
                    authProvider.Authenticate(conn);
                }

                // range
                if (offset != null && length != null)
                {
                    if (offset < Int32.MaxValue && offset + length - 1 < Int32.MaxValue)
                    {
                        conn.AddRange((int)offset, (int)offset + (int)length - 1);
                    }
                    else
                    {
                        try
                        {
                            MethodInfo mi = conn.GetType().GetMethod("AddRange", new Type[] { typeof(Int64), typeof(Int64) });
                            mi.Invoke(conn, new object[] { offset, offset + length - 1 });
                        }
                        catch (Exception e)
                        {
                            throw new CmisInvalidArgumentException("Offset or length too big!", e);
                        }
                    }
                }
                else if (offset != null)
                {
                    if (offset < Int32.MaxValue)
                    {
                        conn.AddRange((int)offset);
                    }
                    else
                    {
                        try
                        {
                            MethodInfo mi = conn.GetType().GetMethod("AddRange", new Type[] { typeof(Int64) });
                            mi.Invoke(conn, new object[] { offset });
                        }
                        catch (Exception e)
                        {
                            throw new CmisInvalidArgumentException("Offset too big!", e);
                        }
                    }
                }

                // compression
                string compressionFlag = session.GetValue(SessionParameter.Compression) as string;
                if (compressionFlag != null && compressionFlag.ToLower().Equals("true"))
                {
                    conn.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
                }

                // send data
                if (writer != null)
                {
                    conn.SendChunked = true;
                    Stream requestStream = conn.GetRequestStream();
                    writer(requestStream);
                    requestStream.Close();
                }
                else
                {
#if __MonoCS__
                    //around for MONO HTTP DELETE issue
                    //http://stackoverflow.com/questions/11785597/monotouch-iphone-call-to-httpwebrequest-getrequeststream-connects-to-server
                    if (method == "DELETE")
                    {
                        conn.ContentLength = 0;
                        Stream requestStream = conn.GetRequestStream();
                        requestStream.Close();
                    }
#endif
                }

                // connect
                try
                {
                    HttpWebResponse response = (HttpWebResponse)conn.GetResponse();

                    if (authProvider != null)
                    {
                        authProvider.HandleResponse(response);
                    }

                    return new Response(response);
                }
                catch (WebException we)
                {
                    return new Response(we);
                }
            }
            catch (Exception e)
            {
                throw new CmisConnectionException("Cannot access " + url + ": " + e.Message, e);
            }
        }
Exemple #4
0
        private static Response Invoke(UrlBuilder url, String method, String contentType, Output writer, BindingSession session,
            long? offset, long? length, IDictionary<string, string> headers)
        {
            try
            {
                // log before connect
                if (DotCMISDebug.DotCMISSwitch.TraceInfo)
                {
                    Trace.WriteLine(method + " " + url);
                }

                // create connection
                HttpWebRequest conn = (HttpWebRequest)WebRequest.Create(url.Url);
                conn.Method = method;
                conn.UserAgent = "Apache Chemistry DotCMIS";

                // timeouts
                int connectTimeout = session.GetValue(SessionParameter.ConnectTimeout, -2);
                if (connectTimeout >= -1)
                {
                    conn.Timeout = connectTimeout;
                }

                int readTimeout = session.GetValue(SessionParameter.ReadTimeout, -2);
                if (readTimeout >= -1)
                {
                    conn.ReadWriteTimeout = readTimeout;
                }

                // set content type
                if (contentType != null)
                {
                    conn.ContentType = contentType;
                }

                // set additional headers
                if (headers != null)
                {
                    foreach (KeyValuePair<string, string> header in headers)
                    {
                        conn.Headers.Add(header.Key, header.Value);
                    }
                }

                // authenticate
                IAuthenticationProvider authProvider = session.GetAuthenticationProvider();
                if (authProvider != null)
                {
                    conn.PreAuthenticate = true;
                    authProvider.Authenticate(conn);
                }

                // range
                if (offset != null && length != null)
                {
                    if (offset < Int32.MaxValue && offset + length - 1 < Int32.MaxValue)
                    {
                        conn.AddRange((int)offset, (int)offset + (int)length - 1);
                    }
                    else
                    {
                        try
                        {
                            MethodInfo mi = conn.GetType().GetMethod("AddRange", new Type[] { typeof(Int64), typeof(Int64) });
                            mi.Invoke(conn, new object[] { offset, offset + length - 1 });
                        }
                        catch (Exception e)
                        {
                            throw new CmisInvalidArgumentException("Offset or length too big!", e);
                        }
                    }
                }
                else if (offset != null)
                {
                    if (offset < Int32.MaxValue)
                    {
                        conn.AddRange((int)offset);
                    }
                    else
                    {
                        try
                        {
                            MethodInfo mi = conn.GetType().GetMethod("AddRange", new Type[] { typeof(Int64) });
                            mi.Invoke(conn, new object[] { offset });
                        }
                        catch (Exception e)
                        {
                            throw new CmisInvalidArgumentException("Offset too big!", e);
                        }
                    }
                }

                // compression
                string compressionFlag = session.GetValue(SessionParameter.Compression) as string;
                if (compressionFlag != null && compressionFlag.ToLower().Equals("true"))
                {
                    conn.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
                }

                // send data
                if (writer != null)
                {
                    conn.SendChunked = true;
                    Stream requestStream = conn.GetRequestStream();
                    writer(requestStream);
                    requestStream.Close();
                }
                else
                {
            #if __MonoCS__
                    //around for MONO HTTP DELETE issue
                    //http://stackoverflow.com/questions/11785597/monotouch-iphone-call-to-httpwebrequest-getrequeststream-connects-to-server
                    if (method == "DELETE")
                    {
                        conn.ContentLength = 0;
                        Stream requestStream = conn.GetRequestStream();
                        requestStream.Close();
                    }
            #endif
                }

                // connect
                try
                {
                    HttpWebResponse response = (HttpWebResponse)conn.GetResponse();

                    if (authProvider != null)
                    {
                        authProvider.HandleResponse(response);
                    }

                    return new Response(response);
                }
                catch (WebException we)
                {
                    return new Response(we);
                }
            }
            catch (Exception e)
            {
                throw new CmisConnectionException("Cannot access " + url + ": " + e.Message, e);
            }
        }
Exemple #5
0
        public TypeDefinitionCache(BindingSession session)
        {
            int repCount = session.GetValue(SessionParameter.CacheSizeRepositories, CacheSizeRepositories);
            if (repCount < 1)
            {
                repCount = CacheSizeRepositories;
            }

            int typeCount = session.GetValue(SessionParameter.CacheSizeTypes, CacheSizeTypes);
            if (typeCount < 1)
            {
                typeCount = CacheSizeTypes;
            }

            cache = new Cache("Type Definition Cache");
            cache.Initialize(new string[] {
                typeof(DictionaryCacheLevel).FullName + " " + DictionaryCacheLevel.Capacity + "=" + repCount, // repository
                typeof(LruCacheLevel).FullName + " " + LruCacheLevel.MaxEntries + "=" + typeCount // type
        });
        }
Exemple #6
0
        public RepositoryInfoCache(BindingSession session)
        {
            int repCount = session.GetValue(SessionParameter.CacheSizeRepositories, CacheSizeRepositories);
            if (repCount < 1)
            {
                repCount = CacheSizeRepositories;
            }

            cache = new Cache("Repository Info Cache");
            cache.Initialize(new string[] { 
                typeof(DictionaryCacheLevel).FullName + " " + DictionaryCacheLevel.Capacity + "=" + repCount });
        }
Exemple #7
0
        private static Response Invoke(UrlBuilder url, String method, String contentType, Output writer, BindingSession session,
                int? offset, int? length, IDictionary<string, string> headers)
        {
            try
            {
                // log before connect
                if (DotCMISDebug.DotCMISSwitch.TraceInfo)
                {
                    Trace.WriteLine(method + " " + url);
                }

                // create connection           
                HttpWebRequest conn = (HttpWebRequest)WebRequest.Create(url.Url);
                conn.Method = method;
                conn.UserAgent = "Apache Chemistry DotCMIS";

                // timeouts
                int connectTimeout = session.GetValue(SessionParameter.ConnectTimeout, -2);
                if (connectTimeout >= -1)
                {
                    conn.Timeout = connectTimeout;
                }

                int readTimeout = session.GetValue(SessionParameter.ReadTimeout, -2);
                if (readTimeout >= -1)
                {
                    conn.ReadWriteTimeout = readTimeout;
                }

                // set content type
                if (contentType != null)
                {
                    conn.ContentType = contentType;
                }

                // set additional headers
                if (headers != null)
                {
                    foreach (KeyValuePair<string, string> header in headers)
                    {
                        conn.Headers.Add(header.Key, header.Value);
                    }
                }

                // authenticate
                IAuthenticationProvider authProvider = session.GetAuthenticationProvider();
                if (authProvider != null)
                {
                    conn.PreAuthenticate = true;
                    authProvider.Authenticate(conn);
                }

                // range
                if (offset != null && length != null)
                {
                    conn.AddRange(offset ?? 0, offset + length - 1 ?? 0);
                }
                else if (offset != null)
                {
                    conn.AddRange(offset ?? 0);
                }

                // compression
                string compressionFlag = session.GetValue(SessionParameter.Compression) as string;
                if (compressionFlag != null && compressionFlag.ToLower().Equals("true"))
                {
                    conn.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
                }

                // send data
                if (writer != null)
                {
                    conn.SendChunked = true;
                    Stream requestStream = conn.GetRequestStream();
                    writer(requestStream);
                    requestStream.Close();
                }

                // connect
                try
                {
                    HttpWebResponse response = (HttpWebResponse)conn.GetResponse();

                    if (authProvider != null)
                    {
                        authProvider.HandleResponse(response);
                    }

                    return new Response(response);
                }
                catch (WebException we)
                {
                    return new Response(we);
                }
            }
            catch (Exception e)
            {
                throw new CmisConnectionException("Cannot access " + url + ": " + e.Message, e);
            }
        }
Exemple #8
0
        private static Response Invoke(UrlBuilder url, String method, String contentType, Output writer, BindingSession session,
                                       long?offset, long?length, IDictionary <string, string> headers)
        {
            try
            {
                // log before connect
                if (DotCMISDebug.DotCMISSwitch.TraceInfo)
                {
                    Trace.WriteLine(method + " " + url);
                }

                // create connection
                HttpWebRequest conn = (HttpWebRequest)WebRequest.Create(url.Url);
                conn.Method    = method;
                conn.UserAgent = "Apache Chemistry DotCMIS";

                // timeouts
                int connectTimeout = session.GetValue(SessionParameter.ConnectTimeout, -2);
                if (connectTimeout >= -1)
                {
                    conn.Timeout = connectTimeout;
                }

                int readTimeout = session.GetValue(SessionParameter.ReadTimeout, -2);
                if (readTimeout >= -1)
                {
                    conn.ReadWriteTimeout = readTimeout;
                }

                //KaliConseil addition start
                ServicePointManager.DefaultConnectionLimit = 1000;
                conn.ServicePoint.Expect100Continue        = false;
                conn.KeepAlive                 = true;
                conn.Timeout                   = System.Threading.Timeout.Infinite;
                conn.ProtocolVersion           = HttpVersion.Version10;
                conn.AllowWriteStreamBuffering = false;

                if (DotCMIS.ProxyParameters.GlbProxyMode == 0) //No proxy
                {
                    conn.Proxy = null;
                }
                else if (DotCMIS.ProxyParameters.GlbProxyMode == 1) //Autoproxy (IE)
                {
                    IWebProxy webProxy = WebRequest.DefaultWebProxy;
                    webProxy.Credentials = CredentialCache.DefaultNetworkCredentials;
                    conn.Proxy           = webProxy;
                }
                else if (DotCMIS.ProxyParameters.GlbProxyMode == 2) //Custom proxy
                {
                    WebProxy webProxy2 = new WebProxy(DotCMIS.ProxyParameters.GlbProxyURL);
                    webProxy2.BypassProxyOnLocal = false;

                    if (DotCMIS.ProxyParameters.GlbProxyAuthentication)
                    {
                        webProxy2.Credentials = new NetworkCredential(DotCMIS.ProxyParameters.GlbProxyLogin, DotCMIS.ProxyParameters.GlbProxyPassword);
                    }

                    conn.Proxy = webProxy2;
                }
                ////KaliConseil addition end

                // set content type
                if (contentType != null)
                {
                    conn.ContentType = contentType;
                }

                // set additional headers
                if (headers != null)
                {
                    foreach (KeyValuePair <string, string> header in headers)
                    {
                        conn.Headers.Add(header.Key, header.Value);
                    }
                }

                // authenticate
                IAuthenticationProvider authProvider = session.GetAuthenticationProvider();
                if (authProvider != null)
                {
                    conn.PreAuthenticate = true;
                    authProvider.Authenticate(conn);
                }

                // range
                if (offset != null && length != null)
                {
                    if (offset < Int32.MaxValue && offset + length - 1 < Int32.MaxValue)
                    {
                        conn.AddRange((int)offset, (int)offset + (int)length - 1);
                    }
                    else
                    {
                        try
                        {
                            MethodInfo mi = conn.GetType().GetMethod("AddRange", new Type[] { typeof(Int64), typeof(Int64) });
                            mi.Invoke(conn, new object[] { offset, offset + length - 1 });
                        }
                        catch (Exception e)
                        {
                            throw new CmisInvalidArgumentException("Offset or length too big!", e);
                        }
                    }
                }
                else if (offset != null)
                {
                    if (offset < Int32.MaxValue)
                    {
                        conn.AddRange((int)offset);
                    }
                    else
                    {
                        try
                        {
                            MethodInfo mi = conn.GetType().GetMethod("AddRange", new Type[] { typeof(Int64) });
                            mi.Invoke(conn, new object[] { offset });
                        }
                        catch (Exception e)
                        {
                            throw new CmisInvalidArgumentException("Offset too big!", e);
                        }
                    }
                }

                // compression
                string compressionFlag = session.GetValue(SessionParameter.Compression) as string;
                if (compressionFlag != null && compressionFlag.ToLower().Equals("true"))
                {
                    conn.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
                }

                // send data
                if (writer != null)
                {
                    conn.SendChunked = true;
                    System.IO.Stream requestStream = conn.GetRequestStream();
                    writer(requestStream);
                    requestStream.Close();
                }
                else
                {
#if __MonoCS__
                    //around for MONO HTTP DELETE issue
                    //http://stackoverflow.com/questions/11785597/monotouch-iphone-call-to-httpwebrequest-getrequeststream-connects-to-server
                    if (method == "DELETE")
                    {
                        conn.ContentLength = 0;
                        Stream requestStream = conn.GetRequestStream();
                        requestStream.Close();
                    }
#endif
                }

                // connect
                try
                {
                    HttpWebResponse response = (HttpWebResponse)conn.GetResponse();

                    if (authProvider != null)
                    {
                        authProvider.HandleResponse(response);
                    }

                    return(new Response(response));
                }
                catch (WebException we)
                {
                    return(new Response(we));
                }
            }
            catch (Exception e)
            {
                throw new CmisConnectionException("Cannot access " + url + ": " + e.Message, e);
            }
        }