Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 900531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:24:10+00:00 2026-05-15T15:24:10+00:00

I have classes Project , Resource and File . where A Project contains LIST

  • 0

I have classes Project,Resource and File.
where

A Project contains LIST of Resources.
Each Resource contains LIST of of Files of particular type.

This is mapped to an XML :

<Project>
<Resource id=1>
<File id="1" path="" type="A" />
<File id="2" path="" type="B" />
<File id="3" path="" type="B" />
<File id="4" path="" type="B" />
</Resource>
<Resource id=2>
<File id="1" path="" type="A" />
<File id="2" path="" type="B" />
<File id="3" path="" type="B" />
<File id="4" path="" type="B" />
</Resource>    
</Project>

So basically every resource has to have at-most one file of type "A" and any number of files of type "B" . The file type is selected by user from a dialog where he selects the file and adds to the resource.

The problem is for every file of type "A", i need to create a new Resource and hence and new node in XML.(which my current code isn’t able to do)

Initially i came with the following (generalised for brevity)

    Project p =new Project("Untitled project"); //Will happen once per project
    Resource res = p.CreateProjectResource("resource1"); 
                  //various params to create resource 
    p.AddResource(res);
    
    //now lets add files to a resource 
    AddFileHelper(res,"C:\myfile1.bin","A",guid.toString()); 
    AddFileHelper(res,"C:\myfile32.bin","B",guid.toString());
    AddFileHelper(res,"C:\myfile56.bin","B",guid.toString());

  
    //The next statement should create a new resource and add the  file to 
    //the new created design
    AddFileHelper(res,"C:\myfile4.bin","A",guid.toString()); // 
    
   //some helper class     :
    //Adds a file of type "type" to a resource "res" with file ID as "id" 
    private AddFileHelper(Resource res,string path,FileType type,string id)
    {
         // path is user defined file path from OpenFile dialog, 
        //type is selected from a Dropdown (of Enum values "A","B",...)
        //id is GUID
        res.AddFile(path,type,id); 
        
       //************ OR it could be also written as  *******
       //ResFile file =new ResFile(path,type,id); 
       //res.AddFile(file);  
                 
       //Update XML file here.. 
    }

The main problem is the User does not create the resources "explicitly" (except for the first resource) and creation of new Resource depends on the type of the file being added by the user.

Also due this design it is difficult to figure out the Resource given a File id.
Only way to track is using the file collection in each Resource class.

Any help??

Thanks All.

This is in reference to a question I asked before post

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:24:11+00:00Added an answer on May 15, 2026 at 3:24 pm

    The problem as I understand it:

    As of now, your AddFileHelper only adds files to your project resource labeled ''resource1'' which is a problem because every time a filetype “A” is passed your AddFileHelper, you to make a new resource for your project (''resource2'') and add it to that.

    There is a very simple way to do this. Within AddFileHelper test the FileType of the added file and determine whether or not you need a new resource to be added to your project. If the type isn’t “A” you’ll call the code that you have now and add the file with:

    res.AddFile(path, type, id);
    

    If the type to add is “A” and you need a new resource, just redefine res and increment a counter variable of how many resources you have in your project:

    Resource res = p.CreateProjectResource(resourceName);
    resourceCounter++;
    

    Where resourceName is the string:

    string resourceName = ''resource'' + resourceCounter;
    

    All this should be implemented as your AddFileHelper method.

    Regarding the overall structure of your code, the AddFileHelper should be a project class method. Here’s why:

    The AddFile method, and the AddFileHelper method sound similar but do two very different things. The AddFile method belongs to the resource class because it acts on a well defined resource object. However, the AddFile method is not enough for your purposes because the resource file to append to is not immediately apparent to the client who has a file and wants to add it to your project. Bbefore the AddFile method can be called, the target resource needs to be determined. The job of the AddFileHelper method is to determine which resource will call the AddFile method. Therefore, the AddFileHelper method belongs to the project class and the AddFile method to the resource class.

    The logical connection between the AddFileHelper method and the project class might be more apparent if you renamed the method to FileResourceAssignment or something like that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.