Example #1
0
        public void TestMethod1()
        {
            var content2  = new Content();
            var languages = new List <ContentLanguage>();

            content2.ContentLanguages = languages;

            var lang1 = new ContentLanguage();

            languages.Add(lang1);

            var lockingLang1 = new Locking();
            var pubLang1     = new Publishing();

            lang1.Locking    = lockingLang1;
            lang1.Publishing = pubLang1;

            var iterator      = new ContentGraphIterator(content2);
            var iteratedItems = new List <object>();

            foreach (var item in iterator)
            {
                iteratedItems.Add(item);
            }

            Assert.IsTrue(iteratedItems.Contains(content2));
            Assert.IsTrue(iteratedItems.Contains(lang1));
            Assert.IsTrue(iteratedItems.Contains(lockingLang1));
            Assert.IsTrue(iteratedItems.Contains(pubLang1));
        }
Example #2
0
 public void Lock(string uid)
 {
     if (!(Effects.OfType <LockEffect>().Any()))
     {
         Locking.SafeInvoke(null, EventArgs.Empty);
     }
     Effects.Add(new LockEffect(uid, Int32.MaxValue));
 }
Example #3
0
    // Use this for initialization
    void Start()
    {
        locking     = GetComponent <Locking>();
        sprRend     = GetComponent <SpriteRenderer>();
        audioSource = GetComponent <AudioSource>();

        hasSounded = false;
    }
Example #4
0
        public async Task <bool> DownloadRepo(string user, string repo, string commitId)
        {
            var cacheDir = Path.Combine(AppConfiguration["cacheDir"], user, repo, commitId);

            //已經有快取項目
            if (Directory.Exists(cacheDir))
            {
                return(true);
            }

            // 檢查目前是否正在下載中了
            lock (DownloadLocker) {
                // 沒在下載中
                if (!DownloadLocker.ContainsKey(commitId))
                {
                    // 建立lock物件
                    DownloadLocker[commitId] = new object();
                }
            }

            // 標註正在被locking的數量
            lock (Locking) {
                if (!Locking.ContainsKey(commitId))
                {
                    Locking[commitId] = 0;
                }
                Locking[commitId]++;
            }

            lock (DownloadLocker[commitId]) {
                // 如果快取項目,其他request在lock期間已經完成下載
                if (!Directory.Exists(cacheDir))
                {
                    var        url    = $"{AppConfiguration["giteaHost"]}/{user}/{repo}/archive/{commitId}.zip";
                    HttpClient client = new HttpClient();

                    Stream downloadStream = null;
                    try {
                        downloadStream = client.GetStreamAsync(url).GetAwaiter().GetResult();
                    } catch { // 無法取得串流
                        return(false);
                    }

                    using (ZipArchive arch = new ZipArchive(downloadStream, ZipArchiveMode.Read, true)) {
                        arch.ExtractToDirectory(cacheDir, true);
                    }
                }
            }

            // 解鎖
            Locking[commitId]--;
            return(true);
        }
        private static void TrySend(
            int numThreads,
            int numEvents,
            bool isPreserveOrder,
            Locking locking,
            Configuration configuration)
        {
            configuration.Runtime.Threading.IsListenerDispatchPreserveOrder = isPreserveOrder;
            configuration.Runtime.Threading.ListenerDispatchLocking = locking;
            configuration.Common.AddEventType(typeof(SupportBean));

            var runtime = EPRuntimeProvider.GetRuntime(typeof(MultithreadDeterminismListener).Name, configuration);
            runtime.Initialize();

            // setup statements
            var deployed = SupportCompileDeployUtil.CompileDeploy(
                "@Name('s0') select count(*) as cnt from SupportBean",
                runtime,
                configuration);
            var listener = new SupportMTUpdateListener();
            deployed.Statements[0].AddListener(listener);

            // execute
            var threadPool = Executors.NewFixedThreadPool(
                numThreads,
                new SupportThreadFactory(typeof(MultithreadDeterminismListener)).ThreadFactory);
            var future = new IFuture<bool>[numThreads];
            for (var i = 0; i < numThreads; i++) {
                future[i] = threadPool.Submit(new SendEventCallable(i, runtime, new GeneratorEnumerator(numEvents)));
            }

            threadPool.Shutdown();
            SupportCompileDeployUtil.ExecutorAwait(threadPool, 10, TimeUnit.SECONDS);
            SupportCompileDeployUtil.AssertFutures(future);

            var events = listener.GetNewDataListFlattened();
            var result = new long[events.Length];
            for (var i = 0; i < events.Length; i++) {
                result[i] = events[i].Get("cnt").AsInt64();
            }
            //log.info(".trySend result=" + Arrays.toString(result));

            // assert result
            Assert.AreEqual(numEvents * numThreads, events.Length);
            for (var i = 0; i < numEvents * numThreads; i++) {
                Assert.AreEqual(result[i], (long) i + 1);
            }

            runtime.Destroy();
        }
Example #6
0
        public void Lock(Locking locking)
        {
            if (locking != Locking.ReadWrite && _locking != Locking.ReadWrite)
            {
                throw new InvalidOperationException("Project is already unlocked");
            }

            if (locking == Locking.ReadWrite && _locking == Locking.ReadWrite)
            {
                throw new InvalidOperationException("Project is not locked");
            }

            _locking = locking;
        }
Example #7
0
        private static async Task <Response> Execute(Locking locking, string xmlFile)
        {
            using (var featureStream = File.OpenRead(xmlFile))
            {
                var timer = new Stopwatch();

                timer.Start();

                var response = await Client.UpdateDatasetFeaturesAsync(clientString, DatasetId, locking, featureStream);

                timer.Stop();

                Console.WriteLine($"Execute took {timer.Elapsed}");

                return(response);
            };
        }
Example #8
0
        public void Lock(Topic topic)
        {
            var eventArgs = new TopicEventArgs()
            {
                Topic = topic
            };

            if (Locking.RaiseAndContinue(this, eventArgs))
            {
                topic.Locked = true;
                _databaseContext.Database.Save(topic);
                Locked.Raise(this, eventArgs);
            }
            else
            {
                CancelledByEvent.Raise(this, eventArgs);
            }
        }
Example #9
0
        public PagesController(LiteDatabase database)
        {
            this.Database = database;
            if (LockClear == null)
            {
                LockClear = Task.Run(() => {
                    for (; ;)
                    {
                        Thread.Sleep(TimeSpan.FromSeconds(30));
                        lock (Locking) {
                            var willDelete = Locking.Where(x => x.Value == 0).ToArray();

                            foreach (var commit in willDelete)
                            {
                                DownloadLocker.Remove(commit.Key);
                                Locking.Remove(commit.Key);
                            }
                        }
                    }
                });
            }
        }
Example #10
0
        /// <summary>
        /// 扫描事件
        /// </summary>
        /// <param name="isCloseWhenCancel">是否换型</param>
        private void SelectMode()
        {
            try
            {
                bool isAdmin = Global.userLevel == UserLevel.设计者 || Global.userLevel == UserLevel.工程师;
                using (svfrmScanAndSelectMode frm = new svfrmScanAndSelectMode(AppConfig.ProductIntrinsicConfigModel, isAdmin))
                {
                    frm.ShowDialog();
                    if (string.IsNullOrEmpty(frm.A2C))
                    {
                        Close();
                        return;
                    }
                    AppConfig.ProductPath      = frm.A2C;
                    interLockingParam.Instance = SerializerManager <interLockingParam> .Instance.Load(AppConfig.MesConfigPathName);

                    locking = new Locking();
                    interLockingParam.Instance.EvData.DeviceA2C = frm.A2C;
                    interLockingParam.Instance.EvData.LoginName = lbJobnumber.Text;
                    lbA2C.Text         = AppConfig.ProductPath;
                    lbModel.Text       = interLockingParam.Instance.EvData.ModelName = frm.Model;
                    lb.Text            = interLockingParam.Instance.EvData.StationID = Config.Instance.StationID;
                    lbCustomer.Text    = frm.Customer;
                    lbStationName.Text = frm.Line;
                    Delay.Instance     = SerializerManager <Delay> .Instance.Load(AppConfig.ConfigDelayName);

                    Position.Instance = SerializerManager <Position> .Instance.Load(AppConfig.ConfigPositionName);

                    ProductConfig.Instance = SerializerManager <ProductConfig> .Instance.Load(AppConfig.ConfigOtherParamName);

                    interlock = new InterlockingClass();
                    lbInterlockingModel.Text = ProductConfig.Instance.switchCom.ToString();
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("扫描调取程序异常", ex);
            }
        }
Example #11
0
        /// <summary>
        ///     Ctor.
        /// </summary>
        /// <param name="name">the factory name</param>
        /// <param name="msecWait">the number of milliseconds latches will await maximally</param>
        /// <param name="locking">the blocking strategy to employ</param>
        /// <param name="timeSourceService">time source provider</param>
        /// <param name="stateless">indicator whether stateless</param>
        public InsertIntoLatchFactory(
            string name,
            bool stateless,
            int msecWait,
            Locking locking,
            TimeSourceService timeSourceService)
        {
            Name = name;
            this.msecWait = msecWait;
            TimeSourceService = timeSourceService;
            this.stateless = stateless;

            useSpin = locking == Locking.SPIN;

            // construct a completed latch as an initial root latch
            if (useSpin) {
                currentLatchSpin = new InsertIntoLatchSpin(this);
            }
            else {
                currentLatchWait = new InsertIntoLatchWait(this);
            }
        }
        /// <summary>
        ///     Ctor.
        /// </summary>
        /// <param name="name">the factory name</param>
        /// <param name="msecWait">the number of milliseconds latches will await maximally</param>
        /// <param name="locking">the blocking strategy to employ</param>
        /// <param name="timeSourceService">time source provider</param>
        /// <param name="initializeNow">for initializing</param>
        /// <param name="enabled">for active indicator</param>
        public NamedWindowConsumerLatchFactory(
            string name,
            bool enabled,
            int msecWait,
            Locking locking,
            TimeSourceService timeSourceService,
            bool initializeNow)
        {
            this.name = name;
            this.enabled = enabled;
            this.msecWait = msecWait;
            this.timeSourceService = timeSourceService;

            useSpin = enabled && locking == Locking.SPIN;

            // construct a completed latch as an initial root latch
            if (initializeNow && useSpin) {
                currentLatchSpin = new NamedWindowConsumerLatchSpin(this);
            }
            else if (initializeNow && enabled) {
                currentLatchWait = new NamedWindowConsumerLatchWait(this);
            }
        }
Example #13
0
        private async Task <string> LockAndSaveFeatureByLokalIdAsync(Guid lokalId, Locking locking)
        {
            var fileResponse = await Client.GetDatasetFeaturesAsync(clientString, DatasetId, locking, null, References.Direct, epsg25833, GetLokalIdQuery(lokalId));

            return(General.WriteStreamToDisk(fileResponse));
        }
Example #14
0
        private async Task DeleteByLokalIdAsync(string tempFile, List <Guid> lokalIds, Locking locking)
        {
            string deleteXmlPath = Wfs.CreateDeleteTransaction(tempFile, lokalIds);

            Console.WriteLine($"Executing Delete");

            var response = await Execute(locking, deleteXmlPath);

            Assert.IsTrue(response.Features_erased > 0, $"Feature with lokalIds ({string.Join(',', lokalIds)}) not deleted");
        }
Example #15
0
 private async Task DeleteByLokalIdAsync(string tempFile, Guid lokalId, Locking locking)
 {
     await DeleteByLokalIdAsync(tempFile, new List <Guid> {
         lokalId
     }, locking);
 }
        private static void TrySendCountFollowedBy(
            int numThreads,
            int numEvents,
            Locking locking,
            Configuration configuration)
        {
            configuration.Runtime.Threading.InsertIntoDispatchLocking = locking;
            configuration.Runtime.Threading.InsertIntoDispatchTimeout = 5000; // 5 second timeout
            configuration.Common.AddEventType(typeof(SupportBean));

            // This should fail all test in this class
            // config.getEngineDefaults().getThreading().setInsertIntoDispatchPreserveOrder(false);
            var runtime = EPRuntimeProvider.GetRuntime(
                typeof(MultithreadDeterminismInsertIntoLockConfig).Name,
                configuration);
            runtime.Initialize();

            // setup statements
            var path = new RegressionPath();
            var eplInsert = "insert into MyStream select count(*) as cnt from SupportBean";
            var compiledInsert = Compile(eplInsert, configuration, path);
            path.Add(compiledInsert);
            var deployedInsert = Deploy(compiledInsert, runtime);
            deployedInsert.Statements[0].Events += (
                sender,
                updateEventArgs) => {
                log.Debug(".update cnt=" + updateEventArgs.NewEvents[0].Get("cnt"));
            };

            var listeners = new SupportUpdateListener[numEvents];
            for (var i = 0; i < numEvents; i++) {
                var text = "select * from pattern [MyStream(cnt=" + (i + 1) + ") -> MyStream(cnt=" + (i + 2) + ")]";
                var compiled = Compile(text, configuration, path);
                var deployedPattern = Deploy(compiled, runtime);
                listeners[i] = new SupportUpdateListener();
                deployedPattern.Statements[0].AddListener(listeners[i]);
            }

            // execute
            var threadPool = Executors.NewFixedThreadPool(
                numThreads,
                new SupportThreadFactory(typeof(MultithreadDeterminismInsertIntoLockConfig)).ThreadFactory);
            var future = new IFuture<object>[numThreads];
            var sharedStartLock = new SlimReaderWriterLock();
            using (sharedStartLock.WriteLock.Acquire()) {
                for (var i = 0; i < numThreads; i++) {
                    future[i] = threadPool.Submit(
                        new SendEventRWLockCallable(i, sharedStartLock, runtime, new GeneratorEnumerator(numEvents)));
                }

                ThreadSleep(100);
            }

            threadPool.Shutdown();
            ExecutorAwait(threadPool, 10, TimeUnit.SECONDS);
            AssertFutures(future);

            // assert result
            for (var i = 0; i < numEvents - 1; i++) {
                Assert.AreEqual(1, listeners[i].NewDataList.Count, "Listener not invoked: #" + i);
            }

            runtime.Destroy();
        }