Example #1
0
        /// <summary>
        /// Login with the details provided
        /// </summary>
        private async void Login(string email, string password)
        {
            try
            {
                try
                {
                    App.user = await User.Logon(email, password);
                }
                catch (AuthenticationException)
                {
                    this.ErrorMessage.Visibility = Visibility.Visible;
                    this.ErrorMessage.Text       = "Email or password is invalid";
                    this.Password_box.Password   = "";
                    Connection.Reset();
                    return;
                }
            }
            catch (Exception)
            {
                User.SetupConnection(email, password);
            }

            App.localStorage.Values["username"] = email;
            App.vault.Add(new PasswordCredential(App.AppName, email, password));
            this.Hide();
        }
Example #2
0
        public void Open()
        {
            if (Connection != null)
            {
                return;
            }

            if (!string.IsNullOrWhiteSpace(ConnectionString))
            {
                Helper.ParseConnectionString(ConnectionString, Options);
            }

            Connection = MyRawConnectionPool.Next(Options.Key);
            if (Connection != null)
            {
                // Reuse a pooled connection
                Pooled = true;
                Connection.Reset();
            }
            else
            {
                // Create a new connection
                Pooled     = false;
                Connection = new Connection();
                HandleOkPacket(Connection.Setup(Options));
            }

            UpdateDatabaseName();
            if (Database != Options.Database)
            {
                ChangeDatabase(Options.Database);
            }
        }
Example #3
0
        /// <summary>Tries to connect to a server.</summary>
        /// <param name="conData">Set the connection information properties as needed.
        /// For further details about each setting see the respective property documentation in <see cref="ConnectionData"/></param>
        /// <exception cref="ArgumentException">When some required values are not set or invalid.</exception>
        /// <exception cref="TsException">When the connection could not be established.</exception>
        public override async CmdR Connect(ConnectionData conData)
        {
            scheduler.VerifyOwnThread();
            if (!(conData is ConnectionDataFull conDataFull))
            {
                throw new ArgumentException($"Use the {nameof(ConnectionDataFull)} derivative to connect with the full client.", nameof(conData));
            }
            if (conDataFull.Identity is null)
            {
                throw new ArgumentNullException(nameof(conDataFull.Identity));
            }
            if (conDataFull.VersionSign is null)
            {
                throw new ArgumentNullException(nameof(conDataFull.VersionSign));
            }

            await Disconnect();

            remoteAddress = await TsDnsResolver.TryResolve(conData.Address);

            if (remoteAddress is null)
            {
                return(CommandError.Custom("Could not read or resolve address."));
            }

            ConnectionData  = conData;
            ServerConstants = TsConst.Default;
            Book.Reset();
            returnCode = 0;

            var ctx = new ConnectionContext(conDataFull);

            context = ctx;

            ctx.PacketHandler.PacketEvent = (ref Packet <S2C> packet) =>
            {
                if (status == TsClientStatus.Disconnected)
                {
                    return;
                }
                PacketEvent(ctx, ref packet);
            };
            ctx.PacketHandler.StopEvent = (closeReason) =>
            {
                _ = scheduler.Invoke(() =>
                {
                    ctx.ExitReason ??= closeReason;
                    ChangeState(ctx, TsClientStatus.Disconnected);
                });
            };

            ChangeState(ctx, TsClientStatus.Connecting);
            if (!ctx.PacketHandler.Connect(remoteAddress).GetOk(out var error))
            {
                ChangeState(ctx, TsClientStatus.Disconnected);
                return(CommandError.Custom(error));
            }
            return(await ctx.ConnectEvent.Task);            // TODO check error state
        }
Example #4
0
 static void Reset()
 {
     Variables.persChoiceNumber = -1;
     Variables.work             = false;
     Variables.waitMees         = false;
     Variables.needPersActive   = false;
     Variables.status           = "None";
     Variables.lastSend         = 0;
     Variables.lastUpd          = 0;
     Connection.Reset();
 }
Example #5
0
 /// <summary>
 /// Método para achar a instância da Connection. Lança uma NullReferenceException caso nenhum GameObject com esse MonoBehaviour exista.
 /// </summary>
 /// <returns>A instância atual da Connection.</returns>
 public static Connection Instance()
 {
     if (instance == null)
     {
         throw new System.NullReferenceException();
     }
     if (instance.sfs == null)
     {
         instance.Reset();
     }
     return(instance);
 }
Example #6
0
 private async Task InnerLoop(SAV8BS sav, CancellationToken token)
 {
     while (!token.IsCancellationRequested)
     {
         Config.IterateNextRoutine();
         var task = Config.CurrentRoutineType switch
         {
             PokeRoutineType.Idle => DoNothing(token),
             _ => DoTrades(sav, token),
         };
         try
         {
             await task.ConfigureAwait(false);
         }
         catch (SocketException e)
         {
             Log(e.Message);
             Connection.Reset();
         }
     }
 }
Example #7
0
        // dereferences <ftp connection="fromRefID" /> and sets up the
        // internal Connection object accordingly.
        protected void DereferenceConnectionAttribute(string fromRefID)
        {
            _connection.RefID = fromRefID;

            // the following code block was modified from
            // from NAnt.Core\Element.cs:line 1247 {v0.85-rc1)
            if (Project.DataTypeReferences.Contains(_connection.RefID)
                && Project.DataTypeReferences[_connection.RefID] is Connection) {
                _connection = (Connection)Project.DataTypeReferences[_connection.RefID];
                // clear any instance specific state
                _connection.Reset();
            } else {

                //_connection = new Connection();

                // try to load the password from the file
                if (!_connection.LoadPasswords(_connection.RefID)) {

                    // reference not found exception
                    throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                        "Connection '{0}' is not defined in the current project.", _connection.RefID),
                        this.Location);
                }
            }
        }
 private void ResetConnection()
 {
     _connection.Reset();
 }
Example #9
0
 public void ResetConnection()
 {
     AssertConnected();
     HandleOkPacket(Connection.Reset());
 }
Example #10
0
 public void BeforeEach()
 {
     Connection.Reset();
     User.Logon("e1f948fc1c6b2a09186309e61bfb4743").Wait();
 }
Example #11
0
        public bool TryPush(Connection connection)
        {
            #if DEBUG
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            if (connection.SendQueue.Count > 0)
            {
                //TODO: Error
                return false;
            }
            #endif

            connection.Reset();

            lock (pool)
            {
                pool.Push(connection);
            }

            return true;
        }
Example #12
0
        private List<string> _UpdateStructure(List<ExtractedTableMap> tables, List<Trigger> triggers, List<Generator> generators, List<IdentityField> identities, List<View> views, List<StoredProcedure> procedures,Connection conn)
        {
            List<string> ret = new List<string>();

            List<string> alteredTables = new List<string>();
            foreach (ExtractedTableMap map in tables)
            {
                foreach (ExtractedTableMap cmap in _tables)
                {
                    if (map.TableName == cmap.TableName)
                    {
                        if (map.ToString() != cmap.ToString())
                            alteredTables.Add(map.TableName);
                        else if (!(conn is MsSqlConnection ? Utility.StringsEqualIgnoreWhitespaceBracketsCase(map.ToComputedString(), cmap.ToComputedString()) : Utility.StringsEqualIgnoreWhitespace(map.ToComputedString(), cmap.ToComputedString())))
                            alteredTables.Add(map.TableName);
                        break;
                    }
                }
            }

            List<Trigger> dropTriggers = new List<Trigger>();
            List<Trigger> createTriggers = new List<Trigger>();
            List<StoredProcedure> createProcedures = new List<StoredProcedure>();
            List<StoredProcedure> dropProcedures = new List<StoredProcedure>();
            List<StoredProcedure> updateProcedures = new List<StoredProcedure>();
            List<Generator> createGenerators = new List<Generator>();
            List<string> constraintDrops = new List<string>();
            List<string> constraintCreations = new List<string>();
            List<PrimaryKey> primaryKeyDrops = new List<PrimaryKey>();
            List<PrimaryKey> primaryKeyCreations = new List<PrimaryKey>();
            List<ForeignKey> foreignKeyDrops = new List<ForeignKey>();
            List<ForeignKey> foreignKeyCreations = new List<ForeignKey>();
            List<IdentityField> createIdentities = new List<IdentityField>();
            List<IdentityField> setIdentities = new List<IdentityField>();
            Dictionary<string, List<Index>> dropIndexes = new Dictionary<string, List<Index>>();
            Dictionary<string, List<Index>> createIndexes = new Dictionary<string, List<Index>>();
            List<View> createViews = new List<View>();
            List<View> dropViews = new List<View>();

            _ExtractPrimaryKeyCreationsDrops(tables, out primaryKeyDrops, out primaryKeyCreations);

            _CompareViews(views, alteredTables, out createViews, out dropViews);

            _CompareStoredProcedures(procedures, alteredTables,dropViews, out createProcedures, out updateProcedures,out dropProcedures);

            _CompareTriggers(triggers,alteredTables,dropViews,dropProcedures, out dropTriggers, out createTriggers);

            _CompareGenerators(generators, out createGenerators);

            _ExtractConstraintDropsCreates(tables, conn, out constraintDrops, out constraintCreations);

            _ExtractForeignKeyCreatesDrops(tables, out foreignKeyDrops, out foreignKeyCreations);

            _CompareIdentities(identities, out createIdentities, out setIdentities);

            _ExtractIndexCreationsDrops(tables, out dropIndexes, out createIndexes);

            List<string> tableCreations = new List<string>();
            List<string> tableAlterations = new List<string>();
            List<string> computedFieldDeletions = new List<string>();
            List<string> computedFieldAdditions = new List<string>();

            foreach (ExtractedTableMap map in tables)
            {
                bool foundTable = false;
                for(int x=0;x<_tables.Count;x++){
                    if (map.TableName == _tables[x].TableName)
                    {
                        foundTable = true;
                        foreach (ExtractedFieldMap efm in map.Fields)
                        {
                            bool foundField = false;
                            foreach (ExtractedFieldMap ee in _tables[x].Fields)
                            {
                                if (efm.FieldName == ee.FieldName)
                                {
                                    foundField = true;
                                    if (efm.ComputedCode != null)
                                    {
                                        if ((efm.FullFieldType != ee.FullFieldType) || !(conn is MsSqlConnection ? Utility.StringsEqualIgnoreWhitespaceBracketsCase(efm.ComputedCode, ee.ComputedCode) : Utility.StringsEqualIgnoreWhitespace(efm.ComputedCode, ee.ComputedCode)))
                                        {
                                            computedFieldDeletions.Add(conn.queryBuilder.DropColumn(map.TableName, efm.FieldName));
                                            computedFieldAdditions.Add(conn.queryBuilder.CreateColumn(map.TableName, efm));
                                        }
                                    }
                                    else
                                    {
                                        if ((efm.FullFieldType!=ee.FullFieldType) &&
                                            !((efm.Type == "BLOB") && (ee.Type == "BLOB")))
                                        {
                                            if (efm.PrimaryKey && ee.PrimaryKey)
                                            {
                                                primaryKeyDrops.Add(new PrimaryKey(map));
                                                primaryKeyCreations.Add(new PrimaryKey(map));
                                            }
                                            else
                                            {
                                                foreach (ForeignRelationMap frms in _tables[x].ForeignFields)
                                                {
                                                    if (frms.InternalField == efm.FieldName)
                                                    {
                                                        foreignKeyDrops.Add(new ForeignKey(_tables[x], frms.ExternalTable, frms.ID));
                                                        foreignKeyCreations.Add(new ForeignKey(_tables[x], frms.ExternalTable, frms.ID));
                                                        break;
                                                    }
                                                }
                                            }
                                            foreach (ExtractedFieldMap cefm in _tables[x].GetComputedFieldsForField(efm.FieldName))
                                                computedFieldDeletions.Add(conn.queryBuilder.DropColumn(map.TableName, cefm.FieldName));
                                            tableAlterations.Add(conn.queryBuilder.AlterFieldType(map.TableName, efm, ee));
                                            foreach (ExtractedFieldMap cefm in map.GetComputedFieldsForField(efm.FieldName))
                                                computedFieldAdditions.Add(conn.queryBuilder.CreateColumn(map.TableName, cefm));
                                        }
                                        if (efm.Nullable != ee.Nullable)
                                        {
                                            foreach (ExtractedFieldMap cefm in _tables[x].GetComputedFieldsForField(efm.FieldName))
                                                computedFieldDeletions.Add(conn.queryBuilder.DropColumn(map.TableName, cefm.FieldName));
                                            foreach (ExtractedFieldMap cefm in map.GetComputedFieldsForField(efm.FieldName))
                                                computedFieldAdditions.Add(conn.queryBuilder.CreateColumn(map.TableName, cefm));
                                            if (efm.PrimaryKey && ee.PrimaryKey)
                                            {
                                                primaryKeyDrops.Add(new PrimaryKey(map));
                                                primaryKeyCreations.Add(new PrimaryKey(map));
                                            }
                                            else
                                            {
                                                foreach (ForeignRelationMap frms in _tables[x].ForeignFields)
                                                {
                                                    if (frms.InternalField == efm.FieldName)
                                                    {
                                                        foreignKeyDrops.Add(new ForeignKey(_tables[x], frms.ExternalTable, frms.ID));
                                                        foreignKeyCreations.Add(new ForeignKey(_tables[x], frms.ExternalTable, frms.ID));
                                                        break;
                                                    }
                                                }
                                            }
                                            if (!efm.Nullable)
                                                constraintCreations.Add(conn.queryBuilder.CreateNullConstraint(map.TableName, efm));
                                            else
                                                constraintDrops.Add(conn.queryBuilder.DropNullConstraint(map.TableName, efm));
                                        }
                                    }
                                    break;
                                }
                            }
                            if (!foundField)
                                tableAlterations.Add(conn.queryBuilder.CreateColumn(map.TableName, efm));
                        }
                        foreach (ExtractedFieldMap efm in _tables[x].Fields)
                        {
                            bool foundField = false;
                            foreach (ExtractedFieldMap ee in map.Fields)
                            {
                                if (efm.FieldName == ee.FieldName)
                                {
                                    foundField = true;
                                    break;
                                }
                            }
                            if (!foundField)
                            {
                                if (efm.PrimaryKey)
                                {
                                    primaryKeyDrops.Add(new PrimaryKey(map));
                                    primaryKeyCreations.Add(new PrimaryKey(map));
                                }
                                else
                                {
                                    foreach (ForeignRelationMap frms in _tables[x].ForeignFields)
                                    {
                                        if (frms.InternalField == efm.FieldName)
                                        {
                                            foreignKeyDrops.Add(new ForeignKey(_tables[x], frms.ExternalTable, frms.ID));
                                            break;
                                        }
                                    }
                                }
                                tableAlterations.Add(conn.queryBuilder.DropColumn(map.TableName, efm.FieldName));
                            }
                        }
                    }
                }
                if (!foundTable)
                {
                    ret.Add(map.TableName);
                    tableCreations.Add(conn.queryBuilder.CreateTable(map));
                }
            }

            foreach (PrimaryKey pk in primaryKeyDrops)
            {
                foreach (Trigger t in _triggers)
                {
                    if (t.Conditions.Contains("FOR " + pk.Name + " "))
                        dropTriggers.Add(t);
                }
                foreach (Trigger t in triggers)
                {
                    if (t.Conditions.Contains("FOR " + pk.Name + " "))
                        createTriggers.Add(t);
                }
            }

            _CleanUpForeignKeys(ref foreignKeyDrops);
            _CleanUpForeignKeys(ref foreignKeyCreations);

            List<string> alterations = new List<string>();

            foreach (Trigger trig in dropTriggers)
                alterations.Add(conn.queryBuilder.DropTrigger(trig.Name));
            alterations.Add(_COMMIT_STRING);

            foreach (StoredProcedure sp in dropProcedures)
                alterations.Add(conn.queryBuilder.DropProcedure(sp.ProcedureName));
            alterations.Add(_COMMIT_STRING);

            foreach (View vw in dropViews)
                alterations.Add(conn.queryBuilder.DropView(vw.Name));
            alterations.Add(_COMMIT_STRING);

            //add drops to alterations
            alterations.AddRange(constraintDrops);
            alterations.Add(_COMMIT_STRING);

            foreach (string str in dropIndexes.Keys)
            {
                foreach (Index ind in dropIndexes[str])
                    alterations.Add(conn.queryBuilder.DropTableIndex(str, ind.Name));
            }
            alterations.Add(_COMMIT_STRING);

            foreach (ForeignKey fk in foreignKeyDrops)
                alterations.Add(conn.queryBuilder.DropForeignKey(fk.InternalTable, fk.ExternalTable, fk.ExternalFields[0], fk.InternalFields[0]));
            alterations.Add(_COMMIT_STRING);

            foreach (PrimaryKey pk in primaryKeyDrops)
            {
                foreach (string field in pk.Fields)
                    alterations.Add(conn.queryBuilder.DropPrimaryKey(pk));
            }
            alterations.Add(_COMMIT_STRING);

            alterations.AddRange(computedFieldDeletions);
            alterations.Add(_COMMIT_STRING);

            alterations.AddRange(tableAlterations);
            alterations.Add(_COMMIT_STRING);

            alterations.AddRange(tableCreations);
            alterations.Add(_COMMIT_STRING);

            //add creations to alterations
            alterations.AddRange(constraintCreations);
            alterations.Add(_COMMIT_STRING);

            alterations.AddRange(computedFieldAdditions);
            alterations.Add(_COMMIT_STRING);

            foreach (View vw in createViews)
                alterations.Add(conn.queryBuilder.CreateView(vw));
            alterations.Add(_COMMIT_STRING);

            foreach (PrimaryKey pk in primaryKeyCreations)
                alterations.Add(conn.queryBuilder.CreatePrimaryKey(pk));
            alterations.Add(_COMMIT_STRING);

            foreach (ForeignKey fk in foreignKeyCreations)
                alterations.Add(conn.queryBuilder.CreateForeignKey(fk));
            alterations.Add(_COMMIT_STRING);

            foreach (string str in createIndexes.Keys)
            {
                foreach (Index ind in createIndexes[str])
                    alterations.Add(conn.queryBuilder.CreateTableIndex(str, ind.Fields, ind.Name, ind.Unique, ind.Ascending));
            }
            alterations.Add(_COMMIT_STRING);

            foreach (StoredProcedure proc in updateProcedures)
                alterations.Add(conn.queryBuilder.UpdateProcedure(proc));
            alterations.Add(_COMMIT_STRING);

            foreach (StoredProcedure proc in createProcedures)
                alterations.Add(conn.queryBuilder.CreateProcedure(proc));
            alterations.Add(_COMMIT_STRING);

            foreach (Generator gen in createGenerators)
            {
                alterations.Add(conn.queryBuilder.CreateGenerator(gen.Name));
                alterations.Add(conn.queryBuilder.SetGeneratorValue(gen.Name, gen.Value));
            }
            alterations.Add(_COMMIT_STRING);

            foreach (Trigger trig in createTriggers)
            {
                alterations.Add(conn.queryBuilder.CreateTrigger(trig));
            }
            alterations.Add(_COMMIT_STRING);

            foreach (IdentityField idf in createIdentities)
                alterations.Add(conn.queryBuilder.CreateIdentityField(idf));
            alterations.Add(_COMMIT_STRING);

            foreach (IdentityField idf in setIdentities)
                alterations.Add(conn.queryBuilder.SetIdentityFieldValue(idf));
            alterations.Add(_COMMIT_STRING);

            for (int x = 0; x < alterations.Count; x++)
            {
                if (alterations[x].Contains(";ALTER")&&!alterations[x].StartsWith("CREATE TRIGGER")
                    && !alterations[x].StartsWith("ALTER TRIGGER"))
                {
                    string tmp = alterations[x];
                    alterations.RemoveAt(x);
                    alterations.Insert(x, tmp.Substring(0, tmp.IndexOf(";ALTER") + 1));
                    alterations.Insert(x + 1, tmp.Substring(tmp.IndexOf(";ALTER") + 1));
                }
                else if (alterations[x].Contains(";\nALTER") && !alterations[x].StartsWith("CREATE TRIGGER")
                    && !alterations[x].StartsWith("ALTER TRIGGER"))
                {
                    string tmp = alterations[x];
                    alterations.RemoveAt(x);
                    alterations.Insert(x, tmp.Substring(0, tmp.IndexOf(";\nALTER") + 1));
                    alterations.Insert(x + 1, tmp.Substring(tmp.IndexOf(";\nALTER") + 1));
                }
                if (alterations[x].StartsWith("ALTER") && !alterations[x].TrimEnd(new char[] { '\n', ' ', '\t' }).EndsWith(";"))
                {
                    alterations[x] = alterations[x] + ";";
                }
            }

            Utility.RemoveDuplicateStrings(ref alterations, new string[] { _COMMIT_STRING });
            for (int x = 0; x < alterations.Count; x++)
            {
                if (x + 1 < alterations.Count)
                {
                    if (alterations[x + 1].Trim() == alterations[x].Trim() && alterations[x].Trim() == "COMMIT;")
                    {
                        alterations.RemoveAt(x);
                        x--;
                    }
                }
            }

            if (!Utility.OnlyContains(alterations,new string[]{_COMMIT_STRING}))
            {
                if (alterations[0].Trim() == _COMMIT_STRING)
                    alterations.RemoveAt(0);
                try
                {
                    if (_pool.DebugMode)
                    {
                        foreach (string str in alterations)
                        {
                            if (!str.EndsWith(";"))
                                Logger.LogLine(str + ";");
                            else
                                Logger.LogLine(str);
                        }
                    }
                    else
                    {
                        foreach (string str in alterations)
                        {
                            if (str.Length > 0)
                            {
                                if (str == _COMMIT_STRING)
                                    conn.Commit();
                                else if (str.EndsWith(_COMMIT_STRING))
                                {
                                    conn.ExecuteNonQuery(str.Substring(0, str.Length - 8));
                                    conn.Commit();
                                }
                                else
                                    conn.ExecuteNonQuery(str);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Logger.LogLine(e.Message);
                    Logger.LogLine(e.StackTrace);
                    throw e;
                }
            }
            conn.Commit();
            conn.Reset();
            _pool.Translator.ApplyAllDescriptions(tables, triggers, generators, identities, views, procedures,conn);
            conn.Commit();

            return ret;
        }
Example #13
0
 public void OnClick()
 {
     Connection.Reset();
     SceneManager.LoadScene("Login");
 }
Example #14
0
 public void BeforeEach()
 {
     Connection.Reset();
 }