예제 #1
0
파일: Actor.cs 프로젝트: luyikk/NetX
        public void Action(long id, int cmd, OpenAccess access, params object[] args)
        {
            if (status == Disposed)
            {
                throw new ObjectDisposedException("this actor is dispose");
            }

            if (maxQueuelen > 0)
            {
                if (ActorRunQueue.Count > maxQueuelen)
                {
                    throw new NetxException($"this actor queue count >{maxQueuelen}", ErrorType.ActorQueueMaxErr);
                }
            }

            var sa = new ActorMessage <object>(id, cmd, access, args);

            ActorRunQueue.Enqueue(sa);

            try
            {
                Runing().Wait();
            }
            catch (Exception er)
            {
                Log.Error(er);
            }
        }
예제 #2
0
 protected ActorMessage(long id, int cmd, OpenAccess access, object[] args)
 {
     Id           = id;
     Cmd          = cmd;
     Args         = args;
     PushTime     = TimeHelper.GetTime();
     CompleteTime = 0;
     this.Access  = access;
 }
예제 #3
0
 public ActorMessage(long id, int cmd, OpenAccess access, object[] args)
 {
     Id           = id;
     Cmd          = cmd;
     Args         = args;
     PushTime     = TimeHelper.GetTime();
     CompleteTime = 0;
     this.Access  = access;
     Awaiter      = new ActorResultAwaiter <T>();
 }
예제 #4
0
 public void SyncAction(long id, int cmd, OpenAccess access, params object[] args)
 {
     if (ActorCollect.ContainsKey(cmd))
     {
         ActorCollect[cmd].Action(id, cmd, access, args);
     }
     else
     {
         Log.ErrorFormat("not found actor service cmd:{cmd}", cmd);
     }
 }
예제 #5
0
 public ValueTask <T> CallFunc <T>(long id, int cmd, OpenAccess access, params object[] args)
 {
     if (ActorCollect.TryGetValue(cmd, out Actor m))
     {
         return(m.AsyncFunc <T>(id, cmd, access, args));
     }
     else
     {
         throw new NetxException($"not found actor service cmd:{cmd}", ErrorType.ActorErr);
     }
 }
 protected VB6File(string sPath, OpenAccess access, OpenShare share, int lRecordLen)
 {
     if (((access != OpenAccess.Read) && (access != OpenAccess.ReadWrite)) && (access != OpenAccess.Write))
     {
         throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", new string[] { "Access" }));
     }
     this.m_access = access;
     if (((share != OpenShare.Shared) && (share != OpenShare.LockRead)) && ((share != OpenShare.LockReadWrite) && (share != OpenShare.LockWrite)))
     {
         throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", new string[] { "Share" }));
     }
     this.m_share = share;
     this.m_lRecordLen = lRecordLen;
     this.m_sFullPath = new FileInfo(sPath).FullName;
 }
 private void OpenFileHelper(FileMode fm, OpenAccess fa)
 {
     try
     {
         base.m_file = new FileStream(base.m_sFullPath, fm, (FileAccess)fa, (FileShare)base.m_share);
     }
     catch (FileNotFoundException exception)
     {
         throw ExceptionUtils.VbMakeException(exception, 0x35);
     }
     catch (DirectoryNotFoundException exception2)
     {
         throw ExceptionUtils.VbMakeException(exception2, 0x4c);
     }
     catch (SecurityException exception3)
     {
         throw ExceptionUtils.VbMakeException(exception3, 0x35);
     }
     catch (IOException exception4)
     {
         throw ExceptionUtils.VbMakeException(exception4, 0x4b);
     }
     catch (UnauthorizedAccessException exception5)
     {
         throw ExceptionUtils.VbMakeException(exception5, 0x4b);
     }
     catch (ArgumentException exception6)
     {
         throw ExceptionUtils.VbMakeException(exception6, 0x4b);
     }
     catch (StackOverflowException exception7)
     {
         throw exception7;
     }
     catch (OutOfMemoryException exception8)
     {
         throw exception8;
     }
     catch (ThreadAbortException exception9)
     {
         throw exception9;
     }
     catch (Exception)
     {
         throw ExceptionUtils.VbMakeException(0x33);
     }
 }
예제 #8
0
 private void OpenFileHelper(FileMode fm, OpenAccess fa)
 {
     try
     {
         this.m_file = new FileStream(this.m_sFullPath, fm, (FileAccess)fa, (FileShare)this.m_share);
     }
     catch (FileNotFoundException ex)
     {
         throw ExceptionUtils.VbMakeException((Exception)ex, 53);
     }
     catch (DirectoryNotFoundException ex)
     {
         throw ExceptionUtils.VbMakeException((Exception)ex, 76);
     }
     catch (SecurityException ex)
     {
         throw ExceptionUtils.VbMakeException((Exception)ex, 53);
     }
     catch (IOException ex)
     {
         throw ExceptionUtils.VbMakeException((Exception)ex, 75);
     }
     catch (UnauthorizedAccessException ex)
     {
         throw ExceptionUtils.VbMakeException((Exception)ex, 75);
     }
     catch (ArgumentException ex)
     {
         throw ExceptionUtils.VbMakeException((Exception)ex, 75);
     }
     catch (StackOverflowException ex)
     {
         throw ex;
     }
     catch (OutOfMemoryException ex)
     {
         throw ex;
     }
     catch (ThreadAbortException ex)
     {
         throw ex;
     }
     catch (Exception ex)
     {
         throw ExceptionUtils.VbMakeException(51);
     }
 }
예제 #9
0
파일: Actor.cs 프로젝트: luyikk/NetX
        public ValueTask <T> AsyncFunc <T>(long id, int cmd, OpenAccess access, params object[] args)
        {
            if (status == Disposed)
            {
                throw new ObjectDisposedException("this actor is dispose");
            }

            if (maxQueuelen > 0)
            {
                if (ActorRunQueue.Count > maxQueuelen)
                {
                    throw new NetxException($"this actor queue count >{maxQueuelen}", ErrorType.ActorQueueMaxErr);
                }
            }

            var sa = new ActorMessage <T>(id, cmd, access, args);

            ActorRunQueue.Enqueue(sa);
            Runing().Wait();
            return(sa.Awaiter);
        }
 private void OpenFileHelper(FileMode fm, OpenAccess fa)
 {
     try
     {
         base.m_file = new FileStream(base.m_sFullPath, fm, (FileAccess) fa, (FileShare) base.m_share);
     }
     catch (FileNotFoundException exception)
     {
         throw ExceptionUtils.VbMakeException(exception, 0x35);
     }
     catch (DirectoryNotFoundException exception2)
     {
         throw ExceptionUtils.VbMakeException(exception2, 0x4c);
     }
     catch (SecurityException exception3)
     {
         throw ExceptionUtils.VbMakeException(exception3, 0x35);
     }
     catch (IOException exception4)
     {
         throw ExceptionUtils.VbMakeException(exception4, 0x4b);
     }
     catch (UnauthorizedAccessException exception5)
     {
         throw ExceptionUtils.VbMakeException(exception5, 0x4b);
     }
     catch (ArgumentException exception6)
     {
         throw ExceptionUtils.VbMakeException(exception6, 0x4b);
     }
     catch (StackOverflowException exception7)
     {
         throw exception7;
     }
     catch (OutOfMemoryException exception8)
     {
         throw exception8;
     }
     catch (ThreadAbortException exception9)
     {
         throw exception9;
     }
     catch (Exception)
     {
         throw ExceptionUtils.VbMakeException(0x33);
     }
 }
	public static void FileOpen(int FileNumber, string FileName, OpenMode Mode, OpenAccess Access, OpenShare Share, int RecordLength) {}
예제 #12
0
        // Open a file.
        public static void FileOpen
            (int FileNumber, String FileName, OpenMode Mode,
            [Optional][DefaultValue(OpenAccess.Default)]
            OpenAccess Access,
            [Optional][DefaultValue(OpenShare.Default)]
            OpenShare Share,
            [Optional][DefaultValue(-1)] int RecordLength)
        {
            FileMode   mode;
            FileAccess access;
            FileShare  share;
            int        recordLength;
            int        bufferSize;

            // Validate the parameters and convert them into
            // something that System.IO is more comfortable with.
            if (Mode != OpenMode.Input && Mode != OpenMode.Output &&
                Mode != OpenMode.Random && Mode != OpenMode.Append &&
                Mode != OpenMode.Binary)
            {
                throw new ArgumentException
                          (S._("VB_InvalidFileMode"), "Mode");
            }
            if (Access == OpenAccess.Default)
            {
                access = FileAccess.ReadWrite;
            }
            else if (Access == OpenAccess.Read)
            {
                access = FileAccess.Read;
            }
            else if (Access == OpenAccess.Write)
            {
                access = FileAccess.Write;
            }
            else if (Access == OpenAccess.ReadWrite)
            {
                access = FileAccess.ReadWrite;
            }
            else
            {
                throw new ArgumentException
                          (S._("VB_InvalidFileAccess"), "Access");
            }
            if (Share == OpenShare.Default)
            {
                share = FileShare.ReadWrite;
            }
            else if (Share == OpenShare.LockReadWrite)
            {
                share = FileShare.ReadWrite;
            }
            else if (Share == OpenShare.LockRead)
            {
                share = FileShare.Read;
            }
            else if (Share == OpenShare.LockWrite)
            {
                share = FileShare.Write;
            }
            else if (Share == OpenShare.Shared)
            {
                share = FileShare.None;
            }
            else
            {
                throw new ArgumentException
                          (S._("VB_InvalidFileShare"), "Share");
            }
            if (RecordLength != -1)
            {
                if (RecordLength < 1 || RecordLength > 32767)
                {
                    throw new ArgumentException
                              (S._("VB_InvalidRecordLength"), "RecordLength");
                }
                if (Mode == OpenMode.Random)
                {
                    recordLength = RecordLength;
                    bufferSize   = -1;
                }
                else
                {
                    recordLength = 1;
                    bufferSize   = RecordLength;
                }
            }
            else
            {
                recordLength = 1;
                bufferSize   = -1;
            }

            // Determine the appropriate FileMode value.
            if (Mode == OpenMode.Random || Mode == OpenMode.Binary)
            {
                if (System.IO.File.Exists(FileName))
                {
                    mode = FileMode.Open;
                }
                else if (access == FileAccess.Read)
                {
                    mode = FileMode.OpenOrCreate;
                }
                else
                {
                    mode = FileMode.Create;
                }
            }
            else if (Mode == OpenMode.Input)
            {
                mode = FileMode.Open;
            }
            else if (Mode == OpenMode.Output)
            {
                mode = FileMode.Create;
            }
            else
            {
                mode = FileMode.Append;
            }

            // Allocate the file number.
            File file = File.AllocateFile
                            (FileNumber, Mode, Assembly.GetCallingAssembly());

            file.recordLength = recordLength;

            // Attempt to open the file.
            FileStream stream = null;

            try
            {
                if (bufferSize != -1)
                {
                    stream = new FileStream(FileName, mode, access,
                                            share, bufferSize);
                }
                else
                {
                    stream = new FileStream(FileName, mode, access, share);
                }
            }
            finally
            {
                if (stream == null)
                {
                    // The create failed, so clean up the allocated file.
                    file.Close();
                }
            }
            file.stream = stream;
        }
 private static void ValidateAccess(OpenAccess Access)
 {
     if (((Access != OpenAccess.Default) && (Access != OpenAccess.Read)) && ((Access != OpenAccess.ReadWrite) && (Access != OpenAccess.Write)))
     {
         throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", new string[] { "Access" }));
     }
 }
        private static void vbIOOpenFile(Assembly assem, int FileNumber, string FileName, OpenMode Mode, OpenAccess Access, OpenShare Share, int RecordLength)
        {
            VB6File file;
            AssemblyData assemblyData = ProjectData.GetProjectData().GetAssemblyData(assem);
            if (GetChannelOrNull(assemblyData, FileNumber) != null)
            {
                throw ExceptionUtils.VbMakeException(0x37);
            }
            if ((FileName == null) || (FileName.Length == 0))
            {
                throw ExceptionUtils.VbMakeException(0x4b);
            }
            FileName = new FileInfo(FileName).FullName;
            if (CheckFileOpen(assemblyData, FileName, OpenModeTypesFromOpenMode(Mode)))
            {
                throw ExceptionUtils.VbMakeException(0x37);
            }
            if ((RecordLength != -1) && (RecordLength <= 0))
            {
                throw ExceptionUtils.VbMakeException(5);
            }
            if (Mode == OpenMode.Binary)
            {
                RecordLength = 1;
            }
            else if (RecordLength == -1)
            {
                if (Mode == OpenMode.Random)
                {
                    RecordLength = 0x80;
                }
                else
                {
                    RecordLength = 0x200;
                }
            }
            if (Share == OpenShare.Default)
            {
                Share = OpenShare.LockReadWrite;
            }
            OpenMode mode = Mode;
            switch (mode)
            {
                case OpenMode.Input:
                    if ((Access != OpenAccess.Read) && (Access != OpenAccess.Default))
                    {
                        throw new ArgumentException(Utils.GetResourceString("FileSystem_IllegalInputAccess"));
                    }
                    file = new VB6InputFile(FileName, Share);
                    break;

                case OpenMode.Output:
                    if ((Access != OpenAccess.Write) && (Access != OpenAccess.Default))
                    {
                        throw new ArgumentException(Utils.GetResourceString("FileSystem_IllegalOutputAccess"));
                    }
                    file = new VB6OutputFile(FileName, Share, false);
                    break;

                case OpenMode.Random:
                    if (Access == OpenAccess.Default)
                    {
                        Access = OpenAccess.ReadWrite;
                    }
                    file = new VB6RandomFile(FileName, Access, Share, RecordLength);
                    break;

                case OpenMode.Append:
                    if (((Access != OpenAccess.Write) && (Access != OpenAccess.ReadWrite)) && (Access != OpenAccess.Default))
                    {
                        throw new ArgumentException(Utils.GetResourceString("FileSystem_IllegalAppendAccess"));
                    }
                    file = new VB6OutputFile(FileName, Share, true);
                    break;

                default:
                    if (mode != OpenMode.Binary)
                    {
                        throw ExceptionUtils.VbMakeException(0x33);
                    }
                    if (Access == OpenAccess.Default)
                    {
                        Access = OpenAccess.ReadWrite;
                    }
                    file = new VB6BinaryFile(FileName, Access, Share);
                    break;
            }
            AddFileToList(assemblyData, FileNumber, file);
        }
 public static void FileOpen(int FileNumber, string FileName, OpenMode Mode, OpenAccess Access = -1, OpenShare Share = -1, int RecordLength = -1)
 {
     try
     {
         ValidateMode(Mode);
         ValidateAccess(Access);
         ValidateShare(Share);
         if ((FileNumber < 1) || (FileNumber > 0xff))
         {
             throw ExceptionUtils.VbMakeException(0x34);
         }
         vbIOOpenFile(Assembly.GetCallingAssembly(), FileNumber, FileName, Mode, Access, Share, RecordLength);
     }
     catch (Exception exception)
     {
         throw exception;
     }
 }
예제 #16
0
 public VB6BinaryFile(string FileName, OpenAccess access, OpenShare share) : base(FileName, access, share, -1)
 {
 }
 public VB6RandomFile(string FileName, OpenAccess access, OpenShare share, int lRecordLen) : base(FileName, access, share, lRecordLen)
 {
 }
예제 #18
0
 public static void FileOpen(int FileNumber, string FileName, OpenMode Mode, OpenAccess Access, OpenShare Share, int RecordLength)
 {
 }
예제 #19
0
 public VB6RandomFile(string FileName, OpenAccess access, OpenShare share, int lRecordLen)
     : base(FileName, access, share, lRecordLen)
 {
 }
예제 #20
0
 public OpenAttribute(OpenAccess access)
 {
     Access = access;
 }
예제 #21
0
 public ActorMethodRegister(Type instenceType, MethodInfo method, OpenAccess access) : base(instenceType, method)
 {
     Access = access;
 }
예제 #22
0
파일: Actor.cs 프로젝트: luyikk/NetX
        private Dictionary <int, ActorMethodRegister> LoadRegister(Type instanceType)
        {
            Dictionary <int, ActorMethodRegister> registerdict = new Dictionary <int, ActorMethodRegister>();

            foreach (var ainterface in instanceType.GetInterfaces())
            {
                if (ainterface.GetCustomAttribute <Build>(true) != null)
                {
                    foreach (var method in ainterface.GetMethods())
                    {
                        var attrs = method.GetCustomAttributes(true);

                        List <TAG> taglist    = new List <TAG>();
                        OpenAccess openAccess = OpenAccess.Public;
                        foreach (var attr in attrs)
                        {
                            if (attr is TAG attrcmdtype)
                            {
                                taglist.Add(attrcmdtype);
                            }
                            else if (attr is OpenAttribute access)
                            {
                                openAccess = access.Access;
                            }
                        }

                        if (taglist.Count > 0)
                        {
                            if (method.ReturnType == null || TypeHelper.IsTypeOfBaseTypeIs(method.ReturnType, typeof(Task)) || method.ReturnType == typeof(void))
                            {
                                var type = from xx in method.GetParameters()
                                           select xx.ParameterType;

                                var methodx = instanceType.GetMethod(method.Name, type.ToArray());

                                if (methodx != null)
                                {
                                    var openattr = methodx.GetCustomAttribute <OpenAttribute>();

                                    if (openattr != null)
                                    {
                                        openAccess = openattr.Access;
                                    }

                                    foreach (var tag in taglist)
                                    {
                                        var sr = new ActorMethodRegister(instanceType, methodx, openAccess);

                                        if (tag.CmdTag is SleepCmd)
                                        {
                                            Log.ErrorFormat("Register Actor Service Return Type Err:{Name} CmdTag not use {tag}", method.Name, tag.CmdTag);
                                            continue;
                                        }
                                        if (!registerdict.ContainsKey(tag.CmdTag))
                                        {
                                            registerdict.Add(tag.CmdTag, sr);
                                        }
                                        else
                                        {
                                            Log.ErrorFormat("Register actor service {Name},cmd:{CmdTag} repeat", method.Name, tag.CmdTag);
                                            registerdict[tag.CmdTag] = sr;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                Log.ErrorFormat("Register Actor Service Return Type Err:{Name},Use void, Task or Task<T>", method.Name);
                            }
                        }
                    }
                }
            }

            var methods = instanceType.GetMethods();

            foreach (var method in methods)
            {
                if (method.IsPublic)
                {
                    var        attrs      = method.GetCustomAttributes(true);
                    List <TAG> taglist    = new List <TAG>();
                    OpenAccess openAccess = OpenAccess.Public;
                    foreach (var attr in attrs)
                    {
                        if (attr is TAG attrcmdtype)
                        {
                            taglist.Add(attrcmdtype);
                        }
                        else if (attr is OpenAttribute access)
                        {
                            openAccess = access.Access;
                        }
                    }

                    if (taglist.Count > 0)
                    {
                        if (method.ReturnType == null || TypeHelper.IsTypeOfBaseTypeIs(method.ReturnType, typeof(Task)) || method.ReturnType == typeof(void))
                        {
                            foreach (var tag in taglist)
                            {
                                var sr = new ActorMethodRegister(instanceType, method, openAccess);

                                if (!registerdict.ContainsKey(tag.CmdTag))
                                {
                                    registerdict.Add(tag.CmdTag, sr);
                                }
                                else
                                {
                                    Log.ErrorFormat("Register actor service {Name},cmd:{CmdTag} repeat", method.Name, tag.CmdTag);
                                    registerdict[tag.CmdTag] = sr;
                                }
                            }
                        }
                        else
                        {
                            Log.ErrorFormat("Register Actor Service Return Type Err:{Name},Use void, Task or Task<T>", method.Name);
                        }
                    }
                }
            }

            return(registerdict);
        }