示例#1
0
        private static void ProcessTags(DocumentsContext ctx, Document masterDoc, ObjectVersionWrapper sourceDoc)
        {
            masterDoc.Tags.Clear();
            var propertyType = ctx.ValueTypes.First(x => x.Name == ListPropertyTypesNames.Tag);

            foreach (var source in sourceDoc.Tags)
            {
                var values = (source.IsStringProperty
                    ? source.Value.Split(',').Select(x => x.Trim().ToLower()).Where(x => !String.IsNullOrEmpty(x)).ToArray()
                    : new[] { source.Value.ToLower() });
                foreach (var value in values)
                {
                    var target = ctx.Values.FirstOrDefault(t => t.Value == value);
                    if (target == null)
                    {
                        var listPropertyId = Guid.NewGuid();
                        if (!source.IsStringProperty && source.Guid.HasValue)
                        {
                            listPropertyId = source.Guid.Value;
                        }
                        target = new Documents.ListProperty
                        {
                            ListPropertyId = listPropertyId,
                            Value          = value.Trim()
                        };
                        ctx.Values.Add(target);
                    }
                    target.Types.Add(propertyType);
                    masterDoc.Tags.Add(target);
                }
            }
        }
示例#2
0
 public ThesesView()
 {
     InitializeComponent();
     db = new DocumentsContext();
     LoadTheses();
     FindCount();
 }
 public AddOrChangeOtherDocumentation(DocumentsContext db)
 {
     InitializeComponent();
     this.db           = db;
     otherDoc          = new Model.OtherDocumentation();
     btnModify.Content = "Добавить";
 }
示例#4
0
 public OtherDocumentationView()
 {
     InitializeComponent();
     db = new DocumentsContext();
     LoadOtherDoc();
     FindCount();
 }
示例#5
0
 public FolderStore(
     ISecurityContext securityContext,
     DocumentsContext database,
     IServiceProvider serviceProvider
     ) : base(securityContext, database, serviceProvider)
 {
 }
示例#6
0
        public MainProcessor(string connectionString, IDictionary <string, VaultDetails> vaultDetails,
                             string thumbnailsUrlPattern, string brsTermsUrlPattern, string leoTermsUrlPattern, CountriesClient countries,
                             ConferencesClient conferences, bool deleteNotInList)
        {
            ConnectionString     = connectionString;
            VaultDetails         = vaultDetails;
            Countries            = countries;
            Conferences          = conferences;
            ThumbnailsUrlPattern = thumbnailsUrlPattern;
            BrsTermsUrlPattern   = brsTermsUrlPattern;
            LeoTermsUrlPattern   = leoTermsUrlPattern;
            DeleteNotInList      = deleteNotInList;

            _ctx = new DocumentsContext(connectionString);
            _ctx.Database.CreateIfNotExists();
            var connectionForDisplay = _ctx.Database.Connection.ConnectionString.Split(';')[0];

            ClassLogger.Info($"Connection string {connectionForDisplay}");


            foreach (var type in ListPropertyTypesNames.Names)
            {
                if (_ctx.ValueTypes.FirstOrDefault(x => x.Name == type) == null)
                {
                    _ctx.ValueTypes.Add(new ListPropertyType {
                        ListPropertyTypeId = Guid.NewGuid(), Name = type
                    });
                }
            }
            _ctx.SaveChanges();
        }
示例#7
0
        public async Task <User> Update(int id, User user)
        {
            try
            {
                using (var context = new DocumentsContext())
                {
                    var entity = await context.Users.FirstOrDefaultAsync(u => u.Id == id);

                    if (entity != null)
                    {
                        user.Password = Encryption.Encrypt(user.Password);
                        context.Entry(entity).CurrentValues.SetValues(user);
                        await context.SaveChangesAsync();

                        return(await Task.Run(() => user));
                    }

                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#8
0
 public PracticalView()
 {
     InitializeComponent();
     db = new DocumentsContext();
     LoadPractical();
     FindCount();
 }
示例#9
0
文件: Deduct.xaml.cs 项目: Ireki/vkr
 public Deduct(int role)
 {
     InitializeComponent();
     db         = new DocumentsContext();
     itemDeduct = new List <DeducCount>();
     this.role  = role;
     RoleChangeDesiegn();
 }
示例#10
0
        public static bool UpdateMaster(DocumentsContext ctx, MFilesDocument targetDoc, ObjectVersionWrapper sourceDoc,
                                        IDictionary <string, VaultDetails> vaultDetails, CountriesClient countries)
        {
            targetDoc.Guid         = sourceDoc.Guid;
            targetDoc.CreatedDate  = sourceDoc.CreatedDate;
            targetDoc.ModifiedDate = sourceDoc.ModifiedDate;

            var masterDoc = targetDoc.Document;

            masterDoc.MFilesDocument = targetDoc;
            masterDoc.UnNumber       = string.IsNullOrEmpty(sourceDoc.UnNumber)?sourceDoc.Name:sourceDoc.UnNumber;
            masterDoc.Convention     = vaultDetails[sourceDoc.VaultName].NameInDb ?? sourceDoc.VaultName.ToLower();
            var authorAndType = GetAuthor(sourceDoc, countries);

            if (authorAndType != null)
            {
                masterDoc.Author     = authorAndType.Item1;
                masterDoc.AuthorType = authorAndType.Item2 ? "organization" : "person";
            }
            masterDoc.CountryFull = countries.GetCountryIsoCode2(sourceDoc.Country) != null ? sourceDoc.Country: null;
            masterDoc.Country     = countries.GetCountryIsoCode2(masterDoc.CountryFull);
            masterDoc.Copyright   = sourceDoc.Copyright;
            var period = sourceDoc.GetPeriod();

            if (period != null)
            {
                masterDoc.PeriodStartDate = period.Item1;
                masterDoc.PeriodEndDate   = period.Item2;
            }
            masterDoc.PublicationDate = sourceDoc.PublicationDate;

            lock ("Process") {
                ProcessDocumentTypes(ctx, masterDoc, sourceDoc);
                ProcessMeetings(ctx, masterDoc, sourceDoc);
                ProcessMeetingTypes(ctx, masterDoc, sourceDoc);
                ProcessChemicals(ctx, masterDoc, sourceDoc);
                ProcessPrograms(ctx, masterDoc, sourceDoc);
                ProcessTerms(ctx, masterDoc, sourceDoc);
                ProcessTags(ctx, masterDoc, sourceDoc);

                using (var trans = ctx.Database.BeginTransaction())
                {
                    try
                    {
                        ctx.SaveChanges();
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        ClassLogger.Error("SQL exception " + ex);
                        throw;
                    }
                }
            }
            return(true);
        }
示例#11
0
        private void DeductCount()
        {
            DocumentsContext db = new DocumentsContext();
            int k = 0;

            k += db.Vkr.Count(x => DateTime.Now.Year - x.Date.Year >= 5 && x.DateDeleted == null);
            k += db.Theses.Count(x => DateTime.Now.Year - x.Date.Year >= 5 && x.DateDeleted == null);
            k += db.Practical.Count(x => DateTime.Now.Year - x.EndOfPractice.Year >= 5 && x.DateDeleted == null);
            k += db.OtherDocumentation.Count(x => DateTime.Now.Year - x.DateDeposit.Year >= x.ShelfLife && x.DateDeleted == null);
            deductCount.Text = "На списание: " + k.ToString();
        }
 public AddOrChangeOtherDocumentation(Model.OtherDocumentation otherDoc, DocumentsContext db)
 {
     InitializeComponent();
     this.otherDoc             = otherDoc;
     this.db                   = db;
     btnModify.Content         = "Изменить";
     textBlockLocation.Text    = otherDoc.Location;
     textBlockShelfLife.Text   = otherDoc.ShelfLife.ToString();
     textBlockTypeDoc.Text     = otherDoc.TypeDocumentation;
     textBlockDateDeposit.Text = otherDoc.DateDeposit.ToString();
 }
示例#13
0
        public MainProcessorContext(MainProcessor parent)
        {
            _ctx    = new DocumentsContext(parent.ConnectionString);
            _parent = parent;

            _ctx.Database.Connection.Open();


            if (_ctx.Database.Connection.State != ConnectionState.Open)
            {
                ClassLogger.Error("Could not connect to database");
            }
        }
示例#14
0
        public static void Delete(DocumentsContext ctx, MFilesDocument targetDocument)
        {
            if (targetDocument == null)
            {
                return;
            }
            var doc = targetDocument;

            Debug.Assert(doc != null);
            if (doc.Title != null)
            {
                ClassLogger.Info($"Delete document '{doc.Title.Value}'");
            }
            else
            {
                ClassLogger.Warn($"Delete document {doc.Guid}");
            }

            var documents = from x in ctx.Documents where x.DocumentId == doc.Guid select x;

            ctx.Documents.RemoveRange(documents.ToList());

            var titles = from x in ctx.Titles where x.TitleId == doc.Guid select x;

            ctx.Titles.RemoveRange(titles.ToList());

            var descriptions = (from x in ctx.Descriptions where x.DescriptionId == doc.Guid select x).ToList();

            ctx.Descriptions.RemoveRange(descriptions.ToList());

            var files = (from x in ctx.Files where x.FileId == doc.Guid select x).ToList();

            ctx.Files.RemoveRange(files.ToList());

            ctx.MFilesDocuments.Remove(doc);

            using (var trans = ctx.Database.BeginTransaction())
            {
                try
                {
                    ctx.SaveChanges();
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    ClassLogger.Error($"Delete document {ex.Message}");
                    throw;
                }
            }
        }
示例#15
0
 public async Task <Attachment> Find(int id)
 {
     try
     {
         using (var context = new DocumentsContext())
         {
             return(await context.Attachments.FirstOrDefaultAsync(a => a.Id == id));
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#16
0
 public async Task <User> Find(int id)
 {
     try
     {
         using (var context = new DocumentsContext())
         {
             return(await context.Users.FirstOrDefaultAsync(u => u.Id == id));
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#17
0
 public async Task <ICollection <Category> > ListAll()
 {
     try
     {
         using (var context = new DocumentsContext())
         {
             return(await context.Categories.ToListAsync());
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#18
0
        public StoreBase(
            ISecurityContext securityContext,
            DocumentsContext database,
            IServiceProvider serviceProvider
            )
        {
            this.SecurityContext = securityContext;
            this.ServiceProvider = serviceProvider;
            this.Database        = database;

            Cache = serviceProvider.GetService(typeof(IDistributedCache)) as IDistributedCache;

            this.Logger = Logging.CreateLogger(this.GetType());
        }
示例#19
0
        public static MFilesDocument CreateSlave(DocumentsContext ctx, MFilesDocument master, ObjectVersionWrapper sourceDoc, IDictionary <string, VaultDetails> vaultDetails, string thumbnailsUrlPattern)
        {
            MFilesDocument targetDoc = null;

            if (sourceDoc.Guid != master.Guid)
            {
                targetDoc = ctx.MFilesDocuments.Create();
            }
            else
            {
                targetDoc = master;
            }
            return(UpdateSlave(ctx, master, targetDoc, sourceDoc, vaultDetails, thumbnailsUrlPattern));
        }
示例#20
0
 public async Task <Category> Find(int id)
 {
     try
     {
         using (var context = new DocumentsContext())
         {
             return(await context.Categories.FirstOrDefaultAsync(c => c.Id == id));
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#21
0
        public static MFilesDocument CreateMaster(DocumentsContext ctx, ObjectVersionWrapper sourceDoc, IDictionary <string, VaultDetails> vaultDetails, CountriesClient coutries)
        {
            var targetDoc = ctx.MFilesDocuments.Create();

            ctx.MFilesDocuments.Add(targetDoc);

            var masterDoc = new Document {
                MFilesDocument = targetDoc
            };

            ctx.Documents.Add(masterDoc);

            UpdateMaster(ctx, targetDoc, sourceDoc, vaultDetails, coutries);
            return(targetDoc);
        }
示例#22
0
 public AddOrChange(Vkr vkr, DocumentsContext db)
 {
     InitializeComponent();
     this.vkr                     = vkr;
     this.db                      = db;
     textBlockGroup.Text          = vkr.Group;
     textBlockProtocolNumber.Text = vkr.ProtocolNumber;
     textBlockSurname.Text        = vkr.Surname;
     textBlockName.Text           = vkr.Name;
     textBlockPatronymic.Text     = vkr.Patronymic;
     textBlockTheme.Text          = vkr.Theme;
     textBlockDirector.Text       = vkr.Director;
     textBlockDate.Text           = vkr.Date.ToString();
     textBlockLocation.Text       = vkr.Location;
 }
示例#23
0
        public static void DeleteNotInList(DocumentsContext ctx, IDictionary <Guid, bool> guids)
        {
            ClassLogger.Info("Find documents for removing...");
            //ctx.Database.CommandTimeout = 600;
            var delGuids = (from mfdoc in ctx.MFilesDocuments select mfdoc.Guid).ToList().Except(guids.Keys);
            var toDelete =
                (from mfdoc in ctx.MFilesDocuments where delGuids.Contains(mfdoc.Guid) select mfdoc).ToList();

            //ctx.Database.CommandTimeout = 60;
            ClassLogger.Info($"Number of files to remove = {toDelete.Count()}");
            foreach (var doc in toDelete)
            {
                Delete(ctx, doc);
            }
        }
示例#24
0
        public async Task <Category> Insert(Category category)
        {
            try
            {
                using (var context = new DocumentsContext())
                {
                    var categoryInserted = context.Categories.Add(category);
                    await context.SaveChangesAsync();

                    return(await Task.Run(() => categoryInserted));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#25
0
        public AddOrChange(Model.Theses theses, DocumentsContext db)
        {
            InitializeComponent();
            this.theses       = theses;
            this.db           = db;
            btnModify.Content = "Изменить";

            textBlockGroup.Text          = theses.Group;
            textBlockProtocolNumber.Text = theses.ProtocolNumber;
            textBlockSurname.Text        = theses.Surname;
            textBlockName.Text           = theses.Name;
            textBlockPatronymic.Text     = theses.Patronymic;
            textBlockTheme.Text          = theses.Theme;
            textBlockDirector.Text       = theses.Director;
            textBlockDate.Text           = theses.Date.ToString();
            textBlockLocation.Text       = theses.Location;
        }
示例#26
0
        public async Task <Galery> Insert(Galery galery)
        {
            try
            {
                using (var context = new DocumentsContext())
                {
                    var galeryInserted = context.Galeries.Add(galery);
                    await context.SaveChangesAsync();

                    return(await Task.Run(() => galeryInserted));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#27
0
        public async Task <Document> Insert(Document document)
        {
            try
            {
                using (var context = new DocumentsContext())
                {
                    var documentInserted = context.Documents.Add(document);
                    await context.SaveChangesAsync();

                    return(await Task.Run(() => documentInserted));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#28
0
 public AddOrChangePractical(Model.Practical practical, DocumentsContext db)
 {
     InitializeComponent();
     this.practical                = practical;
     this.db                       = db;
     btnModify.Content             = "Изменить";
     textBlockGroup.Text           = practical.Group;
     textBlockName.Text            = practical.Name;
     textBlockSurname.Text         = practical.Surname;
     textBlockPatronymic.Text      = practical.Patronymic;
     textBlockPracticeBase.Text    = practical.PracticeBase;
     textBlockHumanSettlement.Text = practical.HumanSettlement;
     textBlockStartOfPractice.Text = practical.StartOfPractice.ToString();
     textBlockEndOfPractice.Text   = practical.EndOfPractice.ToString();
     textBlockFormOfPractice.Text  = practical.FormOfPractice;
     textBlockFormOfPractice.Text  = practical.Payment;
     textBlockDirector.Text        = practical.Director;
 }
示例#29
0
        public async Task <User> Insert(User user)
        {
            try
            {
                using (var context = new DocumentsContext())
                {
                    user.Password = Encryption.Encrypt(user.Password);
                    var userInserted = context.Users.Add(user);
                    await context.SaveChangesAsync();

                    return(await Task.Run(() => userInserted));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#30
0
        public async Task <IHttpActionResult> Post(Documents documents)
        {
            DocumentsContext context = new DocumentsContext();
            var   userId             = User.Identity.Name;
            Int16 documentStartCount = 0;
            Int16 documentEndCount   = 0;



            if (documents.DocumentType != null)
            {
                if (userId == "*****@*****.**")
                {
                    documents.UserId = "BSK123";
                }
                else
                {
                    documents.UserId = "BAP123";
                }

                if (documents.ImagePath != null)
                {
                    documents.ImagePath = documents.ImagePath.Replace("C:\\fakepath\\", "");
                }

                documentStartCount = Convert.ToInt16(context.Documents.Count());

                context.Documents.Add(documents);

                context.SaveChanges();


                documentEndCount = Convert.ToInt16(context.Documents.Count());
            }
            if (documentEndCount > documentStartCount)
            {
                //return RedirectToRoute("Home/Index","");
                return(this.Ok(true));
            }
            else
            {
                return(this.Ok(false));
            }
        }