Ejemplo n.º 1
0
        static void Write(IPlant plant, ICompany company)
        {
            Multicast writeInfo = plant.Write_Plant;

            writeInfo += company.Write_Company;
            writeInfo();
        }
Ejemplo n.º 2
0
        public void DuplicateDataInto3Destinations()
        {
            //Arrange
            TwoColumnsTableFixture sourceTable = new TwoColumnsTableFixture("Source");

            sourceTable.InsertTestData();
            TwoColumnsTableFixture dest1Table = new TwoColumnsTableFixture("Destination1");
            TwoColumnsTableFixture dest2Table = new TwoColumnsTableFixture("Destination2");
            TwoColumnsTableFixture dest3Table = new TwoColumnsTableFixture("Destination3");

            DbSource <MySimpleRow>      source = new DbSource <MySimpleRow>(Connection, "Source");
            DbDestination <MySimpleRow> dest1  = new DbDestination <MySimpleRow>(Connection, "Destination1");
            DbDestination <MySimpleRow> dest2  = new DbDestination <MySimpleRow>(Connection, "Destination2");
            DbDestination <MySimpleRow> dest3  = new DbDestination <MySimpleRow>(Connection, "Destination3");

            //Act
            Multicast <MySimpleRow> multicast = new Multicast <MySimpleRow>();

            source.LinkTo(multicast);
            multicast.LinkTo(dest1);
            multicast.LinkTo(dest2);
            multicast.LinkTo(dest3);
            source.Execute();
            dest1.Wait();
            dest2.Wait();
            dest3.Wait();

            //Assert
            dest1Table.AssertTestData();
            dest2Table.AssertTestData();
            dest3Table.AssertTestData();
        }
Ejemplo n.º 3
0
        public void StartSendingAndReceiving(ClientType typeOfClient)
        {
            m_CurrentClientType = typeOfClient;

            if (m_CurrentClientType == ClientType.MultiCast)
            {
                m_Multicast = new Multicast(m_Port, m_MultiCastEndpoint);
                m_Multicast.Start();
                m_Multicast.StartPulse(((int)MessageHeaders.USERSNAMES).ToString() + m_UserName);
            }

            if (m_CurrentClientType == ClientType.TCP)
            {
                m_TCPClient = new TCPClient();
                m_TCPClient.Start();
            }

            m_displayAllMessages = false;

            m_ProcessorThread = new Thread(new ThreadStart(Processor));
            m_ProcessorThread.IsBackground = true;
            m_ProcessorThread.Start();

            AssembleSendString(MessageHeaders.CONNECT, " Has Connected");
        }
Ejemplo n.º 4
0
        public void TwoTransactionsAndParallelWriting(IConnectionManager connection)
        {
            if (connection.ConnectionManagerType == ConnectionManagerType.SQLite)
            {
                return;
            }
            //Arrange
            var concopy = connection.Clone();
            TwoColumnsTableFixture s2c = new TwoColumnsTableFixture(connection, "TransactionSourceParallelWrite");

            s2c.InsertTestData();
            TwoColumnsTableFixture      d2c1      = new TwoColumnsTableFixture(connection, "TransactionDest1");
            TwoColumnsTableFixture      d2c2      = new TwoColumnsTableFixture(connection, "TransactionDest2");
            DbSource <MySimpleRow>      source    = new DbSource <MySimpleRow>(connection, "TransactionSourceParallelWrite");
            DbDestination <MySimpleRow> dest1     = new DbDestination <MySimpleRow>(connection, "TransactionDest1", batchSize: 2);
            DbDestination <MySimpleRow> dest2     = new DbDestination <MySimpleRow>(concopy, "TransactionDest2", batchSize: 2);
            Multicast <MySimpleRow>     multicast = new Multicast <MySimpleRow>();

            //Act & Assert
            connection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
            concopy.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
            source.LinkTo(multicast);
            multicast.LinkTo(dest1);
            multicast.LinkTo(dest2);

            source.Execute();
            dest1.Wait();
            dest2.Wait();
            connection.CommitTransaction();
            concopy.CommitTransaction();

            Assert.Equal(3, RowCountTask.Count(connection, "TransactionDest1"));
            Assert.Equal(3, RowCountTask.Count(connection, "TransactionDest2"));
        }
Ejemplo n.º 5
0
        public void DB_Multicast_DB_WithStringArray()
        {
            TableDefinition sourceTableDefinition = CreateTableForMyDataRow("test.Source");
            TableDefinition dest1TableDefinition  = CreateTableForMyDataRow("test.Destination1");
            TableDefinition dest2TableDefinition  = CreateTableForMyDataRow("test.Destination2");

            InsertDemoDataForMyRowTable("test.Source");

            DBSource source = new DBSource();

            source.SourceTableDefinition = sourceTableDefinition;
            Multicast     multicast = new Multicast();
            DBDestination dest1     = new DBDestination();

            dest1.DestinationTableDefinition = dest1TableDefinition;
            DBDestination dest2 = new DBDestination();

            dest2.DestinationTableDefinition = dest2TableDefinition;

            source.LinkTo(multicast);
            multicast.LinkTo(dest1);
            multicast.LinkTo(dest2);
            source.Execute();
            dest1.Wait();
            dest2.Wait();

            Assert.AreEqual(3, RowCountTask.Count("test.Source", "Col2 in (1,2,3)"));
            Assert.AreEqual(3, RowCountTask.Count("test.Destination1", "Col2 in (1,2,3)"));
            Assert.AreEqual(3, RowCountTask.Count("test.Destination2", "Col2 in (1,2,3)"));
        }
Ejemplo n.º 6
0
        //Inform является дочерним классом от двух интерфейсов - вызываем функции этих интерфейсов при помощи многоадресного делегата;
        static void More(IFlat flat, IStreet street)
        {
            Multicast all_in_one = flat.Write_Flat;

            all_in_one += street.Write_Street;
            all_in_one();
        }
Ejemplo n.º 7
0
        public void OneTransactionAndParallelWritingWithMARS()
        {
            //Arrange
            TwoColumnsTableFixture s2c = new TwoColumnsTableFixture(SqlConnection, "TransactionSourceParallelWrite");

            s2c.InsertTestData();
            TwoColumnsTableFixture d2c1   = new TwoColumnsTableFixture(SqlConnection, "TransactionDest1");
            TwoColumnsTableFixture d2c2   = new TwoColumnsTableFixture(SqlConnection, "TransactionDest2");
            DbSource <MySimpleRow> source = new DbSource <MySimpleRow>(SqlConnection, "TransactionSourceParallelWrite");

            string constring = $"{Config.SqlConnection.RawConnectionString("DataFlow")};MultipleActiveResultSets=True;";
            var    marscon   = new SqlConnectionManager(constring);
            DbDestination <MySimpleRow> dest1     = new DbDestination <MySimpleRow>(marscon, "TransactionDest1", batchSize: 2);
            DbDestination <MySimpleRow> dest2     = new DbDestination <MySimpleRow>(marscon, "TransactionDest2", batchSize: 2);
            Multicast <MySimpleRow>     multicast = new Multicast <MySimpleRow>();

            //Act & Assert
            marscon.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
            source.LinkTo(multicast);
            multicast.LinkTo(dest1);
            multicast.LinkTo(dest2);

            source.Execute();
            dest1.Wait();
            dest2.Wait();
            marscon.CommitTransaction();

            d2c1.AssertTestData();
            d2c1.AssertTestData();
        }
Ejemplo n.º 8
0
        public void DB_MulticastWPredicates_DB()
        {
            TableDefinition sourceTableDefinition = CreateTableForMyDataRow("test.Source");
            TableDefinition dest1TableDefinition  = CreateTableForMyDataRow("test.Destination1");
            TableDefinition dest2TableDefinition  = CreateTableForMyDataRow("test.Destination2");

            InsertDemoDataForMyRowTable("test.Source");

            DBSource <MyDataRow> source = new DBSource <MyDataRow>();

            source.SourceTableDefinition = sourceTableDefinition;
            Multicast <MyDataRow>     multicast = new Multicast <MyDataRow>();
            DBDestination <MyDataRow> dest1     = new DBDestination <MyDataRow>();

            dest1.DestinationTableDefinition = dest1TableDefinition;
            DBDestination <MyDataRow> dest2 = new DBDestination <MyDataRow>();

            dest2.DestinationTableDefinition = dest2TableDefinition;

            source.LinkTo(multicast);
            multicast.LinkTo(dest1, row => row.Value2 <= 2);
            multicast.LinkTo(dest2, row => row.Value2 > 2);
            source.Execute();
            dest1.Wait();
            dest2.Wait();

            Assert.AreEqual(3, RowCountTask.Count("test.Source", "Col2 in (1,2,3)"));
            Assert.AreEqual(2, RowCountTask.Count("test.Destination1", "Col2 in (1,2)"));
            Assert.AreEqual(1, RowCountTask.Count("test.Destination2"));
        }
Ejemplo n.º 9
0
        public void Start()
        {
            CSVSource sourceOrderData = new CSVSource("src/DataFlow/DemoData.csv");

            sourceOrderData.Configuration.Delimiter = ";";
            RowTransformation <string[], Order> transIntoObject = new RowTransformation <string[], Order>(CSVIntoObject);
            DBSource <Customer>             sourceCustomerData  = new DBSource <Customer>(CustomerTableDef);
            LookupCustomerKey               lookupCustKeyClass  = new LookupCustomerKey();
            Lookup <Order, Order, Customer> lookupCustomerKey   = new Lookup <Order, Order, Customer>(
                lookupCustKeyClass.FindKey, sourceCustomerData, lookupCustKeyClass.LookupData);

            Multicast <Order>     multiCast      = new Multicast <Order>();
            DBDestination <Order> destOrderTable = new DBDestination <Order>(OrderDataTableDef);

            BlockTransformation <Order>       blockOrders        = new BlockTransformation <Order>(BlockTransformOrders);
            DBDestination <Rating>            destRating         = new DBDestination <Rating>(CustomerRatingTableDef);
            RowTransformation <Order, Rating> transOrderIntoCust = new RowTransformation <Order, Rating>(OrderIntoRating);
            CustomDestination <Order>         destSink           = new CustomDestination <Order>(row => {; });

            sourceOrderData.LinkTo(transIntoObject);
            transIntoObject.LinkTo(lookupCustomerKey);

            lookupCustomerKey.LinkTo(multiCast);
            multiCast.LinkTo(destOrderTable);

            multiCast.LinkTo(blockOrders);
            blockOrders.LinkTo(transOrderIntoCust, ord => ord.Rating != null);
            blockOrders.LinkTo(destSink, ord => ord.Rating == null);
            transOrderIntoCust.LinkTo(destRating);

            sourceOrderData.ExecuteAsync();
            destOrderTable.Wait();
            destRating.Wait();
        }
Ejemplo n.º 10
0
        public void SplitInto2Tables()
        {
            //Arrange
            TwoColumnsTableFixture sourceTable = new TwoColumnsTableFixture("Source");

            sourceTable.InsertTestData();
            TwoColumnsTableFixture dest1Table = new TwoColumnsTableFixture("Destination1");
            TwoColumnsTableFixture dest2Table = new TwoColumnsTableFixture("Destination2");

            DbSource <string[]>      source = new DbSource <string[]>("Source", Connection);
            DbDestination <string[]> dest1  = new DbDestination <string[]>("Destination1", Connection);
            DbDestination <string[]> dest2  = new DbDestination <string[]>("Destination2", Connection);

            //Act
            Multicast <string[]> multicast = new Multicast <string[]>();

            source.LinkTo(multicast);
            multicast.LinkTo(dest1);
            multicast.LinkTo(dest2);
            source.Execute();
            dest1.Wait();
            dest2.Wait();

            //Assert
            dest1Table.AssertTestData();
            dest2Table.AssertTestData();
        }
Ejemplo n.º 11
0
        public void PredicateFilteringWithInteger()
        {
            //Arrange
            TwoColumnsTableFixture sourceTable = new TwoColumnsTableFixture("Source");

            sourceTable.InsertTestData();
            TwoColumnsTableFixture dest1Table = new TwoColumnsTableFixture("Destination1");
            TwoColumnsTableFixture dest2Table = new TwoColumnsTableFixture("Destination2");

            DBSource <MySimpleRow>      source = new DBSource <MySimpleRow>(Connection, "Source");
            DBDestination <MySimpleRow> dest1  = new DBDestination <MySimpleRow>(Connection, "Destination1");
            DBDestination <MySimpleRow> dest2  = new DBDestination <MySimpleRow>(Connection, "Destination2");

            //Act
            Multicast <MySimpleRow> multicast = new Multicast <MySimpleRow>();

            source.LinkTo(multicast);
            multicast.LinkTo(dest1, row => row.Col1 <= 2);
            multicast.LinkTo(dest2, row => row.Col1 > 2);
            source.Execute();
            dest1.Wait();
            dest2.Wait();

            //Assert
            Assert.Equal(1, RowCountTask.Count(Connection, "Destination1", "Col1 = 1 AND Col2='Test1'"));
            Assert.Equal(1, RowCountTask.Count(Connection, "Destination1", "Col1 = 2 AND Col2='Test2'"));
            Assert.Equal(1, RowCountTask.Count(Connection, "Destination2", "Col1 = 3 AND Col2='Test3'"));
        }
Ejemplo n.º 12
0
        public void SplitInto2Tables()
        {
            //Arrange
            TwoColumnsTableFixture sourceTable = new TwoColumnsTableFixture("Source");

            sourceTable.InsertTestData();
            TwoColumnsTableFixture dest1Table = new TwoColumnsTableFixture("Destination1");
            TwoColumnsTableFixture dest2Table = new TwoColumnsTableFixture("Destination2");

            DBSource      source = new DBSource(Connection, "Source");
            DBDestination dest1  = new DBDestination(Connection, "Destination1");
            DBDestination dest2  = new DBDestination(Connection, "Destination2");

            //Act
            Multicast multicast = new Multicast();

            source.LinkTo(multicast);
            multicast.LinkTo(dest1);
            multicast.LinkTo(dest2);
            source.Execute();
            dest1.Wait();
            dest2.Wait();

            //Assert
            dest1Table.AssertTestData();
            dest2Table.AssertTestData();
        }
Ejemplo n.º 13
0
    protected void btnConfirm_Click(object sender, EventArgs e)
    {
        if ((string)Session["direction"] == "delete")
        {
            Session.Remove("direction");
            List <int> delList = new List <int>();
            delList.Add(Convert.ToInt32(group.ID));
            group.Delete(delList);
            if (Utility.Message.Contains("Successfully"))
            {
                Response.Redirect("~/views/groups/search.aspx");
            }
            else
            {
                Master.Msgbox(Utility.Message);
            }
        }
        else
        {
            Image imageInfo = new Image();
            imageInfo.ID       = imageInfo.GetImageID(group.Image);
            Session["imageID"] = imageInfo.ID;
            if (imageInfo.Check_Checksum(imageInfo.ID))
            {
                int isUnicast = Convert.ToInt32(Session["isGroupUnicast"]);
                if (isUnicast == 1)
                {
                    Unicast    unicast    = new Unicast();
                    List <int> listHostID = new List <int>();
                    listHostID = unicast.UnicastFromGroup(Convert.ToInt32(group.ID));
                    for (int z = 0; z < listHostID.Count; z++)
                    {
                        unicast.CreateUnicast("push", listHostID[z]);
                    }
                    Utility.Message = "Started " + listHostID.Count + " Tasks";
                    History history = new History();
                    history.Event  = "Unicast";
                    history.Type   = "Group";
                    history.TypeID = group.ID;
                    history.CreateEvent(history);
                }
                else
                {
                    Multicast multicast = new Multicast();
                    multicast.CreateMulticast(Convert.ToInt32(group.ID));
                }
                Session.Remove("isGroupUnicast");
                Master.Msgbox(Utility.Message);
            }

            else
            {
                lblIncorrectChecksum.Text = "This Image Has Not Been Confirmed And Cannot Be Deployed.  <br>Confirm It Now?";
                ClientScript.RegisterStartupScript(this.GetType(), "modalscript", "$(function() {  var menuTop = document.getElementById('incorrectChecksum'),body = document.body;classie.toggle(menuTop, 'confirm-box-outer-open'); });", true);
            }
        }
    }
Ejemplo n.º 14
0
        public static void Run()
        {
            Console.WriteLine("Running data flow");

            //Read data from csv file
            CsvSource sourceOrderData = new CsvSource("DemoData.csv");

            sourceOrderData.Configuration.Delimiter = ";";

            //Transform into Order object
            RowTransformation <ExpandoObject, Order> transIntoObject = new RowTransformation <ExpandoObject, Order>(
                csvLine =>
            {
                dynamic order = csvLine as dynamic;
                return(new Order()
                {
                    //Header in Csv: OrderNumber;OrderItem;OrderAmount;CustomerName
                    Number = order.OrderNumber,
                    Item = order.OrderItem,
                    Amount = decimal.Parse(order.OrderAmount.ToString().Replace("€", ""), CultureInfo.GetCultureInfo("en-US")),
                    CustomerName = order.CustomerName
                });
            });

            sourceOrderData.LinkTo(transIntoObject);

            //Find corresponding customer id if customer exists in Customer table
            DbSource <Customer> sourceCustomerData = new DbSource <Customer>("customer");
            LookupTransformation <Order, Customer> lookupCustomerKey = new LookupTransformation <Order, Customer>(sourceCustomerData);

            transIntoObject.LinkTo(lookupCustomerKey);

            //Split data
            Multicast <Order> multiCast = new Multicast <Order>();

            lookupCustomerKey.LinkTo(multiCast);

            //Store Order in Orders table
            DbDestination <Order> destOrderTable = new DbDestination <Order>("orders");

            multiCast.LinkTo(destOrderTable);

            //Create rating for existing customers based total of order amount
            Aggregation <Order, Rating> aggregation = new Aggregation <Order, Rating>();

            multiCast.LinkTo(aggregation);

            //Store the rating in the customer rating table
            DbDestination <Rating> destRating = new DbDestination <Rating>("customer_rating");

            aggregation.LinkTo(destRating);

            //Execute the data flow synchronously
            sourceOrderData.Execute();
            destOrderTable.Wait();
            destRating.Wait();
        }
Ejemplo n.º 15
0
    protected void btnUnicast_Click(object sender, EventArgs e)
    {
        Multicast multicast = new Multicast();

        Session["isGroupUnicast"] = 1;
        lblTitle.Text             = "Unicast All The Hosts In The Selected Group?";
        gvConfirm.DataSource      = multicast.Confirm(group.ID);
        gvConfirm.DataBind();
        ClientScript.RegisterStartupScript(this.GetType(), "modalscript", "$(function() { var menuTop = document.getElementById('confirmbox'),body = document.body;classie.toggle(menuTop, 'confirm-box-outer-open'); });", true);
    }
Ejemplo n.º 16
0
 protected void btnMulticast_Click(object sender, EventArgs e)
 {
     Multicast multicast = new Multicast();
     GridViewRow gvRow = (GridViewRow)(sender as Control).Parent.Parent;
     string groupID = gvGroups.DataKeys[gvRow.RowIndex].Value.ToString();
     Session["groupID"] = groupID;
     Session["isGroupUnicast"] = 0;
     lblTitle.Text = "Multicast The Selected Group?";
     gvConfirm.DataSource = multicast.Confirm(groupID);
     gvConfirm.DataBind();
     ClientScript.RegisterStartupScript(this.GetType(), "modalscript", "$(function() { var menuTop = document.getElementById('confirmbox'),body = document.body;classie.toggle(menuTop, 'confirm-box-outer-open'); });", true);
 }
Ejemplo n.º 17
0
    protected void btnUnicast_Click(object sender, EventArgs e)
    {
        Multicast   multicast = new Multicast();
        GridViewRow gvRow     = (GridViewRow)(sender as Control).Parent.Parent;
        string      groupID   = gvGroups.DataKeys[gvRow.RowIndex].Value.ToString();

        Session["groupID"]        = groupID;
        Session["isGroupUnicast"] = 1;
        lblTitle.Text             = "Unicast All The Hosts In The Selected Group?";
        gvConfirm.DataSource      = multicast.Confirm(groupID);
        gvConfirm.DataBind();
        ClientScript.RegisterStartupScript(this.GetType(), "modalscript", "$(function() { var menuTop = document.getElementById('confirmbox'),body = document.body;classie.toggle(menuTop, 'confirm-box-outer-open'); });", true);
    }
Ejemplo n.º 18
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (ddlImage.Text != "Select Image")
        {
            Multicast custom = new Multicast();

            custom.StartCustomMC(ddlImage.Text);

            Master.Msgbox(Utility.Message);
        }
        else
            Master.Msgbox("Select An Image");
    }
Ejemplo n.º 19
0
        public void OneTransactionAndParallelWriting(IConnectionManager connection)
        {
            if (connection.ConnectionManagerType == ConnectionManagerType.SQLite)
            {
                return;
            }
            if (connection.ConnectionManagerType == ConnectionManagerType.Oracle)
            {
                return;
            }

            //Arrange
            TwoColumnsTableFixture s2c = new TwoColumnsTableFixture(connection, "TransactionSourceParallelWrite");

            s2c.InsertTestData();
            TwoColumnsTableFixture      d2c1      = new TwoColumnsTableFixture(connection, "TransactionDest1");
            TwoColumnsTableFixture      d2c2      = new TwoColumnsTableFixture(connection, "TransactionDest2");
            DbSource <MySimpleRow>      source    = new DbSource <MySimpleRow>(connection, "TransactionSourceParallelWrite");
            DbDestination <MySimpleRow> dest1     = new DbDestination <MySimpleRow>(connection, "TransactionDest1", batchSize: 2);
            DbDestination <MySimpleRow> dest2     = new DbDestination <MySimpleRow>(connection, "TransactionDest2", batchSize: 2);
            Multicast <MySimpleRow>     multicast = new Multicast <MySimpleRow>();

            //Act & Assert
            Assert.ThrowsAny <Exception>(() =>
            {
                try
                {
                    connection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
                    source.LinkTo(multicast);
                    multicast.LinkTo(dest1);
                    multicast.LinkTo(dest2);

                    source.Execute();
                    dest1.Wait();
                    dest2.Wait();
                }
                catch
                {
                    throw;
                }
                finally
                {
                    connection.RollbackTransaction();
                    connection.Close();
                }
            });
            if (connection.GetType() == typeof(MySqlConnectionManager))
            {
                Task.Delay(200).Wait(); //MySql needs a little bit longer to free resources
            }
        }
Ejemplo n.º 20
0
        public void SplitCSVSourceIn2Tables()
        {
            //Arrange
            TwoColumnsTableFixture  dest1Table = new TwoColumnsTableFixture("SplitDataDestination1");
            FourColumnsTableFixture dest2Table = new FourColumnsTableFixture("SplitDataDestination2");

            var source = new CSVSource <CSVPoco>("res/Multicast/CSVSourceToSplit.csv")
            {
                Configuration = new CsvHelper.Configuration.Configuration()
                {
                    Delimiter = ";"
                }
            };

            var multicast = new Multicast <CSVPoco>();

            var row1 = new RowTransformation <CSVPoco, Entity1>(input => {
                return(new Entity1
                {
                    Col1 = input.CSVCol1,
                    Col2 = input.CSVCol2
                });
            });
            var row2 = new RowTransformation <CSVPoco, Entity2>(input => {
                return(new Entity2
                {
                    Col2 = input.CSVCol2,
                    Col3 = input.CSVCol3,
                    Col4 = input.CSVCol4
                });
            });

            var destination1 = new DBDestination <Entity1>(Connection, "SplitDataDestination1");
            var destination2 = new DBDestination <Entity2>(Connection, "SplitDataDestination2");

            //Act
            source.LinkTo(multicast);
            multicast.LinkTo(row1);
            multicast.LinkTo(row2);

            row1.LinkTo(destination1);
            row2.LinkTo(destination2);

            source.Execute();
            destination1.Wait();
            destination2.Wait();

            //Assert
            dest1Table.AssertTestData();
            dest2Table.AssertTestData();
        }
Ejemplo n.º 21
0
        /* Data flow
         *
         * JsonSource --> RowTransformation --> Lookup --> Multicast --> DbDestination ("orders" table)
         * (Order data)                        |             |
         *                   CsvSource     <----             --------> TextDestination ("order_data.log")
         *                  ("customer.csv")
         */


        static void Main(string[] args)
        {
            //Preparation
            RecreateTargetTable();

            //Step 1 - creating the components
            var source = new JsonSource <OrderRow>("https://www.etlbox.net/demo/api/orders", ResourceType.Http);

            var rowTransformation = new RowTransformation <OrderRow>();

            rowTransformation.TransformationFunc = row => {
                row.Quantity = int.Parse(row.Description.Split(":").ElementAt(1));
                return(row);
            };

            var lookup = new LookupTransformation <OrderRow, ExpandoObject>();

            lookup.Source = new CsvSource("files/customer.csv");

            lookup.MatchColumns = new[] {
                new MatchColumn()
                {
                    LookupSourcePropertyName = "Id", InputPropertyName = "CustomerId"
                }
            };
            lookup.RetrieveColumns = new[] {
                new RetrieveColumn()
                {
                    LookupSourcePropertyName = "Name", InputPropertyName = "CustomerName"
                }
            };

            var multicast = new Multicast <OrderRow>();

            var dbDest   = new DbDestination <OrderRow>(sqlConnMan, "orders");
            var textDest = new TextDestination <OrderRow>("files/order_data.log");

            textDest.WriteLineFunc = row => {
                return($"{row.OrderNumber}\t{row.CustomerName}\t{row.Quantity}");
            };

            //Step2 - linking components
            source.LinkTo(rowTransformation);
            rowTransformation.LinkTo(lookup);
            lookup.LinkTo(multicast);
            multicast.LinkTo(dbDest);
            multicast.LinkTo(textDest, row => row.CustomerName == "Clark Kent", row => row.CustomerName != "Clark Kent");

            //Step3 - executing the network
            Network.Execute(source);  //Shortcut for Network.ExecuteAsync(source).Wait();
        }
Ejemplo n.º 22
0
    public void OnMulticastTest()
    {
        dashLog("Multicast Test");
        buttons_["multicast"].interactable = false;

        Multicast multicast = new Multicast();

        multicast.FinishedCallback += delegate() {
            multicast = null;
            buttons_["multicast"].interactable = true;
        };

        StartCoroutine(multicast.Start(session_, encoding, sendingCount));
    }
Ejemplo n.º 23
0
        public void TestDuplicateCheckInRowTrans()
        {
            CreateLogTablesTask.CreateLog();
            DataFlow.LoggingThresholdRows = 2;
            CSVSource <Poco> source = new CSVSource <Poco>("src/DataFlowExamples/Duplicate.csv");

            source.Configuration.Delimiter         = ";";
            source.Configuration.TrimOptions       = CsvHelper.Configuration.TrimOptions.Trim;
            source.Configuration.MissingFieldFound = null;
            List <int> IDs = new List <int>(); //at the end of the flow, this list will contain all IDs of your source
            RowTransformation <Poco, Poco> rowTrans = new RowTransformation <Poco, Poco>(input =>
            {
                if (IDs.Contains(input.ID))
                {
                    input.IsDuplicate = true;
                }
                else
                {
                    IDs.Add(input.ID);
                }
                return(input);
            });

            var multicast = new Multicast <Poco>();


            var             dest         = new DBDestination <Poco>("dbo.Staging");
            TableDefinition stagingTable = new TableDefinition("dbo.Staging", new List <TableColumn>()
            {
                new TableColumn("Key", "INT", allowNulls: false, isPrimaryKey: true, isIdentity: true),
                new TableColumn("ID", "INT", allowNulls: false),
                new TableColumn("Value", "NVARCHAR(100)", allowNulls: false),
                new TableColumn("Name", "NVARCHAR(100)", allowNulls: false)
            });

            stagingTable.CreateTable();


            var trash = new VoidDestination <Poco>();

            source.LinkTo(rowTrans);
            rowTrans.LinkTo(multicast);
            multicast.LinkTo(dest, input => input.IsDuplicate == false);
            multicast.LinkTo(trash, input => input.IsDuplicate == true);

            source.Execute();
            dest.Wait();
            trash.Wait();
        }
Ejemplo n.º 24
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (ddlImage.Text != "Select Image")
        {
            Multicast custom = new Multicast();

            custom.StartCustomMC(ddlImage.Text);

            Master.Msgbox(Utility.Message);
        }
        else
        {
            Master.Msgbox("Select An Image");
        }
    }
Ejemplo n.º 25
0
        public void Multicast_Into2Tables()
        {
            var tableDestination1 = this.CreateTable("test.Table1");
            var tableDestination2 = this.CreateTable("test.Table2");

            var row1 = new RowTransformation <TestPoco, TestEntity1>(input => {
                return(new TestEntity1
                {
                    Col1 = input.Value1,
                    Col3 = input.Value3
                });
            });
            var row2 = new RowTransformation <TestPoco, TestEntity2>(input => {
                return(new TestEntity2
                {
                    Col2 = input.Value2,
                    Col4 = input.Value4
                });
            });

            var source = new CSVSource <TestPoco>("src/DataFlowExamples/Issue5.csv")
            {
                Configuration = new CsvHelper.Configuration.Configuration()
                {
                    Delimiter = ";"
                }
            };
            var multicast    = new Multicast <TestPoco>();
            var destination1 = new DBDestination <TestEntity1>("test.Table1");
            var destination2 = new DBDestination <TestEntity2>("test.Table2");

            source.LinkTo(multicast);
            multicast.LinkTo(row1);
            multicast.LinkTo(row2);

            row1.LinkTo(destination1);
            row2.LinkTo(destination2);

            source.Execute();
            destination1.Wait();
            destination2.Wait();

            Assert.AreEqual(2, RowCountTask.Count("test.Table1", "Col1 in ('one','five') and Col3 in ('three','seven')"));
            Assert.AreEqual(2, RowCountTask.Count("test.Table2", "Col2 in ('two','six') and Col4 in ('four','eight')"));
        }
Ejemplo n.º 26
0
        public static void Main(string[] args)
        {
            PrepareSqlLiteDestination();

            var currentYear = StartYear;

            var source = new CustomBatchSource <Accident>();

            source.ReadBatchFunc = _ => {
                var accidents = ParseAccidentsFromUrl($"https://aviation-safety.net/database/dblist.php?Year={currentYear}");
                currentYear++;
                return(accidents);
            };
            source.ReadingCompleted = _ => currentYear > EndYear;

            var filter = new FilterTransformation <Accident>();

            filter.FilterPredicate = accident => accident.Year <= 1;

            var multicast = new Multicast <Accident>();

            var memDest = new MemoryDestination <Accident>();

            var sqlLiteDest = new DbDestination <Accident>(SQLiteConnection, "Accidents");

            var aggregation = new Aggregation <Accident, AccidentsPerYear>();
            var csvDest     = new CsvDestination <AccidentsPerYear>("aggregated.csv");

            source.LinkTo(filter);
            filter.LinkTo(multicast);
            multicast.LinkTo(memDest);
            multicast.LinkTo(sqlLiteDest);

            multicast.LinkTo(aggregation, row => row.Year > 1);
            aggregation.LinkTo(csvDest);

            Network.Execute(source);

            Console.WriteLine($"Imported {memDest.Data.Count} rows from aviation-safety.net");
            for (int year = StartYear; year <= EndYear; year++)
            {
                Console.WriteLine($"There were {memDest.Data.Where(a => a.Year == year).Count()} accidents in {year}");
            }
        }
Ejemplo n.º 27
0
    protected void btnConfirm_Click(object sender, EventArgs e)
    {
        int   groupID   = Convert.ToInt32((string)(Session["groupID"]));
        int   isUnicast = Convert.ToInt32(Session["isGroupUnicast"]);
        Group groupInfo = new Group();

        groupInfo.ID = groupID.ToString();
        groupInfo.Read(groupInfo);
        Image imageInfo = new Image();

        imageInfo.ID       = imageInfo.GetImageID(groupInfo.Image);
        Session["imageID"] = imageInfo.ID;
        if (imageInfo.Check_Checksum(imageInfo.ID))
        {
            if (isUnicast == 1)
            {
                Unicast    unicast    = new Unicast();
                List <int> listHostID = new List <int>();
                listHostID = unicast.UnicastFromGroup(groupID);

                for (int z = 0; z < listHostID.Count; z++)
                {
                    unicast.CreateUnicast("push", listHostID[z]);
                }
                Utility.Message = "Started " + listHostID.Count + " Tasks";
            }
            else
            {
                Multicast multicast = new Multicast();
                multicast.CreateMulticast(groupID);
            }
            Session.Remove("groupID");
            Session.Remove("isGroupUnicast");
            Master.Msgbox(Utility.Message);
        }
        else
        {
            lblIncorrectChecksum.Text = "This Image Has Not Been Confirmed And Cannot Be Deployed.  <br>Confirm It Now?";
            ClientScript.RegisterStartupScript(this.GetType(), "modalscript", "$(function() {  var menuTop = document.getElementById('incorrectChecksum'),body = document.body;classie.toggle(menuTop, 'confirm-box-outer-open'); });", true);
        }
    }
Ejemplo n.º 28
0
    protected void btnConfirm_Click(object sender, EventArgs e)
    {
        int groupID = Convert.ToInt32((string)(Session["groupID"]));
        int isUnicast = Convert.ToInt32(Session["isGroupUnicast"]);
        Group groupInfo = new Group();
        groupInfo.ID = groupID.ToString();
        groupInfo.Read(groupInfo);
        Image imageInfo = new Image();
        imageInfo.ID = imageInfo.GetImageID(groupInfo.Image);
        Session["imageID"] = imageInfo.ID;
        if (imageInfo.Check_Checksum(imageInfo.ID))
        {
            if (isUnicast == 1)
            {
                Unicast unicast = new Unicast();
                List<int> listHostID = new List<int>();
                listHostID = unicast.UnicastFromGroup(groupID);

                for (int z = 0; z < listHostID.Count; z++)
                    unicast.CreateUnicast("push", listHostID[z]);
                Utility.Message = "Started " + listHostID.Count + " Tasks";
            }
            else
            {
                Multicast multicast = new Multicast();
                multicast.CreateMulticast(groupID);
            }
            Session.Remove("groupID");
            Session.Remove("isGroupUnicast");
            Master.Msgbox(Utility.Message);
        }
        else
        {

            lblIncorrectChecksum.Text = "This Image Has Not Been Confirmed And Cannot Be Deployed.  <br>Confirm It Now?";
            ClientScript.RegisterStartupScript(this.GetType(), "modalscript", "$(function() {  var menuTop = document.getElementById('incorrectChecksum'),body = document.body;classie.toggle(menuTop, 'confirm-box-outer-open'); });", true);

        }
    }
Ejemplo n.º 29
0
        public static void Main(string[] args)
        {
            // TODO: Implement Functionality Here


            // Initialize the multicast address group and multicast port.
            // Both address and port are selected from the allowed sets as
            // defined in the related RFC documents. These are the same
            // as the values used by the sender.0
            mcastAddress = IPAddress.Parse(VM.Yantra.Common.GetIpAddress());            //  IPAddress.Parse("224.168.100.2");
            mcastPort    = 8080;

            try
            {
                string cmdIPAddress = args[0];
                localAddress = IPAddress.Parse(args[0]);
            }
            catch (Exception e)
            {
                localAddress = IPAddress.Parse("127.0.0.1");
            }


            // Start a multicast group.
            Multicast.StartMulticast(mcastAddress, mcastPort, localAddress);

            // Display MulticastOption properties.
            //Multicast.MulticastOptionProperties();

            // Receive broadcast messages.

            Console.WriteLine("Message will be sent to ..." + localAddress);
            Multicast.ReceiveBroadcastMessages(mcastAddress, mcastPort, localAddress);


            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
Ejemplo n.º 30
0
        public void WriteIntoMultipleDestinations()
        {
            //Arrange
            var source = new MemorySource <string[]>();

            source.DataAsList.Add(new string[] { "Test" });
            var trans = new RowTransformation <string[]>();

            trans.TransformationFunc = r => throw new Exception();
            var dest = new MemoryDestination <string[]>();

            CreateErrorTableTask.Create(SqlConnection, "error_log");
            var mc       = new Multicast <ETLBoxError>();
            var errorMem = new MemoryDestination <ETLBoxError>();
            var errorDb  = new DbDestination <ETLBoxError>(SqlConnection, "error_log");
            var errorCsv = new CsvDestination <ETLBoxError>("error_csv.csv");

            source.LinkTo(trans);
            trans.LinkTo(dest);

            //Act
            trans.LinkErrorTo(mc);
            mc.LinkTo(errorMem);
            mc.LinkTo(errorDb);
            mc.LinkTo(errorCsv);

            source.Execute();
            dest.Wait();
            errorMem.Wait();
            errorDb.Wait();
            errorCsv.Wait();

            //Assert
            Assert.True(errorMem.Data.Count > 0);
            Assert.True(RowCountTask.Count(SqlConnection, "error_log") > 0);
            Assert.True(File.ReadAllText("error_csv.csv").Length > 0);
        }
Ejemplo n.º 31
0
        public void WriteParallelWhileTransactionOpen(IConnectionManager connection, int numberOfRows)
        {
            //Arrange
            BigDataCsvSource.CreateCSVFileIfNeeded(numberOfRows);
            ReCreateDestinationTable(connection, "TransactionDestination1");
            ReCreateDestinationTable(connection, "TransactionDestination2");

            var source = new CsvSource(BigDataCsvSource.GetCompleteFilePath(numberOfRows));
            var dest1  = new DbDestination(connection, "TransactionDestination1");
            var dest2  = new DbDestination(connection, "TransactionDestination2");
            var multi  = new Multicast();

            //Act & Assert
            Assert.ThrowsAny <Exception>(() =>
            {
                connection.BeginTransaction();
                source.LinkTo(multi);
                multi.LinkTo(dest1);
                multi.LinkTo(dest2);
                source.Execute();
                dest1.Wait();
                dest2.Wait();
            });
        }
Ejemplo n.º 32
0
        public void DuplicateCheckInRowTrans()
        {
            //Arrange
            CsvSource <Poco> source = CreateDuplicateCsvSource("res/UseCases/DuplicateCheck.csv");
            List <int>       IDs    = new List <int>(); //at the end of the flow, this list will contain all IDs of your source

            //Act
            RowTransformation <Poco, Poco> rowTrans = new RowTransformation <Poco, Poco>(input =>
            {
                if (IDs.Contains(input.ID))
                {
                    input.IsDuplicate = true;
                }
                else
                {
                    IDs.Add(input.ID);
                }
                return(input);
            });

            Multicast <Poco>       multicast = new Multicast <Poco>();
            DbDestination <Poco>   dest      = CreateDestinationTable("dbo.DuplicateCheck");
            VoidDestination <Poco> trash     = new VoidDestination <Poco>();

            source.LinkTo(rowTrans);
            rowTrans.LinkTo(multicast);
            multicast.LinkTo(dest, input => input.IsDuplicate == false);
            multicast.LinkTo(trash, input => input.IsDuplicate == true);

            source.Execute();
            dest.Wait();
            trash.Wait();

            //Assert
            AssertDataWithoutDuplicates();
        }
Ejemplo n.º 33
0
 public bool Create(Multicast multicast)
 {
     bool mcTaskCreated = false;
     try
     {
         using (NpgsqlConnection conn = new NpgsqlConnection(Utility.DBString))
         {
             NpgsqlCommand cmd = new NpgsqlCommand("multicast_create", conn);
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.Add(new NpgsqlParameter("@multicastName", multicast.GroupName));
             conn.Open();
             string result = cmd.ExecuteScalar() as string;
             if (result != null)
                 Utility.Message = result;
             else
                 mcTaskCreated = true;
         }
     }
     catch (Exception ex)
     {
         Utility.Message = "Could Not Create Multicast.  Check The Exception Log For More Info";
         Logger.Log(ex.ToString());
     }
     return mcTaskCreated;
 }
Ejemplo n.º 34
0
    public Multicast CreateHostTask(Multicast multicast)
    {
        multicast.ActiveTaskCreated = false;
        try
        {
            using (NpgsqlConnection conn = new NpgsqlConnection(Utility.DBString))
            {
                NpgsqlCommand cmd = new NpgsqlCommand("multicast_createhosts", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new NpgsqlParameter("@hostName", NpgsqlDbType.Varchar));
                cmd.Parameters.Add(new NpgsqlParameter("@multicastName", multicast.GroupName));

                conn.Open();
                for (int i = 0; i < multicast.HostNames.Count; i++)
                {
                    cmd.Parameters["@hostName"].Value = multicast.HostNames[i];
                    multicast.TaskIDs.Add(cmd.ExecuteScalar() as string);
                }

                multicast.ActiveTaskCreated = true;
            }
        }
        catch (Exception ex)
        {
            Utility.Message = "Could Not Create Host Tasks.  Check The Exception Log For More Info";
            Logger.Log(ex.ToString());
        }
        return multicast;
    }
Ejemplo n.º 35
0
    public void CreateMulticast(int groupID)
    {
        Multicast multicast = new Multicast();
        Utility settings = new Utility();
        Task task = new Task();
        int portBase = task.GetPort();

        if (portBase != 0)
        {
            multicast = multicast.Read(groupID);
            if (multicast != null)
            {
                if (String.IsNullOrEmpty(multicast.GroupSenderArgs))
                    multicast.GroupSenderArgs = settings.GetSettings("Sender Args");

                if (multicast.HostNames.Count > 0)
                {
                    if (CheckAllHostsEqual(multicast))
                    {
                        if (CreateMulticastTask(multicast, "push", "true", portBase))
                        {
                            if (StartMulticastSender(multicast, portBase))
                            {
                                History history = new History();
                                history.Event = "Multicast";
                                history.Type = "Group";
                                history.TypeID = groupID.ToString();
                                history.CreateEvent(history);

                                Host host = new Host();
                                foreach (string mac in HostMacs)
                                {
                                    history.Event = "Deploy";
                                    history.Type = "Host";
                                    history.Notes = "Via Group Multicast: " + multicast.GroupName;
                                    history.TypeID = host.GetHostID(mac);
                                    history.CreateEvent(history);
                                }

                                foreach (string name in HostNames)
                                {
                                    Image image = new Image();
                                    history.Event = "Deploy";
                                    history.Type = "Image";
                                    history.Notes = name;
                                    history.TypeID = image.GetImageID(multicast.GroupImage);
                                    history.CreateEvent(history);
                                }
                            }
                            else
                                RollBack(multicast, true, true, true);

                        }
                    }
                }
                else
                    Utility.Message = "The Group Does Not Have Any Hosts";
            }
        }
    }
Ejemplo n.º 36
0
    public bool CreatePxeBootMC(Multicast multicast, string direction, string isMulticast, int portBase, int i)
    {
        Utility settings = new Utility();
        string path = null;
        string[] lines = null;
        string wds_key = null;
        string proxyDHCP = settings.GetSettings("Proxy Dhcp");
        string biosFile = settings.GetSettings("Proxy Bios File");
        string efi32File = settings.GetSettings("Proxy Efi32 File");
        string efi64File = settings.GetSettings("Proxy Efi64 File");
        string biosPath = null;
        string efi32Path = null;
        string efi64Path = null;
        string biosPathipxe = null;
        string efi32Pathipxe = null;
        string efi64Pathipxe = null;
        string mode = settings.GetSettings("PXE Mode");

        if (settings.GetSettings("Server Key Mode") == "Automated")
             wds_key = settings.GetSettings("Server Key");
        else
             wds_key = "";

        if (proxyDHCP == "Yes")
        {

            biosPathipxe = settings.GetSettings("Tftp Path") + "proxy" + Path.DirectorySeparatorChar + "bios" + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + multicast.PXEHostMac + ".ipxe";
            string[] biosLinesipxe = {@"#!ipxe",
                           @"kernel " + "http://"+ settings.GetServerIP() +"/cruciblewds/data/boot/kernels/" + multicast.GroupKernel + ".krn" + " initrd=" + multicast.GroupBootImage + " root=/dev/ram0 rw ramdisk_size=127000 ip=dhcp imgDirection=" + direction + " consoleblank=0" + " web=" + settings.GetSettings("Web Path") + " WDS_KEY=" + wds_key + " " + settings.GetSettings("Global Host Args") + " " + multicast.HostArguments,
                           @"imgfetch " + "http://"+ settings.GetServerIP() +"/cruciblewds/data/boot/images/" + multicast.GroupBootImage ,
                           @"boot"};

            biosPath = settings.GetSettings("Tftp Path") + "proxy" + Path.DirectorySeparatorChar + "bios" + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + multicast.PXEHostMac;
            string[] biosLines = { @"DEFAULT cruciblewds",
                           @"LABEL cruciblewds", @"KERNEL kernels" + Path.DirectorySeparatorChar + multicast.GroupKernel ,
                           @"APPEND initrd=images" + Path.DirectorySeparatorChar + multicast.GroupBootImage + " root=/dev/ram0 rw ramdisk_size=127000 ip=dhcp imgDirection=" + direction + " consoleblank=0" + " web=" + settings.GetSettings("Web Path") + " WDS_KEY=" + wds_key + " " + settings.GetSettings("Global Host Args") + " " + multicast.HostArguments};

            efi32Pathipxe = settings.GetSettings("Tftp Path") + "proxy" + Path.DirectorySeparatorChar + "efi32" + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + multicast.PXEHostMac + ".ipxe";
            string[] efi32Linesipxe = {@"#!ipxe",
                           @"kernel " + "http://"+ settings.GetServerIP() +"/cruciblewds/data/boot/kernels/" + multicast.GroupKernel + ".krn" + " initrd=" + multicast.GroupBootImage + " root=/dev/ram0 rw ramdisk_size=127000 ip=dhcp imgDirection=" + direction + " consoleblank=0" + " web=" + settings.GetSettings("Web Path") + " WDS_KEY=" + wds_key + " " + settings.GetSettings("Global Host Args") + " " + multicast.HostArguments,
                           @"imgfetch " + "http://"+ settings.GetServerIP() +"/cruciblewds/data/boot/images/" + multicast.GroupBootImage ,
                           @"boot"};

            efi32Path = settings.GetSettings("Tftp Path") + "proxy" + Path.DirectorySeparatorChar + "efi32" + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + multicast.PXEHostMac;
            string[] efi32Lines = { @"DEFAULT cruciblewds",
                           @"LABEL cruciblewds", @"KERNEL kernels" + Path.DirectorySeparatorChar + multicast.GroupKernel ,
                           @"APPEND initrd=images" + Path.DirectorySeparatorChar + multicast.GroupBootImage + " root=/dev/ram0 rw ramdisk_size=127000 ip=dhcp imgDirection=" + direction + " consoleblank=0" + " web=" + settings.GetSettings("Web Path") + " WDS_KEY=" + wds_key + " " + settings.GetSettings("Global Host Args") + " " + multicast.HostArguments};

            efi64Pathipxe = settings.GetSettings("Tftp Path") + "proxy" + Path.DirectorySeparatorChar + "efi64" + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + multicast.PXEHostMac + ".ipxe";
            string[] efi64Linesipxe = {@"#!ipxe",
                           @"kernel " + "http://"+ settings.GetServerIP() +"/cruciblewds/data/boot/kernels/" + multicast.GroupKernel + ".krn" + " initrd=" + multicast.GroupBootImage + " root=/dev/ram0 rw ramdisk_size=127000 ip=dhcp imgDirection=" + direction + " consoleblank=0" + " web=" + settings.GetSettings("Web Path") + " WDS_KEY=" + wds_key + " " + settings.GetSettings("Global Host Args") + " " + multicast.HostArguments,
                           @"imgfetch " + "http://"+ settings.GetServerIP() +"/cruciblewds/data/boot/images/" + multicast.GroupBootImage ,
                           @"boot"};

            efi64Path = settings.GetSettings("Tftp Path") + "proxy" + Path.DirectorySeparatorChar + "efi64" + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + multicast.PXEHostMac;
            string[] efi64Lines = { @"DEFAULT cruciblewds",
                           @"LABEL cruciblewds", @"KERNEL kernels" + Path.DirectorySeparatorChar + multicast.GroupKernel ,
                           @"APPEND initrd=images" + Path.DirectorySeparatorChar + multicast.GroupBootImage + " root=/dev/ram0 rw ramdisk_size=127000 ip=dhcp imgDirection=" + direction + " consoleblank=0" + " web=" + settings.GetSettings("Web Path") + " WDS_KEY=" + wds_key + " " + settings.GetSettings("Global Host Args") + " " + multicast.HostArguments};

            if (File.Exists(biosPath))
            {
                Host hostFunction = new Host();
                if (hostFunction.IsCustomBootEnabled(Task.PXEMacToMac(multicast.PXEHostMac)))
                {
                    Utility.MoveFile(biosPath, biosPath + ".custom");
                }
                else
                {
                    Utility.Message = "The PXE File Already Exists";
                    return false;
                }
            }

            if (File.Exists(biosPathipxe))
            {
                Host hostFunction = new Host();
                if (hostFunction.IsCustomBootEnabled(Task.PXEMacToMac(multicast.PXEHostMac)))
                {
                    Utility.MoveFile(settings.GetSettings("Tftp Path") + "proxy" + Path.DirectorySeparatorChar + "bios" + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + multicast.PXEHostMac + ".ipxe", settings.GetSettings("Tftp Path") + "proxy" + Path.DirectorySeparatorChar + "bios" + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + multicast.PXEHostMac + ".ipxe.custom");
                }
                else
                {
                    Utility.Message = "The PXE File Already Exists";
                    return false;
                }
            }

            if (File.Exists(efi32Path))
            {
                Host hostFunction = new Host();
                if (hostFunction.IsCustomBootEnabled(Task.PXEMacToMac(multicast.PXEHostMac)))
                {
                    Utility.MoveFile(efi32Path, efi32Path + ".custom");
                }
                else
                {
                    Utility.Message = "The PXE File Already Exists";
                    return false;
                }
            }

            if (File.Exists(efi32Pathipxe))
            {
                Host hostFunction = new Host();
                if (hostFunction.IsCustomBootEnabled(Task.PXEMacToMac(multicast.PXEHostMac)))
                {

                    Utility.MoveFile(settings.GetSettings("Tftp Path") + "proxy" + Path.DirectorySeparatorChar + "efi32" + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + multicast.PXEHostMac + ".ipxe", settings.GetSettings("Tftp Path") + "proxy" + Path.DirectorySeparatorChar + "efi32" + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + multicast.PXEHostMac + ".ipxe.custom");
                }
                else
                {
                    Utility.Message = "The PXE File Already Exists";
                    return false;
                }
            }

            if (File.Exists(efi64Path))
            {
                Host hostFunction = new Host();
                if (hostFunction.IsCustomBootEnabled(Task.PXEMacToMac(multicast.PXEHostMac)))
                {
                    Utility.MoveFile(efi64Path, efi64Path + ".custom");
                }
                else
                {
                    Utility.Message = "The PXE File Already Exists";
                    return false;
                }
            }

            if (File.Exists(efi64Pathipxe))
            {
                Host hostFunction = new Host();
                if (hostFunction.IsCustomBootEnabled(Task.PXEMacToMac(multicast.PXEHostMac)))
                {

                    Utility.MoveFile(settings.GetSettings("Tftp Path") + "proxy" + Path.DirectorySeparatorChar + "efi64" + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + multicast.PXEHostMac + ".ipxe", settings.GetSettings("Tftp Path") + "proxy" + Path.DirectorySeparatorChar + "efi64" + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + multicast.PXEHostMac + ".ipxe.custom");
                }
                else
                {
                    Utility.Message = "The PXE File Already Exists";
                    return false;
                }
            }

            try
            {
                System.IO.File.WriteAllLines(biosPath, biosLines);
                if (Environment.OSVersion.ToString().Contains("Unix"))
                    Syscall.chmod(biosPath, (FilePermissions.S_IWUSR | FilePermissions.S_IRGRP | FilePermissions.S_IROTH | FilePermissions.S_IRUSR));

                System.IO.File.WriteAllLines(efi32Path, efi32Lines);
                if (Environment.OSVersion.ToString().Contains("Unix"))
                    Syscall.chmod(efi32Path, (FilePermissions.S_IWUSR | FilePermissions.S_IRGRP | FilePermissions.S_IROTH | FilePermissions.S_IRUSR));

                System.IO.File.WriteAllLines(efi64Path, efi64Lines);
                if (Environment.OSVersion.ToString().Contains("Unix"))
                    Syscall.chmod(efi64Path, (FilePermissions.S_IWUSR | FilePermissions.S_IRGRP | FilePermissions.S_IROTH | FilePermissions.S_IRUSR));

                System.IO.File.WriteAllLines(biosPathipxe, biosLinesipxe);
                if (Environment.OSVersion.ToString().Contains("Unix"))
                    Syscall.chmod(biosPathipxe, (FilePermissions.S_IWUSR | FilePermissions.S_IRGRP | FilePermissions.S_IROTH | FilePermissions.S_IRUSR));

                System.IO.File.WriteAllLines(efi32Pathipxe, efi32Linesipxe);
                if (Environment.OSVersion.ToString().Contains("Unix"))
                    Syscall.chmod(efi32Pathipxe, (FilePermissions.S_IWUSR | FilePermissions.S_IRGRP | FilePermissions.S_IROTH | FilePermissions.S_IRUSR));

                System.IO.File.WriteAllLines(efi64Pathipxe, efi64Linesipxe);
                if (Environment.OSVersion.ToString().Contains("Unix"))
                    Syscall.chmod(efi64Pathipxe, (FilePermissions.S_IWUSR | FilePermissions.S_IRGRP | FilePermissions.S_IROTH | FilePermissions.S_IRUSR));

            }

            catch (Exception ex)
            {
                Logger.Log(ex.ToString());
                Utility.Message = "Could Not Create PXE File";
                return false;
            }

        }
        else
        {
            if (mode == "pxelinux" || mode == "syslinux_32_efi" || mode == "syslinux_64_efi")
            {
                path = settings.GetSettings("Tftp Path") + "pxelinux.cfg" + Path.DirectorySeparatorChar + multicast.PXEHostMac;
                string[] tmplines = { @"DEFAULT cruciblewds",
                           @"LABEL cruciblewds", @"KERNEL " + "kernels" + Path.DirectorySeparatorChar + multicast.GroupKernel ,
                           @"APPEND initrd=" + "images" + Path.DirectorySeparatorChar + multicast.GroupBootImage + " root=/dev/ram0 rw ramdisk_size=127000 ip=dhcp imgDirection=" + direction + " consoleblank=0" + " web=" + settings.GetSettings("Web Path") + " WDS_KEY=" + wds_key + " " + settings.GetSettings("Global Host Args") + " " + multicast.GroupArguments};

                lines = tmplines;
            }
            else if (mode.Contains("ipxe"))
            {
                path = settings.GetSettings("Tftp Path") + "pxelinux.cfg" + Path.DirectorySeparatorChar + multicast.PXEHostMac + ".ipxe";
                string[] tmplines = {@"#!ipxe",
                           @"kernel " + "http://"+ settings.GetServerIP() +"/cruciblewds/data/boot/kernels/" + multicast.GroupKernel + ".krn" + " initrd=" + multicast.GroupBootImage + " root=/dev/ram0 rw ramdisk_size=127000 ip=dhcp imgDirection=" + direction + " consoleblank=0" + " web=" + settings.GetSettings("Web Path") + " WDS_KEY=" + wds_key + " " + settings.GetSettings("Global Host Args") + " " + multicast.HostArguments,
                           @"imgfetch " + "http://"+ settings.GetServerIP() +"/cruciblewds/data/boot/images/" + multicast.GroupBootImage ,
                           @"boot"};
                lines = tmplines;
            }

            else
            {
                Utility.Message = "PXE Mode Is Not Set Correctly";
                return false;
            }

            if (File.Exists(path))
            {
                Host hostFunction = new Host();
                if (hostFunction.IsCustomBootEnabled(Task.PXEMacToMac(PXEHostMac)))
                {
                    if (mode.Contains("ipxe"))
                        Utility.MoveFile(settings.GetSettings("Tftp Path") + "pxelinux.cfg" + Path.DirectorySeparatorChar + PXEHostMac + ".ipxe", settings.GetSettings("Tftp Path") + "pxelinux.cfg" + Path.DirectorySeparatorChar + PXEHostMac + ".ipxe.custom");
                    else
                        Utility.MoveFile(settings.GetSettings("Tftp Path") + "pxelinux.cfg" + Path.DirectorySeparatorChar + PXEHostMac, settings.GetSettings("Tftp Path") + "pxelinux.cfg" + Path.DirectorySeparatorChar + PXEHostMac + ".custom");
                }
                else
                {
                    Utility.Message = "The PXE File Already Exists";
                    return false;
                }
            }

            try
            {
                System.IO.File.WriteAllLines(path, lines);
                if (Environment.OSVersion.ToString().Contains("Unix"))
                {
                    Syscall.chmod(path, (FilePermissions.S_IWUSR | FilePermissions.S_IRGRP | FilePermissions.S_IROTH | FilePermissions.S_IRUSR));
                }

            }
            catch (Exception ex)
            {
                Utility.Message = "Could Not Create PXE File";
                Logger.Log(ex.ToString());
                return false;
            }

        }
        try
        {

            string storagePath = null;
            string xferMode = settings.GetSettings("Image Transfer Mode");
            if (xferMode == "smb" || xferMode == "smb+http")
                storagePath = "SMB Path";
            else
            {
                if (direction == "pull")
                    storagePath = "Nfs Upload Path";
                else
                    storagePath = "Nfs Deploy Path";
            }
            string hostArgs = "imgName=" + multicast.GroupImage + " storage=" + settings.GetSettings(storagePath) + " hostID=" + multicast.HostIDs[i] +
                              " imgOS=" + multicast.ImageOS + " multicast=true " + " hostScripts=" + multicast.GroupScripts +  " xferMode=" + xferMode + " serverIP=" + settings.GetSettings("Server IP") +
                              " hostName=" + multicast.HostNames[i] + " portBase=" + portBase + " " + "clientReceiverArgs=" + settings.GetSettings("Client Receiver Args");

            Task task = new Task();
            if (task.CreateTaskArgs(hostArgs,multicast.TaskIDs[i]))
                return true;
            else
                return false;
        }
        catch (Exception ex)
        {
            Utility.Message = "Could Not Create PXE File";
            Logger.Log(ex.ToString());
            return false;
        }
    }
Ejemplo n.º 37
0
    public bool CreatePXEFiles(Multicast multicast, int portBase)
    {
        Task task = new Task();

        for (int i = 0; i < multicast.HostMacs.Count; i++)
        {
            multicast.PXEHostMac = task.MacToPXE(multicast.HostMacs[i]);
            multicast.PXEBoot.Add(CreatePxeBootMC(multicast, "push", "true", portBase, i));
        }
        if (multicast.PXEBoot.Contains(false))
            return false;
        else
            return true;
    }
Ejemplo n.º 38
0
    public Multicast GetHostIDs(Multicast multicast)
    {
        try
        {
            using (NpgsqlConnection conn = new NpgsqlConnection(Utility.DBString))
            {
                NpgsqlCommand cmd = new NpgsqlCommand("hosts_readhostid", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new NpgsqlParameter("@hostMac", NpgsqlDbType.Varchar));

                conn.Open();
                for (int i = 0; i < multicast.HostNames.Count; i++)
                {
                    cmd.Parameters["@hostMac"].Value = multicast.HostMacs[i];
                    multicast.HostIDs.Add(cmd.ExecuteScalar().ToString());
                }
            }
        }
        catch (Exception ex)
        {
            Utility.Message = "Could Not Read Host IDs.  Check The Exception Log For More Info";
            Logger.Log(ex.ToString());
        }
        return multicast;
    }
Ejemplo n.º 39
0
    protected bool CheckAllHostsEqual(Multicast multicast)
    {
        bool allEqual = true;

        for (int i = 0; i < multicast.HostNames.Count; i++)
        {
            allEqual = multicast.HostImages.TrueForAll(x => x == multicast.HostImages[i]);
            if (!allEqual)
                break;
            allEqual = multicast.HostKernels.TrueForAll(x => x == multicast.HostKernels[i]);
            if (!allEqual)
                break;
            allEqual = multicast.HostBootImages.TrueForAll(x => x == multicast.HostBootImages[i]);
            if (!allEqual)
                break;
            allEqual = multicast.HostArguments.TrueForAll(x => x == multicast.HostArguments[i]);
            if (!allEqual)
                break;
        }
        if (!allEqual)
            Utility.Message = "All Hosts Are Not Equal";
        return allEqual;
    }
Ejemplo n.º 40
0
    public Multicast Read(int groupID)
    {
        Multicast multicast = new Multicast();
        try
        {
            using (NpgsqlConnection conn = new NpgsqlConnection(Utility.DBString))
            {
                NpgsqlCommand cmd = new NpgsqlCommand("multicast_read", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new NpgsqlParameter("@groupID", groupID));
                conn.Open();
                NpgsqlDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    multicast.HostNames.Add((string)rdr["_hostname"]);
                    multicast.HostMacs.Add((string)rdr["_hostmac"]);
                    multicast.HostImages.Add((string)rdr["_hostimage"]);
                    multicast.HostKernels.Add((string)rdr["_hostkernel"]);
                    multicast.HostBootImages.Add((string)rdr["_hostbootimage"]);
                    multicast.HostArguments.Add((string)rdr["_hostarguments"]);
                    multicast.ImageOS = (string)rdr["_imageos"];
                    multicast.GroupImage = (string)rdr["_groupimage"];
                    multicast.GroupKernel = (string)rdr["_groupkernel"];
                    multicast.GroupBootImage = (string)rdr["_groupbootimage"];
                    multicast.GroupArguments = (string)rdr["_grouparguments"];
                    multicast.GroupSenderArgs = (string)rdr["_groupsenderargs"];
                    multicast.GroupName = (string)rdr["_groupname"];
                    multicast.GroupScripts = rdr["_groupscripts"].ToString();
                }
            }
        }
        catch (Exception ex)
        {
            Utility.Message = "Could Not Read Multicast Info.  Check The Exception Log For More Info.";
            Logger.Log(ex.ToString());
            multicast = null;
        }

        return multicast;
    }
Ejemplo n.º 41
0
 public void RollBackActiveTasks(Multicast multicast)
 {
     try
     {
         using (NpgsqlConnection conn = new NpgsqlConnection(Utility.DBString))
         {
             NpgsqlCommand cmd = new NpgsqlCommand("multicast_rollbackhosts", conn);
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.Add(new NpgsqlParameter("@taskname", multicast.GroupName));
             conn.Open();
             cmd.ExecuteNonQuery();
         }
     }
     catch (Exception ex)
     {
         Logger.Log(ex.ToString());
     }
 }
Ejemplo n.º 42
0
    public void RollBack(Multicast multicast, bool mcTaskCreated, bool activeTaskCreated, bool pxeBootCreated)
    {
        Task task = new Task();
        if (pxeBootCreated)
        {
            string pxeHostMac;
            for (int i = 0; i < multicast.HostNames.Count; i++)
            {
                pxeHostMac = task.MacToPXE(multicast.HostMacs[i]);
                task.CleanPxeBoot(pxeHostMac);
            }
        }

        if (activeTaskCreated)
            multicast.RollBackActiveTasks(multicast);

        if (mcTaskCreated)
            multicast.RollBackActiveMCTask(multicast);
    }
Ejemplo n.º 43
0
    public bool StartCustomMC(string imageName)
    {
        string appPath = null;
        string logPath = null;
        string shell = null;

        if (Environment.OSVersion.ToString().Contains("Unix"))
        {
             string dist = null;
             ProcessStartInfo distInfo = new ProcessStartInfo();
             distInfo.UseShellExecute = false;
             distInfo.FileName = "uname";
             distInfo.RedirectStandardOutput = true;
             distInfo.RedirectStandardError = true;

             using (Process process = Process.Start(distInfo))
             {
                  dist = process.StandardOutput.ReadToEnd();
             }
             Logger.Log("Distro is " + dist);

             if(dist.ToLower().Contains("bsd"))
               shell = "/bin/csh";
             else
               shell = "/bin/bash";

             logPath = HttpContext.Current.Server.MapPath("~") + @"/data/logs" + @"/";

        }
        else
        {
             appPath = HttpContext.Current.Server.MapPath("~") + Path.DirectorySeparatorChar + "data" + Path.DirectorySeparatorChar + "apps" + Path.DirectorySeparatorChar;
             logPath = HttpContext.Current.Server.MapPath("~") + Path.DirectorySeparatorChar + "data" + Path.DirectorySeparatorChar + "logs" + Path.DirectorySeparatorChar;
             shell = "cmd.exe";
        }

        Multicast multicast = new Multicast();
        Utility settings = new Utility();
        string fullImagePath = null;

        Task task = new Task();
        int portBase = task.GetPort();
        string senderArgs = settings.GetSettings("Sender Args");
        Process multiSender = null;
        ProcessStartInfo senderInfo = new ProcessStartInfo();

        senderInfo.FileName = (shell);
        string udpFile = null;
        String[] partFiles = null;
        string compExt = null;
        string compAlg = null;
        string stdout = null;

        //Multicasting currently only supports the first active hd
        //Find First Active HD
        Image image = new Image();
        image.ID = image.GetImageID(imageName);
        image.Read(image);
        Image_Physical_Specs ips = new Image_Physical_Specs();
        if (!string.IsNullOrEmpty(image.ClientSizeCustom))
        {
            ips = JsonConvert.DeserializeObject<Image_Physical_Specs>(image.ClientSizeCustom);
            try
            {
                ips = JsonConvert.DeserializeObject<Image_Physical_Specs>(image.ClientSizeCustom);
            }
            catch { }
        }
        else
        {
            ips = JsonConvert.DeserializeObject<Image_Physical_Specs>(image.ClientSize);
            try
            {
                ips = JsonConvert.DeserializeObject<Image_Physical_Specs>(image.ClientSize);
            }
            catch { }
        }
        string activeHD = null;
        int activeCounter = 0;
        foreach (var hd in ips.hd)
        {
            if (hd.active == "1")
            {
                activeHD = activeCounter.ToString();
                break;
            }
            activeCounter++;
        }

        if (activeCounter == 0)
        {
            fullImagePath = settings.GetSettings("Image Store Path") + imageName;
        }
        else
        {
            fullImagePath = settings.GetSettings("Image Store Path") + imageName + Path.DirectorySeparatorChar + "hd" + (activeCounter + 1).ToString();
        }

        try
        {
            // modified by cocoon
            string[] ImageExtensions = new string[3] { ".gz", ".lz4", ".none" }; // modified by cocoon

            foreach (var ext in ImageExtensions)
            {
                partFiles = Directory.GetFiles(fullImagePath + Path.DirectorySeparatorChar, "*" + ext);
                if (partFiles != null && partFiles.Length > 0)
                {
                    compExt = ext;
                    if (compExt == ".lz4")
                    {
                        compAlg = Environment.OSVersion.ToString().Contains("Unix") ? "lz4 -d " : "lz4.exe -d ";
                        stdout = " - ";
                    }
                    else if (compExt == ".gz")
                    {
                        compAlg = Environment.OSVersion.ToString().Contains("Unix") ? "gzip -c -d " : "gzip.exe -c -d ";
                        stdout = "";
                    }
                    else
                    {
                        compAlg = Environment.OSVersion.ToString().Contains("Unix") ? "cat " : "type ";
            stdout = "";
                    }
                    break;
                }
            }
            if (partFiles.Length == 0)
            {
               	Utility.Message = "Image Files Could Not Be Located";
        return false;
            }
        }
        catch
        {
            Utility.Message = "Image Files Could Not Be Located";
            return false;
        }

        int x = 0;
        foreach (var part in ips.hd[activeCounter].partition)
        {
            udpFile = null;
            if (part.active == "1")
            {
                if (File.Exists(fullImagePath + Path.DirectorySeparatorChar + "part" + part.number + ".ntfs" + compExt))
                    udpFile = fullImagePath + Path.DirectorySeparatorChar + "part" + part.number + ".ntfs" + compExt;
                else if (File.Exists(fullImagePath + Path.DirectorySeparatorChar + "part" + part.number + ".fat" + compExt))
                    udpFile = fullImagePath + Path.DirectorySeparatorChar + "part" + part.number + ".fat" + compExt;
                else if (File.Exists(fullImagePath + Path.DirectorySeparatorChar + "part" + part.number + ".extfs" + compExt))
                    udpFile = fullImagePath + Path.DirectorySeparatorChar + "part" + part.number + ".extfs" + compExt;
                else if (File.Exists(fullImagePath + Path.DirectorySeparatorChar + "part" + part.number + ".hfsp" + compExt))
                    udpFile = fullImagePath + Path.DirectorySeparatorChar + "part" + part.number + ".hfsp" + compExt;
                else if (File.Exists(fullImagePath + Path.DirectorySeparatorChar + "part" + part.number + ".imager" + compExt))
                    udpFile = fullImagePath + Path.DirectorySeparatorChar + "part" + part.number + ".imager" + compExt;
                else
                {
                    //Look for lvm
                    if (part.vg != null)
                    {
                        if (part.vg.lv != null)
                        {
                            foreach (var lv in part.vg.lv)
                            {
                                if (lv.active == "1")
                                {

                                    if (File.Exists(fullImagePath + Path.DirectorySeparatorChar + lv.vg + "-" + lv.name + ".ntfs" + compExt))
                                        udpFile = fullImagePath + Path.DirectorySeparatorChar + lv.vg + "-" + lv.name + ".ntfs" + compExt;
                                    else if (File.Exists(fullImagePath + Path.DirectorySeparatorChar + lv.vg + "-" + lv.name + ".fat" + compExt))
                                        udpFile = fullImagePath + Path.DirectorySeparatorChar + lv.vg + "-" + lv.name + ".fat" + compExt;
                                    else if (File.Exists(fullImagePath + Path.DirectorySeparatorChar + lv.vg + "-" + lv.name + ".extfs" + compExt))
                                        udpFile = fullImagePath + Path.DirectorySeparatorChar + lv.vg + "-" + lv.name + ".extfs" + compExt;
                                    else if (File.Exists(fullImagePath + Path.DirectorySeparatorChar + lv.vg + "-" + lv.name + ".hfsp" + compExt))
                                        udpFile = fullImagePath + Path.DirectorySeparatorChar + lv.vg + "-" + lv.name + ".hfsp" + compExt;
                                    else if (File.Exists(fullImagePath + Path.DirectorySeparatorChar + lv.vg + "-" + lv.name + ".imager" + compExt))
                                        udpFile = fullImagePath + Path.DirectorySeparatorChar + lv.vg + "-" + lv.name + ".imager" + compExt;
                                }
                            }
                        }
                    }
                }

                if (udpFile == null)
                    continue;
                else
                    x++;

                if (Environment.OSVersion.ToString().Contains("Unix"))
                {
                    if (x == 1)
                        senderInfo.Arguments = (" -c \"" + compAlg + udpFile + stdout + " | udp-sender" +
                                           " --portbase " + portBase + " " + senderArgs + " --ttl 32");
                    else
                        senderInfo.Arguments += (" ; " + compAlg + udpFile + stdout + " | udp-sender" +
                                           " --portbase " + portBase + " " + senderArgs + " --ttl 32");
                }
                else
                {
                    if (x == 1)
                        senderInfo.Arguments = (" /c " + appPath + compAlg + udpFile + stdout + " | " + appPath + "udp-sender.exe" +
                                           " --portbase " + portBase + " " + senderArgs + " --ttl 32");
                    else
                        senderInfo.Arguments += (" & " + appPath + compAlg + udpFile + stdout + " | " + appPath + "udp-sender.exe" +
                                           " --portbase " + portBase + " " + senderArgs + " --ttl 32");
                }
            }
        }

        string log = ("\r\n" + DateTime.Now.ToString("MM.dd.yy hh:mm") + " Starting Multicast Session " + portBase +
                      " With The Following Command:\r\n\r\n" + senderInfo.FileName + senderInfo.Arguments + "\r\n\r\n");
        System.IO.File.AppendAllText(logPath + "multicast.log", log);

        if (Environment.OSVersion.ToString().Contains("Unix"))
        {
             senderInfo.Arguments += "\"";
        }

        try
        {
            multiSender = Process.Start(senderInfo);

        }
        catch (Exception ex)
        {
            Logger.Log(ex.ToString());
            Utility.Message = "Could Not Start Multicast Sender.  Check The Exception Log For More Info";
            System.IO.File.AppendAllText(logPath + "multicast.log", "Could Not Start Session " + portBase + " Try Pasting The Command Into A Command Prompt");
            return false;
        }

        Thread.Sleep(2000);

        if (multiSender.HasExited)
        {
            Utility.Message = "Could Not Start Multicast Sender";
            System.IO.File.AppendAllText(logPath + "multicast.log", "Session " + portBase + @" Started And Was Forced To Quit, Try Pasting The Command Into A Command Prompt");
            return false;
        }
        try
        {
            using (NpgsqlConnection conn = new NpgsqlConnection(Utility.DBString))
            {
                NpgsqlCommand cmd = new NpgsqlCommand("multicast_createcustom", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new NpgsqlParameter("@mcTaskName", portBase.ToString()));
                cmd.Parameters.Add(new NpgsqlParameter("@mcPID", multiSender.Id));
                cmd.Parameters.Add(new NpgsqlParameter("@mcPortBase", portBase));
                cmd.Parameters.Add(new NpgsqlParameter("@mcImage", imageName));

                conn.Open();
                cmd.ExecuteNonQuery();
                Utility.Message = "Successfully Started Task " + portBase;
            }
        }
        catch (Exception ex)
        {
            Utility.Message = "Could Not Create Custom Multicast.  Check The Exception Log For More Info";
            Logger.Log(ex.ToString());
            return false;
        }
        return true;
    }
Ejemplo n.º 44
0
 protected void btnUnicast_Click(object sender, EventArgs e)
 {
     Multicast multicast = new Multicast();
     Session["isGroupUnicast"] = 1;
     lblTitle.Text = "Unicast All The Hosts In The Selected Group?";
     gvConfirm.DataSource = multicast.Confirm(group.ID);
     gvConfirm.DataBind();
     ClientScript.RegisterStartupScript(this.GetType(), "modalscript", "$(function() { var menuTop = document.getElementById('confirmbox'),body = document.body;classie.toggle(menuTop, 'confirm-box-outer-open'); });", true);
 }
Ejemplo n.º 45
0
    protected void btnConfirm_Click(object sender, EventArgs e)
    {
        if ((string)Session["direction"] == "delete")
        {
            Session.Remove("direction");
            List<int> delList = new List<int>();
            delList.Add(Convert.ToInt32(group.ID));
            group.Delete(delList);
            if (Utility.Message.Contains("Successfully"))
                Response.Redirect("~/views/groups/search.aspx");
            else
                Master.Msgbox(Utility.Message);
        }
        else
        {
            Image imageInfo = new Image();
            imageInfo.ID = imageInfo.GetImageID(group.Image);
            Session["imageID"] = imageInfo.ID;
            if (imageInfo.Check_Checksum(imageInfo.ID))
            {
                int isUnicast = Convert.ToInt32(Session["isGroupUnicast"]);
                if (isUnicast == 1)
                {
                    Unicast unicast = new Unicast();
                    List<int> listHostID = new List<int>();
                    listHostID = unicast.UnicastFromGroup(Convert.ToInt32(group.ID));
                    for (int z = 0; z < listHostID.Count; z++)
                        unicast.CreateUnicast("push", listHostID[z]);
                    Utility.Message = "Started " + listHostID.Count + " Tasks";
                    History history = new History();
                    history.Event = "Unicast";
                    history.Type = "Group";
                    history.TypeID = group.ID;
                    history.CreateEvent(history);

                }
                else
                {
                    Multicast multicast = new Multicast();
                    multicast.CreateMulticast(Convert.ToInt32(group.ID));
                }
                Session.Remove("isGroupUnicast");
                Master.Msgbox(Utility.Message);
            }

            else
            {
                lblIncorrectChecksum.Text = "This Image Has Not Been Confirmed And Cannot Be Deployed.  <br>Confirm It Now?";
                ClientScript.RegisterStartupScript(this.GetType(), "modalscript", "$(function() {  var menuTop = document.getElementById('incorrectChecksum'),body = document.body;classie.toggle(menuTop, 'confirm-box-outer-open'); });", true);
            }
        }
    }
Ejemplo n.º 46
0
    protected bool CreateMulticastTask(Multicast multicast, string direction, string isMulticast, int portBase)
    {
        bool mcTaskCreated = false;
        bool pxeBootCreated = false;
        bool activeTaskCheck = true;

        if (multicast.GroupImage != null)
        {
            mcTaskCreated = multicast.Create(multicast);

            if (mcTaskCreated)
                activeTaskCheck = multicast.IsHostAlreadyActive(multicast);

            if (activeTaskCheck && mcTaskCreated)
                multicast = multicast.CreateHostTask(multicast);

            if (mcTaskCreated && multicast.ActiveTaskCreated)
            {
                multicast = GetHostIDs(multicast);
                pxeBootCreated = multicast.CreatePXEFiles(multicast, portBase);
            }
        }
        else
        {
            Utility.Message = "The Groups Current Image No Longer Exists";
            return false;
        }

        if (mcTaskCreated && multicast.ActiveTaskCreated && pxeBootCreated)
            return true;
        else
            RollBack(multicast, mcTaskCreated, multicast.ActiveTaskCreated, pxeBootCreated);
        return false;
    }
Ejemplo n.º 47
0
 public bool IsHostAlreadyActive(Multicast multicast)
 {
     bool activeTaskCheck = true;
     try
     {
         using (NpgsqlConnection conn = new NpgsqlConnection(Utility.DBString))
         {
             NpgsqlCommand cmd = new NpgsqlCommand("multicast_readactivehosts", conn);
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.Add(new NpgsqlParameter("@hostName", NpgsqlDbType.Varchar));
             conn.Open();
             for (int i = 0; i < multicast.HostNames.Count; i++)
             {
                 cmd.Parameters["@hostName"].Value = multicast.HostNames[i];
                 string result = cmd.ExecuteScalar() as string;
                 if (result != null)
                 {
                     Utility.Message = result;
                     activeTaskCheck = false;
                     break;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Utility.Message = "Could Not Determine If Any Hosts Are Already Active.  Check The Exception Log For More Info";
         Logger.Log(ex.ToString());
         activeTaskCheck = false;
     }
     return activeTaskCheck;
 }
Ejemplo n.º 48
0
 public void UpdatePID(int pid, Multicast multicast, int portBase, string mcImage)
 {
     try
     {
         using (NpgsqlConnection conn = new NpgsqlConnection(Utility.DBString))
         {
             NpgsqlCommand cmd = new NpgsqlCommand("multicast_updatepid", conn);
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.Add(new NpgsqlParameter("@mcPID", pid));
             cmd.Parameters.Add(new NpgsqlParameter("@mcPortBase", portBase));
             cmd.Parameters.Add(new NpgsqlParameter("@mcTaskName", multicast.GroupName));
             cmd.Parameters.Add(new NpgsqlParameter("@mcImage", mcImage));
             conn.Open();
             bool result = Convert.ToBoolean(cmd.ExecuteScalar());
             if (!result)
                 Utility.Message = result.ToString();
         }
     }
     catch (Exception ex)
     {
         Logger.Log(ex.ToString());
     }
 }
Ejemplo n.º 49
0
        public static async Task Run([TimerTrigger("0 */1 * * * *"
                                                   //, RunOnStartup=true) //only for testing purposes
                                                   )] TimerInfo myTimer, ILogger log)
        {
            Logging.LogInstance = log;

            string sqlConnectionString = Environment.GetEnvironmentVariable("SqlServerConnectionString", EnvironmentVariableTarget.Process);
            string storageConnString   = Environment.GetEnvironmentVariable("AzureWebJobsStorage", EnvironmentVariableTarget.Process);

            SqlConnectionManager conn = new SqlConnectionManager(sqlConnectionString);


            if (!DemoHelper.WasInitialized)
            {
                containerName = DemoHelper.PrepareForDemo(storageConnString, conn);
            }

            SyncData syncDataLastRun = ReadLastSyncKey();

            var parameter = new[] { new QueryParameter()
                                    {
                                        Name = "syncId", Value = syncDataLastRun.SyncId
                                    } };
            var dbSource = new DbSource <Order>()
            {
                ConnectionManager = conn,
                Sql          = $"SELECT Id, Number, Details, Date FROM Orders WHERE Id > @syncId ORDER BY Date",
                SqlParameter = parameter
            };

            var jsonDest = new JsonDestination <Order>();

            jsonDest.ResourceType = ResourceType.AzureBlob;
            jsonDest.AzureBlobStorage.ConnectionString = storageConnString;
            jsonDest.AzureBlobStorage.ContainerName    = containerName;

            var currentDate = new DateTime(1900, 1, 1);

            jsonDest.HasNextUri = (_, order) => {
                if (order.Date.Date > currentDate.Date)
                {
                    currentDate = order.Date;
                    return(true);
                }
                return(false);
            };
            jsonDest.GetNextUri = (_, order) => "OrderData_" + order.Date.ToString("yyyy-MM-dd") + ".json";

            var multicast   = new Multicast <Order>();
            var aggregation = new Aggregation <Order, SyncData>();

            aggregation.AggregateColumns = new[] {
                new AggregateColumn()
                {
                    InputValuePropName      = "Id",
                    AggregatedValuePropName = "SyncId",
                    AggregationMethod       = AggregationMethod.Max
                }
            };
            var syncMemoryDest = new MemoryDestination <SyncData>();

            /*
             *                  |---> jsonDest ("OrderData_2020-01-01.json", "OrderData_2020-01-02.json", ..)
             *                  |
             *  dbSource --> multicast
             *                  |
             *                  |---> aggregation --> syncMemoryDest (1st run: SyncId = 5, 2nd run: SyncId = 7)
             */
            dbSource.LinkTo(multicast);
            multicast.LinkTo(jsonDest);
            multicast.LinkTo(aggregation);
            aggregation.LinkTo(syncMemoryDest);

            Network.Execute(dbSource);

            if (syncMemoryDest.Data.Count > 0)
            {
                SyncData syncDataThisRun = syncMemoryDest.Data.First();
                StoreLastSyncKey(syncDataThisRun);
            }
        }