예제 #1
0
파일: Server.cs 프로젝트: baffled/bookstore
 public Boolean Execute(String cmd)
 {
     lock (_syncCall) {
         try {
             UniCommand c = _sess.CreateUniCommand();
             c.Command = cmd;
             c.Execute();
         } catch (Exception ex) {
             _lastError = ex.Message;
             return(false);
         }
     }
     return(true);
 }
예제 #2
0
        // constructor
        public U2DataReader(UniSession uSession, string fileName)
        {
            _uSession = uSession;

            try
            {
                uFile = _uSession.CreateUniFile(fileName);

                UniCommand uCmd = _uSession.CreateUniCommand();
                uCmd.Command = string.Format("SELECT {0} BY @ID SAMPLED 100", uFile.FileName);
                uCmd.Execute();
                usl        = _uSession.CreateUniSelectList(0);
                _keySample = usl.ReadListAsStringArray();

                RecordsAffected = 0;
            }
            catch (UniSessionException e)   // unisession file not exists
            {
                if (e.ErrorCode == 14002)
                {
                    Console.WriteLine("U2 file not found");
                }
                else
                {
                    // dont know, so rethrow
                    throw;
                }
            }
        }
예제 #3
0
 private void ExecuteCommand(U2Connection con)
 {
     try
     {
         if (settings.AccessMode == "Native")
         {
             // Native mode
             UniSession us1    = con.UniSession;
             UniCommand uniCmd = us1.CreateUniCommand();
             uniCmd.Command = settings.CommandText;
             uniCmd.Execute();
             // Get response string but not output
             string strNative = uniCmd.Response;
         }
         else
         {
             // SQL mode
             U2Command cmd = con.CreateCommand();
             cmd.Connection  = con;
             cmd.CommandText = settings.CommandText;
             cmd.ExecuteNonQuery();
         }
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
     finally
     {
     }
 }
        private static CssCommandResult Filter(string indexFile, string developerCode, string filterCriteria,
            AccountList saveListName, CssCredentials cssCredentials)
        {
            var result = new CssCommandResult();
            var lHostName = _cssHostname ?? cssCredentials.Hostname;
            var lAccount = _cssAccount ?? cssCredentials.Account;
            var lUser = _cssUserName ?? cssCredentials.User;
            var lPassword = _cssUserPassword ?? cssCredentials.UserPassword;
            const string lServiceType = CssServiceType;

            UniSession us = null;

            try
            {
                Console.WriteLine($"{lHostName}, {lUser}, {lAccount}, {lServiceType}");

                //get the session object
                us = UniObjects.OpenSession(lHostName, lUser, lPassword, lAccount, lServiceType);

                UniCommand cmd = us.CreateUniCommand();
                cmd.Command = $"SELECT {indexFile} WITH DEV.CODE = \"{developerCode}\"";
                cmd.Execute();
                result.Results.Add(new CommandResponse(cmd.Command, cmd.Response));

                cmd.Command = $"QSELECT {indexFile}";
                cmd.Execute();
                result.Results.Add(new CommandResponse(cmd.Command, cmd.Response));

                cmd.Command = filterCriteria;
                cmd.Execute();
                result.Results.Add(new CommandResponse(cmd.Command, cmd.Response));

                cmd.Command = $"SAVE-LIST {saveListName}";
                cmd.Execute();
                result.Results.Add(new CommandResponse(cmd.Command, cmd.Response));

                return result;

            }
            catch (Exception ex)
            {
                result.Results.Add(new CommandResponse("Exception", ex.ToString()));
            }
            finally
            {
                if (us != null && us.IsActive)
                {
                    UniObjects.CloseSession(us);
                }
            }

            result.Results.Add(new CommandResponse("Error", "There was an error procesing your request."));
            return result;
        }
        private static CssCommandResult MakeMultiNote(AccountList list, Note note, CssCredentials cssCredentials)
        {
            var result = new CssCommandResult();

            var          lHostName    = _cssHostname ?? cssCredentials.Hostname;
            var          lAccount     = _cssAccount ?? cssCredentials.Account;
            var          lUser        = _cssUserName ?? cssCredentials.User;
            var          lPassword    = _cssUserPassword ?? cssCredentials.UserPassword;
            const string lServiceType = CssServiceType;

            UniSession us = null;

            try
            {
                Console.WriteLine($"{lHostName}, {lUser}, {lAccount}, {lServiceType}");

                us = UniObjects.OpenSession(lHostName, lUser, lPassword, lAccount, lServiceType);

                UniCommand cmd = us.CreateUniCommand();
                cmd.Command = $"GET-LIST {list.AccountListName}";
                cmd.Execute();

                cmd.Command = "MULTI.NOTES";
                cmd.Execute();

                cmd.Reply($"{note.Message}");

                cmd.Reply("AGHERRERA");

                cmd.Reply("G");

                int lineNumber = 0;
                foreach (var line in cmd.Response.Split("\r\n"))
                {
                    result.Results.Add(new CommandResponse($"Response Line: {++lineNumber}", line));
                }

                return(result);
            }
            catch (Exception ex)
            {
                result.Results.Add(new CommandResponse("Exception", ex.ToString()));
            }
            finally
            {
                if (us != null && us.IsActive)
                {
                    UniObjects.CloseSession(us);
                }
            }

            result.Results.Add(new CommandResponse("Error", "There was an error procesing your request."));
            return(result);
        }
        private static CssCommandResult CustomGetList(IEnumerable<string> accountList, AccountList saveListName, CssCredentials cssCredentials)
        {
            var result = new CssCommandResult();
            var lHostName = _cssHostname ?? cssCredentials.Hostname;
            var lAccount = _cssAccount ?? cssCredentials.Account;
            var lUser = _cssUserName ?? cssCredentials.User;
            var lPassword = _cssUserPassword ?? cssCredentials.UserPassword;
            const string lServiceType = CssServiceType;

            UniSession us = null;

            try
            {
                Console.WriteLine($"{lHostName}, {lUser}, {lAccount}, {lServiceType}");
                //get the session object
                us = UniObjects.OpenSession(lHostName, lUser, lPassword, lAccount, lServiceType);

                UniCommand cmd = us.CreateUniCommand();
                cmd.Command = $"EDIT-LIST {saveListName.AccountListName}";
                cmd.Execute();
                result.Results.Add(new CommandResponse(cmd.Command, cmd.Response));

                cmd.Reply("I"); //Get list ready for insert

                foreach (var acct in accountList)
                {
                    if (!acct.Contains("=")) continue;
                    var account = acct.Split("=")[1].Replace("]","");
                    cmd.Reply($"{account}");
                }
                cmd.Reply(""); // Send empty marker to close list

                cmd.Reply("FI"); // Save list
                result.Results.Add(new CommandResponse(cmd.CommandStatus.ToString(), cmd.Response));

                return result;

            }
            catch (Exception ex)
            {
                result.Results.Add(new CommandResponse("Exception", ex.ToString()));
            }
            finally
            {
                if (us != null && us.IsActive)
                {
                    UniObjects.CloseSession(us);
                }
            }

            result.Results.Add(new CommandResponse("Error", "There was an error procesing your request."));
            return result;
        }
예제 #7
0
        static void Main(string[] args)
        {
            try
            {
                U2ConnectionStringBuilder conn_str = new U2ConnectionStringBuilder();
                conn_str.UserID         = "user";
                conn_str.Password       = "******";
                conn_str.Server         = "localhost";
                conn_str.Database       = "demo";
                conn_str.ServerType     = "UNIDATA";
                conn_str.AccessMode     = "Native"; // FOR UO
                conn_str.RpcServiceType = "udcs";   // FOR UO
                conn_str.Pooling        = false;
                string       s   = conn_str.ToString();
                U2Connection con = new U2Connection();
                con.ConnectionString = s;
                con.Open();
                Console.WriteLine("Connected.........................");


                UniSession us1 = con.UniSession;

                UniCommand cmd = us1.CreateUniCommand();
                cmd.Command = "LIST STUDENT ALL  SAMPLE 10";
                cmd.Execute();
                string response_str = cmd.Response;
                Console.WriteLine("UniCommand Output" + response_str + Environment.NewLine);

                con.Close();
            }
            catch (Exception e)
            {
                string s = e.Message;
                if (e.InnerException != null)
                {
                    s += e.InnerException.Message;
                }

                Console.WriteLine(s);
            }
            finally
            {
                Console.WriteLine("Enter to exit:");
                string line = Console.ReadLine();
            }
        }
예제 #8
0
        /// <summary>
        /// Get native string in Native mode
        /// </summary>
        /// <param name="conStrBdr"></param>
        /// <param name="strFileName"></param>
        /// <returns></returns>
        private string GetNativeString(U2ConnectionStringBuilder conStrBdr, string strFileName)
        {
            try
            {
                U2Connection con = new U2Connection();
                con.ConnectionString = conStrBdr.ToString();
                con.Open();

                string strInfo = string.Format("Connected......{0}{0}", Environment.NewLine);
                // 0 is meaningless
                bwkRetrieve.ReportProgress(0, strInfo);
                string     strNative = string.Empty;
                UniSession us1       = con.UniSession;
                UniCommand cmd       = us1.CreateUniCommand();

                // List no more than 10 records for sample
                if (conStrBdr.ServerType == "UNIDATA")
                {
                    cmd.Command = string.Format("LIST {0} ALL SAMPLE 10", strFileName);
                }
                else
                {
                    cmd.Command = string.Format("LIST {0} SAMPLE 10", strFileName);
                }
                cmd.Execute();

                if (cmd.Response != null)
                {
                    strNative = cmd.Response.Trim();
                }

                con.Close();
                return(strNative);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
예제 #9
0
        public bool Read()
        {
            if (_keySample == null)
            {
                return(false);
            }

            if ((_blockIdx > _keySample.Length) || (Limit > 0 && RecordsAffected >= Limit))
            {
                return(false);
            }

            if (0 == _rowIdx)
            {
                UniCommand uCmd = _uSession.CreateUniCommand();

                _keyBlock = null;
                while (_keyBlock == null)
                {
                    uCmd.Command = string.Format("SELECT {0} BY @ID", uFile.FileName);

                    if (_blockIdx > 0)
                    {
                        uCmd.Command += string.Format(" WITH @ID >= \"{0}\"",
                                                      _keySample[_blockIdx - 1].Replace("\"", "\"\""));
                    }


                    if (_blockIdx < _keySample.Length)
                    {
                        if (_blockIdx > 0)
                        {
                            uCmd.Command += " AND ";
                        }
                        else
                        {
                            uCmd.Command += " WITH ";
                        }

                        uCmd.Command += string.Format("@ID < \"{0}\"", _keySample[_blockIdx].Replace("\"", "\"\""));
                    }

                    uCmd.Execute();
                    usl       = _uSession.CreateUniSelectList(0);
                    _keyBlock = usl.ReadListAsStringArray();
                    if (_keyBlock == null)
                    {
                        _blockIdx++;
                    }
                }
                // Console.Write(_keyBlock.ToString());
                _uds = uFile.ReadRecords(_keyBlock);
            }

            if (_rowIdx < _keyBlock.Length)
            {
                _row.Clear();

                _row.Add(_keyBlock[_rowIdx]);
                _row.Add(_uds.GetRecord(_rowIdx).Record.ToString());

                _rowIdx++;
                if (_rowIdx == _keyBlock.Length)
                {
                    _rowIdx = 0;
                    _blockIdx++;
                }
            }

            RecordsAffected++;

            return(true);



            /*
             * try
             * {
             *
             * if (0 == i)
             * value = key;
             * else
             * {
             * var fld = udaRow.Extract(i).ToString();
             * if ("" != fld)
             * {
             * var xf = new XElement("fld" / *, new XAttribute("loc", i) * /);
             * for (var v = 1; v <= udaRow.Dcount(i); v++)
             * {
             * / *
             * XElement xv = new XElement("val", new XAttribute("loc", v));
             * string val = udaRow.Extract(i, v).ToString();
             * if ("" != val)
             * {
             * for (int s = 1; s <= udaRow.Dcount(i, v); s++)
             * {
             *  xv.Add(new XElement("sub", new XAttribute("loc", s), udaRow.Extract(i, v, s).ToString()));
             * }
             * }
             * xf.Add(xv);
             * /
             *
             * var val = udaRow.Extract(i, v).ToString();
             *
             *
             * //replace control characters that are invalid in xml with empty string
             * var re = @"[^\x09\x0A\x0D\x20-\xD7FF\xE000-\xFFFD\x10000-x10FFFF]";
             * val = Regex.Replace(val, re, "");
             *
             * // replace text and subtext remarks with carriage return
             * re = @"[\xFB\xFC]";
             * val = Regex.Replace(val, re, "\n");
             * //const string TM_CHAR = "\xFB";
             * //const string SM_CHAR = "\xFC";
             * //val.Replace(SM_CHAR, "\n");
             * //val.Replace(TM_CHAR, "\n");
             *
             * xf.Add(new XElement("val", new XAttribute("loc", v), val));
             * }
             * value = xf.ToString();
             * }
             * }
             * }
             * catch (Exception e)
             * {
             * Console.WriteLine(e.ToString());
             * }
             * if (null == value)
             * return DBNull.Value;
             * else
             * return value;
             *     */
        }
예제 #10
0
        private static CssCommandResult ChangeIt2(CssAccountFile file, AccountList list, string developerCode, string projectCode, string lenderCode, string accountCode, Note changeNote, CssCredentials cssCredentials)
        {
            var result = new CssCommandResult();

            var          lHostName    = _cssHostname ?? cssCredentials.Hostname;
            var          lAccount     = _cssAccount ?? cssCredentials.Account;
            var          lUser        = _cssUserName ?? cssCredentials.User;
            var          lPassword    = _cssUserPassword ?? cssCredentials.UserPassword;
            const string lServiceType = CssServiceType;

            string     fileInitial = file.FileName.ToCharArray() [0].ToString();
            UniSession us          = null;

            try {
                Console.WriteLine($"{lHostName}, {lUser}, {lAccount}, {lServiceType}");

                //get the session object
                us = UniObjects.OpenSession(lHostName, lUser, lPassword, lAccount, lServiceType);

                UniCommand cmd = us.CreateUniCommand();
                cmd.Command = "CHANGE.IT2";
                cmd.Execute();
                //result.Results.Add(new CommandResponse(cmd.Command, cmd.Response));

                //ENTER THE LIST NAME YOU ARE USING
                cmd.Reply($"{list.AccountListName}");
                //result.Results.Add(new CommandResponse("", cmd.Response));

                //'C'ONTRACT OR 'M'AINTENANCE IDS? ?
                cmd.Reply($"{fileInitial}");
                //result.Results.Add(new CommandResponse($"{fileInitial}", cmd.Response));

                //CHANGE MAINTENANCE TOO? (IF APPLICABLE) ?
                cmd.Reply("N");
                //result.Results.Add(new CommandResponse("N", cmd.Response));

                //ENTER NEW DEVELOPER CODE, IF ANY ?
                if (!string.IsNullOrEmpty(developerCode))
                {
                    cmd.Reply($"{developerCode}");
                    //result.Results.Add(new CommandResponse($"{developerCode}", cmd.Response));

                    //WARNING: Dev Code changes may cause conflict with legal agreements.\r\n
                    //Is our legal department aware of new dev/len relationships? (Y/N)
                    cmd.Reply("Y");
                    //result.Results.Add(new CommandResponse("Legal Department", cmd.Response));
                }
                else
                {
                    cmd.Reply($"{developerCode}");
                    //result.Results.Add(new CommandResponse($"{projectCode}", cmd.Response));
                }

                //Project?
                cmd.Reply($"{projectCode}");
                //result.Results.Add(new CommandResponse($"{projectCode}", cmd.Response));

                //Lender
                cmd.Reply($"{lenderCode}");
                //result.Results.Add(new CommandResponse($"{lenderCode}", cmd.Response));

                //AccountCode
                cmd.Reply($"{accountCode}");
                //result.Results.Add(new CommandResponse($"{accountCode}", cmd.Response));

                //Note
                cmd.Reply($"{changeNote.Message}");
                //result.Results.Add(new CommandResponse($"{changeNote.Message}", cmd.Response));

                //Note Type
                cmd.Reply("G");
                //result.Results.Add(new CommandResponse($"NoteType", cmd.Response));

                if (cmd.Response.Contains("OKAY TO PROCEED? (Y/N)"))
                {
                    //OKAY TO PROCEED? (Y/N)
                    cmd.Reply("Y");
                }
                else
                {
                    throw new Exception($"Could not get confirmation message. Raw result: {cmd.Response}");
                }

                int lineNumber = 0;
                foreach (var line in cmd.Response.Split("\r\n"))
                {
                    result.Results.Add(new CommandResponse($"Response Line: {++lineNumber}", line));
                }

                return(result);
            } catch (Exception ex) {
                result.Results.Add(new CommandResponse("Exception", ex.ToString()));
            } finally {
                if (us != null && us.IsActive)
                {
                    UniObjects.CloseSession(us);
                }
            }

            result.Results.Add(new CommandResponse("Error", "There was an error procesing your request."));
            return(result);
        }