Example #1
0
        public void obter_scripts_com_erro()
        {
            var scriptAplicado1 = new ChangeEntry("2.0.0.0", 8);

            scriptAplicado1.ScriptName = "8.Create Product Table.sql";
            scriptAplicado1.Status     = ScriptStatus.Failure;
            scriptAplicado1.Output     = "Ocorreu algum erro ao executar";

            var scriptAplicado2 = new ChangeEntry("2.0.0.0", 9);

            scriptAplicado2.ScriptName = "09.Add Product Data.sql";
            scriptAplicado2.Status     = ScriptStatus.Failure;
            scriptAplicado2.Output     = "Insert duplicate ID error";

            var scriptAplicado3 = new ChangeEntry("2.0.0.0", 10);

            scriptAplicado3.ScriptName = "10.Add Product Data.sql";
            scriptAplicado3.Status     = ScriptStatus.Success;

            databaseSchemaVersionManager.Setup(x => x.GetAppliedChanges()).Returns(new List <ChangeEntry>
            {
                scriptAplicado1,
                scriptAplicado2,
                scriptAplicado3
            });

            var scripsComErroDeExecucao = repositorioScripts.ObterScritpsExecutadosComErro();

            scripsComErroDeExecucao.Should().NotBeEmpty();
            scripsComErroDeExecucao.Count.Should().Be(2);
            scripsComErroDeExecucao[0].ScriptName.Should().Be("8.Create Product Table.sql");
            scripsComErroDeExecucao[0].Output.Should().Be("Ocorreu algum erro ao executar");
            scripsComErroDeExecucao[1].ScriptName.Should().Be("09.Add Product Data.sql");
            scripsComErroDeExecucao[1].Output.Should().Be("Insert duplicate ID error");
        }
Example #2
0
        public void retornar_que_script_foi_executado_com_sucesso(ScriptStatus scriptStatus)
        {
            var changeEntry = new ChangeEntry("Folder", 1)
            {
                Status = scriptStatus
            };

            changeEntry.ExecutedSuccessfully.Should().BeTrue();
        }
Example #3
0
        public void retorar_que_o_script_nao_foi_executado_com_sucesso()
        {
            var changeEntry = new ChangeEntry("Folder", 1)
            {
                Status = ScriptStatus.Failure
            };

            changeEntry.ExecutedSuccessfully.Should().BeFalse();
        }
Example #4
0
        public async Task <CommandExecutionResult> HandleAsync(CloseNotificationCommand command)
        {
            var changeEntry = new ChangeEntry <NotificationEntity>().Key(notification => notification.NotificationId, command.NotificationId)
                              .Property(notification => notification.Closed, DateTime.UtcNow);

            await _repository.UpdateAsync(changeEntry.Entity, changeEntry.Properties);

            return(CommandExecutionResult.Success);
        }
Example #5
0
        public async Task <CommandExecutionResult> HandleAsync(UpdateEmployeeGeneralInfoCommand command)
        {
            var changeEntry = new ChangeEntry <EmployeeEntity>().Key(employee => employee.EmployeeId, command.EmployeeId)
                              .Property(employee => employee.FirstName, command.FirstName)
                              .Property(employee => employee.LastName, command.LastName)
                              .Property(employee => employee.EmployeeNo, command.EmployeeNo);

            await _repository.UpdateAsync(changeEntry.Entity, changeEntry.Properties);

            return(CommandExecutionResult.Success);
        }
        public void TestRequestDiscard()
        {
            m_Presenter.Start();
            const string path  = "path";
            var          entry = new ChangeEntry(path);

            m_Presenter.RequestDiscard(entry);
            Assert.AreEqual(1, m_Model.RequestDiscardCount);
            Assert.AreEqual(path, m_Model.RequestDiscardEntry.Path);
            // Ensure it created a dialogue
            Assert.AreEqual(1, m_View.DisplayDialogueCount);
        }
Example #7
0
        private IList <ChangeEntry> createTestData(int commonAmount, bool keepProperties)
        {
            IList <ChangeEntry> result = new List <ChangeEntry>();

            for (int i = 0; i < commonAmount; i++)
            {
                //TODO: Change document creation to default versioning state after versioning problem will be fixed
                string objectId = createAndAssertObject(getAndAssertRootFolder(), enumVersioningState.none).ObjectId;

                ChangeEntry entry = new ChangeEntry(objectId, enumTypeOfChanges.created);
                result.Add(entry);
            }
            return(result);
        }
Example #8
0
        public void TestRequestDiscard()
        {
            var provider = new TestSourceControlProvider();
            var model    = new ChangesModel(provider);

            model.OnStart();

            const string path  = "path";
            var          entry = new ChangeEntry(path);

            model.RequestDiscard(entry);
            Assert.AreEqual(1, provider.RequestedDiscardCount);
            Assert.AreEqual(path, provider.RequestedDiscardEntry?.Path);
        }
Example #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static <Key> boolean performLookup(ReadableState<Key> store, org.neo4j.io.pagecache.tracing.cursor.context.VersionContext versionContext, java.util.concurrent.ConcurrentMap<Key,ChangeEntry> changes, Key key, ValueSink sink) throws java.io.IOException
        private static bool PerformLookup <Key>(ReadableState <Key> store, VersionContext versionContext, ConcurrentMap <Key, ChangeEntry> changes, Key key, ValueSink sink)
        {
            ChangeEntry change = changes.get(key);

            if (change != null)
            {
                if (change.Version > versionContext.LastClosedTransactionId())
                {
                    versionContext.MarkAsDirty();
                }
                sink.Value(new BigEndianByteArrayBuffer(change.Data));
                return(true);
            }
            return(store.Lookup(key, sink));
        }
Example #10
0
        public void obter_scripts_pedente_execucao_e_marcados_como_resolvido()
        {
            var scriptAplicado1 = new ChangeEntry("2.0.0.0", 8);

            scriptAplicado1.ScriptName = "8.Create Product Table.sql";
            scriptAplicado1.Status     = ScriptStatus.ProblemResolved;

            var scriptAplicado2 = new ChangeEntry("2.0.0.0", 9);

            scriptAplicado2.ScriptName = "09.Add Product Data.sql";
            scriptAplicado2.Status     = ScriptStatus.Success;

            var scriptAplicado3 = new ChangeEntry("2.0.0.0", 10);

            scriptAplicado2.ScriptName = "10.Add Product Data.sql";
            scriptAplicado2.Status     = ScriptStatus.SucessRevisedUser;

            databaseSchemaVersionManager.Setup(x => x.GetAppliedChanges()).Returns(new List <ChangeEntry>
            {
                scriptAplicado1,
                scriptAplicado2,
                scriptAplicado3,
            });

            var changeScript1 = new ChangeScript("2.0.0.0", 8, "8.Create Product Table.sql");
            var changeScript2 = new ChangeScript("2.0.0.0", 9, "09.Add Product Data.sql");
            var changeScript3 = new ChangeScript("2.10.0.0", 1, "1.SQLCMD Add Customer Table.sql");

            changeScriptRepository.Setup(x => x.GetAvailableChangeScripts()).Returns(new List <ChangeScript>
            {
                changeScript1,
                changeScript2,
                changeScript3
            });

            var listaChangeScripts = repositorioScripts.ObterScriptsPendenteExecucao(null);

            listaChangeScripts.Should().NotBeEmpty();
            listaChangeScripts.Count.Should().Be(2);

            listaChangeScripts.Should().NotContain(x => x.ScriptName == "09.Add Product Data.sql" && x.Folder == "2.0.0.0");
            listaChangeScripts.Should().NotContain(x => x.ScriptName == "10.Add Product Data.sql" && x.Folder == "2.0.0.0");
            listaChangeScripts.Should().Contain(x => x.ScriptName == "8.Create Product Table.sql" && x.Folder == "2.0.0.0");
            listaChangeScripts.Should().Contain(x => x.ScriptName == "1.SQLCMD Add Customer Table.sql" && x.Folder == "2.10.0.0");
        }
Example #11
0
        public void obter_script_especifico()
        {
            var changeEntryASerRetornado = new ChangeEntry("folder2", 1);

            databaseSchemaVersionManager.Setup(x => x.GetAppliedChanges()).Returns(new List <ChangeEntry>
            {
                new ChangeEntry("folder1", 1),
                new ChangeEntry("folder1", 2),
                changeEntryASerRetornado,
                new ChangeEntry("folder2", 2),
            });
            var changeScript = new ChangeScript("folder2", 1, new FileInfo("script.sql"), Encoding.UTF8);

            var changeEntry = repositorioScripts.ObterScriptExecutado(changeScript);

            changeEntry.Should().NotBeNull();
            changeEntry.Should().Be(changeEntryASerRetornado);
        }
Example #12
0
        public void aplicar_mudancas_ate_script_informado()
        {
            var scriptAplicado1 = new ChangeEntry("2.0.0.0", 8);

            scriptAplicado1.ScriptName = "8.Create Product Table.sql";
            scriptAplicado1.Status     = ScriptStatus.Success;

            var scriptAplicado2 = new ChangeEntry("2.0.0.0", 9);

            scriptAplicado2.ScriptName = "09.Add Product Data.sql";
            scriptAplicado2.Status     = ScriptStatus.Success;

            databaseSchemaVersionManager.Setup(x => x.GetAppliedChanges()).Returns(new List <ChangeEntry>
            {
                scriptAplicado1,
                scriptAplicado2
            });

            var changeScript1 = new ChangeScript("2.0.0.0", 8);
            var changeScript2 = new ChangeScript("2.0.0.0", 9);
            var changeScript3 = new ChangeScript("2.10.0.0", 1);
            var changeScript4 = new ChangeScript("2.10.0.0", 2);
            var changeScript5 = new ChangeScript("2.10.0.0", 3);

            changeScriptRepository.Setup(x => x.GetAvailableChangeScripts()).Returns(new List <ChangeScript>
            {
                changeScript1,
                changeScript2,
                changeScript3,
                changeScript4,
                changeScript5
            });

            var pendenteExecucao = repositorioScripts.ObterScriptsPendenteExecucao(new UniqueChange("2.10.0.0", 2));

            pendenteExecucao.Should().NotBeEmpty();
            pendenteExecucao.Count.Should().Be(2);
            pendenteExecucao[0].Folder.Should().Be("2.10.0.0");
            pendenteExecucao[0].ScriptNumber.Should().Be(1);
            pendenteExecucao[1].Folder.Should().Be("2.10.0.0");
            pendenteExecucao[1].ScriptNumber.Should().Be(2);
        }
Example #13
0
        public void obter_scripts_aplicados()
        {
            var scriptAplicado1 = new ChangeEntry("2.0.0.0", 8);

            scriptAplicado1.ScriptName = "8.Create Product Table.sql";

            var scriptAplicado2 = new ChangeEntry("2.0.0.0", 9);

            scriptAplicado2.ScriptName = "09.Add Product Data.sql";

            databaseSchemaVersionManager.Setup(x => x.GetAppliedChanges()).Returns(new List <ChangeEntry>
            {
                scriptAplicado1,
                scriptAplicado2
            });

            var scriptsAplicados = repositorioScripts.ObterScriptsAplicados();

            scriptsAplicados.Should().NotBeEmpty();
            scriptsAplicados.Count.Should().Be(2);
            scriptsAplicados.Should().Contain(x => x.ScriptName == "8.Create Product Table.sql" && x.Folder == "2.0.0.0");
            scriptsAplicados.Should().Contain(x => x.ScriptName == "09.Add Product Data.sql" && x.Folder == "2.0.0.0");
        }
Example #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter") static <Key> void applyUpdate(ReadableState<Key> store, java.util.concurrent.ConcurrentMap<Key, ChangeEntry> changes, Key key, ValueUpdate update, boolean reset, long version) throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal static void ApplyUpdate <Key>(ReadableState <Key> store, ConcurrentMap <Key, ChangeEntry> changes, Key key, ValueUpdate update, bool reset, long version)
        {
            ChangeEntry value = changes.get(key);

            if (value == null)
            {
                ChangeEntry newEntry = ChangeEntry.Of(new sbyte[store.KeyFormat().valueSize()], version);
                lock ( newEntry )
                {
                    value = changes.putIfAbsent(key, newEntry);
                    if (value == null)
                    {
                        BigEndianByteArrayBuffer buffer = new BigEndianByteArrayBuffer(newEntry.Data);
                        if (!reset)
                        {
                            PreviousValue lookup = new PreviousValue(newEntry.Data);
                            if (!store.Lookup(key, lookup))
                            {
                                buffer.Clear();
                            }
                        }
                        update.Update(buffer);
                        return;
                    }
                }
            }
            lock ( value )
            {
                BigEndianByteArrayBuffer target = new BigEndianByteArrayBuffer(value.Data);
                value.Version = version;
                if (reset)
                {
                    target.Clear();
                }
                update.Update(target);
            }
        }
        /// <summary>
        /// 取得異動集合
        /// </summary>
        /// <returns></returns>
        public List<ChangeEntry> GetChangeSet()
        {
            List<ChangeEntry> ChangeEntries = new List<ChangeEntry>();

            DSXmlHelper helper = new DSXmlHelper("Request");

            //<Request>
            //<All/>
            //<Condition>
            //<Sequence>1</Sequence>
            //</Condition>
            //</Request>
            helper.AddElement("All");
            helper.AddElement("Condition");
            helper.AddElement("Condition", "Sequence", CurrentSequence.ToString());

            DSRequest Req = new DSRequest(helper.BaseElement);

            DSXmlHelper rsp = DSAServices.CallService(GETCHANGESET_SERVICENAME, Req).GetContent();

            //從Server端取回多筆的ChangeEntry
            foreach (XmlElement element in rsp.GetElements("Change"))
            {
                //將ChangeEntry的XML格式轉為物件
                ChangeEntry Entry = new ChangeEntry();
                Entry.Load(element);

                //將ChangeEntry根據表格名稱、異動類別(Insert、Update、Delete)及鍵值組合成異動鍵值
                string UID = Entry.TableName + "-" + Entry.Action.ToString() + "-" + Entry.DataID;

                Console.WriteLine("UID:"+UID);
                Console.WriteLine("ClientChangeSetCount:"+mClientChangeSet.Count);

                //假設在ClientChangeSet當中有對應的異動鍵值,並且該異動鍵值裡的集合數大於零,那麼就進行合併消去動作
                if (mClientChangeSet.ContainsKey(UID) && mClientChangeSet[UID].Count>0)
                {
                    List<ChangeEntry> RemoveEntries = new List<ChangeEntry>();

                    foreach (ChangeEntry LocalEntry in mClientChangeSet[UID])
                    {
                        //狀況一:本機異動(ClientChangeEntry)與遠端異動(ServerChangeEntry)的異動筆數(Count)一樣:
                        //1.遠端異動(ServerChangeEntry)不加入到實際異動(GetChangeSet的傳回值)。
                        //2.本機異動(ClientChangeEntry)移除。
                        //3.發生情況:當新增本機異動至取得遠端異動期間,只有本機對於該筆資料做異動。
                        if (LocalEntry.Count == Entry.Count)
                        {
                            Console.WriteLine("狀況一");
                            RemoveEntries.Add(LocalEntry); //將ClientChangeEntry及ServerChangeEntry進行對消。
                        }
                        //狀況二:本機異動(ClientChangeEntry)大於遠端異動(ServerChangeEntry)的異動筆數(Count):
                        //1.遠端異動(ServerChangeEntry)不加入到實際異動(GetChangeSet的傳回值)。
                        //2.本機異動(ClientChangeEntry)的異動筆數減去遠端異動(ServerChangeEntry)並保留本機異動。
                        //3.發生情況:理論上不會有此種情況發生,可能情況是新增本機異動時,馬上就取得遠端異動,而本機異動尚未反應到遠端異動。
                        else if (LocalEntry.Count > Entry.Count)
                        {
                            Console.WriteLine("狀況二");
                            LocalEntry.Count -= Entry.Count; //保留ClientChangeEntry,消去ServerChangeEntry
                        }
                        //狀況三:本機異動(ClientChangeEntry)小於遠端異動(ServerChangeEntry)的異動筆數(Count):
                        //1.遠端異動(ServerChangeEntry)加入到實際異動(GetChangeSet的傳回值),並且減去本機異動的異動筆數。
                        //2.本機異動(ClientChangeEntry)移除。
                        //3.發生情況:當新增本機異動至取得遠端異動期間,還有其他機器對於此筆資料做修改。
                        else if (LocalEntry.Count < Entry.Count)
                        {
                            Console.WriteLine("狀況三");

                            Entry.Count -= LocalEntry.Count;

                            RemoveEntries.Add(LocalEntry); //將ClientChangeEntry移除

                            ChangeEntries.Add(Entry); //將ServerChangeEntry加入到ChangeSet當中
                        }
                    }

                    //將ClientEntry自ClientChangeSet當中移除
                    foreach (ChangeEntry RemoveEntry in RemoveEntries)
                        mClientChangeSet[UID].Remove(RemoveEntry);
                }
                //本機沒有異動,但是遠端有異動的情況
                else
                {
                    Console.WriteLine("狀況四");
                    ChangeEntries.Add(Entry);
                }

                //不管是哪種狀況,都要將Sequence的值設為最大值,下次才不會重覆取得
                if (Entry.Sequence > CurrentSequence)
                    CurrentSequence = Entry.Sequence;
            }

            return ChangeEntries;
        }
        private IList<ChangeEntry> createTestData(int commonAmount, bool keepProperties)
        {
            IList<ChangeEntry> result = new List<ChangeEntry>();
            for (int i = 0; i < commonAmount; i++)
            {
                //TODO: Change document creation to default versioning state after versioning problem will be fixed
                string objectId = createAndAssertObject(getAndAssertRootFolder(), enumVersioningState.none).ObjectId;

                ChangeEntry entry = new ChangeEntry(objectId, enumTypeOfChanges.created);
                result.Add(entry);
            }
            return result;
        }
Example #17
0
        public override async Task <ReqResult> OnUiRequestAsync(string command, DataValue parameters)
        {
            switch (command)
            {
            case "ReadModuleVariables":

                if (activeModuleID != "")
                {
                    await Connection.DisableChangeEvents();
                }

                var    pars     = parameters.Object <ReadModuleVariables_Params>() ?? throw new Exception("ReadModuleVariables_Params is null");
                string moduleID = string.IsNullOrEmpty(pars.ModuleID) ? modules[0].ID : pars.ModuleID;

                ObjectInfo?rootObjInfo;
                while (true)
                {
                    rootObjInfo = await Connection.GetRootObject(moduleID);

                    if (rootObjInfo != null)
                    {
                        break;
                    }
                    await Task.Delay(500);
                }

                ObjectRef rootObj = rootObjInfo.ID;

                var objects = await Connection.GetAllObjects(moduleID);

                SetObjectNameMap(objects);

                List <VariableValue> values = await Connection.ReadAllVariablesOfObjectTree(rootObj);

                await Connection.EnableVariableValueChangedEvents(SubOptions.AllUpdates(sendValueWithEvent: true), rootObj);

                VarEntry[] entries = values.Select(MapVarValue).ToArray();

                activeModuleID = moduleID;

                var locations = await Connection.GetLocations();

                var result = new ReadModuleVariables_Result()
                {
                    Modules    = modules,
                    ModuleID   = moduleID,
                    ModuleName = modules.FirstOrDefault(m => m.ID == moduleID).Name,
                    Variables  = entries,
                    Locations  = locations.ToArray(),
                };

                mapIdx.Clear();
                for (int n = 0; n < values.Count; ++n)
                {
                    mapIdx[values[n].Variable] = n;
                }

                return(ReqResult.OK(result));

            case "WriteVariable": {
                var write = parameters.Object <WriteVariable_Params>() ?? throw new Exception("WriteVariable_Params is null");
                VTQ vtq   = new VTQ(Timestamp.Now, Quality.Good, DataValue.FromJSON(write.V));
                await Connection.WriteVariable(ObjectRef.FromEncodedString(write.ObjID), write.Var, vtq);

                return(ReqResult.OK());
            }

            case "SyncRead": {
                var         sread  = parameters.Object <ReadSync_Params>() ?? throw new Exception("ReadSync_Params is null");
                ObjectRef   obj    = ObjectRef.FromEncodedString(sread.ObjID);
                VariableRef varRef = VariableRef.Make(obj, sread.Var);
                VTQ         vtq    = await Connection.ReadVariableSync(varRef);

                int idx   = mapIdx[varRef];
                var entry = new ChangeEntry()
                {
                    N = idx,
                    V = vtq.V,
                    T = Timestamp2Str(vtq.T),
                    Q = vtq.Q
                };
                return(ReqResult.OK(entry));
            }

            default:
                return(ReqResult.Bad("Unknown command: " + command));
            }
        }