示例#1
0
                /// <summary>
                /// ランキングリストに予測状態とその出現確率を格納する
                /// </summary>
                /// <param name="expectedState"></param>
                /// <remarks></remarks>
                public void Add(ExpectedState expectedState)
                {
                    //既に同じ状態が存在する場合は、出現確率を合計する
                    for (int i = 0; i <= _rank.Count - 1; i++)
                    {
                        if (expectedState.State == _rank[i].State)
                        {
                            expectedState = new ExpectedState(expectedState.State, expectedState.Appended, expectedState.Provably + _rank[i].Provably);
                            _rank.RemoveAt(i);
                            break;
                        }
                    }

                    for (int i = _rank.Count - 1; i >= 0; i += -1)
                    {
                        if (expectedState.Provably > _rank[i].Provably)
                        {
                            _rank.Insert(i + 1, expectedState);
                            return;
                        }
                    }
                }
示例#2
0
                /// <summary>
                /// 予測状態の確率順リストを出力する
                /// </summary>
                /// <param name="priorProbability">事前確率</param>
                /// <param name="top">出力数</param>
                /// <returns></returns>
                /// <remarks></remarks>
                public ExpectedState[] GetExpectedStateRank(double priorProbability, int top)
                {
                    int retCount = System.Math.Min(top - 1, _stateToFrequency.Count - 1);

                    ExpectedState[] ret = new ExpectedState[retCount + 1];

                    for (int frequency = 1; frequency <= _frequencyRank.Count; frequency++)
                    {
                        foreach (string state in _frequencyRank[frequency - 1])
                        {
                            if (retCount < 0)
                            {
                                return(ret);
                            }
                            ret[retCount] = new ExpectedState(state
                                                              , this.GetAppended(state)
                                                              , (double)frequency / (double)_totalFreqency * priorProbability);
                            retCount -= 1;
                        }
                    }

                    return(ret);
                }
示例#3
0
    public MyProjectInstaller(ExpectedState expectedState, string RelatPath)
    {
        // Instantiate installers for process and services.
        serviceInstaller = new ServiceInstaller();
        ServiceProcessInstaller ProcesServiceInstaller = new ServiceProcessInstaller();

        InstallContext Context = new InstallContext();

        String AbsolPath = Path.GetFullPath(RelatPath);

        AbsolPath = Path.Combine(AbsolPath, WyprostujSie.Files.WSB);
        AbsolPath = String.Format("/assemblypath={0}", AbsolPath);
        String[] cmdline = { AbsolPath };

        serviceInstaller.Parent = ProcesServiceInstaller;
        Context = new InstallContext("", cmdline);

        serviceInstaller.Context = Context;

        // The services are started automaticly.
        serviceInstaller.StartType = ServiceStartMode.Automatic;

        serviceInstaller.ServiceName = ServiceName;

        // Info for users
        serviceInstaller.DisplayName = "Wyprostuj się";
        serviceInstaller.Description = WyprostujSie.Properties.Resources.ServiceInstallerDescr.ToString();
        ServiceController serviceController = new ServiceController(serviceInstaller.ServiceName);

        System.Collections.Specialized.ListDictionary stateSaver = new System.Collections.Specialized.ListDictionary();

        switch (expectedState)
        {
        case ExpectedState.Install:
        {
            if (!Installed())
            {
                try
                {
                    serviceInstaller.Install(null);
                }
                catch { }
            }
            break;
        }

        case ExpectedState.Uninstall:
        {
            if (Installed())
            {
                try
                {
                    if (serviceController.Status == ServiceControllerStatus.Running || serviceController.Status == ServiceControllerStatus.StartPending)
                    {
                        serviceController.Stop();
                        serviceController.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(3));
                    }
                    serviceInstaller.Uninstall(null);
                }
                catch { }
            }
            break;
        }

        case ExpectedState.Stop:
        {
            if (Installed())
            {
                if (serviceController.Status == ServiceControllerStatus.Running || serviceController.Status == ServiceControllerStatus.StartPending)
                {
                    try
                    {
                        serviceController.Stop();
                        serviceController.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(5));
                    }
                    catch { }
                }
            }
            break;
        }

        case ExpectedState.Start:
        {
            if (Installed())
            {
                if (serviceController.Status == ServiceControllerStatus.Stopped || serviceController.Status == ServiceControllerStatus.StopPending)
                {
                    try
                    {
                        serviceController.Start();
                        serviceController.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(5));
                    }
                    catch { }
                }
            }
            break;
        }
        }
    }
示例#4
0
        public void TestStoreAsEpoch(Table hashRangeTable, Table numericHashRangeTable)
        {
            // verify conversions
            var e1 = DateTimeToEpochSeconds((Primitive)EpochDate, "test") as Primitive;

            Assert.IsNotNull(e1);
            Assert.AreEqual(DynamoDBEntryType.Numeric, e1.Type);
            Assert.AreEqual(EpochSeconds, e1.AsInt());

            var e2 = EpochSecondsToDateTime((Primitive)EpochSeconds, "test") as Primitive;

            Assert.IsNotNull(e2);
            Assert.AreEqual(DynamoDBEntryType.String, e2.Type);
            ApproximatelyEqual(EpochDate, e2.AsDateTime());

            // construct tables with StoreAsEpoch
            var config = new TableConfig(hashRangeTable.TableName)
            {
                AttributesToStoreAsEpoch = new List <string> {
                    "CreationTime", "EpochDate2"
                }
            };
            var epochTable = Table.LoadTable(Client, config);

            CollectionAssert.AreEqual(config.AttributesToStoreAsEpoch, epochTable.GetStoreAsEpoch().ToList());

            config = new TableConfig(numericHashRangeTable.TableName)
            {
                AttributesToStoreAsEpoch = new List <string> {
                    "CreationTime", "EpochDate2"
                }
            };
            var numericEpochTable = Table.LoadTable(Client, config);

            CollectionAssert.AreEqual(config.AttributesToStoreAsEpoch, epochTable.GetStoreAsEpoch().ToList());

            // verify ToAttributeMap calls
            var map = hashRangeTable.ToAttributeMap(CreateTestDocument());

            Assert.IsNotNull(map["CreationTime"].S);
            Assert.IsNotNull(map["EpochDate2"].S);
            Assert.IsNotNull(map["NonEpochDate"].S);

            var epochMap = epochTable.ToAttributeMap(CreateTestDocument());

            Assert.IsNotNull(epochMap["CreationTime"].N);
            Assert.IsNotNull(epochMap["EpochDate2"].N);
            Assert.IsNotNull(epochMap["NonEpochDate"].S);

            // put
            epochTable.PutItem(CreateTestDocument());
            TestWrittenData("Bob", 42, hashRangeTable, epochTable);
            numericEpochTable.PutItem(CreateTestDocument());
            // accessing this item with non-epoch table will throw an exception
            TestWrittenData(EpochDate, "Bob", null, numericEpochTable);
            var exception = AssertExtensions.ExpectException <InvalidOperationException>(() => numericHashRangeTable.GetItem(EpochDate, "Bob"));

            Assert.IsTrue(exception.Message.Contains("hash key CreationTime, is inconsistent with specified hash key value."));

            // conditional put
            epochTable.PutItem(CreateTestDocument());
            var newDoc = CreateTestDocument();

            newDoc["ConditionalUpdate"] = "yes";
            var expectedState = new ExpectedState();

            expectedState.AddExpected("CreationTime", ScanOperator.Equal, EpochDate);
            epochTable.PutItem(newDoc, new PutItemOperationConfig {
                ExpectedState = expectedState
            });
            TestWrittenData("Bob", 42, hashRangeTable, epochTable, checkForConditionalUpdate: true);

            // update
            epochTable.UpdateItem(CreateTestDocument());
            TestWrittenData("Bob", 42, hashRangeTable, epochTable);

            // conditional update
            epochTable.UpdateItem(CreateTestDocument());
            newDoc = CreateTestDocument();
            newDoc["ConditionalUpdate"] = "yes";
            expectedState = new ExpectedState();
            expectedState.AddExpected("CreationTime", ScanOperator.Equal, EpochDate);
            epochTable.UpdateItem(newDoc, new UpdateItemOperationConfig {
                ExpectedState = expectedState
            });
            TestWrittenData("Bob", 42, hashRangeTable, epochTable, checkForConditionalUpdate: true);

            // second item for batch operations
            var doc2 = new Document();

            doc2["Name"]         = "Bob";
            doc2["Age"]          = 43;
            doc2["CreationTime"] = EpochDate;
            doc2["EpochDate2"]   = EpochDate;
            doc2["NonEpochDate"] = EpochDate;

            // batchWrite epoch seconds
            var batchWrite = epochTable.CreateBatchWrite();

            batchWrite.AddDocumentToPut(CreateTestDocument());
            batchWrite.AddDocumentToPut(doc2);
            batchWrite.Execute();
            TestWrittenData("Bob", 42, hashRangeTable, epochTable);
            TestWrittenData("Bob", 43, hashRangeTable, epochTable);
            // execute again, since TestWrittenData deletes the items
            batchWrite.Execute();

            // batchGet epoch seconds as DateTime
            var epochBatchGet = epochTable.CreateBatchGet();

            epochBatchGet.ConsistentRead = true;
            epochBatchGet.AddKey("Bob", 42);
            epochBatchGet.AddKey("Bob", 43);
            epochBatchGet.Execute();
            TestForDateTime(epochBatchGet.Results);

            // batchGet epoch seconds as int
            var batchGet = hashRangeTable.CreateBatchGet();

            batchGet.ConsistentRead = true;
            batchGet.AddKey("Bob", 42);
            batchGet.AddKey("Bob", 43);
            batchGet.Execute();
            TestForInts(batchGet.Results);

            // batchWrite ISO-8601
            batchWrite = hashRangeTable.CreateBatchWrite();
            batchWrite.AddDocumentToPut(CreateTestDocument());
            batchWrite.AddDocumentToPut(doc2);
            batchWrite.Execute();

            // batchGet ISO-8601 as DateTime
            epochBatchGet = epochTable.CreateBatchGet();
            epochBatchGet.ConsistentRead = true;
            epochBatchGet.AddKey("Bob", 42);
            epochBatchGet.AddKey("Bob", 43);
            epochBatchGet.Execute();
            TestForDateTime(epochBatchGet.Results);

            // batchGet ISO-8601 as DateTime with non-epoch table
            batchGet = hashRangeTable.CreateBatchGet();
            batchGet.ConsistentRead = true;
            batchGet.AddKey("Bob", 42);
            batchGet.AddKey("Bob", 43);
            batchGet.Execute();
            TestForDateTime(batchGet.Results);

            // write epoch seconds data data for Scan and Query
            batchWrite = epochTable.CreateBatchWrite();
            batchWrite.AddDocumentToPut(CreateTestDocument());
            batchWrite.AddDocumentToPut(doc2);
            batchWrite.Execute();

            // query
            var toTest = hashRangeTable.Query("Bob", new QueryFilter()).GetRemaining();

            TestForInts(toTest);
            toTest = epochTable.Query("Bob", new QueryFilter()).GetRemaining();
            TestForDateTime(toTest);

            //// query, filter is epoch seconds attribute
            //var queryFilter = new QueryFilter("CreationTime", QueryOperator.Equal, EpochDate);
            //toTest = numericHashRangeTable.Query(queryFilter).GetRemaining();
            //TestForDateTime(toTest);

            // scan, condition is epoch seconds attribute
            var scanFilter = new ScanFilter();

            scanFilter.AddCondition("CreationTime", ScanOperator.Equal, EpochDate);
            toTest = hashRangeTable.Scan(scanFilter).GetRemaining();
            Assert.AreEqual(0, toTest.Count);
            toTest = epochTable.Scan(scanFilter).GetRemaining();
            TestForDateTime(toTest);

            // scan, condition is Name
            scanFilter = new ScanFilter();
            scanFilter.AddCondition("Name", ScanOperator.Equal, "Bob");
            toTest = hashRangeTable.Scan(scanFilter).GetRemaining();
            TestForInts(toTest);
            toTest = epochTable.Scan(scanFilter).GetRemaining();
            TestForDateTime(toTest);
        }