Esempio n. 1
0
        public PocketModel(Guid _id, string _sourceurl, string _allpocketsfolderpath, string _serverdomainname, string _serverfolderpath, string _messagefrom, string _messageto, bool _locked = false)
        {
            id                   = _id;
            sourceurl            = _sourceurl.TrimEnd('/');
            serverdomainname     = _serverdomainname;
            serverfolderpath     = _serverfolderpath;
            allpocketsfolderpath = _allpocketsfolderpath;

            messagefrom = _messagefrom;
            messageto   = _messageto;
            locked      = _locked;

            XElement xConfiguration = null;

            if (CacheMode)
            {
                if (File.Exists(ConfigFilePath))
                {
                    xConfiguration = XElement.Load(ConfigFilePath);
                    XElement xNotifications = xConfiguration.Element(XName.Get("Notifications"));
                    messagefrom = xNotifications.Element(XName.Get("MessageFrom")).Value;
                    messageto   = xNotifications.Element(XName.Get("MessageTo")).Value;
                    XElement xLocked = xConfiguration.Element(XName.Get("Locked"));
                    if (xLocked != null)
                    {
                        locked = Convert.ToBoolean(xLocked.Value);
                    }
                }
                else
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(ConfigFilePath));
                    xConfiguration = CreateEmptyConfigFile(id, messagefrom, messageto, ConfigFilePath, locked);
                }
            }
            ReplacementModel = new ReplacementModel(xConfiguration);
            ReplacementModel.Items.Add(new Replacement(new Uri(sourceurl).Host, serverdomainname, "", true));

            EnhanceModel = new EnhanceModel(this);
        }
        public PocketModel(string _sourceurl, string _allpocketsfolderpath, string _serverdomainname, string _serverfolderpath, string _messagefrom, string _messageto, bool _locked = false)
        {
            sourceurl            = _sourceurl.TrimEnd('/');
            serverdomainname     = _serverdomainname;
            serverfolderpath     = _serverfolderpath;
            allpocketsfolderpath = _allpocketsfolderpath;

            messagefrom = _messagefrom;
            messageto   = _messageto;
            locked      = _locked;

            UserLogin = "";

            cookiecontainer = new CookieContainer();

            var LoginRequest = (HttpWebRequest)WebRequest.Create("https://xn--e1araccdibh8b.xn--p1ai/Account/Login?NumberOfError=0");

            LoginRequest.CookieContainer = cookiecontainer;
            LoginRequest.Method          = "POST";
            LoginRequest.ContentType     = "application/x-www-form-urlencoded";
            var loginData = String.Format("UserName={0}&Password={1}&NumberOfError=0", "*****@*****.**", "Asc0depr0");
            var buffer    = Encoding.ASCII.GetBytes(loginData);

            LoginRequest.ContentLength = buffer.Length;
            var requestStream = LoginRequest.GetRequestStream();

            requestStream.Write(buffer, 0, buffer.Length);
            requestStream.Close();

            string loginresult = "";
            var    response    = (HttpWebResponse)LoginRequest.GetResponse();

            using (var streamReader = new StreamReader(response.GetResponseStream()))
            {
                loginresult = streamReader.ReadToEnd();
            }

            XElement xConfiguration = null;

            if (CacheMode)
            {
                if (File.Exists(ConfigFilePath))
                {
                    xConfiguration = XElement.Load(ConfigFilePath);
                    XElement xNotifications = xConfiguration.Element(XName.Get("Notifications"));
                    messagefrom = xNotifications.Element(XName.Get("MessageFrom")).Value;
                    messageto   = xNotifications.Element(XName.Get("MessageTo")).Value;
                    XElement xLocked = xConfiguration.Element(XName.Get("Locked"));
                    if (xLocked != null)
                    {
                        if (!Boolean.TryParse(xLocked.Value, out locked))
                        {
                            DateTime LockedFrom = new DateTime();
                            if (DateTime.TryParse(xLocked.Value, out LockedFrom))
                            {
                                locked = (DateTime.Now > LockedFrom);
                            }
                        }
                    }
                }
                else
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(ConfigFilePath));
                    xConfiguration = CreateEmptyConfigFile(ConfigFilePath, messagefrom, messageto, locked);
                }
            }
            ReplacementModel = new ReplacementModel(xConfiguration);
            ReplacementModel.Items.Add(new Replacement(new Uri(sourceurl).Host, serverdomainname, "", true));

            EnhanceModel = new EnhanceModel(this);
        }