static void Main(string[] args) { ShowMessageClass message = new ShowConsoleMessage(); try { task_timer = new Timer(CheckTasks, null, Timeout.Infinite, Timeout.Infinite); task_timer.Change(0, Timeout.Infinite); Console.ReadLine(); task_timer.Dispose(); } catch (Exception ex) { message.ShowMessage(ex.Message); } Console.ReadLine(); }
public static async Task<CookieContainer> GetCookiesAsync(string url, string name, string password) { ShowMessageClass showMessage = new ShowConsoleMessage(); var request = (HttpWebRequest)WebRequest.Create(url); request.CookieContainer = new CookieContainer(); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; try { using (var requestStream = await request.GetRequestStreamAsync()) using (var writer = new StreamWriter(requestStream)) { writer.Write($"Name={name}&Password={password}&returnUrl="); } using (var responseStream = await request.GetResponseAsync()) return request.CookieContainer; } catch (WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError) { showMessage.ShowMessage("Доступ закрыт"); } else { showMessage.ShowMessage(ex.Message); } return null; } }
public static async Task<bool> AddMessageToEoClient(string shortID, string message) { ShowMessageClass showMessage = new ShowConsoleMessage(); var dataContex = new DataContext(); var _message = new EoMessages(); _message.From = "Kobelev"; // от кого _message.To = "Handogka"; // кому _message.Message = message; _message.PutDate = DateTime.Now.ToLocalTime(); var findResult = await dataContex.EoClients.Find<EOData>((x) => x.Short_Id == shortID).FirstOrDefaultAsync(); if (findResult.Message == null) { findResult.Message = new List<EoMessages>(); findResult.Message.Add(_message); var replaceResult = await dataContex.EoClients.ReplaceOneAsync<EOData>((x) => x.Short_Id == findResult.Short_Id, findResult); if (replaceResult.ModifiedCount != 0) { showMessage.ShowMessage("Сообщеине добавленно"); return true; } else { showMessage.ShowMessage("Сообщеине добавленно"); return false; } } else { var builder = Builders<EOData>.Update.Push("Message", _message); var result = await dataContex.EoClients.UpdateOneAsync<EOData>((x) => x.Short_Id == shortID, builder); if (result.ModifiedCount != 0) { return true; } else { return false; } } }
public static async Task<bool> NewEoTask(string _title, string _task, string _from, string _to, string _shortId, double _hours) { ShowMessageClass message = new ShowConsoleMessage(); DataContext dataContex = new DataContext(); DbWorkingTasks newTask = new DbWorkingTasks { _id = ObjectId.GenerateNewId(), ShortEoClientId = _shortId, Title = _title, PutTime = DateTime.Now.ToLocalTime(), TillDone = DateTime.Now.AddHours(_hours), To = _to, From = _from, IsDone = false, Messages = new List<EoMessages>(), Work = new List<EoWork>(), Task = _task }; try { await dataContex.WorkingTasks.InsertOneAsync(newTask); message.ShowMessage($"Задача {_to} для {_shortId} поставлена!"); return true; } catch (Exception) { throw; } }
//TODO: разобраться с возвратом //Подключается к серверу, скачевает xlsx фаил, разархивируетв в xml и десереализует/ public async Task<bool> GetDataFromServer() { //Рабочая часть, соединяемся с сервером и получаем куки var cookie = await GetCookiesAsync("http://bo-otchet.1gl.ru/Account/Login", _loginName, _loginPwd); //Получаем данные с помошью WebClient using (var client = new CookieAwareWebClient(cookie)) { Uri newUri = new Uri("http://bo-otchet.1gl.ru/Registration/RepostRegistrationExcel?Caption=%D0%A1%20%D0%B2%D1%8B%D0%BF%D1%83%D1%89%D0%B5%D0%BD%D0%BD%D0%BE%D0%B9%20%D0%9A%D0%AD%D0%9F&ShowSearchForm=False&PageId=0&PageSize=50&SuppressFlags=0&ViewId=HaveCertificate&PartnerId=" + PartnerId); client.DownloadFile(newUri, $"{_partnerId}.xlsx"); using (ZipFile zip = ZipFile.Read($"{_partnerId}.xlsx")) { if (zip == null) Console.WriteLine("Null"); else { foreach (var zp in zip) { zp.Extract(ExtractExistingFileAction.OverwriteSilently); } } } } ShowMessageClass showMessage = new ShowConsoleMessage(); try { XmlDocument _xml = new XmlDocument(); try { _xml.Load("xl\\worksheets\\sheet1.xml"); } catch (System.IO.FileNotFoundException ex) { showMessage.ShowMessage($"File not found!{Environment.NewLine} Error: {ex.ToString()}"); } string str = _xml.OuterXml; str = str.Replace("<v>", "").Replace("</v>", "") .Replace("<f>=TEXT", "").Replace("</f>", ""); XmlRootAttribute xRoot = new XmlRootAttribute(); xRoot.ElementName = "worksheet"; xRoot.Namespace = "http://schemas.openxmlformats.org/spreadsheetml/2006/main"; xRoot.IsNullable = true; var xml = new XmlSerializer(typeof(Worksheet), xRoot); Data = xml.Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(str))) as Worksheet; return true; } catch (Exception ex) { showMessage.ShowMessage(ex.Message); return false; } }