+9 votes
by (100 points)

I have a problem here that i need some help with. Look at these lines:

HEADING
TYPE       NAME      PBOR0    SHOP     CATREF    DETAIL    MATXT    CMPREF    BLTREF    TMPREF     PRTREF
DEFAULTS
-           -        -       =
TUBE       */Cb_N76f-RDX/T0A2013010-00:DD 0.50     TRUE  /RDX_R_AAPA1A0DD /RDX_T0A2013010-00 /RDX_VAZIO-MT   /Cb_N76f-RDX/RDX_T0A0AC0010-00:DD =0          =0          =0

And also these lines:

HEADING
TYPE       NAME      PBOR0    STYP    SHOP     CATREF    DETAIL    MATXT    CMPREF    BLTREF    TMPREF     PRTREF
DEFAULTS
-           -        -   CT      =
ELBO       */C9B0020101-00:DD 0.50     CT  TRUE  /RDX_R_ABEB360DD /C9B0020101-00  /RDX_VAZIO-MT   /Cb_N76f-RDX/RDX_C9B002AC01-00:DD =0          =0          =0

As you can see above, the first block is from a TUBE and the second one is from a ELBO. Both have different header columns. This problem i solved wirting a xml configuraiton like this:

<?xml version="1.0" encoding="UTF-8"?>
<Components>
    <Component type="TUBE">
        <Header size="11">
            <Columns>
                <Column>
                    <Name>TYPE</Name>
                    <Defaults>-</Defaults>
                </Column>
                <Column>
                    <Name>NAME</Name>
                    <Defaults>-</Defaults>
                </Column>
                <Column>
                    <Name>PBOR0</Name>
                    <Defaults>-</Defaults>
                </Column>
                <Column>
                    <Name>SHOP</Name>
                    <Defaults>=</Defaults>
                </Column>
                <Column>
                    <Name>CATREF</Name>
                    <Defaults></Defaults>
                </Column>
                <Column>
                    <Name>DETAIL</Name>
                    <Defaults></Defaults>
                </Column>
                <Column>
                    <Name>MATXT</Name>
                    <Defaults></Defaults>
                </Column>
                <Column>
                    <Name>CMPREF</Name>
                    <Defaults></Defaults>
                </Column>
                <Column>
                    <Name>BLTREF</Name>
                    <Defaults></Defaults>
                </Column>
                <Column>
                    <Name>TMPREF</Name>
                    <Defaults></Defaults>
                </Column>
                <Column>
                    <Name>PRTREF</Name>
                    <Defaults></Defaults>
                </Column>
            </Columns>
        </Header>
    </Component>
    <Component type="ELBO">
        <Header size="12">
            <Columns>
                <Column>
                    <Name>TYPE</Name>
                    <Defaults>-</Defaults>
                </Column>
                <Column>
                    <Name>NAME</Name>
                    <Defaults>-</Defaults>
                </Column>
                <Column>
                    <Name>PBOR0</Name>
                    <Defaults>-</Defaults>
                </Column>
                <Column>
                    <Name>STYP</Name>
                    <Defaults>CT</Defaults>
                </Column>
                <Column>
                    <Name>SHOP</Name>
                    <Defaults>=</Defaults>
                </Column>
                <Column>
                    <Name>CATREF</Name>
                    <Defaults></Defaults>
                </Column>
                <Column>
                    <Name>DETAIL</Name>
                    <Defaults></Defaults>
                </Column>
                <Column>
                    <Name>MATXT</Name>
                    <Defaults></Defaults>
                </Column>
                <Column>
                    <Name>CMPREF</Name>
                    <Defaults></Defaults>
                </Column>
                <Column>
                    <Name>BLTREF</Name>
                    <Defaults></Defaults>
                </Column>
                <Column>
                    <Name>TMPREF</Name>
                    <Defaults></Defaults>
                </Column>
                <Column>
                    <Name>PRTREF</Name>
                    <Defaults></Defaults>
                </Column>
            </Columns>
        </Header>
    </Component>
    <Component type="GASKET">
        <Header size="12">
            <Columns>
                <Column>
                    <Name>TYPE</Name>
                    <Defaults>-</Defaults>
                </Column>
                <Column>
                    <Name>NAME</Name>
                    <Defaults>-</Defaults>
                </Column>
                <Column>
                    <Name>PBOR0</Name>
                    <Defaults>-</Defaults>
                </Column>
                <Column>
                    <Name>STYP</Name>
                    <Defaults>RF</Defaults>
                </Column>
                <Column>
                    <Name>SHOP</Name>
                    <Defaults>=</Defaults>
                </Column>
                <Column>
                    <Name>CATREF</Name>
                    <Defaults></Defaults>
                </Column>
                <Column>
                    <Name>DETAIL</Name>
                    <Defaults></Defaults>
                </Column>
                <Column>
                    <Name>MATXT</Name>
                    <Defaults></Defaults>
                </Column>
                <Column>
                    <Name>CMPREF</Name>
                    <Defaults></Defaults>
                </Column>
                <Column>
                    <Name>BLTREF</Name>
                    <Defaults></Defaults>
                </Column>
                <Column>
                    <Name>TMPREF</Name>
                    <Defaults></Defaults>
                </Column>
                <Column>
                    <Name>PRTREF</Name>
                    <Defaults></Defaults>
                </Column>
            </Columns>
        </Header>
    </Component>
</Components>

The problem now is: I have a lot of different rules to write values in the column, for example: To write NAME i must follow certain rules, to write STYP another, etc. Is there a simple and easy way to describe these rules in a XML, read and interpret them and write correct values according to rules in output?

Thanks in advance, guys!

6 Answers

+12 votes
by (100 points)

Try to checkout:

  • Regular Expressions
  • validation with XSD schemas (I doubt that that is the case)

Probably it is not so cool answer as you expect, but anyway

+7 votes
by (100 points)

If you create classes for each type, then you would have the rules. You'd have the API for that xml to read/write with. The advantage of classes, written in C# they are strongly typed.

Example,

public class Elbo
{
    XElement self;
    public Elbo(XElement elbo) { self = elbo; }

    public string Name
    {
         get { return self.Element("Name").Value; }
         set 
         { 
               XElement name = self.Element("Name");
               if(null == name)
                    self.Add(name = new XElement("Name"));
               name.Value = value;
         }
    }
}

Now Name is strongly typed, only a string can be written to it and read from it. Also this is an example, you have a lot more rules (nodes) such as Column nodes etc that I skipped over. I hope you get the point of what I wrote.

If you go with your generic approach of generic columns that can hold anything and any type, then you are going to have a lot more difficult time of developing rules to govern it all.

+2 votes
by (100 points)

I think the format for json is wrong. It should be something like:-

"posts":[{"id":917,"tags":39},{"id":918,"tags":38}]

This is an array of one 2 dictionary objects. Then, you can get the objects using

NSArray * postArray = [json objectForKey:@"posts"];
NSDictionary * firstObject = [postArray firstObject];
NSNumber * id1 = [firstObject objectForKey:@"id"];
NSArray * tags1 = [firstObject objectForKey:@"tags"];
NSNumber* tag1 = [[tags firstObject] objectForKey:@"id"];

Try this out.

Updated answer:

NSArray * postArray = [json objectForKey:@"posts"];

for(int i=0;i<postArray.count;i++){
 NSDictionary * postObject = [postArray objectAtIndex:i];
 NSNumber * postId = [postObject objectForKey:@"id"];
 NSLog(@"PostID:%@",postId);

 NSArray * postTag = [postObject objectForKey:@"tags"];
   for(int j=0;j<postTag.count;j++){
        NSDictionary * postTagIdDic = [postTag objectAtIndex:j];
        NSNumber * postTagId = [postTagIdDic objectForKey:@"id"];
        NSLog(@"postTagId:%@",postTagId);
    }
}
0 votes
by (100 points)

The div.info-message will only appear if $flag == 0 . If you don´t want to show an empty div with padding you have to check also if $error_message == false ! If that is not helpful I don´t understand your question!

0 votes
by (100 points)

I got to know from google bigquery documentation that - because of security reasons form JS we can't able to use service accounts.

0 votes
by (100 points)

In general, as IHostingEnvironment is just an interface, you can simply mock it to return whatever you want.

If you are using TestServer in your tests, the best way to mock is to use WebHostBuilder.Configure method. Something like this:

var testHostingEnvironment = new MockHostingEnvironment(); 
var builder = new WebHostBuilder()
            .Configure(app => { })
            .ConfigureServices(services =>
            {
                services.TryAddSingleton<IHostingEnvironment>(testHostingEnvironment);
            });
var server = new TestServer(builder);

No related questions found

...