Beispiel #1
0
        private void InitializeCommandsDictionary()
        {
            _handlers.Add("" + COMMANDS.Save,
                          (p, ret) =>
            {
                var m  = GetSave(p.Data.GetType());
                ret.OK = true;
                m.Invoke(_raptor, new object[] { p.Docid, p.Data });
            });

            _handlers.Add("" + COMMANDS.SaveBytes,
                          (p, ret) =>
            {
                ret.OK = _raptor.SaveBytes(p.Docid, (byte[])p.Data);
            });

            _handlers.Add("" + COMMANDS.QueryType,
                          (p, ret) =>
            {
                var param       = (object[])p.Data;
                Type t          = Type.GetType((string)param[0]);
                string viewname = _raptor.GetViewName(t);
                ret.OK          = true;
                ret.Data        = _raptor.Query(viewname, (string)param[1], p.Start, p.Count, p.OrderBy);
            });

            _handlers.Add("" + COMMANDS.QueryStr,
                          (p, ret) =>
            {
                ret.OK   = true;
                ret.Data = _raptor.Query(p.Viewname, (string)p.Data, p.Start, p.Count, p.OrderBy);
            });

            _handlers.Add("" + COMMANDS.Fetch,
                          (p, ret) =>
            {
                ret.OK   = true;
                ret.Data = _raptor.Fetch(p.Docid);
            });

            _handlers.Add("" + COMMANDS.FetchBytes,
                          (p, ret) =>
            {
                ret.OK   = true;
                ret.Data = _raptor.FetchBytes(p.Docid);
            });

            _handlers.Add("" + COMMANDS.Backup,
                          (p, ret) =>
            {
                ret.OK = _raptor.Backup();
            });

            _handlers.Add("" + COMMANDS.Delete,
                          (p, ret) =>
            {
                ret.OK = _raptor.Delete(p.Docid);
            });

            _handlers.Add("" + COMMANDS.DeleteBytes,
                          (p, ret) =>
            {
                ret.OK = _raptor.DeleteBytes(p.Docid);
            });

            _handlers.Add("" + COMMANDS.Restore,
                          (p, ret) =>
            {
                ret.OK = true;
                Task.Factory.StartNew(() => _raptor.Restore());
            });

            _handlers.Add("" + COMMANDS.AddUser,
                          (p, ret) =>
            {
                var param = (object[])p.Data;
                ret.OK    = AddUser((string)param[0], (string)param[1], (string)param[2]);
            });

            _handlers.Add("" + COMMANDS.ServerSide,
                          (p, ret) =>
            {
                var param = (object[])p.Data;
                ret.OK    = true;
                ret.Data  = _raptor.ServerSide(GetServerSideFuncCache(param[0].ToString(), param[1].ToString()), param[2].ToString());
            });

            _handlers.Add("" + COMMANDS.FullText,
                          (p, ret) =>
            {
                var param = (object[])p.Data;
                ret.OK    = true;
                ret.Data  = _raptor.FullTextSearch("" + param[0]);
            });

            _handlers.Add("" + COMMANDS.CountType,
                          (p, ret) =>
            {
                // count type
                var param        = (object[])p.Data;
                Type t           = Type.GetType((string)param[0]);
                string viewname2 = _raptor.GetViewName(t);
                ret.OK           = true;
                ret.Data         = _raptor.Count(viewname2, (string)param[1]);
            });

            _handlers.Add("" + COMMANDS.CountStr,
                          (p, ret) =>
            {
                // count str
                ret.OK   = true;
                ret.Data = _raptor.Count(p.Viewname, (string)p.Data);
            });

            _handlers.Add("" + COMMANDS.GCount,
                          (p, ret) =>
            {
                Type t           = Type.GetType(p.Viewname);
                string viewname3 = _raptor.GetViewName(t);
                ret.OK           = true;
                ret.Data         = _raptor.Count(viewname3, (string)p.Data);
            });

            _handlers.Add("" + COMMANDS.DocHistory,
                          (p, ret) =>
            {
                ret.OK   = true;
                ret.Data = _raptor.FetchHistory(p.Docid);
            });

            _handlers.Add("" + COMMANDS.FileHistory,
                          (p, ret) =>
            {
                ret.OK   = true;
                ret.Data = _raptor.FetchBytesHistory(p.Docid);
            });

            _handlers.Add("" + COMMANDS.FetchVersion,
                          (p, ret) =>
            {
                ret.OK   = true;
                ret.Data = _raptor.FetchVersion((int)p.Data);
            });

            _handlers.Add("" + COMMANDS.FetchFileVersion,
                          (p, ret) =>
            {
                ret.OK   = true;
                ret.Data = _raptor.FetchBytesVersion((int)p.Data);
            });

            _handlers.Add("" + COMMANDS.CheckAssembly,
                          (p, ret) =>
            {
                ret.OK     = true;
                string typ = "";
                ret.Data   = _raptor.GetAssemblyForView(p.Viewname, out typ);
                ret.Error  = typ;
            });
            _handlers.Add("" + COMMANDS.FetchHistoryInfo,
                          (p, ret) =>
            {
                ret.OK   = true;
                ret.Data = _raptor.FetchHistoryInfo(p.Docid);
            });

            _handlers.Add("" + COMMANDS.FetchByteHistoryInfo,
                          (p, ret) =>
            {
                ret.OK   = true;
                ret.Data = _raptor.FetchBytesHistoryInfo(p.Docid);
            });

            _handlers.Add("" + COMMANDS.ViewDelete,
                          (p, ret) =>
            {
                ret.OK    = true;
                var param = (object[])p.Data;
                ret.Data  = _raptor.ViewDelete((string)param[0], (string)param[1]);
            });

            _handlers.Add("" + COMMANDS.ViewDelete_t,
                          (p, ret) =>
            {
                ret.OK           = true;
                var param        = (object[])p.Data;
                Type t           = Type.GetType((string)param[0]);
                string viewname4 = _raptor.GetViewName(t);
                ret.Data         = _raptor.ViewDelete(viewname4, (string)param[1]);
            });

            _handlers.Add("" + COMMANDS.ViewInsert,
                          (p, ret) =>
            {
                ret.OK    = true;
                var param = (object[])p.Data;
                ret.Data  = _raptor.ViewInsert((string)param[0], p.Docid, param[1]);
            });

            _handlers.Add("" + COMMANDS.ViewInsert_t,
                          (p, ret) =>
            {
                ret.OK           = true;
                var param        = (object[])p.Data;
                Type t           = Type.GetType((string)param[0]);
                string viewname5 = _raptor.GetViewName(t);
                ret.Data         = _raptor.ViewInsert(viewname5, p.Docid, param[1]);
            });

            _handlers.Add("" + COMMANDS.DocCount,
                          (p, ret) =>
            {
                ret.OK   = true;
                ret.Data = _raptor.DocumentCount();
            });

            _handlers.Add("" + COMMANDS.GetObjectHF,
                          (p, ret) =>
            {
                ret.OK   = true;
                ret.Data = _raptor.GetKVHF().GetObjectHF((string)p.Data);
            });

            _handlers.Add("" + COMMANDS.SetObjectHF,
                          (p, ret) =>
            {
                ret.OK    = true;
                var param = (object[])p.Data;
                _raptor.GetKVHF().SetObjectHF((string)param[0], param[1]);
            });

            _handlers.Add("" + COMMANDS.DeleteKeyHF,
                          (p, ret) =>
            {
                ret.OK   = true;
                ret.Data = _raptor.GetKVHF().DeleteKeyHF((string)p.Data);
            });

            _handlers.Add("" + COMMANDS.CountHF,
                          (p, ret) =>
            {
                ret.OK   = true;
                ret.Data = _raptor.GetKVHF().CountHF();
            });

            _handlers.Add("" + COMMANDS.ContainsHF,
                          (p, ret) =>
            {
                ret.OK   = true;
                ret.Data = _raptor.GetKVHF().ContainsHF((string)p.Data);
            });

            _handlers.Add("" + COMMANDS.GetKeysHF,
                          (p, ret) =>
            {
                ret.OK   = true;
                ret.Data = _raptor.GetKVHF().GetKeysHF();
            });

            _handlers.Add("" + COMMANDS.CompactStorageHF,
                          (p, ret) =>
            {
                ret.OK = true;
                _raptor.GetKVHF().CompactStorageHF();
            });

            _handlers.Add("" + COMMANDS.IncrementHF,
                          (p, ret) =>
            {
                ret.OK    = true;
                var param = (object[])p.Data;
                if (param[1] is int)
                {
                    ret.Data = _raptor.GetKVHF().Increment((string)param[0], (int)param[1]);
                }
                else
                {
                    ret.Data = _raptor.GetKVHF().Increment((string)param[0], (decimal)param[1]);
                }
            });

            _handlers.Add("" + COMMANDS.DecrementHF,
                          (p, ret) =>
            {
                ret.OK    = true;
                var param = (object[])p.Data;
                if (param[1] is int)
                {
                    ret.Data = _raptor.GetKVHF().Decrement((string)param[0], (int)param[1]);
                }
                else
                {
                    ret.Data = _raptor.GetKVHF().Decrement((string)param[0], (decimal)param[1]);
                }
            });
        }
        private object processpayload(object data)
        {
            Packet p = (Packet)data;

            if (Authenticate(p) == false)
            {
                return(new ReturnPacket(false, "Authentication failed"));
            }

            ReturnPacket ret = new ReturnPacket(true);

            try
            {
                object[] param = null;

                switch (p.Command)
                {
                case "save":
                    var m = GetSave(p.Data.GetType());
                    m.Invoke(_raptor, new object[] { p.Docid, p.Data });
                    break;

                case "savebytes":
                    ret.OK = _raptor.SaveBytes(p.Docid, (byte[])p.Data);
                    break;

                case "querytype":
                    param = (object[])p.Data;
                    Type   t        = Type.GetType((string)param[0]);
                    string viewname = _raptor.GetViewName(t);
                    ret.OK   = true;
                    ret.Data = _raptor.Query(viewname, (string)param[1], p.Start, p.Count, p.OrderBy);
                    break;

                case "querystr":
                    ret.OK   = true;
                    ret.Data = _raptor.Query(p.Viewname, (string)p.Data, p.Start, p.Count, p.OrderBy);
                    break;

                case "fetch":
                    ret.OK   = true;
                    ret.Data = _raptor.Fetch(p.Docid);
                    break;

                case "fetchbytes":
                    ret.OK   = true;
                    ret.Data = _raptor.FetchBytes(p.Docid);
                    break;

                case "backup":
                    ret.OK = _raptor.Backup();
                    break;

                case "delete":
                    ret.OK = _raptor.Delete(p.Docid);
                    break;

                case "deletebytes":
                    ret.OK = _raptor.DeleteBytes(p.Docid);
                    break;

                case "restore":
                    ret.OK = true;
                    Task.Factory.StartNew(() => _raptor.Restore());
                    break;

                case "adduser":
                    param  = (object[])p.Data;
                    ret.OK = AddUser((string)param[0], (string)param[1], (string)param[2]);
                    break;

                case "serverside":
                    param    = (object[])p.Data;
                    ret.OK   = true;
                    ret.Data = _raptor.ServerSide(GetServerSideFuncCache(param[0].ToString(), param[1].ToString()), param[2].ToString());
                    break;

                case "fulltext":
                    param    = (object[])p.Data;
                    ret.OK   = true;
                    ret.Data = _raptor.FullTextSearch("" + param[0]);
                    break;

                case "counttype":
                    // count type
                    param = (object[])p.Data;
                    Type   t2        = Type.GetType((string)param[0]);
                    string viewname2 = _raptor.GetViewName(t2);
                    ret.OK   = true;
                    ret.Data = _raptor.Count(viewname2, (string)param[1]);
                    break;

                case "countstr":
                    // count str
                    ret.OK   = true;
                    ret.Data = _raptor.Count(p.Viewname, (string)p.Data);
                    break;

                case "gcount":
                    Type   t3        = Type.GetType(p.Viewname);
                    string viewname3 = _raptor.GetViewName(t3);
                    ret.OK   = true;
                    ret.Data = _raptor.Count(viewname3, (string)p.Data);
                    break;

                case "dochistory":
                    ret.OK   = true;
                    ret.Data = _raptor.FetchHistory(p.Docid);
                    break;

                case "filehistory":
                    ret.OK   = true;
                    ret.Data = _raptor.FetchBytesHistory(p.Docid);
                    break;

                case "fetchversion":
                    ret.OK   = true;
                    ret.Data = _raptor.FetchVersion((int)p.Data);
                    break;

                case "fetchfileversion":
                    ret.OK   = true;
                    ret.Data = _raptor.FetchBytesVersion((int)p.Data);
                    break;

                case "checkassembly":
                    ret.OK = true;
                    string typ = "";
                    ret.Data  = _raptor.GetAssemblyForView(p.Viewname, out typ);
                    ret.Error = typ;
                    break;

                case "fetchhistoryinfo":
                    ret.OK   = true;
                    ret.Data = _raptor.FetchHistoryInfo(p.Docid);
                    break;

                case "fetchbytehistoryinfo":
                    ret.OK   = true;
                    ret.Data = _raptor.FetchBytesHistoryInfo(p.Docid);
                    break;

                case "viewdelete":
                    ret.OK   = true;
                    param    = (object[])p.Data;
                    ret.Data = _raptor.ViewDelete((string)param[0], (string)param[1]);
                    break;

                case "viewdelete-t":
                    ret.OK = true;
                    param  = (object[])p.Data;
                    Type   t4        = Type.GetType((string)param[0]);
                    string viewname4 = _raptor.GetViewName(t4);
                    ret.Data = _raptor.ViewDelete(viewname4, (string)param[1]);
                    break;

                case "viewinsert":
                    ret.OK   = true;
                    param    = (object[])p.Data;
                    ret.Data = _raptor.ViewInsert((string)param[0], p.Docid, param[1]);
                    break;

                case "viewinsert-t":
                    ret.OK = true;
                    param  = (object[])p.Data;
                    Type   t5        = Type.GetType((string)param[0]);
                    string viewname5 = _raptor.GetViewName(t5);
                    ret.Data = _raptor.ViewInsert(viewname5, p.Docid, param[1]);
                    break;

                case "doccount":
                    ret.OK   = true;
                    ret.Data = _raptor.DocumentCount();
                    break;

                case "getobjecthf":
                    ret.OK   = true;
                    ret.Data = _raptor.GetKVHF().GetObjectHF((string)p.Data);
                    break;

                case "setobjecthf":
                    ret.OK = true;
                    param  = (object[])p.Data;
                    _raptor.GetKVHF().SetObjectHF((string)param[0], param[1]);
                    break;

                case "deletekeyhf":
                    ret.OK   = true;
                    ret.Data = _raptor.GetKVHF().DeleteKeyHF((string)p.Data);
                    break;

                case "counthf":
                    ret.OK   = true;
                    ret.Data = _raptor.GetKVHF().CountHF();
                    break;

                case "containshf":
                    ret.OK   = true;
                    ret.Data = _raptor.GetKVHF().ContainsHF((string)p.Data);
                    break;

                case "getkeyshf":
                    ret.OK   = true;
                    ret.Data = _raptor.GetKVHF().GetKeysHF();
                    break;

                case "compactstoragehf":
                    ret.OK = true;
                    _raptor.GetKVHF().CompactStorageHF();
                    break;
                }
            }
            catch (Exception ex)
            {
                ret.OK = false;
                log.Error(ex);
            }
            return(ret);
        }