Пример #1
0
        /* Updates all loaded models */
        public async Task Update()
        {
            /* Load models */
            String[] Files = Directory.GetFiles(Environment.GetFolderPath(
                Environment.SpecialFolder.CommonDocuments) + "\\EIA\\Models\\", "*.*", 
                SearchOption.AllDirectories);

            /* Iterate */
            using (EIA.Repository.ModelRepository mRepo = new Repository.ModelRepository())
            {
                /* Get a list of models */
                List<CModel> DbModels = (List<CModel>)(await mRepo.Get()).Data;

                foreach (String mFile in Files)
                {
                    /* Skip templates */
                    if (mFile.EndsWith("Template.xlsx"))
                        continue;

                    /* Sanity ending */
                    if (!mFile.ToLower().EndsWith(".xlsx")
                        && !mFile.ToLower().EndsWith(".xlsm"))
                        continue;

                    /* Parse */
                    EiaModel eModel = ModelParser.ParseModel(mFile);

                    /* Should we update it in db? */
                    CModel dbModel = DbModels.Find(dbMod => dbMod.Guid == eModel.Guid);

                    /* Try to find it's equalivent in our own list */

                    /* Sanity */
                    if (dbModel == null)
                    {
                        /* NEW MOOODEL */
                        CModel nDbModel = new CModel();
                        nDbModel.Guid = eModel.Guid;
                        nDbModel.Template = eModel.Template;
                        nDbModel.Name = eModel.Name;
                        nDbModel.Version = eModel.Version;
                        nDbModel.Country = eModel.Country;
                        nDbModel.Type = eModel.Type;

                        nDbModel.ShortDescription = eModel.ShortDescription;
                        nDbModel.LongDescription = eModel.LongDescription;

                        /* Insert */
                        await mRepo.Create(nDbModel);
                    }
                    else if (dbModel.Version != eModel.Version)
                    {
                        /* Update info */
                        dbModel.Template = eModel.Template;
                        dbModel.Version = eModel.Version;
                        dbModel.ShortDescription = eModel.ShortDescription;
                        dbModel.LongDescription = eModel.LongDescription;

                        /* Update */
                        await mRepo.Update(dbModel, "");
                    }

                    /* Add to list */
                    //lModels.Add(eModel);
                }
            }
        }
        /* PARSER - Get next request */
        public async Task<CModelRequest> GetNext()
        {
            /* Lookup */
            var tLookup = await (from Obj in Database.TransactionRequests
                                 where Obj.Status == (int)RequestStatus.InQueue
                                 select Obj).FirstOrDefaultAsync();

            /* Sanity */
            if (tLookup == null)
                return null;

            /* Proxy */
            CModelRequest nRequest = new CModelRequest()
            {
                Guid = tLookup.Id.ToString(),
                Status = (RequestStatus)tLookup.Status,
                Parameters = (RequestParameters)
                Enum.Parse(typeof(RequestParameters), tLookup.Parameters, true),
                TemplateWithData = tLookup.Template,
                CreatedAt = tLookup.Created,
                Model = null
            };

            /* Fill in model */
            var mLookup = await (from Obj in Database.Models
                                 where Obj.MasterId == tLookup.ModelMasterId
                                     && Obj.Deleted == false
                                 select Obj).FirstOrDefaultAsync();

            /* Proxy */
            CModel nModel = new CModel()
            {
                Guid = mLookup.Guid.ToString(),
                Name = mLookup.Type,
                Type = mLookup.SubType,
                Template = mLookup.Template,
                Version = mLookup.Version,
                Country = mLookup.Country
            };

            /* Set */
            nRequest.Model = nModel;

            /* Done */
            return nRequest;
        }