Ejemplo n.º 1
0
        int NewDictFileProcessing(Stream stream, string uploadPath, DictionaryInfo dictInfo)
        {
            var tmpFolder = FileHelper.GetTemporaryDirectory();
            var tmpFile   = Path.Combine(tmpFolder, dictInfo.FileName);

            FileHelper.LoadFileFromStream(stream, tmpFile);
            ZipHelper.UnZip(tmpFile);
            var file = Directory.GetFiles(tmpFolder, "*.mdb").Single();

            if (!dictInfo.Dictionary_id.HasValue)
            {
                using (var db = new DictServiceEntities())
                {
                    var dict = new Dictionary()
                    {
                        FileName     = dictInfo.FileName,
                        Category_id  = dictInfo.Category_id,
                        Description  = dictInfo.Description,
                        PathToDict   = Path.Combine(uploadPath, dictInfo.FileName),
                        FriendlyName = dictInfo.FriendlyName
                    };
                    db.Dictionaries.Add(dict);
                    db.SaveChanges();
                    AccessHelper.SetDbStamp(file, dict.Dictionary_id);
                    dictInfo.Dictionary_id = dict.Dictionary_id;
                }
            }
            ZipHelper.CreateZipDictionary(file, uploadPath);
            return(dictInfo.Dictionary_id.Value);
        }
Ejemplo n.º 2
0
        private async void btnAddDict_Click(object sender, EventArgs e)
        {
            DictionaryInfo dictInfo;
            string         path;

            using (var form = new AddDictForm(cbCategory))
            {
                form.ShowDialog(this);
                if (form.DialogResult != DialogResult.OK)
                {
                    return;
                }
                dictInfo = form.GetUploadData();
                var mdbPath = form.GetFilePath();
                try
                {
                    AccessHelper.CheckExistPrimaryKey(AccessHelper.CreateMdbConnectionString(mdbPath));
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
                path = ZipHelper.CreateZipDictionary(mdbPath, FileHelper.GetTemporaryDirectory());
            }
            var id = StartTask(this,
                               new TaskEventArgs()
            {
                Name = $"Добавление {dictInfo.FriendlyName}", Status = "Started"
            });

            try
            {
                using (var client = new FileUploadClient())
                {
                    using (Stream file = new FileStream(path, FileMode.Open))
                    {
                        await client.UploadAsync(dictInfo, file);
                    }
                }
                RefreshTaskStatus(this, new TaskEventArgs()
                {
                    Status = "Complete", Taskid = id
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                FileHelper.DeleteFolder(Path.GetDirectoryName(path));
            }
        }
Ejemplo n.º 3
0
 private async void resfreshBtn_Click(object sender, EventArgs e)
 {
     if (uploadChkBx.Checked)
     {
         using (var client = new FileUploadClient())
         {
             try
             {
                 string path;
                 path = ZipHelper.CreateZipDictionary(tbFilePath.Text);
                 DictionaryInfo dictInfo = new DictionaryInfo()
                 {
                     Dictionary_id = Convert.ToInt32(tbDictionaryId.Text)
                     , SenderLogin = AccountHelper.GetAccount(), Action = ActionEnum.EditDict
                 };
                 Stream file = new FileStream(path, FileMode.Open);
                 await client.UploadAsync(dictInfo, file);
             }
             catch (Exception)
             {
             }
         }
     }
     using (var client = new DataClient())
     {
         var dictInfo = new DictionaryData()
         {
             Dictionary_id = Convert.ToInt32(tbDictionaryId.Text),
             Category_id   = ((CategoryData)categoryCb.SelectedItem).Category_id,
             FriendlyName  = FrendlyNameTb.Text,
             Description   = DescriptionRtb.Text
         };
         client.ChangeDictionaryInfo(dictInfo);
         client.ChangeDictionaryStatus(Convert.ToInt32(tbDictionaryId.Text), DictionaryStateEnum.Available);
     }
 }