Exemple #1
0
        /// <summary>
        /// Opens the transaction log and runs it.
        /// </summary>
        private void RunScript()
        {
            if (TracingHelper.TraceEnabled)
            {
                TracingHelper.Write();
            }

            if (!(new FileInfo(sFileScript)).Exists)
            {
                return;
            }

            bRestoring = true;

            dDatabase.IsReferentialIntegrity = false;

            ArrayList channel = new ArrayList();

            channel.Add(cSystem);

            Channel current = cSystem;
            int     size    = 1;

            try
            {
                DateTime     time = DateTime.Now;
                StreamReader r    = new StreamReader(sFileScript);

                while (true)
                {
                    string s = r.ReadLine();

                    if (s == null)
                    {
                        break;
                    }

                    if (s.StartsWith("/*C"))
                    {
                        int id = Int32.Parse(s.Substring(3, (s.IndexOf('*', 4) - 3)));

                        if (id > (channel.Count - 1))
                        {
                            current = new Channel(cSystem, id);
                            channel.Add(current);
                            dDatabase.RegisterChannel(current);
                        }
                        else
                        {
                            current = (Channel)channel[id];
                        }

                        s = s.Substring(s.IndexOf('/', 1) + 1);
                    }

                    if (!s.Equals(""))
                    {
                        dDatabase.Execute(s, current);
                    }

                    if (s.Equals("DISCONNECT"))
                    {
                        int id = current.Id;

                        current = new Channel(cSystem, id);

                        channel.RemoveAt(id);
                        channel.Insert(id, current);
                    }
                }

                r.Close();

                for (int i = 0; i < size; i++)
                {
                    current = (Channel)channel[i];

                    if (current != null)
                    {
                        current.Rollback();
                    }
                }

                TimeSpan execution = DateTime.Now.Subtract(time);

                if (TracingHelper.TraceEnabled)
                {
                    TracingHelper.Write((Int64)execution.TotalMilliseconds);
                }
            }
            catch (IOException e)
            {
                throw TracingHelper.Error(TracingHelper.FILE_IO_ERROR, sFileScript + " " + e);
            }

            dDatabase.IsReferentialIntegrity = true;

            bRestoring = false;
        }