Example #1
0
        /// <summary>
        /// WSClient
        /// </summary>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        /// <param name="subProtocol"></param>
        /// <param name="origin"></param>
        /// <param name="bufferSize"></param>
        public WSClient(string ip = "127.0.0.1", int port = 16666, string subProtocol = SubProtocolType.Default, string origin = "", int bufferSize = 10 * 1024)
        {
            _serverIP   = ip;
            _serverPort = port;

            if (string.IsNullOrEmpty(_url))
            {
                _url = $"ws://{ip}:{port}/";
            }

            _origin = origin;

            _wsContext = new WSContext();

            var option = SocketOptionBuilder.Instance
                         .UseIocp(_wsContext)
                         .SetIP(ip)
                         .SetPort(port)
                         .SetReadBufferSize(bufferSize)
                         .SetReadBufferSize(bufferSize)
                         .Build();

            _subProtocol = subProtocol;

            _client = SocketFactory.CreateClientSocket(option);

            _client.OnReceive      += _client_OnReceive;
            _client.OnDisconnected += WSClient_OnDisconnected;
            _client.OnError        += WSClient_OnError;
        }
Example #2
0
 /// <summary>
 /// 有新用户连接过来并且成功完成了握手等操作
 /// </summary>
 /// <param name="content">与新连接绑定的"会话对象"</param>
 protected override void OnAccept(WSContext content)
 {
     // 可以做一些初始化工作,比如登记客户IP地址之类的事情
     // var rip = content.RemoteIpAddress;
     // var url = content.RequestPath;
     // content.Tag = "xxx";
 }
Example #3
0
 public NoteService(ILoggerFactory logger,
                    IUserService user,
                    WSContext wsContext)
 {
     _logger    = logger?.CreateLogger <NoteService>() ?? throw new ArgumentNullException("Logger factory is null");
     _user      = user ?? throw new ArgumentNullException("User service is null");
     _wsContext = wsContext ?? throw new ArgumentNullException("Webserver context is null");
 }
Example #4
0
        /// <summary>
        /// 接到到了数据的事件
        /// </summary>
        /// <param name="content">会话对象</param>
        /// <param name="message">消息内容</param>
        protected override void OnMessage(WSContext content, string message)
        {
            //约定:如果客户端发来 "exit" "close" 字串
            //服务器就关闭这个连接
            if (message == "exit" || message == "close")
            {
                //服务器关闭会话
                content.Close();
                return;
            }

            //回应客户端发送过来的内容
            content.SendMessage(message);
        }
        /// <summary>
        /// Connection strings and database setup for the application
        /// </summary>
        /// <param name="services"></param>
        /// <param name="config"></param>
        public static void AddCustomDataStore(this IServiceCollection services, IConfiguration config)
        {
            string userConnectionString      = config.GetConnectionString("UserDbConnectionString");
            string webServerConnectionString = config.GetConnectionString("WebServerDbConnectionString");

            DatabaseTypes dbType = (DatabaseTypes)config.GetValue <int>("Options:DatabaseType");

            if (dbType == DatabaseTypes.MSSQLSERVER)
            {
                using (var client = new UserContext(new DbContextOptionsBuilder <UserContext>().UseSqlServer(userConnectionString, a => a.MigrationsAssembly("VueServer")).Options))
                {
                    client.Database.EnsureCreated();
                }

                using (var client = new WSContext(new DbContextOptionsBuilder <WSContext>().UseSqlServer(webServerConnectionString, a => a.MigrationsAssembly("VueServer")).Options))
                {
                    client.Database.Migrate();
                }

                services.AddEntityFrameworkSqlServer().AddDbContext <UserContext>
                    (options => options.UseSqlServer(userConnectionString, a => a.MigrationsAssembly("VueServer")), ServiceLifetime.Scoped);

                services.AddEntityFrameworkSqlServer().AddDbContext <WSContext>
                    (options => options.UseSqlServer(webServerConnectionString, a => a.MigrationsAssembly("VueServer")), ServiceLifetime.Scoped);
            }
            else if (dbType == DatabaseTypes.SQLITE)
            {
                using (var client = new UserContext(new DbContextOptionsBuilder <UserContext>().UseSqlite(userConnectionString, a => a.MigrationsAssembly("VueServer")).Options))
                {
                    client.Database.EnsureCreated();
                }

                using (var client = new WSContext(new DbContextOptionsBuilder <WSContext>().UseSqlite(webServerConnectionString, a => a.MigrationsAssembly("VueServer")).Options))
                {
                    client.Database.Migrate();
                }

                services.AddEntityFrameworkSqlite().AddDbContext <UserContext>
                    (options => options.UseSqlite(userConnectionString, a => a.MigrationsAssembly("VueServer")), ServiceLifetime.Scoped);

                services.AddEntityFrameworkSqlite().AddDbContext <WSContext>
                    (options => options.UseSqlite(webServerConnectionString, a => a.MigrationsAssembly("VueServer")), ServiceLifetime.Scoped);
            }
        }
Example #6
0
        public string getWSProjName(string WSurl, string projNumber)
        {
            string projName   = "";
            string WSuserName = ConfigurationSettings.AppSettings["WS_USR"];
            string WSpwd      = ConfigurationSettings.AppSettings["WS_PWD"];

            WSContext         ctx         = new WSContext(WSuserName, WSpwd, WSurl);
            WSWorkflowManager workflowMgr = ctx.getWorkflowManager();
            int intProjNumber             = Int32.Parse(projNumber);

            if (workflowMgr.getProjectGroup(intProjNumber) == null)
            {
                return("Project does not exist");
            }
            else
            {
                projName = workflowMgr.getProjectGroup(intProjNumber).getName;
            }
            return(projName);
        }
Example #7
0
        public WSClient(string ip = "127.0.0.1", int port = 39654, int bufferSize = 10 * 1024)
        {
            _serverIP   = ip;
            _serverPort = port;
            _bufferSize = bufferSize;
            _buffer     = new byte[_bufferSize];

            _wsContext = new WSContext();

            var option = SocketOptionBuilder.Instance
                         .UseIocp(_wsContext)
                         .SetIP(ip)
                         .SetCount(port)
                         .SetReadBufferSize(bufferSize)
                         .SetReadBufferSize(bufferSize)
                         .Build();

            _client = SocketFactory.CreateClientSocket(option);

            _client.OnReceive      += _client_OnReceive;
            _client.OnDisconnected += WSClient_OnDisconnected;
            _client.OnError        += WSClient_OnError;
        }
Example #8
0
        private static async Task testItemListAsync()
        {
            string aspKey      = "micpg";
            string customerKey = "kupac";
            string password    = "******";
            string cookie      = "39983830859dJFaogrSxpgIcfvfy1T";

            System.IO.FileInfo f = new FileInfo(String.Format(@"C:\Temp\itemList_{0}.xml", DateTime.Now.ToString("ddMMyyyy_HH_mm")));

            using (StreamWriter sw = f.AppendText())
            {
                try
                {
                    WSContext ctx    = new WSContext(aspKey, customerKey, password, @"http://www.microline.hr/WebServices/MOL.asmx", @"C:\Temp", cookie);
                    WSClient  client = new WSClient(ctx);
                    var       report = await client.GetItemsFilteredAsync(null, "sam", "itemsFilteredSam");

                    sw.WriteLine(report);
                }
                catch (Exception ex)
                {
                    sw.WriteLine(ex.Message);
                    sw.WriteLine(ex.StackTrace);
                    if (ex.InnerException != null)
                    {
                        sw.WriteLine(ex.InnerException.Message);
                        sw.WriteLine(ex.InnerException.StackTrace);

                        if (ex.InnerException.InnerException != null)
                        {
                            sw.WriteLine(ex.InnerException.InnerException.Message);
                            sw.WriteLine(ex.InnerException.InnerException.StackTrace);
                        }
                    }
                }
            }
        }
Example #9
0
 public EfProductService(WSContext context) : base(context)
 {
 }
Example #10
0
 static OrdersController()
 {
     context = new WSContext(connectionString);
 }
Example #11
0
 public AccountsController(WSContext context)
 {
     _context = context;
 }
Example #12
0
 public EfCustomerService(WSContext context) : base(context)
 {
 }
Example #13
0
 public EfOrderDetailService(WSContext context) : base(context)
 {
 }
Example #14
0
        /// <summary>
        /// 数据发送完成的事件
        /// </summary>
        /// <param name="content">会话对象</param>
        protected override void OnSendComplete(WSContext content)
        {
            // your code ...

            /// ..... ////
        }
Example #15
0
 /// <summary>
 /// 客户端关闭连接事件
 /// </summary>
 /// <param name="content">会话对象</param>
 protected override void OnClose(WSContext content)
 {
     // your code;
 }
Example #16
0
 public InscritosController(WSContext context)
 {
     _context = context;
 }
Example #17
0
 static ProductsController()
 {
     context = new WSContext(connectionString);
 }
Example #18
0
 public EfEntityService(WSContext context)
 {
     this.context = context;
 }
Example #19
0
        public string[] getScopeInfo(string srcName, string projName, string projDescription, string file, Code srcLocale, Code[] dstLocales, int localeCount, string datatype, BaseExtendable mtdProject, IMTDService service, string WS_Client_Name, string Project_Type, string quoteType, string WSurl, string ProjectNum, string[] projectAttribs)
        {
            string retVal        = "success";
            string FILE_NAME     = "473263";
            string workgroupName = "default";
            string workflowName  = "1. Translation Only";

            string[] entityIIDArray = new string[4];
            string   update         = "no";
            string   review         = "no";
            string   client_review  = "no";

            if (projectAttribs != null)
            {
                foreach (string projectAtrib in projectAttribs)
                {
                    if (projectAtrib == "update")
                    {
                        update = "yes";
                    }
                    else if (projectAtrib == "review")
                    {
                        review = "yes";
                    }
                    else if (projectAtrib == "client_review")
                    {
                        client_review = "yes";
                    }
                }
            }
            projName = projName.Replace("\\", "-");
            projName = projName.Replace("/", "-");
            projName = projName.Replace(":", "-");
            string src_asset  = srcName.Replace("\\", "/");
            string WSuserName = ConfigurationSettings.AppSettings["WS_USR"];
            string WSpwd      = ConfigurationSettings.AppSettings["WS_PWD"];

            WSContext ctx = new WSContext(WSuserName, WSpwd, WSurl); //http://172.20.20.36:8585/ws/services

            string debugLine = DateTime.Now + " Got WS context "; WriteDebugfile(debugLine);

            debugLine = DateTime.Now + " source asset name = " + src_asset; WriteDebugfile(debugLine);

            WSAisManager      aisManager  = ctx.getAisManager();
            WSUserManager     userMgr     = ctx.getUserManager();
            WSAssetManager    assetMgr    = ctx.getAssetManager();
            WSWorkflowManager workflowMgr = ctx.getWorkflowManager();
            WSQuoteManager    quoteMgr    = ctx.getQuoteManager();
            WSScopeManager    scopeMgr    = ctx.getScopeManager();
            Code mdlCode = null;

            Base.Text codeID = null;
            int       ID     = 0;

            codeID = srcLocale.Description_TID;
            ID     = Convert.ToInt32(codeID.Text_IID.ToString());

            debugLine = DateTime.Now + " Got src locale id= " + ID.ToString(); WriteDebugfile(debugLine);
            WSLocale wslocale = null;

            if (WS_Client_Name == "Seagate")
            {
                wslocale = userMgr.getLocale2(GetSeagateLocID(ID));
            }
            else
            {
                wslocale = userMgr.getLocale2(ID);
            }

            if (wslocale == null)
            {
                throw new System.InvalidOperationException("Invalid src locale");
            }

            try
            {
                WSWorkgroup workgroup = userMgr.getWorkgroup(workgroupName);
                WSWorkflow  workflow  = workflowMgr.getWorkflow(workflowName);
                //int pId = 13066;

                //tokenize dest locales
                //char[] sep = { ';' };
                //String[] res = dstLocales.Split(sep);
                int        numLocs = localeCount; //dstLocales.Length;
                WSLocale[] locales = null;
                Code       targCode;
                locales = new WSLocale[numLocs];
                for (int i = 0; i < numLocs; i++)
                {
                    //string localeName = res[i].Trim();
                    targCode  = dstLocales[i];
                    debugLine = DateTime.Now + " Got target locale code= " + targCode; WriteDebugfile(debugLine);
                    if (targCode != null)
                    {
                        //mdlCode = Code.FindAltType("LOC", localeName);
                        codeID    = targCode.Description_TID;
                        debugLine = DateTime.Now + " Got target locale codeID= " + codeID; WriteDebugfile(debugLine);
                        ID        = Convert.ToInt32(codeID.Text_IID.ToString());
                        debugLine = DateTime.Now + " Got target locale id= " + ID.ToString(); WriteDebugfile(debugLine);
                        WSLocale locale = null;
                        if (WS_Client_Name == "Seagate")
                        {
                            locale = userMgr.getLocale2(GetSeagateLocID(ID));
                        }
                        else
                        {
                            locale = userMgr.getLocale2(ID);
                        }
                        locales[i] = locale;
                        if (locale == null)
                        {
                            throw new System.InvalidOperationException("Error in target locale " + locale);
                        }
                    }
                    else
                    {
                        throw new System.InvalidOperationException("Error in target code " + targCode);
                    }
                }
                if (locales[0] == null)
                {
                    throw new System.InvalidOperationException("No target locales defined");
                }
//                WSClient[] ctxclients = ctx.getUser.get.getClients();
                WSWorkflow    DefaultWF   = null;
                WSTm          DefaultTm   = null;
                WSClient      client      = userMgr.getClient(WS_Client_Name);
                WSProjectType projectType = null;
//                for (int o = 0; o < ctxclients.Length; o++)
//               {

                if (!(client == null))
                {
//                        client = ctxclients[o];

//                        WSProjectType[] ctxtypes = client.;

                    String inProjType = Project_Type.Trim();
//                        inProjType = inProjType.Replace(" ","");
                    projectType = workflowMgr.getProjectType(inProjType);
                    if (projectType == null)
                    {
                        throw new System.InvalidOperationException("No match in WS found for project type " + Project_Type);
                    }
//                       for (int p = 0; p < ctxtypes.Length; p++)
//                       {
//                           String projType = ctxtypes[p].getName.Trim();
//                           projType = projType.Replace(" ","");
//                           //if (String.Compare(projType, Project_Type) == 0)
//                           if (projType.Equals(inProjType) )
//                           {
//                                projectType = ctxtypes[p];
                    DefaultWF = projectType.getDefaultWorkflow;
                    DefaultTm = projectType.getDefaultTm;
                    debugLine = DateTime.Now + " Got project type " + projectType.getDisplayString; WriteDebugfile(debugLine);

//                                break;
//                            }
//
//                       }
                }
                else
                {
                    throw new System.InvalidOperationException("Client Name does not exist \"" + WS_Client_Name + "\"");
                }

//                }


                string[] attachedFile = new string[1];
                attachedFile[0] = src_asset;  //file to 'attach' to project
                string[] custom = new string[2];
                custom[0] = null;
                custom[1] = null; //custom ais properties

                try
                {
                    string clientPath = "/Client Files/" + WS_Client_Name;
                    if (clientPath == null)
                    {
                        debugLine = DateTime.Now + " Parameter clientPath cannot be null = " + clientPath; WriteDebugfile(debugLine);
                        throw new System.ArgumentException("Parameter clientPath cannot be null", clientPath);
                    }
                    WSNode clientNode     = aisManager.getNode(clientPath);
                    string clientTempPath = clientPath + "/Temp";
                    if (clientTempPath == null)
                    {
                        aisManager.create(clientTempPath, clientNode);
                    }
                    WSNode clientTempNode = aisManager.getNode(clientTempPath);
                    string aisPath        = clientTempPath + "/Upload";
                    if (aisPath == null)
                    {
                        aisManager.create(aisPath, clientTempNode);
                    }
                    string         oldPath      = aisPath;
                    WSNode         oldNode      = aisManager.getNode(oldPath);
                    WSProjectGroup projectGroup = workflowMgr.createProjectGroup(ProjectNum + "-" + WS_Client_Name + "-" + projName, projDescription, locales, attachedFile, client, projectType, custom);
                    WSProject[]    theProjects  = projectGroup.getProjects;
                    foreach (WSProject theProject in theProjects)
                    {
                        theProject.setAttribute("update", update);
                        theProject.setAttribute("review", review);
                        theProject.setAttribute("creview", client_review);

                        //string theLocaleString = "Target-" + theProject.getTargetLocale.getDisplayString;
                        //WSTask[] theProjectTasks = theProject.getTasks();
                        //string theNodeString = "";
                        //string [] theNodeStringArray = theProjectTasks[0].getTargetPath.Split('/');
                        //int countHolder = 0;
                        //for (int i = theNodeStringArray.Length -1; theNodeStringArray.Length > 0; i--)
                        //{
                        //    if ( theNodeStringArray[i].Equals(theLocaleString))
                        //    {
                        //        countHolder = i;
                        //        break;
                        //    }
                        //}

                        //for (int j=1; j <= countHolder; j++)
                        //{
                        //    theNodeString += "/" + theNodeStringArray[j];
                        //}
                    }


                    debugLine      = DateTime.Now + " Created WS Project Group = " + projectGroup.getId; WriteDebugfile(debugLine);
                    entityIIDArray = createProjectScope(mtdProject, service, projectGroup, projName, projDescription, locales, attachedFile, client, projectType);
                }
                catch (Exception e)
                {
                    debugLine = DateTime.Now + " " + e.Message; WriteDebugfile(debugLine);
                    throw new System.InvalidOperationException(e.Message);
                }
            }
            catch (Exception e)
            {
                throw new System.InvalidOperationException(e.Message);
            }
            return(entityIIDArray);
        }
Example #20
0
 static CustomersController()
 {
     context = new WSContext(connectionString);
 }