Exemplo n.º 1
0
 public bool SendSyncDataThroughLAN(SystemUser user)
 {
     if (LoginRemoteService(user))
     {
         //XDocument doc = GetDataToSyncSecure(user);
         string feedback = syncProxy.ReceiveSyncTransaDataObjects(_tokenHeader, GetDataToSyncSecure(user), SiteConfigServices.SiteID);
         XDocument xDoc = XDocument.Parse(feedback);
         return (bool)xDoc.Element("SecuredWebService").Attribute("success");
     }
     return false;
 }
Exemplo n.º 2
0
        public bool ReceiveSyncDataTroughLAN(SystemUser user)
        {
            if (LoginRemoteService(user))
            {
                string feedback = syncProxy.SendApprovedData(_tokenHeader, SiteConfigServices.SiteID);
                XDocument xDoc = XDocument.Parse(Crypto.DecryptStringAES(feedback, SiteConfigServices.InstallationToken));
                if ((bool)xDoc.Element("SecuredWebService").Attribute("success"))
                {
                    //TODO using .Value throws "Data at the root level is invalid. Line 1, position 1." exception
                    //investigate whether the server is using wrong encoding which can be a pain in the ass in future.
                    //However it seems using .ToString() solves it.
                    //string test = xDoc.Element("SecuredWebService").ToString();
                    //string test1 = xDoc.Element("SecuredWebService").Value;

                    XDocument xDocData = XDocument.Parse(xDoc.Element("SecuredWebService").Element("data").Element("Approved").ToString());
                    ImportApprovedData(xDocData);
                    return true;
                }
            }
            return false;
        }
Exemplo n.º 3
0
        /// <summary>
        /// This methode will not login on the server because it will try to use the servers credentials
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool LoginRemoteService(SystemUser user)
        {
            SyncServiceReference.SecuredWebServiceHeader header = new SyncServiceReference.SecuredWebServiceHeader();
            header.SiteID = SiteConfigServices.SiteID.ToString();
            header.InstallationToken = SiteConfigServices.InstallationToken;

            try
            {
                string feedback = syncProxy.AuthenticateUser(header);
                XDocument xDoc = XDocument.Parse(feedback);

                if (!(bool)xDoc.Element("SecuredWebService").Attribute("success")) return false;
                else
                {
                    _tokenHeader.AuthenticatedToken = xDoc.Element("SecuredWebService").Element("token").Value;
                    return true;
                }
            }
            catch (EndpointNotFoundException ex)
            {
                return false;
            }
        }
Exemplo n.º 4
0
 public bool ImportDataForApproval(SystemUser user, string data, int siteId)
 {
     if (LoginRemoteService(user))
     {
         string feedback = syncProxy.ReceiveSyncTransaDataObjects(_tokenHeader, data, siteId);
         XDocument xDoc = XDocument.Parse(feedback);
         return (bool)xDoc.Element("SecuredWebService").Attribute("success");
     }
     return false;
 }
Exemplo n.º 5
0
        public XDocument GetDataToSyncXML(SystemUser user)
        {
            List<TransData> dataToSync = GetDataToSync(user);
            XDocument xDoc = new XDocument(new XDeclaration("1.0", "UTF-16", null),
                new XElement("Sync",
                    new XElement("Sync-data"),
                    new XElement("Consolidation-data")));

            foreach (TransData data in dataToSync)
            {
                if (data.state == (int)SyncState.ConsolidateOnly)
                {
                    GetConsolidationData(xDoc.Element("Sync").Element("Consolidation-data"), data);
                }
                else
                {
                    GetSyncData(xDoc.Element("Sync").Element("Sync-data"), data);
                }
            }

            xDoc.Element("Sync").Add(GetEmployeesToTransferToServer());
            return xDoc;
        }
Exemplo n.º 6
0
 public bool ServerIsAvailable(SystemUser user)
 {
     return LoginRemoteService(user);
 }
Exemplo n.º 7
0
        public List<TransData> GetDataToSync(SystemUser user)
        {
            using (SsepsIISynEntities ents = new SsepsIISynEntities())
            {
                //Mark them as exported
                foreach (TransData row in ents.TransDatas.Where(x => user.AssignedMdaIdList.Contains(x.MdaId) && x.state == (int)SyncState.Normal).ToList())
                {
                    row.state = (int)SyncState.Exported;
                }

                ents.SaveChanges();

                return ents.TransDatas.Where(x => user.AssignedMdaIdList.Contains(x.MdaId) &&
                    (x.state == (int)SyncState.Normal || x.state == (int)SyncState.Exported || x.state == (int)SyncState.ConsolidateOnly)).OrderBy(o => o.MdaId).ToList();

            }
        }
Exemplo n.º 8
0
 public string GetDataToSyncSecure(SystemUser user)
 {
     return Crypto.EncryptStringAES(GetDataToSyncXML(user).ToString(), SiteConfigServices.InstallationToken);
 }
Exemplo n.º 9
0
        public string GetApprovedDataToSyncSecure(List<int> mdaIdList, SystemUser user)
        {
            if (mdaIdList.Count == 0) return string.Empty;

            //TODO check that all these mda's are from the same installation
            if (LoginRemoteService(user))
            {
                InstallationServices installationServices = new InstallationServices();
                int siteId = installationServices.GetSiteIdFromMDAIdOnServer(mdaIdList.First());
                string feedback = syncProxy.SendApprovedData(_tokenHeader, siteId);
                XDocument xDoc = XDocument.Parse(Crypto.DecryptStringAES(feedback, installationServices.InstallationTokenBySiteId(siteId)));
                if ((bool)xDoc.Element("SecuredWebService").Attribute("success"))
                {
                    //TODO using .Value throws "Data at the root level is invalid. Line 1, position 1." exception
                    //investigate whether the server is using wrong encoding which can be a pain in the ass in future.
                    //However it seems using .ToString() solves it.
                    //string test = xDoc.Element("SecuredWebService").ToString();
                    //string test1 = xDoc.Element("SecuredWebService").Value;

                    XDocument xDocData = XDocument.Parse(xDoc.Element("SecuredWebService").Element("data").Element("Approved").ToString());
                    ImportApprovedData(xDocData);
                    return Crypto.EncryptStringAES(xDocData.ToString(), installationServices.InstallationTokenByMDAId(mdaIdList.First()));
                }
            }
            return string.Empty;
        }
Exemplo n.º 10
0
 private void SetLoggedInUserText(SystemUser user)
 {
     _lblLoggedInUser.Text = string.Format("Welcome {0} {1} {2}",user.GivenName, user.OtherNames, user.Surname);
 }
Exemplo n.º 11
0
 public static void Log(string callingObject,string callingMethode,string message, SystemUser user, int level = 3, string exception = null)
 {
     Log(callingObject,callingMethode, message, user.Username, level, exception);
 }
Exemplo n.º 12
0
 public void Login(string username, string password)
 {
     LoggedInUser = _systemUserServices.LogIn(username, password);
 }
Exemplo n.º 13
0
 public void Logout()
 {
     LoggedInUser = null;
 }