Exemplo n.º 1
0
        public FileContentResult GetImage(int id)
        {
            ServiceReference.Service1Client product = new ServiceReference.Service1Client();
            var pro = product.GetProduct(id);

            return(File(pro.Picture, "image/jpeg"));
        }
        public ActionResult Login(string username, string password, string ReturnUrl)
        {
            ServiceReference.Customer cus = new ServiceReference.Customer();
            if (ModelState.IsValid)
            {
                ServiceReference.Service1Client customer = new ServiceReference.Service1Client();
                cus = customer.Login(username, password);
                if (cus == null)
                {
                    ModelState.AddModelError("", "The username or password is incorrect");
                }
                else
                {
                    FormsAuthentication.SetAuthCookie(cus.FirstName, false);
                    int c = cus.CustomerID;
                    Session["CustomerId"] = c;
                    if (ReturnUrl != null)
                    {
                        return(Redirect(ReturnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }

            return(View(cus));
        }
        public ActionResult PartialRegisterAddress()
        {
            ServiceReference.Service1Client address = new ServiceReference.Service1Client();
            ViewBag.AddressTypes = new SelectList(address.GetAddressTypes(), "TypeID", "Type");

            return(PartialView());
        }
Exemplo n.º 4
0
        public ActionResult Index()
        {
            ServiceReference.Service1Client product = new ServiceReference.Service1Client();
            var p = product.GetPopularProducts();

            return(View(p));
        }
Exemplo n.º 5
0
 /// <summary>
 /// Method to register a new user in the database
 /// Using an email and 2 identical passwords, in order protect against typoes
 /// </summary>
 /// <param name="email">The users email</param>
 /// <param name="passUnencrypted1">unencrypted first password</param>
 /// <param name="passUnencrypted2">unencrypted second password</param>
 /// <returns>Wheter the creation of the user was successful - return -1 if it was unsuccesful</returns>
 public void RegisterUser(string email, string passUnencrypted1, string passUnencrypted2)
 {
     //Check if something have been entered as email - WE DO NOT CHECK THAT IT IS AN EMAIL
     if (email != null && email.Length > 0)
     {
         //Check that something has been entered as been entered as passwords and check that the two passwords are identical
         if (passUnencrypted1 != null && passUnencrypted1.Length > 0 && passUnencrypted2 != null && passUnencrypted1 == passUnencrypted2)
         {
             //encrypt password
             string pass = Security.EncryptString(passUnencrypted1);
             //connect to webservice
             ServiceReference.Service1Client proxy = new ServiceReference.Service1Client();
             proxy.AddUserAsync(email, pass);
             proxy.AddUserCompleted += new EventHandler <ServiceReference.AddUserCompletedEventArgs>(proxy_AddUserCompleted);
             session.Email           = email;
         }
         else //the passwords does not match
         {
             System.Windows.MessageBox.Show("User could not be created. Entered passwords does not match");
         }
     }
     else //no email was entered
     {
         System.Windows.MessageBox.Show("Enter email address");
     }
 }
Exemplo n.º 6
0
        public ActionResult Details(int id)
        {
            ServiceReference.Service1Client order = new ServiceReference.Service1Client();
            var orderDetails = order.GetOrderDetails(id);

            return(View(orderDetails));
        }
Exemplo n.º 7
0
        public ActionResult TryUpdatePasswd(StudentsVM model)
        {
            using (var MyService = new ServiceReference.Service1Client())
            {
                string sifre = MyService.TryChangePassword(new ServiceReference.Student {
                    EMail = model.EMail
                });
                if (sifre != "")
                {
                    SmtpClient sc = new SmtpClient
                    {
                        Port        = 587,
                        Host        = "mail.notdefterim.pro",
                        EnableSsl   = false,
                        Credentials = new NetworkCredential("*****@*****.**", "393M6znreh.A")
                    };
                    MailMessage mail = new MailMessage
                    {
                        From = new MailAddress("*****@*****.**", "NotDefterimPro")
                    };
                    mail.To.Add(model.EMail);
                    mail.Subject    = "Şifre İsteği";
                    mail.IsBodyHtml = true;
                    mail.Body       = "<div class='container'> <div style='background:white;'><h3 style='color:red'>Not Defterim Pro</h3>" + "<br/>Şifreniz: " + sifre + "<p>Şifreniz başarılı bir şekilde gönderilmiştir.<br/></br>Uygulamamızı kullandığınız için teşekkür eder,<br/> başarılarınızın devamını dileriz...<p/>" + "<p style='font - family:Helvetica, Arial, sans - serif; font - size:12px; line - height:16px; color:#aaaaaa;'>© 2018 - All Rights Reserved. </p><div/><div/>";
                    sc.Send(mail);

                    ViewBag.Script = "swal('Şifre Maile Gönderildi!', 'Şifrenizi unutmayınız', 'success')";
                }
                else
                {
                    ViewBag.Script = "swal('Hatalı Giriş', 'Sistemde Böyle Bir Mail Kayıtlı Değil.', 'error')";
                }
            }
            return(View());
        }
        // GET: Product
        public ActionResult Index(string searchString, int?page, string currentFilter)
        {
            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.CurrentFilter = searchString;

            ServiceReference.Service1Client product = new ServiceReference.Service1Client();
            var pro = product.GetAllProducts();
            var cat = product.GetAllCategories();
            var sub = product.GetAllSubCategories();

            if (!String.IsNullOrEmpty(searchString))
            {
                var cid = cat.Where(c => c.Category.ToUpper() == searchString.ToUpper()).Select(c => c.CategoryID).FirstOrDefault();
                var sid = sub.Where(s => s.CategoryID == cid).Select(s => s.SubCategoryID).FirstOrDefault();
                pro = pro.Where(p => p.SubCategoryID == sid).Select(p => p).ToList();
            }
            int pageSize   = 10;
            int pageNumber = (page ?? 1);

            return(View(pro.ToPagedList(pageNumber, pageSize)));
        }
        public ActionResult Details(int id)
        {
            ServiceReference.Service1Client product = new ServiceReference.Service1Client();
            var pro = product.GetProduct(id);

            return(View(pro));
        }
        public ActionResult Manage()
        {
            int c = Convert.ToInt32(Session["CustomerId"]);

            ServiceReference.Service1Client order = new ServiceReference.Service1Client();
            var            o      = order.GetOrder(c);
            var            od     = new List <ServiceReference.OrderDetail>();
            var            p      = new ServiceReference.Product();
            List <decimal> prices = new List <decimal>();

            foreach (var item in o)
            {
                od = order.GetOrderDetails(item.OrderID);
                ViewBag.OrderDtails = od;

                foreach (var detail in od)
                {
                    p = order.GetProduct(detail.ProductID);
                    if (p.UnitsInStock < detail.Quantity && p.UnitsInStock == 0)
                    {
                        ViewBag.IsBackOrder = true;
                    }
                    else
                    {
                        ViewBag.IsBackOrder = false;
                    }
                }
            }

            return(View(o));
        }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ServiceReference.Service1Client client = new ServiceReference.Service1Client();
        string url = "";

        url = DropDownList1.Text;
        Boolean isInvalidURL = false;

        if ((url == "") || (url.Equals("http://")))
        {
            string script = "alert('Please enter a valid URL !!!');";
            ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", script, true);
            isInvalidURL = true;
            clearFields();
        }
        if (!isInvalidURL)
        {
            try
            {
                string[] titles   = client.GetNewsHeadlines(url);
                string   newsList = "";

                for (Int32 i = 0; i < titles.Length; i++)
                {
                    newsList += "<br>" + (i + 1) + ". " + titles[i] + "<br>";
                }
                this.Label2.Text = newsList;
            }
            catch (Exception exception)
            {
                MessageBox("Error !!! " + exception.Message.Substring(0, 37));
                clearFields();
            }
        }
    }
        public string Retailer(int id)
        {
            ServiceReference.Service1Client product = new ServiceReference.Service1Client();
            var ret      = product.GetAllRetailers();
            var retailer = ret.Where(r => r.RetailerID == id).Select(r => r.Retailer1).FirstOrDefault();

            return(retailer);
        }
Exemplo n.º 13
0
        public void PopulateHistory(Web_Solution.GUI.RevisionHistoryDialog revDia)
        {
            session.RevisionDialog = revDia;

            ServiceReference.Service1Client proxy = new ServiceReference.Service1Client();
            proxy.GetAllDocumentRevisionsByDocumentIdAsync(session.CurrentDocumentID);
            proxy.GetAllDocumentRevisionsByDocumentIdCompleted += new EventHandler <ServiceReference.GetAllDocumentRevisionsByDocumentIdCompletedEventArgs>(proxy_GetAllDocumentRevisionsByDocumentIdCompleted);
        }
        public string SubCategory(int id)
        {
            ServiceReference.Service1Client product = new ServiceReference.Service1Client();
            var cat    = product.GetAllSubCategories();
            var subCat = cat.Where(c => c.SubCategoryID == id).Select(c => c.SubCategory).FirstOrDefault();

            return(subCat);
        }
Exemplo n.º 15
0
        public void DeleteDocument(TreeViewItem item, ItemCollection items)
        {
            ServiceReference.Service1Client proxy = new ServiceReference.Service1Client();
            int documentId = int.Parse(((object[])item.Tag)[0].ToString());

            proxy.DeleteDocumentReferenceAsync(session.UserID, documentId);
            TreeViewModel.GetInstance().RemoveDocument(documentId, items);
        }
Exemplo n.º 16
0
 /// <summary>
 /// Shares a document with another user.
 /// </summary>
 /// <param name="email">The email of the user</param>
 public void ShareDocument(string email)
 {
     if (email != null && email.Length > 0 && session.CurrentDocumentID != -1 && email != session.Email)
     {
         ServiceReference.Service1Client proxy = new ServiceReference.Service1Client();
         proxy.GetUserByEmailAsync(email);
         proxy.GetUserByEmailCompleted += new EventHandler <ServiceReference.GetUserByEmailCompletedEventArgs>(proxy_GetUserByEmailCompleted);
     }
 }
Exemplo n.º 17
0
 public ActionResult UserList()
 {
     using (var myservice = new ServiceReference.Service1Client())
     {
         int id = 1;
         ViewBag.Ogrenciler = myservice.GetAllStudents(id);
     }
     return(View());
 }
Exemplo n.º 18
0
 public ActionResult UpdateUsers(StudentsVM model)
 {
     using (var MyService = new ServiceReference.Service1Client())
     {
         MyService.UpdateUser(new ServiceReference.Student {
             Id = model.Id, AdSoyad = model.AdSoyad, EMail = model.EMail, GizliSoru = model.GizliSoru, GizliSoruCevap = model.GizliSoruCevap, KullaniciAdi = model.KullaniciAdi, Oturum = model.Oturum, Sifre = model.Sifre
         });
     }
     return(Json(true));
 }
Exemplo n.º 19
0
        /// <summary>
        /// Creates a folder by calling asynchrounous calls and setting session data.
        /// </summary>
        /// <param name="folderName">The name of the folder</param>
        /// <param name="parentFolderId">The id of the containing folder</param>
        public void CreateFolder(String folderName, int parentFolderId)
        {
            if (parentFolderId == -1) parentFolderId = session.RootFolderID;

            ServiceReference.Service1Client proxy = new ServiceReference.Service1Client();
            proxy.AddFolderAsync(folderName, parentFolderId);
            proxy.AddFolderCompleted += new EventHandler<ServiceReference.AddFolderCompletedEventArgs>(proxy_AddFolderCompleted);
            session.NewlyCreatedFolderName = folderName;
            session.NewlyCreatedFolderParentId = parentFolderId;
        }
Exemplo n.º 20
0
        public ActionResult ChangeAddress()
        {
            ServiceReference.Service1Client address = new ServiceReference.Service1Client();
            var customerId = Convert.ToInt32(Session["CustomerId"]);
            var a          = address.GetAddresses(customerId);

            //ViewBag.AddressTypes = new SelectList(address.GetAddressTypes(), "TypeID", "Type");


            return(View(a));
        }
Exemplo n.º 21
0
 public ActionResult KullaniciSil(int id)
 {
     using (var MyService = new ServiceReference.Service1Client())
     {
         if (Convert.ToInt32(Session["UserId"]) != id)
         {
             MyService.DeleteUser(id, Convert.ToInt32(Session["UserId"]));
         }
         return(RedirectToAction("UserList"));
     }
 }
Exemplo n.º 22
0
        public ActionResult EditAddress([Bind(Include = "AddressType,City,Country,PostalCode,Street,Suburb")] ServiceReference.Address add)
        {
            Debug.WriteLine("AddressType:" + add.AddressType);
            int a = add.AddressType;

            ServiceReference.Service1Client address = new ServiceReference.Service1Client();
            address.EditAddress(add);
            List <int> l = new List <int>();

            return(RedirectToAction("Index", "Order", new { quantity = l }));
        }
Exemplo n.º 23
0
        /// <summary>
        /// Saves the content specified in the merge view to the server.
        /// </summary>
        /// <param name="pureContent">Pure content of the text in the document</param>
        public void SaveMergedDocument(string pureContent)
        {
            int      documentid = session.CurrentDocumentID;
            int      userid     = session.UserID;
            DateTime timestamp  = DateTime.UtcNow;

            String metadata = Metadata.GenerateMetadataString(documentid, userid, timestamp);

            ServiceReference.Service1Client proxy = new ServiceReference.Service1Client();
            proxy.AddDocumentRevisionWebAsync(documentid, session.UserID, pureContent, metadata);
            proxy.CloseAsync();
        }
Exemplo n.º 24
0
 public ActionResult LessonTable(LessonVM model)
 {
     using (var MyService = new ServiceReference.Service1Client())
     {
         model.Adı       = "Ders Adı Giriniz";
         model.GecmeNotu = 60;
         MyService.InsertLesson(new ServiceReference.Lesson {
             Id = model.Id, Adi = model.Adı, Büt = model.Büt, BütTahmin = model.BütTahmin, Final = model.Final, FinalDurum = model.FinalDurum, FinalTahmin = model.FinalTahmin, Vize = model.Vize, VizeDurum = model.VizeDurum, VizeTahmin = model.VizeTahmin, GecmeNotu = model.GecmeNotu, GecerNot = model.GecerNot, StudentId = Convert.ToInt32(Session["UserId"].ToString())
         });
     }
     return(RedirectToAction("LessonTable"));
 }
Exemplo n.º 25
0
        // GET: Product
        public ActionResult Index(string searchString, int?page, string currentFilter)
        {
            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.CurrentFilter = searchString;

            int pageSize = 10;
            int pageNumber;

            pageNumber = (page ?? 1);

            ServiceReference.Service1Client product = new ServiceReference.Service1Client();
            try
            {
                var pro = product.GetAllProducts();
                var cat = product.GetAllCategories();
                var sub = product.GetAllSubCategories();


                if (!String.IsNullOrEmpty(searchString))
                {
                    var products = new List <ServiceReference.Product>();
                    var cid      = cat.Where(c => c.Category.ToUpper() == searchString.ToUpper()).Select(c => c.CategoryID).FirstOrDefault();
                    var sid      = sub.Where(s => s.CategoryID == cid).Select(s => s.SubCategoryID).ToList();
                    foreach (var item in pro)
                    {
                        foreach (var i in sid)
                        {
                            if (item.SubCategoryID == i)
                            {
                                products.Add(item);
                            }
                        }
                    }

                    return(View(products.ToPagedList(pageNumber, pageSize)));
                }

                return(View(pro.ToPagedList(pageNumber, pageSize)));
            }
            catch (System.ServiceModel.EndpointNotFoundException e)
            {
                return(RedirectToAction("DatabaseError", "Error"));
            }
        }
Exemplo n.º 26
0
        private void item_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            bool doubleClick = MouseButtonHelper.IsDoubleClick(sender, e);

            if (doubleClick)
            {
                TreeViewItem item = (TreeViewItem)sender;
                session.RevisionDialog.labelCurrentTimeStamp.Text = "Opened revision: " + item.Header.ToString();
                ServiceReference.Service1Client proxy = new ServiceReference.Service1Client();
                proxy.GetDocumentRevisionContentByIdAsync((int)item.Tag);
                proxy.GetDocumentRevisionContentByIdCompleted += new EventHandler <ServiceReference.GetDocumentRevisionContentByIdCompletedEventArgs>(proxy_GetDocumentRevisionContentByIdCompleted);
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Creates a folder by calling asynchrounous calls and setting session data.
        /// </summary>
        /// <param name="folderName">The name of the folder</param>
        /// <param name="parentFolderId">The id of the containing folder</param>
        public void CreateFolder(String folderName, int parentFolderId)
        {
            if (parentFolderId == -1)
            {
                parentFolderId = session.RootFolderID;
            }

            ServiceReference.Service1Client proxy = new ServiceReference.Service1Client();
            proxy.AddFolderAsync(folderName, parentFolderId);
            proxy.AddFolderCompleted          += new EventHandler <ServiceReference.AddFolderCompletedEventArgs>(proxy_AddFolderCompleted);
            session.NewlyCreatedFolderName     = folderName;
            session.NewlyCreatedFolderParentId = parentFolderId;
        }
Exemplo n.º 28
0
        // GET: Order
        public ActionResult Index()
        {
            List <int> productIDs = Session["ShoppingCart"] as List <int>;

            ServiceReference.Service1Client order = new ServiceReference.Service1Client();
            var orderList = order.GetOrderProducts(productIDs);

            if (orderList.Count == 0)
            {
                ViewBag.Message = "Your Cart is Empty";
            }
            return(View(orderList));
        }
Exemplo n.º 29
0
 public ActionResult Sil(int id)
 {
     using (var MyService = new ServiceReference.Service1Client())
     {
         if (MyService.DeleteLesson(id, Convert.ToInt32(Session["UserId"])))
         {
             return(RedirectToAction("LessonTable"));
         }
         else
         {
             return(RedirectToAction("LessonTable"));
         }
     }
 }
Exemplo n.º 30
0
        public ActionResult EditAddress()
        {
            ServiceReference.Service1Client address = new ServiceReference.Service1Client();
            var customerId = Convert.ToInt32(Session["CustomerId"]);

            ViewBag.AddressTypes = new SelectList(address.GetAddressTypes(), "TypeID", "Type");
            var a = address.GetAddresses(customerId).FirstOrDefault();

            //if(a == null)
            //{
            //    a = address.GetAddresses(id, 1);
            //}
            return(View(a));
        }
Exemplo n.º 31
0
 static void Main(string[] args)
 {
     //PersistentStorage.GetInstance().AddDocumentWithUserDocument("somename", 207, 305, "[docid 0|userid 207|timestamp 13-12-2012 11:10:16|fid 305]<FlowDocument PagePadding=\"5,0,5,0\" AllowDrop=\"True\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><Paragraph><Run xml:lang=\"da-dk\">virk nu for satan!</Run></Paragraph><Paragraph><Run xml:lang=\"da-dk\">!</Run></Paragraph><Paragraph><Run xml:lang=\"da-dk\">!</Run></Paragraph></FlowDocument>");
     //DAO.GetInstance().GetLatestDocumentRevisions(109);
     //Model.GetInstance().GetContentAsStringArray(120);
     //String s = "[docid 132|userid 213|timestamp 14-12-2012 15:53:00|fid 318]<FlowDocument PagePadding=\"5,0,5,0\" AllowDrop=\"True\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><Paragraph><Run xml:lang=\"da-dk\">hej</Run></Paragraph><Paragraph><Run xml:lang=\"da-dk\">fifty</Run></Paragraph></FlowDocument>";
     //String s2 = "hej\r\nfifty\r\n";
     //PersistentStorage.GetInstance().SyncDocument(213, 132, 318, new DateTime(2012, 12, 14, 15, 53, 00), s, "b", s2.Split(new string[] { "\r\n, \n" }, StringSplitOptions.None));
     using (ServiceReference.Service1Client proxy = new ServiceReference.Service1Client())
     {
         ServiceReference.ServiceDocumentrevision[] list = proxy.GetAllDocumentRevisionsByDocumentId(1);
         ServiceReference.ServiceDocumentrevision doc = list[0];
     }
 }
Exemplo n.º 32
0
        /// <summary>
        /// Syncs a document and calls the asynchronous calls, resolving the merge.
        /// </summary>
        /// <param name="pureContent">The content of the document being synchronized</param>
        public void SyncDocument(string pureContent)
        {
            if (session.CurrentDocumentID != -1)
            {
                int      documentId = session.CurrentDocumentID;
                DateTime baseDocumentCreationTime = session.CurrentDocumentTimeStampMetadata;

                string metadata = Metadata.GenerateMetadataString(documentId, session.UserID, DateTime.UtcNow);
                string filePath = TreeViewModel.GetInstance().GetRelativePath(session.FolderID, gui.ExplorerTree.Items);

                ServiceReference.Service1Client proxy = new ServiceReference.Service1Client();
                proxy.SyncDocumentWebAsync(session.UserID, documentId, filePath, metadata, session.CurrentDocumentTitle, pureContent);
                proxy.SyncDocumentWebCompleted += new EventHandler <ServiceReference.SyncDocumentWebCompletedEventArgs>(proxy_SyncDocumentWebCompleted);
            }
        }
Exemplo n.º 33
0
 /// <summary>
 /// Method to register a new user in the database
 /// Using an email and 2 identical passwords, in order protect against typoes
 /// </summary>
 /// <param name="email">The users email</param>
 /// <param name="passUnencrypted1">unencrypted first password</param>
 /// <param name="passUnencrypted2">unencrypted second password</param>
 /// <returns>Wheter the creation of the user was successful - return -1 if it was unsuccesful</returns>
 public void RegisterUser(string email, string passUnencrypted1, string passUnencrypted2)
 {
     //Check if something have been entered as email - WE DO NOT CHECK THAT IT IS AN EMAIL
     if (email != null && email.Length > 0)
     {
         //Check that something has been entered as been entered as passwords and check that the two passwords are identical
         if (passUnencrypted1 != null && passUnencrypted1.Length > 0 && passUnencrypted2 != null && passUnencrypted1 == passUnencrypted2)
         {
             //encrypt password
             string pass = Security.EncryptString(passUnencrypted1);
             //connect to webservice
             ServiceReference.Service1Client proxy = new ServiceReference.Service1Client();
             proxy.AddUserAsync(email, pass);
             proxy.AddUserCompleted += new EventHandler<ServiceReference.AddUserCompletedEventArgs>(proxy_AddUserCompleted);
             session.Email = email;
         }
         else //the passwords does not match
         {
             System.Windows.MessageBox.Show("User could not be created. Entered passwords does not match");
         }
     }
     else //no email was entered
     {
         System.Windows.MessageBox.Show("Enter email address");
     }
 }
Exemplo n.º 34
0
        public void PopulateHistory(Web_Solution.GUI.RevisionHistoryDialog revDia)
        {
            session.RevisionDialog = revDia;

            ServiceReference.Service1Client proxy = new ServiceReference.Service1Client();
            proxy.GetAllDocumentRevisionsByDocumentIdAsync(session.CurrentDocumentID);
            proxy.GetAllDocumentRevisionsByDocumentIdCompleted +=new EventHandler<ServiceReference.GetAllDocumentRevisionsByDocumentIdCompletedEventArgs>(proxy_GetAllDocumentRevisionsByDocumentIdCompleted);
        }
Exemplo n.º 35
0
        public void MoveFileToFolder(int fromId, int toId, int documentId, TreeViewItem item)
        {
            if (toId == -1) toId = session.RootFolderID;

            ServiceReference.Service1Client proxy = new ServiceReference.Service1Client();
            proxy.MoveDocumentWebAsync(session.UserID, documentId, toId);

            TreeViewModel.GetInstance().RemoveDocument(documentId, gui.ExplorerTree.Items);
            object[] tag = (object[])item.Tag;
                //doc id, folder id, navn
            string[] document = new string[] { tag[0].ToString(), toId.ToString(), item.Header.ToString() };
            TreeViewModel.GetInstance().InsertDocument(document, gui.ExplorerTree.Items);
            session.FolderID = toId;
        }
Exemplo n.º 36
0
        /// <summary>
        /// Add file to server
        /// </summary>
        /// <param name="filePath">Path to the file which should be added to the server</param>
        private void AddDocumentToServer(String filePath)
        {
            //load file content
            String content = localPersistence.GetFileContent(filePath);
            //fetch filename
            String fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1, (filePath.IndexOf(".txt") - filePath.LastIndexOf("\\") - 1));

            //Connect to webservice
            using (ServiceReference.Service1Client proxy = new ServiceReference.Service1Client())
            {
                //add document online
                proxy.AddDocumentWithUserDocument(fileName, session.UserID, filePath, content);
            }
        }
Exemplo n.º 37
0
        /// <summary>
        /// Creates a userdocument for the invited user.
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="args">The email of the user</param>
        private void proxy_GetUserByEmailCompleted(Object sender, ServiceReference.GetUserByEmailCompletedEventArgs args)
        {
            ServiceReference.ServiceUser shareUser = args.Result;

            if (shareUser != null)
            {
                ServiceReference.Service1Client proxy = new ServiceReference.Service1Client();
                proxy.AddUserDocumentInRootAsync(shareUser.id, session.CurrentDocumentID);
                proxy.ShareDocumentWebAsync(session.CurrentDocumentID, session.UserID, shareUser.id);
                MessageBox.Show("Document shared with " + shareUser.email);
            }
            else
            {
                MessageBox.Show("User does not exist");
            }
        }
Exemplo n.º 38
0
 private void item_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
 {
     bool doubleClick = MouseButtonHelper.IsDoubleClick(sender, e);
     if (doubleClick)
     {
         TreeViewItem item = (TreeViewItem)sender;
         session.RevisionDialog.labelCurrentTimeStamp.Text = "Opened revision: " + item.Header.ToString();
         ServiceReference.Service1Client proxy = new ServiceReference.Service1Client();
         proxy.GetDocumentRevisionContentByIdAsync((int)item.Tag);
         proxy.GetDocumentRevisionContentByIdCompleted += new EventHandler<ServiceReference.GetDocumentRevisionContentByIdCompletedEventArgs>(proxy_GetDocumentRevisionContentByIdCompleted);
     }
 }
Exemplo n.º 39
0
 /// <summary>
 /// Shares a document with another user.
 /// </summary>
 /// <param name="email">The email of the user</param>
 public void ShareDocument(string email)
 {
     if (email != null && email.Length > 0 && session.CurrentDocumentID != -1 && email != session.Email)
     {
         ServiceReference.Service1Client proxy = new ServiceReference.Service1Client();
         proxy.GetUserByEmailAsync(email);
         proxy.GetUserByEmailCompleted += new EventHandler<ServiceReference.GetUserByEmailCompletedEventArgs>(proxy_GetUserByEmailCompleted);
     }
 }
Exemplo n.º 40
0
        /// <summary>
        /// Method to register a new user in the database
        /// Using an email and 2 identical passwords, in order protect against typoes
        /// </summary>
        /// <param name="email">The users email</param>
        /// <param name="passUnencrypted1">unencrypted first password</param>
        /// <param name="passUnencrypted2">unencrypted second password</param>
        /// <returns>Wheter the creation of the user was successful - return -1 if it was unsuccesful</returns>
        public int RegisterUser(string email, string passUnencrypted1, string passUnencrypted2)
        {
            //boolean which will be returned
            int successful = -1;

            //Check if something have been entered as email
            if (email != null && email.Length > 0)
            {
                //Check that something has been entered as been entered as passwords and check that the two passwords are identical
                if (passUnencrypted1 != null && passUnencrypted1.Length > 0 && passUnencrypted2 != null && passUnencrypted1 == passUnencrypted2)
                {
                    //encrypt password
                    string pass = Security.EncryptString(passUnencrypted1);
                    //connect to webservice
                    using (ServiceReference.Service1Client proxy = new ServiceReference.Service1Client())
                    {
                        //register user
                        successful = proxy.AddUser(email, pass);
                    }

                    if (successful == -1) //if the user already exsist
                    {
                        System.Windows.MessageBox.Show("User aldready exsists", "Creation error");
                    }
                    else //the user has been created
                    {
                        System.Windows.MessageBox.Show("User with email: " + email + " have been successfully created", "Successful");
                    }
                }
                else //the passwords does not match
                {
                    System.Windows.MessageBox.Show("User could not be created. Entered passwords does not match", "Creation error");
                }
            }
            else //no email was entered
            {
                System.Windows.MessageBox.Show("Enter email address", "Creation error");
            }
            return successful; //return the result
        }
Exemplo n.º 41
0
        /// <summary>
        /// Pushes the merged document revision to the server to resolve the conflict.
        /// </summary>
        /// <param name="document">The document content from the UI</param>
        public void SaveMergedDocument(FlowDocument document)
        {
            Object[] oldMetadata = LocalPersistenceHandler.RetrieveMetadataFromFile(session.CurrentDocumentPath);
            int documentid = (int)oldMetadata[0];
            int userid = session.UserID;
            DateTime timestamp = DateTime.UtcNow;
            //int folderid = (int)oldMetadata[3];

            String metadata = Metadata.GenerateMetadataString(documentid, userid, timestamp);//, folderid);
            String xamlContent = System.Windows.Markup.XamlWriter.Save(document);
            String content = metadata + xamlContent;

            using (ServiceReference.Service1Client proxy = new ServiceReference.Service1Client())
            {
                proxy.AddDocumentRevision(session.UserID, documentid, content);
            }
            localPersistence.SaveDocumentToFile(content, session.CurrentDocumentPath);
        }
Exemplo n.º 42
0
 /// <summary>
 /// Method to share the currently opened document with another user
 /// </summary>
 /// <param name="email">The email of the sue rwhich you want to share the doument</param>
 public void ShareDocument(string email)
 {
     if (email != null && email.Length > 0 && session.CurrentDocumentPath.Length > 0 && session.CurrentDocumentID != -1)
     {
         ServiceReference.ServiceUser shareUser = null;
         using (ServiceReference.Service1Client proxy = new ServiceReference.Service1Client())
         {
             shareUser = proxy.GetUserByEmail(email);
         }
         if (shareUser != null)
         {
             using (ServiceReference.Service1Client proxy = new ServiceReference.Service1Client())
             {
                 proxy.AddUserDocumentInRoot(shareUser.id, session.CurrentDocumentID);
             }
             MessageBox.Show("Document shared with " + shareUser.email, "Share success");
         }
         else
         {
             MessageBox.Show("User does not exist", "Email error");
         }
     }
 }
Exemplo n.º 43
0
        /// <summary>
        /// Synchronizes all documents. This includes downloading of files from the server and overwritting of eventual exisiting local saves that can cause conflicts.
        /// Locally absent folders from documents downloaded from the server are created locally.
        /// </summary>
        public void SyncAllDocuments()
        {
            if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
            {
                if (session.UserID != -1) //Check if user is logged in
                {
                    ServiceReference.ServiceUserdocument[] documents;
                    //Connect to webservice
                    using (ServiceReference.Service1Client proxy = new ServiceReference.Service1Client())
                    {
                        //Retrieve all documents the users documents
                        documents = proxy.GetAllUserDocumentsByUserId(session.UserID);
                    }
                    if (documents != null) //check if any documents is found
                    {
                        //For each document found
                        foreach (ServiceReference.ServiceUserdocument currentDoc in documents)
                        {
                            String relativeDirPath = FetchRelativeFilePath(currentDoc);
                            String dirPath = session.RootFolderPath + "\\" + relativeDirPath;
                            ServiceReference.ServiceDocument documentReference = null;

                            using (ServiceReference.Service1Client proxy = new ServiceReference.Service1Client())
                            {
                                //Get the original document from the server
                                documentReference = proxy.GetDocumentById(currentDoc.documentId);
                            }
                            String filePath = dirPath + "\\" + documentReference.name + ".txt";

                            String content;
                            //Connect to webservice
                            using (ServiceReference.Service1Client proxy = new ServiceReference.Service1Client())
                            {
                                //Get the content of the file on the server
                                content = proxy.GetLatestDocumentContent(documentReference.id);
                                //add a document revision in order to be able to detect merge conflicts later
                                proxy.AddDocumentRevision(session.UserID, documentReference.id, content);
                            }
                            //Create the directories needed?
                            Directory.CreateDirectory(Path.GetDirectoryName(filePath));
                            //Create a document locally with the content
                            localPersistence.SaveDocumentToFile(content, filePath);
                        }
                    }
                    else //No documents found by this userId
                    { //loop through all the users folders and add all files to the server
                        List<String> files = new List<String>();
                        foreach (String file in Directory.GetFiles(session.RootFolderPath))
                        {
                            AddDocumentToServer(file);
                        }

                        foreach (String dir in Directory.GetDirectories(session.RootFolderPath))
                        {
                            foreach (String file in Directory.GetFiles(dir))
                            {
                                AddDocumentToServer(file);
                            }
                        }
                    }
                }
                else
                {
                    //not logged in
                }
                UpdateExplorerView();
            }
            else
            {
                MessageBox.Show("No internet connection", "Internet connection error");
            }
        }
Exemplo n.º 44
0
        /// <summary>
        /// Gets the file path that a user's document is locally stored at.
        /// </summary>
        /// <param name="doc">Userdocument from the server</param>
        /// <returns>The file path to the document from the local root directory</returns>
        private string FetchRelativeFilePath(ServiceReference.ServiceUserdocument doc)
        {
            StringBuilder sb = new StringBuilder();
            ServiceReference.ServiceFolder folder = null;

            using (ServiceReference.Service1Client proxy = new ServiceReference.Service1Client())
            {
                folder = proxy.GetFolder(doc.folderId);
            }

            while (folder != null || folder.parentFolderId != null)
            {
                if (folder.parentFolderId == null)
                {
                    break;
                }
                else
                {
                    sb.Insert(0, "\\" + folder.name);
                }
                using (ServiceReference.Service1Client proxy = new ServiceReference.Service1Client())
                {
                    folder = proxy.GetFolder((int)folder.parentFolderId);
                }
            }

            String userEmail = session.Email;
            sb.Insert(0, "");

            return sb.ToString();
        }
Exemplo n.º 45
0
        /// <summary>
        /// Synchronizes a specific document to push changes to the server. If another user made changes meanwhile, a conflict arises and a difference view is displayed.
        /// </summary>
        /// <param name="document">The document content from the UI</param>
        public void SyncDocument(FlowDocument document)
        {
            if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
            {
                //Metadata
                //0: docid -> docid 11
                //1: userid -> userid 11
                //2: timestamp -> timestamp 12-12-2012 12:18:19
                object[] metadata = LocalPersistenceHandler.RetrieveMetadataFromFile(session.CurrentDocumentPath);
                int documentID = (int)metadata[0];
                DateTime baseDocumentCreationTime = (DateTime)metadata[2];
                //int folderID = (int)metadata[3];

                StringBuilder sb = new StringBuilder();
                string metadataString = Metadata.GenerateMetadataString(documentID, session.UserID, DateTime.UtcNow);//, folderID);
                sb.Append(metadataString);
                sb.AppendLine();
                //generate xaml for the document
                String xaml = System.Windows.Markup.XamlWriter.Save(document);
                sb.Append(xaml);

                //get the text from the document
                String content = new TextRange(document.ContentStart, document.ContentEnd).Text;

                String[][] responseArrays = null;
                //connect to the websevice
                using (ServiceReference.Service1Client proxy = new ServiceReference.Service1Client())
                {
                    //push the current document
                    responseArrays = proxy.SyncDocument(session.UserID, documentID, session.CurrentDocumentPath, sb.ToString(), session.CurrentDocumentTitle, content);
                }

                if (responseArrays == null) //if there is no conflict
                {
                    if (documentID == 0)
                    {
                        //connect to the websevice
                        using (ServiceReference.Service1Client proxy = new ServiceReference.Service1Client())
                        {
                            documentID = proxy.GetDocumentId(session.UserID, session.CurrentDocumentTitle);
                        }
                    }
                    //save document with new metadata - basedocument
                    localPersistence.SaveDocumentToFile(document, Metadata.ReplaceDocumentIDInMetadata(metadataString, documentID));
                    session.CurrentDocumentID = documentID;
                }
                else //if there is a conflict
                {
                    gui.SetupMergeView(responseArrays);
                }
            }
            else
            {
                //No web connection
            }
        }
Exemplo n.º 46
0
        /// <summary>
        /// Saves the content specified in the merge view to the server.
        /// </summary>
        /// <param name="pureContent">Pure content of the text in the document</param>
        public void SaveMergedDocument(string pureContent)
        {
            int documentid = session.CurrentDocumentID;
            int userid = session.UserID;
            DateTime timestamp = DateTime.UtcNow;

            String metadata = Metadata.GenerateMetadataString(documentid, userid, timestamp);

            ServiceReference.Service1Client proxy = new ServiceReference.Service1Client();
            proxy.AddDocumentRevisionWebAsync(documentid, session.UserID, pureContent, metadata);
            proxy.CloseAsync();
        }
Exemplo n.º 47
0
 public void SetOpenDocument(int documentId, string documentTitle, int folderId)
 {
     if (documentId != -1)
     {
         ServiceReference.Service1Client proxy = new ServiceReference.Service1Client();
         proxy.GetLatestPureDocumentContentAsync(documentId);
         proxy.GetLatestPureDocumentContentCompleted += new EventHandler<ServiceReference.GetLatestPureDocumentContentCompletedEventArgs>(proxy_GetLatestPureDocumentContentCompleted);
         session.CurrentDocumentID = documentId;
         session.CurrentDocumentTitle = documentTitle;
         session.FolderID = folderId;
         gui.labelOpenDocument.Content = "Current document: " + documentTitle;
     }
     else
     {
         session.CurrentDocumentID = -1;
         session.CurrentDocumentTitle = "";
         gui.labelOpenDocument.Content = "Current document: ";
     }
 }
Exemplo n.º 48
0
        /// <summary>
        /// Calls the asynchrounous calls to create a document. The method sets session data and creates metadata.
        /// </summary>
        /// <param name="title">The title of the document</param>
        public void CreateNewDocumentFile(String title)
        {
            if (title != null && title.Length > 0)
            {
                string emptyDocumentXaml = "<FlowDocument xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" />";
                string metadata = Metadata.GenerateMetadataStringForNewFile();
                string fileContent = metadata + emptyDocumentXaml;

                session.CurrentDocumentTitle = title;

                ServiceReference.Service1Client proxy = new ServiceReference.Service1Client();
                proxy.AddDocumentWithUserDocumentAsync(title, session.UserID, session.Email + "\\", fileContent);
                proxy.AddDocumentWithUserDocumentCompleted += new EventHandler<ServiceReference.AddDocumentWithUserDocumentCompletedEventArgs>(proxy_AddDocumentWithUserDocumentCompleted);
            }
        }
Exemplo n.º 49
0
        /// <summary>
        /// Syncs a document and calls the asynchronous calls, resolving the merge.
        /// </summary>
        /// <param name="pureContent">The content of the document being synchronized</param>
        public void SyncDocument(string pureContent)
        {
            if (session.CurrentDocumentID != -1)
            {
                int documentId = session.CurrentDocumentID;
                DateTime baseDocumentCreationTime = session.CurrentDocumentTimeStampMetadata;

                string metadata = Metadata.GenerateMetadataString(documentId, session.UserID, DateTime.UtcNow);
                string filePath = TreeViewModel.GetInstance().GetRelativePath(session.FolderID, gui.ExplorerTree.Items);

                ServiceReference.Service1Client proxy = new ServiceReference.Service1Client();
                proxy.SyncDocumentWebAsync(session.UserID, documentId, filePath, metadata, session.CurrentDocumentTitle, pureContent);
                proxy.SyncDocumentWebCompleted += new EventHandler<ServiceReference.SyncDocumentWebCompletedEventArgs>(proxy_SyncDocumentWebCompleted);
            }
        }
Exemplo n.º 50
0
        /// <summary>
        /// Method to remove a users participation in a document - the document still lives on the server, but the currently online user can no longer access it
        /// </summary>
        /// <param name="item">TreeViewItem represetation of the item which is to be removed</param>
        /// <param name="items">An item collection which contains the soon to be removed document</param>
        public void DeleteDocument(System.Windows.Controls.TreeViewItem item, System.Windows.Controls.ItemCollection items)
        {
            //get document id for the file
            int documentId = Metadata.FetchDocumentIDFromFileContent(localPersistence.GetFileContent(item.Tag.ToString()));

            using(ServiceReference.Service1Client proxy = new ServiceReference.Service1Client())
            {
                //delete the users document reference
                proxy.DeleteDocumentReference(session.UserID, documentId);
            }
            //delete the file locally
            localPersistence.DeleteFile(item.Tag.ToString());
            UpdateExplorerView();
        }
Exemplo n.º 51
0
        /// <summary>
        /// Sets gui view and session data. Calls additional asynchronous calls to set update view and data.
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="args">The user credentials</param>
        private void proxy_GetUserByEmailAndPassCompleted(Object sender, ServiceReference.GetUserByEmailAndPassCompletedEventArgs args)
        {
            ServiceReference.ServiceUser user = args.Result;
            if (user != null) //login successful
            {
                //User logged in
                session.UserID = user.id;
                session.RootFolderID = user.rootFolderId;

                gui.SetLoginView(true);

                ServiceReference.Service1Client proxy = new ServiceReference.Service1Client();
                proxy.GetAllFilesAndFoldersByUserIdAsync(user.id);
                proxy.GetAllFilesAndFoldersByUserIdCompleted += new EventHandler<ServiceReference.GetAllFilesAndFoldersByUserIdCompletedEventArgs>(proxy_GetAllFilesAndFoldersByUserIdCompleted);
            }
            else
            {
                session.Email = "";
                gui.textBlockOnline.Text = "Offline";
                MessageBox.Show("Wrong email or password");
            }
        }
Exemplo n.º 52
0
 public ServiceManager()
 {
     serviceClient = new ServiceReference.Service1Client();
 }
Exemplo n.º 53
0
        public bool LoginUser(string email, string unencrytedPass)
        {
            bool successfulLogin = false;
            if (email != null && email.Length > 0 && unencrytedPass != null && unencrytedPass.Length > 0)
            {
                //encrypt passowrd
                String pass = Security.EncryptString(unencrytedPass);
                ServiceReference.ServiceUser user = null;
                //connect to webservice
                using (ServiceReference.Service1Client proxy = new ServiceReference.Service1Client())
                {
                    //get the user id - -1 if no user exists
                    user = proxy.GetUserByEmailAndPass(email, pass);
                }
                if (user != null) //login successful
                {
                    //User logged in
                    session.UserID = user.id;
                    session.Email = email;
                    session.RootFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\sliceofpie\\" + email;
                    Directory.CreateDirectory(session.RootFolderPath);

                    System.Windows.MessageBox.Show("Logged in successfully", "Login");
                    successfulLogin = true;
                    UpdateExplorerView();
                }
                else
                {
                    MessageBox.Show("Wrong email or password", "Unable to login");
                }
            }
            else
            {
                MessageBox.Show("Enter email and password", "Login error");
            }
            return successfulLogin;
        }
Exemplo n.º 54
0
 /// <summary>
 /// Logs a user in with an email and an unencrypted password.
 /// </summary>
 /// <param name="email">The email of the user</param>
 /// <param name="unencrytedPass">The password of the user</param>
 public void LoginUser(string email, string unencrytedPass)
 {
     if (email != null && email.Length > 0 && unencrytedPass != null && unencrytedPass.Length > 0)
     {
         //encrypt passowrd
         String pass = Security.EncryptString(unencrytedPass);
         //connect to webservice
         ServiceReference.Service1Client proxy = new ServiceReference.Service1Client();
         //get the user id - -1 if no user exists
         proxy.GetUserByEmailAndPassAsync(email, pass);
         proxy.GetUserByEmailAndPassCompleted += new EventHandler<ServiceReference.GetUserByEmailAndPassCompletedEventArgs>(proxy_GetUserByEmailAndPassCompleted);
         session.Email = email;
     }
     else
     {
         MessageBox.Show("Enter email and password");
     }
 }
Exemplo n.º 55
0
 public void DeleteDocument(TreeViewItem item, ItemCollection items)
 {
     ServiceReference.Service1Client proxy = new ServiceReference.Service1Client();
     int documentId = int.Parse(((object[])item.Tag)[0].ToString());
     proxy.DeleteDocumentReferenceAsync(session.UserID, documentId);
     TreeViewModel.GetInstance().RemoveDocument(documentId, items);
 }
Exemplo n.º 56
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="documentId"></param>
        /// <returns>
        /// [x]a new revision
        /// [x][0]timestamp
        /// [x][1]editor name
        /// [x][2]filecontent with metadata
        /// </returns>
        public string[][] GetAllDocumentRevisionsWithContent(int documentId)
        {
            string[][] returnArray = null;
            if (documentId > 0)
            {
                ServiceReference.ServiceDocumentrevision[] revisions = null;
                using (ServiceReference.Service1Client proxy = new ServiceReference.Service1Client())
                {
                    revisions = proxy.GetAllDocumentRevisionsByDocumentId(documentId);
                }

                //remove duplicates
                //here

                returnArray = new string[revisions.Length][];

                using(ServiceReference.Service1Client proxy = new ServiceReference.Service1Client())
                {
                    for(int i = 0; i < revisions.Length; i++)
                    {
                        ServiceReference.ServiceDocumentrevision doc = revisions[i];
                        ServiceReference.ServiceDocument originalDocument = proxy.GetDocumentById(doc.documentId);

                        String creationTime = doc.creationTime.ToString().Replace(":", ".");
                        String filename = originalDocument.name + "_revision_" + creationTime;
                        String content = proxy.GetDocumentContent(originalDocument.path, filename);

                        string[] item = new string[3];
                        item[0] = doc.creationTime.ToString();
                        item[1] = proxy.GetUserById(doc.editorId).email;
                        item[2] = Metadata.RemoveMetadataFromFileContent(content);

                        returnArray[i] = item;
                    }
                }
            }

            return returnArray;
        }