protected override PendingItem BuildClasspathItem(ItemLocation location, string itemName, Stream content)
        {
            Match matchResult = ScriptNameRegex.Match(itemName);

            if (!matchResult.Success)
            {
                Log.WarnFormat("File name {0} does not match migration script naming convention and will be ignored.", itemName);
                return(null);
            }

            ItemType type    = ScriptTypeUtils.ResolveType(matchResult.Groups[1].Value);
            string   version = string.Join(string.Empty, matchResult.Groups[2].Value.Split('.', '_'));

            using (var reader = new StreamReader(content, Encoding.UTF8))
            {
                string template = reader.ReadToEnd();

                var item = new PendingItem
                {
                    Id       = version,
                    Type     = type,
                    Version  = version,
                    Name     = itemName,
                    Content  = PreprocessScriptTemplate(location, template),
                    Checksum = StringUtils.ByteArrayToHex(HashUtils.GetMD5Hash(Encoding.UTF8.GetBytes(template)))
                };

                Log.DebugFormat("Adding file {0} as update script with version {1}", itemName, version);

                return(item);
            }
        }
        //
        // WINRT - you cannot have overloads with the SAME # OF PARAMETERS
        // We therefore use factory methods.
        //
        public static ViewKey FromPendingItem(PendingItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            return(new ViewKey(item.Key, item.EffectiveDate));
        }
Пример #3
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            DateTime fd = DateTime.Parse(fromDate.ToString());
            DateTime td = DateTime.Parse(toDate.ToString());

            if (type1.IsChecked == false && type2.IsChecked == false && type3.IsChecked == false && type4.IsChecked == false && type5.IsChecked == false || Reason.Text == "" || fromDate.Text == "" || toDate.Text == "" || CB.Text == "")
            {
                MessageBox.Show("Please fill all required Inputs");
            }
            else if (fd > td)
            {
                MessageBox.Show("Invalid Dates");
            }
            else
            {
                RequestItem item = new RequestItem();

                item.EMP_ID      = mitem._EMPID;
                item.DATE        = DateTime.Now.ToString("MM/dd/yyyy");
                item.TYPE        = lastcheckcontent;
                item.REASON      = Reason.Text;
                item.STATUS      = "Waiting for Approval";
                item.LEAVE_START = fromDate.Text;
                item.LEAVE_END   = toDate.Text;

                PendingItem pitem = new PendingItem();

                pitem.EMPID                = mitem._EMPID;
                pitem.PENDING_TYPE         = "Leave";
                pitem.PENDING_LEAVE_REASON = Reason.Text;
                pitem.PENDING_STATUS       = "Waiting for Approval";
                pitem.PENDING_DATE         = DateTime.Now.ToString("MM/dd/yyyy");
                pitem.PENDING_POSITION     = mitem._POSITION;
                pitem.PENDING_TIME         = DateTime.Now.ToString("hh:mm:ss tt");
                pitem.PENDING_LEAVE_FROM   = fromDate.Text;
                pitem.PENDING_LEAVE_TO     = toDate.Text;
                pitem.SEND_TO              = CB.Text;
                pitem.APPROVED_BY          = "Waiting for Approval";


                Addleave(item);
                addPend(pitem, Reason.Text);
                ClearInputs();

                MessageBox.Show("Request sent!");
                this.Close();
            }
        }
        public void ParametersAndFiltersTest()
        {
            DbAccessFacadeMock dbAccessFacade = new DbAccessFacadeMock();

            config.AddScriptsLocation(Assembly.GetExecutingAssembly(), "TemplateTestScripts");

            IDatabaseMigrator migrator = DatabaseMigratorBuilder.Build(config, dbAccessFacade);

            migrator.Migrate(new SqlConnection());

            PendingItem script = dbAccessFacade.ClasspathScripts.First(s => s.Version.Equals("201701171635"));

            Assert.NotNull(script);

            Assert.True(script.Content.ToString().Contains("0x"));
        }
Пример #5
0
        internal void RemoveFromPending()
        {
            if (removedFromPending)
            {
                return;
            }
            removedFromPending = true;

            lock (pendingLock) {
                for (int i = 0; i < pendingNames.Count; i++)
                {
                    PendingItem item = pendingNames[i];
                    if (item.Name != truename)
                    {
                        continue;
                    }
                    pendingNames.RemoveAt(i); return;
                }
            }
        }
        public void ParametersTest()
        {
            DbAccessFacadeMock dbAccessFacade = new DbAccessFacadeMock();

            config.AddParameter("parameters_test_key_1", "col1");
            config.AddParameter("parameters_test_key_2", "col2");

            IDatabaseMigrator migrator = DatabaseMigratorBuilder.Build(config, dbAccessFacade);

            migrator.Migrate(new SqlConnection());

            PendingItem script = dbAccessFacade.ClasspathScripts.First(s => s.Version.Equals("201606201610"));

            Assert.NotNull(script);

            Assert.True(script.Content.ToString().Contains("[col1]"));
            Assert.True(script.Content.ToString().Contains("[col2]"));
            Assert.False(script.Content.ToString().Contains("{{parameters_test_key_1}}"));
            Assert.False(script.Content.ToString().Contains("{{parameters_test_key_2}}"));
        }
Пример #7
0
        //IEnumerable<PendingItem> GetPendingByReceiver(string receiver);
        public IEnumerable <PendingItem> GetPendingByReceiver(string receiver)
        {
            List <HazmatInfo>  pending      = GetHazmatInfoPendingShipping().ToList();
            List <PendingItem> pendingItems = new List <PendingItem>();

            foreach (HazmatInfo item in pending)
            {
                if (item.ToBU == receiver)
                {
                    PendingItem pendingItem = new PendingItem();
                    pendingItem.RecieverId = item.ToBU;
                    pendingItem.OrderNo    = Convert.ToInt16(item.OrderNo);
                    pendingItem.ItemId     = item.InvItemID;
                    pendingItem.ShipName   = GetItem(item.InvItemID).ShipName;
                    pendingItem.Placard    = GetItem(item.InvItemID).Placard;
                    pendingItem.Qty        = Convert.ToInt32(item.Qty);
                    pendingItems.Add(pendingItem);
                }
            }
            return(pendingItems);
        }
Пример #8
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (project.Text == "" || Reasonbox.Text == "" || Timefrom.Text == "" || TimeTo.Text == "" || toDate.Text == "" || CB.Text == "")
            {
                MessageBox.Show("Please fill required inputs");
            }
            else
            {
                RequestItem item = new RequestItem();

                item.EMP_ID    = mitem._EMPID;
                item.DATE      = toDate.Text;
                item.PROJECT   = project.Text;
                item.REASON    = Reasonbox.Text;
                item.STATUS    = "Waiting for Approval";
                item.TIME_FROM = Timefrom.Text;
                item.TIME_TO   = TimeTo.Text;

                PendingItem pitem = new PendingItem();

                pitem.EMPID                = mitem._EMPID;
                pitem.PENDING_TYPE         = "Overtime";
                pitem.PENDING_LEAVE_REASON = Reasonbox.Text;
                pitem.PENDING_STATUS       = "Waiting for Approval";
                pitem.PENDING_DATE         = DateTime.Now.ToString("MM/dd/yyyy");
                pitem.PENDING_POSITION     = mitem._POSITION;
                pitem.PENDING_TIME         = DateTime.Now.ToString("hh:mm:ss tt");
                pitem.PENDING_OT_FROM      = Timefrom.Text;
                pitem.PENDING_OT_TO        = TimeTo.Text;
                pitem.SEND_TO              = CB.Text;
                pitem.APPROVED_BY          = "Waiting for Approval";

                addOT(item);
                addPend(pitem, Reasonbox.Text);
                clear();
                MessageBox.Show("Request sent!");
                this.Close();
            }
        }
Пример #9
0
        public PendingItem convertToPendingItem(HazmatItem item, string orderNo, string receiverId)
        {
            PendingItem pendingItem = new PendingItem();

            pendingItem.ErgNo           = item.ErgNo;
            pendingItem.HazardClass     = item.HazardClass;
            pendingItem.HazmatInfoId    = item.HazmatInfoId;
            pendingItem.ItemId          = item.ItemId;
            pendingItem.OrderLineItemId = item.OrderLineItemId;
            pendingItem.OrderLineNo     = item.OrderLineNo;
            pendingItem.OrderNo         = Convert.ToInt16(orderNo);
            pendingItem.PackingGroup    = item.PackingGroup;
            pendingItem.Placard         = item.Placard;
            pendingItem.Qty             = item.Qty;
            pendingItem.RecieverId      = receiverId;
            pendingItem.ShipName        = item.ShipName;
            pendingItem.Size            = item.Size;
            pendingItem.TotalLbs        = item.TotalLbs;
            pendingItem.UnitLbs         = item.UnitLbs;
            pendingItem.UnnaNo          = item.UnnaNo;
            pendingItem.Uom             = item.Uom;

            return(pendingItem);
        }
 public void AddFromPending(PendingItem item)
 {
     Add(ViewKey.FromPendingItem(item));
 }
Пример #11
0
        private void addPend(PendingItem newitem, string reason)
        {
            UserPending upend = new UserPending();

            upend.AddPending(newitem, reason);
        }
Пример #12
0
        private void RunScript(SqlConnection connection, SqlTransaction tx, IMigratorConfiguration configuration, PendingItem script)
        {
            Log.DebugFormat(script.Type == ItemType.Versioned ? "Applying script {0}" : "Reapplying script {0}", script.Name);

            AppliedItem appliedScript = GetAppliedScript(connection, tx, configuration, script);

            if (appliedScript != null && appliedScript.Type == ItemType.Versioned)
            {
                Log.Debug("Script already applied, skipping.");
                return;
            }

            foreach (var scriptItem in new ScriptSplitter(script.Content.ToString()))
            {
                try
                {
                    using (var command = new SqlCommand(scriptItem, connection, tx))
                    {
                        command.CommandTimeout = configuration.CommandTimeout;
                        command.ExecuteNonQuery();
                    }
                }
                catch (SqlException)
                {
                    Log.Error("Error while running script:\n" + scriptItem);
                    throw;
                }
            }

            if (appliedScript == null)
            {
                InsertIntoSchemaVersion(connection, tx, configuration, script);
            }
            else
            {
                UpdateSchemaVersion(connection, tx, configuration, script);
            }
        }
Пример #13
0
        public AppliedItem GetAppliedScript(SqlConnection connection, SqlTransaction tx, IMigratorConfiguration configuration, PendingItem script)
        {
            AppliedItem result = null;

            using (var command = new SqlCommand(string.Format(SelectSingleFromSchemaVersionSql, configuration.SchemaVersionTable), connection, tx))
            {
                command.CommandTimeout = configuration.CommandTimeout;
                command.Parameters.Add(new SqlParameter("Version", script.Version));

                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        result = BuildAppliedScript(reader);
                    }
                }
            }

            return(result);
        }
Пример #14
0
        private void UpdateSchemaVersion(SqlConnection connection, SqlTransaction tx, IMigratorConfiguration configuration, PendingItem script)
        {
            var updateSql = string.Format(UpdateSchemaVersionHashSql, configuration.SchemaVersionTable);

            using (var command = new SqlCommand(updateSql, connection, tx))
            {
                command.Parameters.Add(new SqlParameter("Hash", script.Checksum));
                command.Parameters.Add(new SqlParameter("Executed", DateTime.Now));
                command.Parameters.Add(new SqlParameter("Version", script.Version));
                command.ExecuteNonQuery();
            }
        }
Пример #15
0
        private void InsertIntoSchemaVersion(SqlConnection connection, SqlTransaction tx, IMigratorConfiguration configuration, PendingItem script)
        {
            var insertSql = string.Format(InsertIntoSchemaVersionSql, configuration.SchemaVersionTable);

            using (var command = new SqlCommand(insertSql, connection, tx))
            {
                command.Parameters.Add(new SqlParameter("Type", ScriptTypeUtils.ResolveString(script.Type)));
                command.Parameters.Add(new SqlParameter("Version", script.Version));
                command.Parameters.Add(new SqlParameter("Script", script.Name));
                command.Parameters.Add(new SqlParameter("Executed", DateTime.Now));
                command.Parameters.Add(new SqlParameter("Hash", script.Checksum));
                command.ExecuteNonQuery();
            }
        }