示例#1
0
        void sinkDeleteLog(StoreEventArgs pArgs)
        {
            Guid tPluginG = TheCommonUtils.CGuid(pArgs.Para);

            if (tPluginG == Guid.Empty)
            {
                return;
            }
            var tPlugin = MyLogFiles.GetEntryByID(tPluginG);

            if (tPlugin != null && File.Exists(tPlugin.FileName))
            {
                File.Delete(tPlugin.FileName);
            }
        }
示例#2
0
        public bool CreateUX()
        {
            if (!mIsUXInitStarted)
            {
                mIsUXInitStarted = true;

                //NUI Definition for All clients
                TheNMIEngine.AddDashboard(MyBaseThing, new TheDashboardInfo(MyBaseEngine, "Thing Provisioner")
                {
                    PropertyBag = new nmiDashboardTile {
                        Caption = "Thing Provisioner", Category = "Services", Thumbnail = "FA5Sf110",
                    }
                });

                if (TheCommonUtils.CBool(TheBaseAssets.MySettings.GetSetting("RedPill")))
                {
                    MyScriptTable = new TheFormInfo(TheThing.GetSafeThingGuid(MyBaseThing, "SCRIPT_TABLE"), eEngineName.NMIService, "Script Table", $"ScriptTableFields{MyBaseThing.ID}")
                    {
                        PropertyBag = new nmiCtrlFormView {
                            TileWidth = 12, TileHeight = 10
                        }
                    };
                    TheNMIEngine.AddFormToThingUX(MyBaseThing, MyScriptTable, "CMyTable", "Script Table", 1, 3, 0xF0, null, null, new ThePropertyBag()
                    {
                        "Visibility=true"
                    });
                    TheNMIEngine.AddSmartControl(MyBaseThing, MyScriptTable, eFieldType.SingleCheck, 48, 2, 0, "Disabled", nameof(ScriptSnapshot.Disabled), new nmiCtrlSingleEnded()
                    {
                        TileWidth = 1, FldWidth = 1
                    });
                    TheNMIEngine.AddSmartControl(MyBaseThing, MyScriptTable, eFieldType.SingleEnded, 50, 0, 0, "Script Name", nameof(ScriptSnapshot.ScriptName), new nmiCtrlSingleEnded()
                    {
                        TileWidth = 2, FldWidth = 2
                    });
                    TheNMIEngine.AddSmartControl(MyBaseThing, MyScriptTable, eFieldType.Number, 55, 0, 0, "Script Step", nameof(ScriptSnapshot.ScriptStep), new nmiCtrlNumber()
                    {
                        TileWidth = 1, FldWidth = 1
                    });
                    TheNMIEngine.AddSmartControl(MyBaseThing, MyScriptTable, eFieldType.SingleEnded, 60, 0, 0, "Step Status", nameof(ScriptSnapshot.ScriptStatus), new nmiCtrlSingleEnded()
                    {
                        TileWidth = 2, FldWidth = 2
                    });
                    TheNMIEngine.AddSmartControl(MyBaseThing, MyScriptTable, eFieldType.SingleEnded, 65, 2, 0, "Step Name", nameof(ScriptSnapshot.StepName), new nmiCtrlSingleEnded()
                    {
                        TileWidth = 2, FldWidth = 2
                    });
                    TheNMIEngine.AddSmartControl(MyBaseThing, MyScriptTable, eFieldType.DateTime, 67, 0, 0, "Time", nameof(ScriptSnapshot.LastUpdate), new nmiCtrlDateTime()
                    {
                        TileWidth = 1, FldWidth = 1
                    });

                    TheNMIEngine.AddTableButtons(MyScriptTable);

                    if (TheCommonUtils.CBool(TheBaseAssets.MySettings.GetSetting("EnableDiagnostics")))
                    {
                        CreateScriptEditTemplate();

                        var button = TheNMIEngine.AddSmartControl(MyBaseThing, MyScriptTable, eFieldType.TileButton, 45, 2, 0, "Replay", null, new nmiCtrlTileButton()
                        {
                            TileWidth = 1, TileHeight = 1, FldWidth = 1, ClassName = "cdeGoodActionButton"
                        });
                        button.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, "test", async(sender, pPara) =>
                        {
                            try
                            {
                                if (!(pPara is TheProcessMessage pMSG) || pMSG.Message == null)
                                {
                                    return;
                                }

                                string[] cmd = pMSG.Message.PLS.Split(':');
                                if (cmd.Length > 2)
                                {
                                    var tScript = MyScriptTableStorage.GetEntryByID(TheCommonUtils.CGuid(cmd[2]));

                                    if (null != tScript)
                                    {
                                        if (string.IsNullOrEmpty(tScript.ScriptName))
                                        {
                                            var script = LoadScript(tScript.FileName);
                                            await RunScriptAsync(script, tScript.Context, tScript.ScriptStep - 1, true);
                                        }
                                        //Rerun script step from snapshot.
                                        await RunScriptAsync(tScript.ContextScript, tScript.Context, tScript.ScriptStep - 1, true);
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                MyBaseThing.LastMessage = $"Error replaying: {e.Message}";
                            }
                        });
                    }
                }

                TheNMIEngine.AddAboutButton(MyBaseThing, false);
                mIsUXInitCompleted = true;
            }
            return(true);
        }
        public void RemoveAnItemByIDFromTheStorageMirrorTest()
        {
            #region ASSEMBLE

            TheStorageMirror <TheStorageEngineTSM> .StoreResponse response = null;
            int totalCandidates       = 5000;
            int indexMiddle           = totalCandidates / 2;
            int indexCurrent          = 0;
            var random                = new Random();
            var data                  = Enumerable.Range(1, totalCandidates).OrderBy(i => random.Next(1, totalCandidates));
            ManualResetEventSlim gate = new ManualResetEventSlim();
            TheStorageMirror <TheStorageEngineTSM> mirror;
            TheStorageEngineTSM        tsmCurrent = null;
            TheStorageEngineTSM        tsmMiddle  = null;
            TheStorageEngineTSM        tsmMatch   = null;
            List <TheStorageEngineTSM> TSMs       = new List <TheStorageEngineTSM>();
            List <TheStorageEngineTSM> myRecords  = new List <TheStorageEngineTSM>();

            // Build the collection of TSMs and cache the middle one
            foreach (var payload in data)
            {
                tsmCurrent = new TheStorageEngineTSM()
                {
                    cdeMID     = Guid.NewGuid(),
                    TXTPattern = payload.ToString()
                };
                TSMs.Add(tsmCurrent);
                if ((indexCurrent++ >= indexMiddle) && (tsmMiddle == null))
                {
                    tsmMiddle = tsmCurrent;
                }
            }
            if (tsmMiddle == null)
            {
                Assert.Fail("Unable to cache the middle TSM!");
            }

            // Spin up your mirror
            mirror = new TheStorageMirror <TheStorageEngineTSM>(TheCDEngines.MyIStorageService)
            {
                IsRAMStore               = true,
                CacheStoreInterval       = 1,
                IsStoreIntervalInSeconds = true,
                IsCachePersistent        = true,
                UseSafeSave              = true,
                AllowFireUpdates         = true,
            };
            mirror.RegisterEvent(eStoreEvents.StoreReady, e => { gate.Set(); });
            mirror.InitializeStore(true);

            // Wait for mirror to initialize...
            gate.Wait(30000);

            // Add your items
            Task.Factory.StartNew(() =>
            {
                mirror.AddItems(TSMs, payload =>
                {
                    response = payload;
                    gate.Set();
                });
            });

            //Wait for response
            gate.Reset();
            gate.Wait(30000);
            if ((response != null) && response.HasErrors)
            {
                Assert.Fail("Unable to add test collection items! Reason: {0}", response.ErrorMsg);
            }

            #endregion

            #region ACT

            // Attempt to remove your middle item
            Task.Factory.StartNew(() =>
            {
                mirror.RemoveAnItemByID(tsmMiddle.cdeMID, payload =>
                {
                    response = payload;
                    gate.Set();
                });
            });

            // Wait for response
            gate.Reset();
            gate.Wait(30000);
            if ((response != null) && response.HasErrors)
            {
                Assert.Fail("Unable to remove item by ID! Reason: {0}", response.ErrorMsg);
            }

            // Attempt to retrieve your middle item
            tsmMatch = mirror.GetEntryByID(tsmMiddle.cdeMID);

            mirror?.Dispose();

            #endregion

            #region ASSERT

            Assert.IsTrue(tsmMatch == null);

            #endregion
        }