Esempio n. 1
0
        public void AddingRunners()
        {
            using (var manager = new ProcessManager())
            {
                int  addedCount        = 0;
                bool addedEventCalled  = false;
                bool changeEventCalled = false;

                manager.ProcessesChanged += () => { changeEventCalled = true; };
                manager.RunnerAdded      += (runner) => { addedEventCalled = true; ++addedCount; };
                manager.Add(ProcessRunnerUnitTests.ResponsiveWindowedProcessOptions);

                Assert.IsTrue(manager.Contains(ProcessRunnerUnitTests.TestProcessWindowedPath));
                Assert.IsTrue(manager.Runners.Contains(manager.Get(ProcessRunnerUnitTests.TestProcessWindowedPath)));
                Assert.IsTrue(manager.Options.Select(opt => opt.Path).Contains(ProcessRunnerUnitTests.TestProcessWindowedPath));
                Assert.IsTrue(addedEventCalled);
                Assert.IsTrue(changeEventCalled);

                manager.Add(ProcessRunnerUnitTests.ResponsiveWindowedProcessOptions);
                Assert.AreEqual(addedCount, 1);

                Assert.IsFalse(manager.Contains(null));
                Assert.IsFalse(manager.Contains(""));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Create a producer.
        /// </summary>
        public IProducer CreateProducer(ProducerOptions options)
        {
            ThrowIfDisposed();

            ICompressorFactory?compressorFactory = null;

            if (options.CompressionType != CompressionType.None)
            {
                var compressionType = (Internal.PulsarApi.CompressionType)options.CompressionType;
                compressorFactory = CompressionFactories.CompressorFactories().SingleOrDefault(f => f.CompressionType == compressionType);
                if (compressorFactory is null)
                {
                    throw new CompressionException($"Support for {compressionType} compression was not found");
                }
            }

            var correlationId = Guid.NewGuid();
            var executor      = new Executor(correlationId, _processManager, _exceptionHandler);
            var factory       = new ProducerChannelFactory(correlationId, _processManager, _connectionPool, executor, options, compressorFactory);
            var stateManager  = new StateManager <ProducerState>(ProducerState.Disconnected, ProducerState.Closed, ProducerState.Faulted);
            var producer      = new Producer(correlationId, ServiceUrl, options.Topic, options.InitialSequenceId, _processManager, new NotReadyChannel(), executor, stateManager);

            if (options.StateChangedHandler is not null)
            {
                _ = StateMonitor.MonitorProducer(producer, options.StateChangedHandler);
            }
            var process = new ProducerProcess(correlationId, stateManager, factory, producer);

            _processManager.Add(process);
            process.Start();
            return(producer);
        }
Esempio n. 3
0
        /// <summary>
        /// Create a producer.
        /// </summary>
        public IProducer CreateProducer(ProducerOptions options)
        {
            ThrowIfDisposed();
            var correlationId = Guid.NewGuid();
            var executor      = new Executor(correlationId, _processManager, _exceptionHandler);
            var factory       = new ProducerChannelFactory(correlationId, _processManager, _connectionPool, executor, options);
            var stateManager  = new StateManager <ProducerState>(ProducerState.Disconnected, ProducerState.Closed, ProducerState.Faulted);
            var producer      = new Producer(correlationId, options.Topic, options.InitialSequenceId, _processManager, new NotReadyChannel(), executor, stateManager);
            var process       = new ProducerProcess(correlationId, stateManager, factory, producer);

            _processManager.Add(process);
            process.Start();
            return(producer);
        }
Esempio n. 4
0
    public void LoadTexture(string path, string default_path, TextureLoadedCallBack textureLoaded, ResourceType resType = ResourceType.RT_TEXTURE_PNG)
    {
        string filePath = GameInfo.FilePath + path;

        if (resType == ResourceType.RT_TEXTURE_PNG)
        {
            filePath += ".png";
        }
        else
        {
            filePath += ".jpg";
        }

        bool      loaded = false;
        Texture2D tex    = ResourceMgr.Instance.LoadRes <Texture2D>(path);

        if (textureLoaded != null)
        {
            textureLoaded(tex);
        }
        if (tex != null || path.Equals(default_path))
        {
            return;
        }

        if (!mCallBackTable.ContainsKey(path))
        {
            DownLoader.Instance.Request(path, resType, ThreadPriority.Normal);
            mCallBackTable.Add(path, new List <TextureLoadedCallBack>());
        }
        mCallBackTable[path].Add(textureLoaded);
        ProcessManager.Add(Instance);
    }
    private void RespCallback(IAsyncResult asynchronousResult)
    {
        try
        {
            // State of request is asynchronous.
            RequestState   myRequestState    = (RequestState)asynchronousResult.AsyncState;
            HttpWebRequest myHttpWebRequest2 = myRequestState.request;
            myRequestState.response = (HttpWebResponse)myHttpWebRequest2.EndGetResponse(asynchronousResult);

            // Read the response into a Stream object.
            Stream responseStream = myRequestState.response.GetResponseStream();
            myRequestState.streamResponse = responseStream;

            // Begin the Reading of the contents of the HTML page and print it to the console.
            responseStream.BeginRead(myRequestState.BufferRead, 0, BUFFER_SIZE, new AsyncCallback(ReadCallBack), myRequestState);
        }
        catch (WebException e)
        {
            // Need to handle the exception
            // ...
            UnityEngine.Debug.Log(e.Message);
            ProcessManager.Add(new CallBackProcess((obj) =>
            {
                _errorCallback(obj as String);
            }, e.Message));
        }
    }
Esempio n. 6
0
//		public void LuaWait(float delay, LuaFunction callback)
//		{
//			Wait(delay, () => {
//				callback.Call ();
//			});
//		}


//
//		public void Wait(float delay, TimerCallback callback,bool loop)
//		{
//			Wait(delay, callback, loop, "", false);
//		}
//
//		public void Wait(float delay, TimerCallback callback,bool loop, string name)
//		{
//			Wait(delay, callback, loop, name, false);
//		}
//
//		public void Wait(float delay, TimerCallback callback,bool loop, bool global)
//		{
//			Wait(delay, callback, loop, "", global);
//		}

    private void Wait(float delay, Action callback, bool loop, string name, WAITTYPE waittype)
    {
        if (delay < 0 || callback == null)
        {
            return;
        }
        TimerEvent tEvent;

        if (EmptyPool.Count > 0)
        {
            tEvent = EmptyPool.Dequeue();
        }
        else
        {
            tEvent = new TimerEvent();
        }
        tEvent.name        = name;
        tEvent.mCallback   = callback;
        tEvent.triggerTime = Time.realtimeSinceStartup + delay;
        tEvent.delay       = delay;
        tEvent.loop        = loop;
        tEvent.dirty       = false;
        tEvent.idle        = false;
        tEvent.waittype    = waittype;
        if (loop)
        {
            callback();
        }
        timeEvents.Add(tEvent);
        ProcessManager.Add(Instance);
    }
Esempio n. 7
0
//		public void Request(string url, ResourceType type, int version, ThreadPriority priority)
//		{
//			Request (url, type, version, priority, false);
//		}

    public void Request(string url, ResourceType type, ThreadPriority priority, bool noticeError = false)
    {
        //Debug.LogError("Request www url:"+url);
        if (!mWorkingPool.ContainsKey(url) && !mStoragePool.ContainsKey(url))
        {
            //Debug.Log("mWaitingPool.Count"+mWaitingPool.Count);
            DownLoadUnitReq req = new DownLoadUnitReq();
            req.mUrl  = url;
            req.mType = type;
            //req.mVersion = version;
            req.mPriority = priority;
            //req.compress = comp;
            req.noticeError = noticeError;
            switch (priority)
            {
            default:
            case ThreadPriority.Normal: mNormalWaitingPool.Enqueue(req); break;

            case ThreadPriority.Low: mLowWaitingPool.Enqueue(req); break;
            }
            ProcessManager.Add(Instance);
            //Debug.Log("mNormalWaitingPool.Count"+mNormalWaitingPool.Count);
            //Debug.Log("mLowWaitingPool.Count"+mLowWaitingPool.Count);
        }
    }
Esempio n. 8
0
 public void Initialize()
 {
     for (int i = 0; i < processes; i++)
     {
         Process process = new Process();
         ProcessManager.Add(process);
     }
 }
Esempio n. 9
0
 public void GettingRunners()
 {
     using (var manager = new ProcessManager())
     {
         Assert.IsNull(manager.Get(ProcessRunnerUnitTests.TestProcessWindowedPath));
         manager.Add(ProcessRunnerUnitTests.ResponsiveWindowedProcessOptions);
         Assert.IsNotNull(manager.Get(ProcessRunnerUnitTests.TestProcessWindowedPath));
     }
 }
Esempio n. 10
0
    public void LoadAsset(string path, AssetLoadedCallBack assetLoaded, bool compress = true)
    {
        Parameters p = new Parameters();

        p.path     = path;
        p.cb       = assetLoaded;
        p.filePath = GameInfo.FilePath + path + ".byte";;
        ResLifeMgr.Instance.Live(path);
        if (mAssetTable.ContainsKey(path))
        {
            //Debug.LogError("mAssetTable Exists");
            assetLoaded(mAssetTable[path]);
            return;
        }
        string    filePath = GameInfo.FilePath + path + ".byte";
        TextAsset asset    = null;

        if (File.Exists(filePath))
        {
            if (!ThreadMgr.Instance.disableThread)
            {
                ThreadMgr.Instance.Start("ReadFileThread", new System.Threading.Thread(new  System.Threading.ParameterizedThreadStart(ReadFileThread)), p as object);
            }
            else
            {
                ReadFileThread(p);
            }
            return;
        }
        else
        {
            Debug.Log("Resources.Load:" + path);
            asset = Resources.Load(path, typeof(TextAsset)) as TextAsset;
            if (asset != null)
            {
                assetLoaded(asset.text);
                return;
            }
        }

        if (!mCallBackTable.ContainsKey(path))
        {
            if (compress)
            {
                DownLoader.Instance.Request(path, ResourceType.RT_ZIP, ThreadPriority.Normal);
            }
            else
            {
                DownLoader.Instance.Request(path, ResourceType.RT_TEXT, ThreadPriority.Normal);
            }
            mCallBackTable.Add(path, new List <AssetLoadedCallBack>());
        }
        mCallBackTable[path].Add(assetLoaded);
        ProcessManager.Add(Instance);
    }
Esempio n. 11
0
        static void Main(string[] args)
        {
            Console.WriteLine("Нажмите любую клавишу для выхода\n\n");

            //ProcessManager<ListPriorityQueue<Process>, Process> pm =
            //    new ProcessManager<ListPriorityQueue<Process>, Process>();

            ProcessManager<HeapPriorityQueue<Process>, Process> pm =
                new ProcessManager<HeapPriorityQueue<Process>, Process>();

            pm.Add(new Process(1));
            pm.Add(new Process(2));
            pm.Add(new Process(3));
            pm.Add(new Process(4));

            pm.Run();

            Console.ReadKey();
            Console.WriteLine(Environment.NewLine);
        }
Esempio n. 12
0
        public void DisposingRemovedRunners()
        {
            using (var manager = new ProcessManager())
            {
                manager.Add(ProcessRunnerUnitTests.ResponsiveWindowedProcessOptions);
                var runner = manager.Get(ProcessRunnerUnitTests.TestProcessWindowedPath);
                manager.Remove(ProcessRunnerUnitTests.TestProcessWindowedPath);

                Assert.IsTrue(runner.IsDisposed);
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Нажмите любую клавишу для выхода\n\n");

            //ProcessManager<ListPriorityQueue<Process>, Process> pm =
            //    new ProcessManager<ListPriorityQueue<Process>, Process>();

            ProcessManager <HeapPriorityQueue <Process>, Process> pm =
                new ProcessManager <HeapPriorityQueue <Process>, Process>();

            pm.Add(new Process(1));
            pm.Add(new Process(2));
            pm.Add(new Process(3));
            pm.Add(new Process(4));

            pm.Run();

            Console.ReadKey();
            Console.WriteLine(Environment.NewLine);
        }
Esempio n. 14
0
    public void LoadUPK(string upkName, UpkLoadedCallBack resLoaded, bool noticeError = true)
    {
        if (!mCallBackTable.ContainsKey(upkName))
        {
            DownLoader.Instance.Request(upkName, ResourceType.RT_STREAM, ThreadPriority.Normal, noticeError);
        }

        if (resLoaded != null)
        {
            mCallBackTable[upkName] = resLoaded;
        }
        ProcessManager.Add(Instance);
    }
Esempio n. 15
0
    public void Init(int _timeZone, int _switchDayHour, double _serveTime = 0)
    {
        switchDayHour = _switchDayHour;
        timeZone      = _timeZone;
        timeZoneMils  = timeZone * 3600 * 1000;

        alarmClock.Clear();
        hour_offset = -switchDayHour;
        if (_serveTime > 0)
        {
            Sync(_serveTime);
        }
        ProcessManager.Add(Instance);
    }
Esempio n. 16
0
        /// <summary>
        /// Create a consumer.
        /// </summary>
        public IConsumer <TMessage> CreateConsumer <TMessage>(ConsumerOptions <TMessage> options)
        {
            ThrowIfDisposed();

            var correlationId = Guid.NewGuid();
            var consumerName  = options.ConsumerName ?? $"Consumer-{correlationId:N}";
            var subscribe     = new CommandSubscribe
            {
                ConsumerName    = consumerName,
                InitialPosition = (CommandSubscribe.InitialPositionType)options.InitialPosition,
                PriorityLevel   = options.PriorityLevel,
                ReadCompacted   = options.ReadCompacted,
                Subscription    = options.SubscriptionName,
                Topic           = options.Topic,
                Type            = (CommandSubscribe.SubType)options.SubscriptionType
            };
            var messagePrefetchCount  = options.MessagePrefetchCount;
            var messageFactory        = new MessageFactory <TMessage>(options.Schema);
            var batchHandler          = new BatchHandler <TMessage>(true, messageFactory);
            var decompressorFactories = CompressionFactories.DecompressorFactories();
            var factory        = new ConsumerChannelFactory <TMessage>(correlationId, _processManager, _connectionPool, subscribe, messagePrefetchCount, batchHandler, messageFactory, decompressorFactories);
            var stateManager   = new StateManager <ConsumerState>(ConsumerState.Disconnected, ConsumerState.Closed, ConsumerState.ReachedEndOfTopic, ConsumerState.Faulted);
            var initialChannel = new NotReadyChannel <TMessage>();
            var executor       = new Executor(correlationId, _processManager, _exceptionHandler);
            var consumer       = new Consumer <TMessage>(correlationId, ServiceUrl, options.SubscriptionName, options.Topic, _processManager, initialChannel, executor, stateManager, factory);

            if (options.StateChangedHandler is not null)
            {
                _ = StateMonitor.MonitorConsumer(consumer, options.StateChangedHandler);
            }
            var process = new ConsumerProcess(correlationId, stateManager, consumer, options.SubscriptionType == SubscriptionType.Failover);

            _processManager.Add(process);
            process.Start();
            return(consumer);
        }
Esempio n. 17
0
    private void ReadCallBack(IAsyncResult asyncResult)
    {
        try
        {
            RequestState myRequestState = (RequestState)asyncResult.AsyncState;
            Stream       responseStream = myRequestState.streamResponse;
            int          read           = responseStream.EndRead(asyncResult);

            // Read the HTML page and then do something with it
            if (read > 0)
            {
                myRequestState.ReadBytes = Combine(myRequestState.ReadBytes, myRequestState.BufferRead, read);
                myRequestState.requestData.Append(Encoding.UTF8.GetString(myRequestState.BufferRead, 0, read));
                responseStream.BeginRead(myRequestState.BufferRead, 0, BUFFER_SIZE, new AsyncCallback(ReadCallBack), myRequestState);
            }
            else
            {
                if (myRequestState.requestData.Length > 1)
                {
                    // do something with the response stream here
                    if (myRequestState.SuccessfulCallBack != null)
                    {
                        ProcessManager.Add(new CallBackProcess(myRequestState.SuccessfulCallBack, myRequestState));
                    }
                }

                responseStream.Close();
                // Release the HttpWebResponse resource.
                myRequestState.response.Close();
                allDone.Set();
            }
        }
        catch (WebException e)
        {
            // Need to handle the exception
            // ...

            UnityEngine.Debug.Log(e.Message);
            ProcessManager.Add(new CallBackProcess((obj) =>
            {
                _errorCallback(obj as String);
            }, e.Message));
        }
    }
Esempio n. 18
0
    public bool WriteUpk(DownLoadUnit dlu, string key, UpkLoadedCallBack cb)
    {
        if (!Application.temporaryCachePath.Equals(""))
        {
            UPKData bd = new UPKData();

            bd.data = dlu.GetWWW().bytes;
            if (bd.data != null && bd.data.Length > 0)
            {
                bd.tarDir  = GameInfo.FilePath;
                bd.tarPath = GameInfo.FilePath + dlu.mReq.mUrl.Replace(".unity3d", ".txt");
                bd.key     = key;
                bd.cb      = cb;
                upkQueue.Enqueue(bd);
                ProcessManager.Add(this);
                return(true);
            }
        }
        return(false);
    }
Esempio n. 19
0
        public void RemovingRunners()
        {
            using (var manager = new ProcessManager())
            {
                int  removedCount       = 0;
                bool removedEventCalled = false;
                bool changeEventCalled  = false;

                manager.RunnerRemoved += (runner) => { removedEventCalled = true; ++removedCount; };
                manager.Add(ProcessRunnerUnitTests.ResponsiveWindowedProcessOptions);
                manager.ProcessesChanged += () => { changeEventCalled = true; };

                manager.Remove(ProcessRunnerUnitTests.TestProcessWindowedPath);
                Assert.IsTrue(removedEventCalled);
                Assert.IsTrue(changeEventCalled);

                manager.Remove(ProcessRunnerUnitTests.TestProcessWindowedPath);
                Assert.AreEqual(removedCount, 1);
            }
        }
Esempio n. 20
0
    public void PreLoadAssetBundle(string path, AssetBundleLoadedCallBack resLoaded, bool forceLoadFromSource = false)
    {
        if (string.IsNullOrEmpty(path))
        {
            return;
        }
        string filePath = GameInfo.FilePath + "AssetBundles_" + GameInfo.RegionString + "/" + path;

        Debug.Log("load filePath:" + filePath);

        if (File.Exists(filePath))
        {
            AssetBundle ab = AssetBundle.LoadFromFile(filePath);

            if (ab != null)
            {
                if (resLoaded != null)
                {
                    resLoaded(true);
                }
                return;
            }
        }


        if (!mCallBackTable.ContainsKey(path))
        {
            DownLoader.Instance.Request(path, ResourceType.RT_ASSETBUNDLE, ThreadPriority.Normal);
        }

        if (resLoaded != null)
        {
            mCallBackTable[path] = resLoaded;
        }
        ProcessManager.Add(Instance);
    }