public SqlPersistenceProviderFactory(string connectionString, bool serializeAsText, TimeSpan lockTimeout)
 {
     this.ConnectionString = connectionString;
     this.LockTimeout = lockTimeout;
     this.SerializeAsText = serializeAsText;
     this.loadHandler = new LoadHandler(this);
     this.createHandler = new CreateHandler(this);
     this.updateHandler = new UpdateHandler(this);
     this.unlockHandler = new UnlockHandler(this);
     this.deleteHandler = new DeleteHandler(this);
 }
Exemplo n.º 2
0
    static AssetLocker()
    {
        EditorApplication.update   += Update;
        Selection.selectionChanged += OnSelectionChanged;

        add       = new AddHandler();
        isTracked = new IsTrackedHandler();
        lck       = new LockHandler();
        unlock    = new UnlockHandler();
        isLocked  = new IsLockedHandler();
        getInfo   = new GetInfoHandler();

        lockedInfo = new Dictionary <string, Asset>();
        Debug.Log("AssetLocker initialized");
    }
Exemplo n.º 3
0
        private void HandleConnection(Socket sock)
        {
            NetworkStream stream    = new NetworkStream(sock);
            string        line      = null;
            bool          error     = false;
            bool          keepAlive = false;
            DateTime      startTime = DateTime.Now;

            sock.ReceiveTimeout      = RequestHandler.Timeout * 100;
            sock.Blocking            = false;
            sock.NoDelay             = true;
            sock.SendBufferSize      = 16 * 1024;
            sock.UseOnlyOverlappedIO = true;

            string type = "";
            string path = "";

            do
            {
                bool           first   = true;
                RequestHandler handler = null;

                do
                {
                    line = null;
                    try
                    {
                        line             = ReadLine(stream);
                        BytesReadHeader += line.Length + 2;
                    }
                    catch (ThreadAbortException e)
                    {
                        keepAlive = false;
                        error     = true;
                        break;
                    }
                    catch (IOException e)
                    {
                        keepAlive = false;
                        error     = true;
                        break;
                    }
                    catch (Exception e)
                    {
                        keepAlive = false;
                        error     = true;
                        break;
                    }

                    /* connection timed out or closed */
                    if (line == null)
                    {
                        sock.Close();
                        LogRequest("  (Socket closed)");
                        return;
                    }

                    if (first)
                    {
                        LogRequest("  (Connection from " + sock.RemoteEndPoint + ")");
                    }
                    LogRequest("< " + line);

                    /* not an empty line? */
                    if (line != "")
                    {
                        /* the first line contains the request */
                        if (first)
                        {
                            if (line.Contains(' '))
                            {
                                type = line.Substring(0, line.IndexOf(' '));
                                path = line.Substring(line.IndexOf(' ')).Trim();
                                try
                                {
                                    switch (type)
                                    {
                                    case "OPTIONS":
                                        handler = new OptionsHandler(this, path);
                                        break;

                                    case "PROPFIND":
                                        handler = new PropFindHandler(this, path);
                                        break;

                                    case "GET":
                                        handler = new GetHandler(this, path);
                                        break;

                                    case "HEAD":
                                        handler = new HeadHandler(this, path);
                                        break;

                                    case "PUT":
                                        handler = new PutHandler(this, path);
                                        break;

                                    case "LOCK":
                                        handler = new LockHandler(this, path);
                                        break;

                                    case "UNLOCK":
                                        handler = new UnlockHandler(this, path);
                                        break;

                                    case "DELETE":
                                        handler = new DeleteHandler(this, path);
                                        break;

                                    case "MOVE":
                                        handler = new MoveHandler(this, path);
                                        break;

                                    case "COPY":
                                        handler = new CopyHandler(this, path);
                                        break;

                                    case "MKCOL":
                                        handler = new MkColHandler(this, path);
                                        break;

                                    case "PROPPATCH":
                                        handler = new PropPatchHandler(this, path);
                                        break;

                                    default:
                                        handler = new RequestHandler(this, "/");
                                        break;
                                    }
                                }
                                catch (IOException e)
                                {
                                    Log("[i] Connection from " + sock.RemoteEndPoint + " (" + type + ") had IOException");
                                }
                                catch (Exception e)
                                {
                                    Log("[E] '" + e.GetType().ToString() + "' in connection from " + sock.RemoteEndPoint + " (" + type + ")");
                                }
                            }

                            first = false;
                        }
                        else
                        {
                            try
                            {
                                handler.AddHeaderLine(line);
                            }
                            catch (IOException e)
                            {
                                /* just close */
                                sock.Close();
                                LogRequest("  (Socket closed)");
                                return;
                            }
                            catch (Exception e)
                            {
                                Log("[E] '" + e.GetType().ToString() + "' in connection from " + sock.RemoteEndPoint + " (AddHeaderLine)");
                            }
                            //stream.Flush();
                        }
                    }
                } while (line != "");

                if (handler == null)
                {
                    Log("[E] Empty request in connection from " + sock.RemoteEndPoint + " (HandleContent/HandleRequest)");
                    handler.KeepAlive = false;
                    return;
                }

                if (!error)
                {
                    try
                    {
                        if (handler.RequestContentLength > 0)
                        {
                            handler.HandleContent(stream);
                        }

                        handler.HandleRequest(stream);
                        stream.Flush();
                    }
                    catch (FileNotFoundException e)
                    {
                        Log("[E] 404 '" + e.GetType().ToString() + ": " + e.Message + "' in connection from " + sock.RemoteEndPoint + " (HandleContent/HandleRequest)");

                        /* respond with error */
                        handler            = new RequestHandler(this, "/");
                        handler.StatusCode = RequestHandler.GetStatusCode(404);
                        handler.KeepAlive  = false;
                        handler.HandleRequest(stream);
                        stream.Flush();
                    }
                    catch (SocketException e)
                    {
                        Log("[E] '" + e.GetType().ToString() + ": " + e.Message + "' in connection from " + sock.RemoteEndPoint + " (HandleContent/HandleRequest)");
                        handler.KeepAlive = false;
                        return;
                    }
                    catch (UnauthorizedAccessException e)
                    {
                        Log("[i] 403 '" + e.GetType().ToString() + ": " + e.Message + "' in connection from " + sock.RemoteEndPoint + " (HandleContent/HandleRequest)");

                        /* respond with error */
                        handler            = new RequestHandler(this, "/");
                        handler.StatusCode = RequestHandler.GetStatusCode(403);
                        handler.KeepAlive  = false;
                        handler.HandleRequest(stream);
                        stream.Flush();
                    }
                    catch (Exception e)
                    {
                        Log("[E] 500 '" + e.GetType().ToString() + ": " + e.Message + "' in connection from " + sock.RemoteEndPoint + " (HandleContent/HandleRequest)");

                        /* respond with error */
                        handler            = new RequestHandler(this, "/");
                        handler.StatusCode = RequestHandler.GetStatusCode(500);
                        handler.KeepAlive  = false;
                        handler.HandleRequest(stream);
                        stream.Flush();
                    }


                    if (EnableRequestLog)
                    {
                        DateTime endTime = DateTime.Now;
                        Log("[i] Connection from " + sock.RemoteEndPoint + " (" + type + " " + path + ") took " + (endTime - startTime).TotalMilliseconds + " ms (" + handler.StatusCode + ")");
                    }
                    LogRequest("");

                    lock (StatisticsLock)
                    {
                        BytesWrittenHeader += handler.BytesWrittenHeader;
                        BytesWrittenData   += handler.BytesWrittenData;
                        BytesReadHeader    += handler.BytesReadHeader;
                        BytesReadData      += handler.BytesReadData;
                    }

                    keepAlive = handler.KeepAlive;

                    /* windows isnt really using keepalive :( */
                    keepAlive = false;
                }
            } while (keepAlive);

            sock.Close();
            LogRequest("  (Socket closed)");
        }
        public SqlPersistenceProviderFactory(NameValueCollection parameters)
        {
            if (parameters == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("parameters");
            }

            this.connectionString = null;
            this.LockTimeout = TimeSpan.Zero;
            this.SerializeAsText = false;

            foreach (string key in parameters.Keys)
            {
                switch (key)
                {
                    case connectionStringNameParameter:
                        ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings[parameters[key]];

                        if (settings == null)
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(
                                SR2.GetString(SR2.ConnectionStringNameIncorrect, parameters[key]));
                        }

                        this.connectionString = settings.ConnectionString;
                        break;
                    case serializeAsTextParameter:
                        this.SerializeAsText = bool.Parse(parameters[key]);
                        break;
                    case lockTimeoutParameter:
                        this.LockTimeout = TimeSpan.Parse(parameters[key], CultureInfo.InvariantCulture);
                        break;
                    default:
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(
                            key,
                            SR2.GetString(SR2.UnknownSqlPersistenceConfigurationParameter, key, connectionStringNameParameter, serializeAsTextParameter, lockTimeoutParameter));
                }
            }

            if (this.connectionString == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(
                    SR2.GetString(SR2.ConnectionStringNameParameterRequired, connectionStringNameParameter));
            }

            this.loadHandler = new LoadHandler(this);
            this.createHandler = new CreateHandler(this);
            this.updateHandler = new UpdateHandler(this);
            this.unlockHandler = new UnlockHandler(this);
            this.deleteHandler = new DeleteHandler(this);
        }