private void save_file(IdoItemWrapper row, LoadCollectionResponseWrapper response)
 {
     var ido = row["CollectionName"].ToString();
     var writer = File.CreateText(string.Format("IDO{0}Builder.cs", ido));
     writer.Write(get_file_text(ido, response.Records.First()).Replace("[", "{").Replace("]", "}"));
     writer.Close();
 }
 private ActiveUserSession map(IdoItemWrapper arg)
 {
     return new ActiveUserSession()
                {
                    UserName = arg[UserSession.UserName].ToString(),
                    RecordDate = arg[UserSession.RecordDate].ToString().FromSytelineDateTime(),
                    ConnectionID = arg[UserSession.ConnectionID].ToString()
                };
 }
        private string get_filter_builder(string ido, IdoItemWrapper response)
        {
            var retstr = string.Format(@"public class {0}FilterExpressionBuilder  
                :   FilterExpressionBuilder<{0}Builder>
                [
                ", ido); 
            foreach (var record in response.Records)
            {
                var val = record.GetValue("PropertyName").ToString();
                retstr += get_filter_builder_declaration(ido, val);
            }
            return retstr + @"

                }

".Replace("[", "{").Replace("]", "}");
        }
 static CustomerEntity map(IdoItemWrapper record)
 {
     return new CustomerEntity()
     {
         CustomerID = record.GetValue(Customers.CustomerNumber).ToString(),
         CustomerName = record.GetValue(Customers.Name).ToString(),
     };
 }
 private CustomerOrder map(IdoItemWrapper arg)
 {
     return new CustomerOrder();
 }
 static void check(IdoItemWrapper record)
 {
     record.GetValue("OrderNumber").ToString().ShouldEqual("234323");
 }
        private IDOUpdateItem getUpdateItem(IIdoCommandBuilder builder, UpdateAction action, IdoItemWrapper idoItemWrapper)
        {
            var item = new IDOUpdateItem(action);
            item.Action = GetUpdateActionFromBuilder(builder);
            item.ItemID = idoItemWrapper[IdoConstants.KEY].ToString();

            var propertyKeys = builder.Properties.Keys;
            
            propertyKeys.ForEach(key =>  item.Properties.Add(key, builder.Properties[key]));


            builder.GetChildren().ForEach(child =>
                {
                    var updateCollectionRequestData = new List<UpdateCollectionRequestData>();

                    idoItemWrapper.Records.Where(record => record.IdoName == child.IdoName)
                                        .ForEach(record => updateCollectionRequestData.Add(getNestedUpdate(child, record)));

                    updateCollectionRequestData.ForEach(request => item.NestedUpdates.Add(request));
                });

            return item;
        }
 private string get_file_text(string ido, IdoItemWrapper response)
 {
     return get_header() + get_constant_class(ido, response) + get_builder(ido, response) + get_filter_builder(ido, response)
         + get_footer();
 }
        private string get_constant_class(string ido, IdoItemWrapper response)
        {
            var retstr = "public class " + ido + @" : IdoConstants 
                { 
                    " +
                         get_const_declaration("IDO_NAME", ido);
            foreach (var record in response.Records)
            {
                var val = record.GetValue("PropertyName").ToString();
                retstr += get_const_declaration(val, val);
            }
            return retstr + @"

                }

            ";
        }
 public void  print_file_to_screen(IdoItemWrapper row, LoadCollectionResponseWrapper response)
 { 
     var ido = row["CollectionName"].ToString();
     Console.WriteLine(get_file_text(ido, response.Records.Find(r => r.GetValue("CollectionName").ToString() == ido)).Replace("[", "{").Replace("]", "}"));
 }
        private UpdateCollectionRequestData getNestedUpdate(IIdoCommandBuilder builder, IdoItemWrapper idoItemWrapper)
        {
            PropertyPair linkBy = null;
            if (builder.GetLinkBy().Length > 0)
                linkBy = builder.GetLinkBy()[0];
            var data = new UpdateCollectionRequestData(builder.GetIDOName());

            var idoUpdateItem = getUpdateItem(builder, builder.GetUpdateAction(), idoItemWrapper);
            
            idoUpdateItem.ItemID = idoItemWrapper[IdoConstants.KEY].ToString(); //not needed!!!
            data.Items.Add(idoUpdateItem);
            if (linkBy != null)
                data.SetLinkBy(linkBy.ParentProperty, linkBy.ChildProperty);
            
            return data;
        }
 private static Foo MapFoo(IdoItemWrapper idoItemWrapper)
 {
     throw new NotImplementedException();
 }
 private string map(IdoItemWrapper arg)
 {
     return arg[CustomerPartNumbers.CustomerPartNumber].ToString();
 }
 private string get_file_text(string ido, string method, IdoItemWrapper response)
 {
     return get_header() + get_method_partial(method) + get_builder(ido, method, response)
         + get_footer();
 }
        private string get_builder(string ido, string method, IdoItemWrapper response)
        {
            var retstr = string.Format(@"public class {0}MethodCallBuilder  
                :   IdoMethodCallBuilder<IIdoMethodParameterBuilder>
                [
                    public string IDOName
                    [
                         get [ return {2}{1}{2}; ]
                    ]


                ", method, ido, "\"").Replace("[", "{");
            retstr += string.Format(@"     

        public {0}MethodParameterBuilder {0}
        [
            get
            [
                var del = _ido = new {0}MethodParameterBuilder(this);
                return ({0}MethodParameterBuilder)del;
            ]
        ]

        ]

        public class {0}MethodParameterBuilder : IdoMethodParameterBuilder
        [

        ", method);

            string mainFunc =
                string.Format(@"
            public {0}MethodParameterBuilder(IdoMethodCallBuilder<IIdoMethodParameterBuilder> parent):base(parent)
            [ 
                _method_name = {1}{0}{1};
            ", method, "\"");
            var seq = 1;
            foreach (var record in response.Records)
            {
                var val = record.GetValue("ParameterName").ToString();
                retstr += get_builder_declaration(method, val, seq);
                mainFunc += get_func_append(seq);
            }
            return retstr + @"
                " + mainFunc + @" 
                }
            }
            ";
        }
 private static CustomerEntity Map(IdoItemWrapper idoItemWrapper)
 {
     return new CustomerEntity() { CustomerID = idoItemWrapper.GetValue(Customers.CustomerNumber).ToString() };
 }
 private static CustomerOrderEntity MapCustomerOrder(IdoItemWrapper idoItemWrapper)
 {
     var loc = TestHelper.GetTestSyteline();
     return new CustomerOrderEntity(loc)
                { 
                    OrderNumber = idoItemWrapper.GetValue(CustomerOrder.OrderNumber).ToString(),
                    CustomerPO = idoItemWrapper.GetValue(CustomerOrder.PONumber).ToString()
     };
 }