コード例 #1
0
        private void frmPrimWorkshop_Shown(object sender, EventArgs e)
        {
            SetupGLControl();

            WorkPool.QueueUserWorkItem(sync =>
            {
                if (Client.Network.CurrentSim.ObjectsPrimitives.ContainsKey(RootPrimLocalID))
                {
                    UpdatePrimBlocking(Client.Network.CurrentSim.ObjectsPrimitives[RootPrimLocalID]);
                    var children = Client.Network.CurrentSim.ObjectsPrimitives.FindAll((Primitive p) => { return(p.ParentID == RootPrimLocalID); });
                    children.ForEach(p => UpdatePrimBlocking(p));
                }
            }
                                       );
        }
コード例 #2
0
ファイル: UpdateChecker.cs プロジェクト: CasperTech/radegast
        public void StartCheck()
        {
            if (client == null)
            {
                client = new WebClient();
                client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(OnDownloadStringCompleted);
            }

            WorkPool.QueueUserWorkItem((object state) =>
            {
                if (Properties.Resources.UpdateCheckUri != "")
                {
                    client.DownloadStringAsync(new Uri(Properties.Resources.UpdateCheckUri));
                }
            }
                                       );
        }
コード例 #3
0
ファイル: Notification.cs プロジェクト: somsomsomi/radegast
 protected void FireNotificationCallback(NotificationEventArgs e)
 {
     if (OnNotificationDisplayed == null)
     {
         return;
     }
     try
     {
         e.Type = this.Type;
         WorkPool.QueueUserWorkItem((object o) => Notificaton_Displayed(this, e));
     }
     catch (Exception ex)
     {
         Console.WriteLine("" + ex);
         OpenMetaverse.Logger.Log("Error executing notification callback", OpenMetaverse.Helpers.LogLevel.Warning, ex);
     }
 }
コード例 #4
0
ファイル: RenderTerrain.cs プロジェクト: somsomsomi/radegast
        void UpdateTerrainTexture()
        {
            if (!fetchingTerrainTexture)
            {
                fetchingTerrainTexture = true;
                WorkPool.QueueUserWorkItem(sync =>
                {
                    Simulator sim = Client.Network.CurrentSim;
                    terrainImage  = TerrainSplat.Splat(Instance, heightTable,
                                                       new UUID[] { sim.TerrainDetail0, sim.TerrainDetail1, sim.TerrainDetail2, sim.TerrainDetail3 },
                                                       new float[] { sim.TerrainStartHeight00, sim.TerrainStartHeight01, sim.TerrainStartHeight10, sim.TerrainStartHeight11 },
                                                       new float[] { sim.TerrainHeightRange00, sim.TerrainHeightRange01, sim.TerrainHeightRange10, sim.TerrainHeightRange11 });

                    fetchingTerrainTexture    = false;
                    terrainTextureNeedsUpdate = false;
                });
            }
        }
コード例 #5
0
        public void AddWork(IModel model, Action fn)
        {
            // two step approach is taken, as TryGetValue does not aquire locks
            // if this fails, GetOrAdd is called, which takes a lock

            if (workPools.TryGetValue(model, out WorkPool workPool) == false)
            {
                var newWorkPool = new WorkPool(model);
                workPool = workPools.GetOrAdd(model, newWorkPool);

                // start if it's only the workpool that has been just created
                if (newWorkPool == workPool)
                {
                    newWorkPool.Start();
                }
            }

            workPool.Enqueue(fn);
        }
コード例 #6
0
        public void Schedule <TWork>(ModelBase model, TWork work)
            where TWork : Work
        {
            // two step approach is taken, as TryGetValue does not aquire locks
            // if this fails, GetOrAdd is called, which takes a lock

            if (workPools.TryGetValue(model, out WorkPool workPool) == false)
            {
                var newWorkPool = new WorkPool(model);
                workPool = workPools.GetOrAdd(model, newWorkPool);

                // start if it's only the workpool that has been just created
                if (newWorkPool == workPool)
                {
                    newWorkPool.Start();
                }
            }

            workPool.Enqueue(work);
        }
コード例 #7
0
        public void Start(int?numberOfWorkers = null)
        {
            int workers = numberOfWorkers.HasValue
                ? numberOfWorkers.Value
                : NumberOfWorkers;

            pools.Clear();
            foreach (var endpointDefinition in transport.EndpointFactory.GetEndpointDefinition(this, subscriptions))
            {
                var      poolName = String.Format("Workpool {0}", endpointDefinition.EndpointName);
                WorkPool pool     = new WorkPool(poolName, workers);
                for (int i = 0; i < workers; i++)
                {
                    IEndpoint endpoint = transport.EndpointFactory.CreateEndpoint(endpointDefinition);
                    pool.AddWork(new PipelineConsumerWork(subscriptions, endpoint, serializer, messageThreshold));
                }
                pools.Add(pool);
                pool.StartCrawlers();
            }
        }
コード例 #8
0
        public void AddWork(IModel model, Action fn)
        {
            // two step approach is taken, as TryGetValue does not aquire locks
            // if this fails, GetOrAdd is called, which takes a lock

            WorkPool workPool;
            if (workPools.TryGetValue(model, out workPool) == false)
            {
                var newWorkPool = new WorkPool(model);
                workPool = workPools.GetOrAdd(model, newWorkPool);

                // start if it's only the workpool that has been just created
                if (newWorkPool == workPool)
                {
                    newWorkPool.Start();
                }
            }

            workPool.Enqueue(fn);
        }
コード例 #9
0
        public void Start(int?numberOfWorkers = null)
        {
            ConsumerStart();
            int workers = numberOfWorkers.HasValue ? numberOfWorkers.Value : NumberOfWorkers;

            pools.Clear();

            foreach (var factory in transport.GetAvailableConsumers(serializer, subscriptions, Name))
            {
                var      poolName = string.Format("cronus: " + Name);
                WorkPool pool     = new WorkPool(poolName, workers);
                for (int i = 0; i < workers; i++)
                {
                    pool.AddWork(factory.CreateConsumer());
                }
                pools.Add(pool);
                pool.StartCrawlers();
            }

            ConsumerStarted();
        }
コード例 #10
0
        void Friends_FriendshipTerminated(object sender, FriendshipTerminatedEventArgs e)
        {
            WorkPool.QueueUserWorkItem(sync =>
            {
                string name           = instance.Names.Get(e.AgentID, true);
                MethodInvoker display = () =>
                {
                    DisplayNotification(e.AgentID, name + " is no longer on your friend list");
                    RefreshFriendsList();
                };

                if (InvokeRequired)
                {
                    BeginInvoke(display);
                }
                else
                {
                    display();
                }
            });
        }
コード例 #11
0
ファイル: Profile.cs プロジェクト: CasperTech/radegast
        private void btnNewPick_Click(object sender, EventArgs e)
        {
            WorkPool.QueueUserWorkItem(sync =>
            {
                UUID parcelID = client.Parcels.RequestRemoteParcelID(client.Self.SimPosition, client.Network.CurrentSim.Handle, client.Network.CurrentSim.ID);
                newPickID     = UUID.Random();

                client.Self.PickInfoUpdate(
                    newPickID,
                    false,
                    parcelID,
                    Instance.State.Parcel.Name,
                    client.Self.GlobalPosition,
                    Instance.State.Parcel.SnapshotID,
                    Instance.State.Parcel.Desc
                    );

                Invoke(new MethodInvoker(() => ClearPicks()));
                client.Avatars.RequestAvatarPicks(agentID);
            });
        }
コード例 #12
0
ファイル: DisplayNameChange.cs プロジェクト: TsengSR/Radegast
 private void StartDisplayNameChage(string name)
 {
     WorkPool.QueueUserWorkItem(sync =>
     {
         Client.Avatars.GetDisplayNames(new List <UUID>()
         {
             Client.Self.AgentID
         },
                                        (success, names, badIDs) =>
         {
             if (!success || names.Length < 1)
             {
                 UpdateStatus("Failed to get curret name");
             }
             else
             {
                 Client.Self.SetDisplayName(names[0].DisplayName, name);
             }
         }
                                        );
     }
                                );
 }
コード例 #13
0
ファイル: LSLHelper.cs プロジェクト: TsengSR/Radegast
        /// <summary>
        /// Dispatcher for incoming IM automation
        /// </summary>
        /// <param name="e">Incoming message</param>
        /// <returns>If message processed correctly, should GUI processing be halted</returns>
        public bool ProcessIM(InstantMessageEventArgs e)
        {
            LoadSettings();

            if (!Enabled)
            {
                return(false);
            }

            switch (e.IM.Dialog)
            {
            case InstantMessageDialog.MessageFromObject:
            {
                if (!AllowedOwners.Contains(e.IM.FromAgentID.ToString()))
                {
                    return(true);
                }
                string[] args = e.IM.Message.Trim().Split('^');
                if (args.Length < 1)
                {
                    return(false);
                }

                switch (args[0].Trim())
                {
                case "group_invite":
                {
                    if (args.Length < 4)
                    {
                        return(false);
                    }
                    ProcessInvite(args);
                    return(true);
                }

                case "send_im":
                {
                    if (args.Length < 3)
                    {
                        return(false);
                    }
                    UUID sendTo = UUID.Zero;
                    if (!UUID.TryParse(args[1].Trim(), out sendTo))
                    {
                        return(false);
                    }
                    string msg = args[2].Trim();
                    client.Self.InstantMessage(sendTo, msg);
                    return(true);
                }

                case "give_inventory":
                {
                    if (args.Length < 3)
                    {
                        return(false);
                    }
                    UUID sendTo    = UUID.Zero;
                    UUID invItemID = UUID.Zero;
                    if (!UUID.TryParse(args[1].Trim(), out sendTo))
                    {
                        return(false);
                    }
                    if (!UUID.TryParse(args[2].Trim(), out invItemID))
                    {
                        return(false);
                    }
                    if (!client.Inventory.Store.Contains(invItemID))
                    {
                        instance.TabConsole.DisplayNotificationInChat(
                            string.Format("Tried to offer {0} but could not find it in my inventory", invItemID),
                            ChatBufferTextStyle.Error);
                        return(false);
                    }
                    InventoryItem item = client.Inventory.Store[invItemID] as InventoryItem;
                    if (item == null)
                    {
                        return(false);
                    }
                    client.Inventory.GiveItem(item.UUID, item.Name, item.AssetType, sendTo, true);
                    WorkPool.QueueUserWorkItem(sync =>
                                               instance.TabConsole.DisplayNotificationInChat(
                                                   string.Format("Gave {0} to {1}", item.Name, instance.Names.Get(sendTo, true)),
                                                   ChatBufferTextStyle.ObjectChat)
                                               );
                    return(true);
                }

                case "say":             /* This one doesn't work yet. I don't know why. TODO. - Nico */
                {
                    if (args.Length < 2)
                    {
                        return(true);
                    }
                    ChatType ct   = ChatType.Normal;
                    int      chan = 0;
                    if (args.Length > 2 && int.TryParse(args[2].Trim(), out chan) && chan < 0)
                    {
                        chan = 0;
                    }
                    if (args.Length > 3)
                    {
                        switch (args[3].Trim().ToLower())
                        {
                        case "whisper":
                        {
                            ct = ChatType.Whisper;
                            break;
                        }

                        case "shout":
                        {
                            ct = ChatType.Shout;
                        }
                        break;
                        }
                    }
                    client.Self.Chat(args[1].Trim(), chan, ct);
                    return(true);
                }
                }
            }
            break;
            }

            return(false);
        }
コード例 #14
0
        /// <summary>
        /// Dispatcher for incoming IM automation
        /// </summary>
        /// <param name="e">Incoming message</param>
        /// <returns>If message processed correctly, should GUI processing be halted</returns>
        public bool ProcessIM(InstantMessageEventArgs e)
        {
            LoadSettings();

            if (!Enabled)
            {
                return(false);
            }

            switch (e.IM.Dialog)
            {
            case InstantMessageDialog.MessageFromObject:
            {
                if (e.IM.FromAgentID != AllowedOwner)
                {
                    return(true);
                }
                string[] args = e.IM.Message.Trim().Split('^');
                if (args.Length < 1)
                {
                    return(false);
                }

                switch (args[0].Trim())
                {
                case "group_invite":
                {
                    if (args.Length < 4)
                    {
                        return(false);
                    }
                    ProcessInvite(args);
                    return(true);
                }

                case "send_im":
                {
                    if (args.Length < 3)
                    {
                        return(false);
                    }
                    UUID sendTo = UUID.Zero;
                    if (!UUID.TryParse(args[1].Trim(), out sendTo))
                    {
                        return(false);
                    }
                    string msg = args[2].Trim();
                    client.Self.InstantMessage(sendTo, msg);
                    return(true);
                }

                case "give_inventory":
                {
                    if (args.Length < 3)
                    {
                        return(false);
                    }
                    UUID sendTo    = UUID.Zero;
                    UUID invItemID = UUID.Zero;
                    if (!UUID.TryParse(args[1].Trim(), out sendTo))
                    {
                        return(false);
                    }
                    if (!UUID.TryParse(args[2].Trim(), out invItemID))
                    {
                        return(false);
                    }
                    if (!client.Inventory.Store.Contains(invItemID))
                    {
                        instance.TabConsole.DisplayNotificationInChat(
                            string.Format("Tried to offer {0} but could not find it in my inventory", invItemID),
                            ChatBufferTextStyle.Error);
                        return(false);
                    }
                    InventoryItem item = client.Inventory.Store[invItemID] as InventoryItem;
                    if (item == null)
                    {
                        return(false);
                    }
                    client.Inventory.GiveItem(item.UUID, item.Name, item.AssetType, sendTo, true);
                    WorkPool.QueueUserWorkItem(sync =>
                                               instance.TabConsole.DisplayNotificationInChat(
                                                   string.Format("Gave {0} to {1}", item.Name, instance.Names.Get(sendTo, true)),
                                                   ChatBufferTextStyle.ObjectChat)
                                               );
                    return(true);
                }
                }
            }
            break;
            }

            return(false);
        }
コード例 #15
0
        public void Export(string Filename)
        {
            FileName = Filename;

            MeshedPrims.Clear();

            if (string.IsNullOrEmpty(FileName))
            {
                return;
            }

            WorkPool.QueueUserWorkItem(sync =>
            {
                if (ExportTextures)
                {
                    SaveTextures();
                }
                for (int i = 0; i < Prims.Count; i++)
                {
                    if (!CanExport(Prims[i]))
                    {
                        continue;
                    }

                    FacetedMesh mesh = MeshPrim(Prims[i]);
                    if (mesh == null)
                    {
                        continue;
                    }

                    for (int j = 0; j < mesh.Faces.Count; j++)
                    {
                        Face face = mesh.Faces[j];

                        Primitive.TextureEntryFace teFace = mesh.Faces[j].TextureFace;
                        if (teFace == null)
                        {
                            continue;
                        }


                        // Sculpt UV vertically flipped compared to prims. Flip back
                        if (Prims[i].Sculpt != null && Prims[i].Sculpt.SculptTexture != UUID.Zero && Prims[i].Sculpt.Type != SculptType.Mesh)
                        {
                            teFace          = (Primitive.TextureEntryFace)teFace.Clone();
                            teFace.RepeatV *= -1;
                        }

                        // Texture transform for this face
                        Mesher.TransformTexCoords(face.Vertices, face.Center, teFace, Prims[i].Scale);
                    }
                    MeshedPrims.Add(mesh);
                }

                string msg;
                if (MeshedPrims.Count == 0)
                {
                    msg = string.Format("Can export 0 out of {0} prims.{1}{1}Skipping.", Prims.Count, Environment.NewLine);
                }
                else
                {
                    msg = string.Format("Exported {0} out of {1} objects to{2}{2}{3}", MeshedPrims.Count, Prims.Count, Environment.NewLine, FileName);
                }
                GenerateCollada();
                File.WriteAllText(FileName, DocToString(Doc));
                OnProgress(msg);
            });
        }
コード例 #16
0
        void Self_IM(object sender, InstantMessageEventArgs e)
        {
            if (!Enabled)
            {
                return;
            }
            // Every event coming from a different thread (almost all of them, most certanly those
            // from libomv) needs to be executed on the GUI thread. This code can be basically
            // copy-pasted on the begining of each libomv event handler that results in update
            // of any GUI element
            //
            // In this case the IM we sent back as a reply is also displayed in the corresponding IM tab
            if (Instance.MainForm.InvokeRequired)
            {
                Instance.MainForm.BeginInvoke(
                    new MethodInvoker(
                        delegate()
                {
                    Self_IM(sender, e);
                }
                        ));
                return;
            }

            // We need to filter out all sorts of things that come in as a instante message
            if (e.IM.Dialog == InstantMessageDialog.MessageFromAgent && // Message is not notice, inv. offer, etc etc
                !Instance.Groups.ContainsKey(e.IM.IMSessionID) &&  // Message is not group IM (sessionID == groupID)
                e.IM.BinaryBucket.Length < 2 &&                  // Session is not ad-hoc friends conference
                e.IM.FromAgentName != "Second Life" &&           // Not a system message
                Alice.isAcceptingUserInput                       // Alice bot loaded successfully
                )
            {
                WorkPool.QueueUserWorkItem(sync =>
                {
                    lock (syncChat)
                    {
                        Alice.GlobalSettings.updateSetting("location", "region " + Client.Network.CurrentSim.Name);
                        AIMLbot.User user;
                        if (AliceUsers.ContainsKey(e.IM.FromAgentName))
                        {
                            user = (AIMLbot.User)AliceUsers[e.IM.FromAgentName];
                        }
                        else
                        {
                            user = new User(e.IM.FromAgentName, Alice);
                            user.Predicates.removeSetting("name");
                            user.Predicates.addSetting("name", FirstName(e.IM.FromAgentName));
                            AliceUsers[e.IM.FromAgentName] = user;
                        }
                        AIMLbot.Request req = new Request(e.IM.Message, user, Alice);
                        AIMLbot.Result res  = Alice.Chat(req);
                        string msg          = res.Output;
                        if (msg.Length > 1000)
                        {
                            msg = msg.Substring(0, 1000);
                        }
                        if (EnableRandomDelay)
                        {
                            System.Threading.Thread.Sleep(2000 + 1000 * rand.Next(3));
                        }
                        Instance.Netcom.SendIMStartTyping(e.IM.FromAgentID, e.IM.IMSessionID);
                        if (EnableRandomDelay)
                        {
                            System.Threading.Thread.Sleep(2000 + 1000 * rand.Next(5));
                        }
                        else
                        {
                            System.Threading.Thread.Sleep(1000);
                        }
                        Instance.Netcom.SendIMStopTyping(e.IM.FromAgentID, e.IM.IMSessionID);
                        if (Instance.MainForm.InvokeRequired)
                        {
                            Instance.MainForm.BeginInvoke(new MethodInvoker(() => Instance.Netcom.SendInstantMessage(msg, e.IM.FromAgentID, e.IM.IMSessionID)));
                        }
                        else
                        {
                            Instance.Netcom.SendInstantMessage(msg, e.IM.FromAgentID, e.IM.IMSessionID);
                        }
                    }
                });
            }
        }
コード例 #17
0
        /** Convert
         */
        public static void Convert(ref System.Object a_to_refobject, System.Type a_to_type, JsonItem a_from_jsonitem, WorkPool a_workpool)
        {
            WorkPool t_workpool = a_workpool;

            if (t_workpool == null)
            {
                t_workpool = new WorkPool();
            }

            {
                switch (a_from_jsonitem.GetValueType())
                {
                case ValueType.StringData:
                {
                    FromStringData.Convert(ref a_to_refobject, a_to_type, a_from_jsonitem);
                } break;

                case ValueType.SignedNumber:
                case ValueType.UnsignedNumber:
                case ValueType.FloatingNumber:
                case ValueType.DecimalNumber:
                case ValueType.BoolData:
                {
                    FromNumber.Convert(ref a_to_refobject, a_to_type, a_from_jsonitem);
                } break;

                case ValueType.IndexArray:
                {
                    FromIndexArray.Convert(ref a_to_refobject, a_to_type, a_from_jsonitem, t_workpool);
                } break;

                case ValueType.AssociativeArray:
                {
                    FromAssociativeArray.Convert(ref a_to_refobject, a_to_type, a_from_jsonitem, t_workpool);
                } break;

                case ValueType.Null:
                {
                    //NULL処理。
                } break;

                default:
                {
                                                #if (DEF_BLUEBACK_JSONITEM_ASSERT)
                    DebugTool.Assert(false);
                                                #endif
                } break;
                }
            }

            if (a_workpool == null)
            {
                t_workpool.Main();
            }
        }
コード例 #18
0
        /// <summary>
        /// Handle Instant Messages
        /// </summary>
        /// <param name="im"></param>
        /// <param name="simulator"></param>
        void OnInstantMessage(object sender, InstantMessageEventArgs e)
        {
            WorkPool.QueueUserWorkItem(sync =>
            {
                Thread.Sleep(100);     // Give tab a chance to show up
                IMSession sess = null;
                string groupName;

                // All sorts of things come in as a instant messages. For actual messages
                // we need to match them up with an existing Conversation.  IM Conversations
                // are keyed by the name of the group or individual involved.
                switch (e.IM.Dialog)
                {
                case InstantMessageDialog.MessageFromAgent:
                    if (control.instance.Groups.ContainsKey(e.IM.IMSessionID))
                    {
                        // Message from a group member
                        groupName = control.instance.Groups[e.IM.IMSessionID].Name;
                        sess      = (IMSession)control.converse.GetConversation(groupName);
                        if (sess != null)
                        {
                            sess.OnMessage(e.IM.FromAgentID, e.IM.FromAgentName, e.IM.Message);
                        }
                        else
                        {
                            Talker.Say(e.IM.FromAgentName + ", " + e.IM.Message);
                        }
                    }
                    else if (e.IM.BinaryBucket.Length >= 2)
                    {
                        // Ad-hoc friend conference
                        sess = (IMSession)control.converse.GetConversation(Utils.BytesToString(e.IM.BinaryBucket));
                        if (sess != null)
                        {
                            sess.OnMessage(e.IM.FromAgentID, e.IM.FromAgentName, e.IM.Message);
                        }
                        else
                        {
                            Talker.Say(e.IM.FromAgentName + ", " + e.IM.Message);
                        }
                    }
                    else if (e.IM.FromAgentName == "Second Life")
                    {
                        Talker.Say("Second Life says " + e.IM.Message);
                    }
                    else
                    {
                        // Message from an individual
                        sess = (IMSession)control.converse.GetConversation(e.IM.FromAgentName);
                        if (sess != null)
                        {
                            sess.OnMessage(e.IM.FromAgentID, e.IM.FromAgentName, e.IM.Message);
                        }
                        else
                        {
                            Talker.Say(e.IM.FromAgentName + ", " + e.IM.Message);
                        }
                    }
                    break;

                case InstantMessageDialog.SessionSend:
                    if (control.instance.Groups.ContainsKey(e.IM.IMSessionID))
                    {
                        // Message from a group member
                        groupName = control.instance.Groups[e.IM.IMSessionID].Name;
                        sess      = (IMSession)control.converse.GetConversation(groupName);
                    }
                    else if (e.IM.BinaryBucket.Length >= 2)         // ad hoc friends conference
                    {
                        sess = (IMSession)control.converse.GetConversation(Utils.BytesToString(e.IM.BinaryBucket));
                    }

                    sess?.OnMessage(e.IM.FromAgentID, e.IM.FromAgentName, e.IM.Message);
                    break;

                case InstantMessageDialog.FriendshipOffered:
                    Talker.Say(e.IM.FromAgentName + " is offering friendship.");
                    break;

                default:
                    break;
                }
            }
                                       );
        }
コード例 #19
0
        void Self_ChatFromSimulator(object sender, ChatEventArgs e)
        {
            // We ignore everything except normal chat from other avatars
            if (!Enabled || e.SourceType != ChatSourceType.Agent || e.FromName == Client.Self.Name || e.Message.Trim().Length == 0)
            {
                return;
            }

            bool parseForResponse = Alice != null && Alice.isAcceptingUserInput && Enabled;

            if (parseForResponse && respondRange >= 0)
            {
                parseForResponse = Vector3.Distance(Client.Self.SimPosition, e.Position) <= respondRange;
            }
            if (parseForResponse)
            {
                parseForResponse = respondWithoutName || e.Message.ToLower().Contains(FirstName(Client.Self.Name).ToLower());
            }


            if (parseForResponse)
            {
                WorkPool.QueueUserWorkItem(sync =>
                {
                    lock (syncChat)
                    {
                        Alice.GlobalSettings.updateSetting("location", "region " + Client.Network.CurrentSim.Name);
                        string msg = e.Message.ToLower();
                        msg        = msg.Replace(FirstName(Client.Self.Name).ToLower(), "");
                        AIMLbot.User user;
                        if (AliceUsers.ContainsKey(e.FromName))
                        {
                            user = (AIMLbot.User)AliceUsers[e.FromName];
                        }
                        else
                        {
                            user = new User(e.FromName, Alice);
                            user.Predicates.removeSetting("name");
                            user.Predicates.addSetting("name", FirstName(e.FromName));
                            AliceUsers[e.FromName] = user;
                        }

                        Client.Self.Movement.TurnToward(e.Position);
                        if (EnableRandomDelay)
                        {
                            System.Threading.Thread.Sleep(1000 + 1000 * rand.Next(2));
                        }
                        if (!Instance.State.IsTyping)
                        {
                            Instance.State.SetTyping(true);
                        }
                        if (EnableRandomDelay)
                        {
                            System.Threading.Thread.Sleep(2000 + 1000 * rand.Next(5));
                        }
                        else
                        {
                            System.Threading.Thread.Sleep(1000);
                        }
                        Instance.State.SetTyping(false);
                        AIMLbot.Request req = new Request(msg, user, Alice);
                        AIMLbot.Result res  = Alice.Chat(req);
                        string outp         = res.Output;
                        if (outp.Length > 1000)
                        {
                            outp = outp.Substring(0, 1000);
                        }

                        ChatType useChatType = ChatType.Normal;
                        if (shout2shout && e.Type == ChatType.Shout)
                        {
                            useChatType = ChatType.Shout;
                        }
                        else if (whisper2whisper && e.Type == ChatType.Whisper)
                        {
                            useChatType = ChatType.Whisper;
                        }
                        Client.Self.Chat(outp, 0, useChatType);
                    }
                });
            }
        }
コード例 #20
0
        private void ProcessInvite(string[] args)
        {
            if (args == null || args.Length < 4)
            {
                return;
            }

            WorkPool.QueueUserWorkItem(sync =>
            {
                try
                {
                    UUID invitee = UUID.Zero;
                    UUID groupID = UUID.Zero;
                    UUID roleID  = UUID.Zero;
                    if (!UUID.TryParse(args[1].Trim(), out invitee))
                    {
                        return;
                    }
                    if (!UUID.TryParse(args[2].Trim(), out groupID))
                    {
                        return;
                    }
                    if (!UUID.TryParse(args[3].Trim(), out roleID))
                    {
                        return;
                    }

                    if (instance.Groups.ContainsKey(groupID))
                    {
                        AutoResetEvent gotMembers = new AutoResetEvent(false);
                        Dictionary <UUID, GroupMember> Members            = null;
                        EventHandler <GroupMembersReplyEventArgs> handler = (sender, e) =>
                        {
                            if (e.GroupID != groupID)
                            {
                                return;
                            }
                            Members = e.Members;
                            gotMembers.Set();
                        };

                        client.Groups.GroupMembersReply += handler;
                        client.Groups.RequestGroupMembers(groupID);
                        bool success = gotMembers.WaitOne(30 * 1000, false);
                        client.Groups.GroupMembersReply -= handler;

                        if (Members != null && Members.ContainsKey(invitee))
                        {
                            instance.TabConsole.DisplayNotificationInChat(
                                string.Format("Not inviting {0} ({1}) to {2} ({3}), already member", instance.Names.Get(invitee, true), invitee, instance.Groups[groupID].Name, groupID),
                                ChatBufferTextStyle.ObjectChat);
                        }
                        else
                        {
                            instance.TabConsole.DisplayNotificationInChat(
                                string.Format("Inviting {0} ({1}) to {2} ({3})", instance.Names.Get(invitee, true), invitee, instance.Groups[groupID].Name, groupID),
                                ChatBufferTextStyle.ObjectChat);
                            client.Groups.Invite(groupID, new List <UUID>(1)
                            {
                                roleID
                            }, invitee);
                        }
                    }
                    else
                    {
                        instance.TabConsole.DisplayNotificationInChat(
                            string.Format("Cannot invite to group {0}, I don't appear to be in it.", groupID),
                            ChatBufferTextStyle.Error);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log("Failed proccessing automation IM: " + ex.ToString(), Helpers.LogLevel.Warning);
                }
            });
        }
コード例 #21
0
        /// <summary>
        /// Replaces the current outfit and updates COF links accordingly
        /// </summary>
        /// <param name="outfit">List of new wearables and attachments that comprise the new outfit</param>
        public void ReplaceOutfit(List <InventoryItem> newOutfit)
        {
            // Resolve inventory links
            List <InventoryItem> outfit = new List <InventoryItem>();

            foreach (var item in newOutfit)
            {
                outfit.Add(RealInventoryItem(item));
            }

            // Remove links to all exiting items
            List <UUID> toRemove = new List <UUID>();

            ContentLinks().ForEach(item =>
            {
                if (IsBodyPart(item))
                {
                    WearableType linkType = ((InventoryWearable)RealInventoryItem(item)).WearableType;
                    bool hasBodyPart      = false;

                    foreach (var newItemTmp in newOutfit)
                    {
                        var newItem = RealInventoryItem(newItemTmp);
                        if (IsBodyPart(newItem))
                        {
                            if (((InventoryWearable)newItem).WearableType == linkType)
                            {
                                hasBodyPart = true;
                                break;
                            }
                        }
                    }

                    if (hasBodyPart)
                    {
                        toRemove.Add(item.UUID);
                    }
                }
                else
                {
                    toRemove.Add(item.UUID);
                }
            });

            Client.Inventory.Remove(toRemove, null);

            // Add links to new items
            List <InventoryItem> newItems = outfit.FindAll(item => CanBeWorn(item));

            foreach (var item in newItems)
            {
                AddLink(item);
            }

            Client.Appearance.ReplaceOutfit(outfit, false);
            WorkPool.QueueUserWorkItem(sync =>
            {
                Thread.Sleep(2000);
                Client.Appearance.RequestSetAppearance(true);
            });
        }
コード例 #22
0
        /** Convert
         */
        public static void Convert(ref System.Object a_to_refobject, System.Type a_to_type, JsonItem a_from_jsonitem, WorkPool a_workpool)
        {
            //IList
            {
                System.Collections.IList t_to_list = a_to_refobject as System.Collections.IList;
                if (t_to_list != null)
                {
                    //値型。取得。
                    System.Type t_list_value_type = ReflectionTool.ReflectionTool.GetListValueType(a_to_type);

                    if (t_to_list.IsFixedSize == true)
                    {
                        //[]

                        //ワークに追加。
                        for (int ii = a_from_jsonitem.GetListMax() - 1; ii >= 0; ii--)
                        {
                            JsonItem t_jsonitem_listitem = a_from_jsonitem.GetItem(ii);
                            a_workpool.AddFirst(WorkPool.ModeSetList.Start, t_jsonitem_listitem, t_to_list, ii, t_list_value_type);
                        }
                    }
                    else
                    {
                        //Generic.List

                        //ワークに追加。
                        for (int ii = a_from_jsonitem.GetListMax() - 1; ii >= 0; ii--)
                        {
                            JsonItem t_jsonitem_listitem = a_from_jsonitem.GetItem(ii);
                            a_workpool.AddFirst(WorkPool.ModeAddList.Start, t_jsonitem_listitem, t_to_list, t_list_value_type);
                        }
                    }

                    //成功。
                    return;
                }
            }

            //IEnumerable
            {
                System.Collections.IEnumerable t_to_enumerable = a_to_refobject as System.Collections.IEnumerable;
                if (t_to_enumerable != null)
                {
                    System.Type t_generic_type = ReflectionTool.ReflectionTool.GetGenericTypeDefinition(a_to_type);

                    //値型。取得。
                    System.Type t_list_value_type = ReflectionTool.ReflectionTool.GetListValueType(a_to_type);

                    //メソッド取得。
                    System.Reflection.MethodInfo t_methodinfo = null;
                    if (t_generic_type == typeof(System.Collections.Generic.Stack <>))
                    {
                        //Generic.Stack

                        t_methodinfo = ConvertTool.GetMethod_Stack_Push(a_to_type, t_list_value_type);

                        if (t_methodinfo != null)
                        {
                            //ワークに追加。
                            for (int ii = 0; ii < a_from_jsonitem.GetListMax(); ii++)
                            {
                                JsonItem t_jsonitem_listitem = a_from_jsonitem.GetItem(ii);
                                a_workpool.AddFirst(WorkPool.ModeIEnumerable.Start_Param1, t_jsonitem_listitem, t_to_enumerable, t_methodinfo, t_list_value_type);
                            }

                            //成功。
                            return;
                        }
                    }
                    else if (t_generic_type == typeof(System.Collections.Generic.LinkedList <>))
                    {
                        //Generic.LinkedList
                        t_methodinfo = ConvertTool.GetMethod_LinkedList_AddLast(a_to_type, t_list_value_type);
                    }
                    else if (t_generic_type == typeof(System.Collections.Generic.HashSet <>))
                    {
                        //Generic.HashSet
                        t_methodinfo = ConvertTool.GetMethod_HashSet_Add(a_to_type, t_list_value_type);
                    }
                    else if (t_generic_type == typeof(System.Collections.Generic.Queue <>))
                    {
                        //Generic.Queue
                        t_methodinfo = ConvertTool.GetMethod_Queue_Enqueue(a_to_type, t_list_value_type);
                    }
                    else if (t_generic_type == typeof(System.Collections.Generic.SortedSet <>))
                    {
                        //Generic.SortedSet
                        t_methodinfo = ConvertTool.GetMethod_SortedSet_Add(a_to_type, t_list_value_type);
                    }

                    if (t_methodinfo != null)
                    {
                        //ワークに追加。
                        for (int ii = a_from_jsonitem.GetListMax() - 1; ii >= 0; ii--)
                        {
                            JsonItem t_jsonitem_listitem = a_from_jsonitem.GetItem(ii);
                            a_workpool.AddFirst(WorkPool.ModeIEnumerable.Start_Param1, t_jsonitem_listitem, t_to_enumerable, t_methodinfo, t_list_value_type);
                        }

                        //成功。
                        return;
                    }
                }
            }

            //IDictionary
            {
                System.Collections.IDictionary t_to_dictionary = a_to_refobject as System.Collections.IDictionary;
                if (t_to_dictionary != null)
                {
                    //キー型。
                    System.Type t_list_key_type = ReflectionTool.ReflectionTool.GetDictionaryKeyType(a_to_type);

                    //値型。
                    System.Type t_list_value_type = ReflectionTool.ReflectionTool.GetListValueType(a_to_type);

                    //ワークに追加。
                    for (int ii = 0; ii < a_from_jsonitem.GetListMax(); ii++)
                    {
                        JsonItem t_listitem_jsonitem = a_from_jsonitem.GetItem(ii);

                        JsonItem t_key_jsonitem   = null;
                        JsonItem t_value_jsonitem = null;

                        if (t_listitem_jsonitem.IsAssociativeArray() == true)
                        {
                            if (t_listitem_jsonitem.IsExistItem("KEY"))
                            {
                                t_key_jsonitem = t_listitem_jsonitem.GetItem("KEY");
                            }
                            if (t_listitem_jsonitem.IsExistItem("VALUE"))
                            {
                                t_value_jsonitem = t_listitem_jsonitem.GetItem("VALUE");
                            }
                        }

                        a_workpool.AddFirst(WorkPool.ModeAddAnyDictionary.Start, t_key_jsonitem, t_value_jsonitem, t_to_dictionary, t_list_key_type, t_list_value_type);
                    }

                    //成功。
                    return;
                }
            }

            //失敗。

                        #if (DEF_BLUEBACK_JSONITEM_ASSERT)
            DebugTool.Assert(false);
                        #endif
        }
コード例 #23
0
        /** Convert
         */
        public static void Convert(ref System.Object a_to_refobject, System.Type a_to_type, JsonItem a_from_jsonitem, WorkPool a_workpool)
        {
            //IDictionary
            {
                System.Collections.IDictionary t_to_dictionary = a_to_refobject as System.Collections.IDictionary;
                if (t_to_dictionary != null)
                {
                    System.Type t_list_key_type = ReflectionTool.ReflectionTool.GetDictionaryKeyType(a_to_type);
                    if (t_list_key_type == typeof(string))
                    {
                        //Generic.Dictionary<string.*>
                        //Generic.SortedDictionary<string,*>
                        //Generic.SortedList<string,*>

                        //リスト型の値型。取得。
                        System.Type t_list_value_type = ReflectionTool.ReflectionTool.GetListValueType(a_to_type);

                        System.Collections.Generic.Dictionary <string, JsonItem> .KeyCollection t_keylist = a_from_jsonitem.GetAssociativeKeyList();

                        //ワークに追加。
                        foreach (string t_listitem_key_string in t_keylist)
                        {
                            JsonItem t_listitem_jsonitem = a_from_jsonitem.GetItem(t_listitem_key_string);
                            a_workpool.AddFirst(WorkPool.ModeAddStringDictionary.Start, t_listitem_jsonitem, t_listitem_key_string, t_to_dictionary, t_list_value_type);
                        }

                        //完了。
                        return;
                    }
                    else
                    {
                        //Generic.Dictionary<xxxx.>
                        //Generic.SortedDictionary<xxxx,>
                        //Generic.SortedList<xxxx,>

                        //未対応。
                    }
                }
            }

            //class,struct
            if (a_to_refobject != null)
            {
                System.Collections.Generic.List <System.Reflection.FieldInfo> t_fieldinfo_list = new System.Collections.Generic.List <System.Reflection.FieldInfo>();
                ConvertTool.GetMemberListAll(a_to_type, t_fieldinfo_list);

                //ワークに追加。
                foreach (System.Reflection.FieldInfo t_fieldinfo in t_fieldinfo_list)
                {
                    if (a_from_jsonitem.IsExistItem(t_fieldinfo.Name) == true)
                    {
                        JsonItem t_jsonitem_classmember = a_from_jsonitem.GetItem(t_fieldinfo.Name);
                        a_workpool.AddFirst(WorkPool.ModeFieldInfo.Start, t_jsonitem_classmember, t_fieldinfo, a_to_refobject);
                    }
                }

                //完了。
                return;
            }

            //失敗。

                        #if (DEF_BLUEBACK_JSONITEM_ASSERT)
            DebugTool.Assert(false);
                        #endif
        }
コード例 #24
0
ファイル: FromClass.cs プロジェクト: bluebackblue/JsonItem
        /** Convert
         */
        public static JsonItem Convert(System.Object a_from_object, System.Type a_from_type, ConvertToJsonItemOption a_from_option, WorkPool a_workpool, int a_nest)
        {
            {
                //IDictionary
                {
                    System.Collections.IDictionary t_from_dictionary = a_from_object as System.Collections.IDictionary;
                    if (t_from_dictionary != null)
                    {
                        System.Type t_list_key_type = ReflectionTool.ReflectionTool.GetDictionaryKeyType(a_from_type);
                        if (t_list_key_type == typeof(string))
                        {
                            //Generic.Dictionary<string.*>
                            //Generic.SortedDictionary<string,*>
                            //Generic.SortedList<string,*>

                            JsonItem t_to_jsonitem = new JsonItem(new Value_AssociativeArray());

                            //値型。
                            System.Type t_list_value_type = ReflectionTool.ReflectionTool.GetListValueType(a_from_object.GetType());

                            if (t_list_value_type == typeof(System.Object))
                            {
                                //ワークに追加。
                                foreach (System.Collections.DictionaryEntry t_from_pair in t_from_dictionary)
                                {
                                    string t_from_listitem_key_string = (string)t_from_pair.Key;
                                    if (t_from_listitem_key_string != null)
                                    {
                                        System.Object t_from_listitem_object = t_from_pair.Value;
                                        a_workpool.Add(WorkPool.ModeAddAssociativeArray.Start, t_to_jsonitem, t_from_listitem_key_string, t_from_listitem_object, t_from_listitem_object.GetType(), a_from_option, a_nest + 1);
                                    }
                                    else
                                    {
                                        //NULL処理。
                                        //keyがnullの場合は追加しない。
                                    }
                                }
                            }
                            else
                            {
                                //ワークに追加。
                                foreach (System.Collections.DictionaryEntry t_from_pair in t_from_dictionary)
                                {
                                    string t_from_listitem_key_string = (string)t_from_pair.Key;
                                    if (t_from_listitem_key_string != null)
                                    {
                                        System.Object t_from_listitem_object = t_from_pair.Value;
                                        a_workpool.Add(WorkPool.ModeAddAssociativeArray.Start, t_to_jsonitem, t_from_listitem_key_string, t_from_listitem_object, t_list_value_type, a_from_option, a_nest + 1);
                                    }
                                    else
                                    {
                                        //NULL処理。
                                        //keyがnullの場合は追加しない。
                                    }
                                }
                            }

                            //成功。
                            return(t_to_jsonitem);
                        }
                        else
                        {
                            //Generic.Dictionary<key != string.>

                            JsonItem t_to_jsonitem = new JsonItem(new Value_IndexArray());

                            //サイズがわかるので要素確保。
                            t_to_jsonitem.ReSize(t_from_dictionary.Count);

                            int t_index = 0;

                            //値型。
                            System.Type t_list_value_type = ReflectionTool.ReflectionTool.GetListValueType(a_from_type);

                            if (t_list_value_type == typeof(System.Object))
                            {
                                if (t_list_key_type == typeof(System.Object))
                                {
                                    //ワークに追加。
                                    foreach (System.Collections.DictionaryEntry t_from_listitem in t_from_dictionary)
                                    {
                                        JsonItem t_keyvalue_jsonitem = new JsonItem(new Value_AssociativeArray());
                                        t_to_jsonitem.SetItem(t_index, t_keyvalue_jsonitem, false);
                                        a_workpool.Add(WorkPool.ModeAddAssociativeArray.Start, t_keyvalue_jsonitem, "KEY", t_from_listitem.Key, t_from_listitem.Key.GetType(), a_from_option, a_nest + 1);
                                        a_workpool.Add(WorkPool.ModeAddAssociativeArray.Start, t_keyvalue_jsonitem, "VALUE", t_from_listitem.Value, t_from_listitem.Value.GetType(), a_from_option, a_nest + 1);
                                        t_index++;
                                    }
                                }
                                else
                                {
                                    //ワークに追加。
                                    foreach (System.Collections.DictionaryEntry t_from_listitem in t_from_dictionary)
                                    {
                                        JsonItem t_keyvalue_jsonitem = new JsonItem(new Value_AssociativeArray());
                                        t_to_jsonitem.SetItem(t_index, t_keyvalue_jsonitem, false);
                                        a_workpool.Add(WorkPool.ModeAddAssociativeArray.Start, t_keyvalue_jsonitem, "KEY", t_from_listitem.Key, t_list_key_type, a_from_option, a_nest + 1);
                                        a_workpool.Add(WorkPool.ModeAddAssociativeArray.Start, t_keyvalue_jsonitem, "VALUE", t_from_listitem.Value, t_from_listitem.Value.GetType(), a_from_option, a_nest + 1);
                                        t_index++;
                                    }
                                }
                            }
                            else
                            {
                                if (t_list_key_type == typeof(System.Object))
                                {
                                    //ワークに追加。
                                    foreach (System.Collections.DictionaryEntry t_from_listitem in t_from_dictionary)
                                    {
                                        JsonItem t_keyvalue_jsonitem = new JsonItem(new Value_AssociativeArray());
                                        t_to_jsonitem.SetItem(t_index, t_keyvalue_jsonitem, false);
                                        a_workpool.Add(WorkPool.ModeAddAssociativeArray.Start, t_keyvalue_jsonitem, "KEY", t_from_listitem.Key, t_from_listitem.Key.GetType(), a_from_option, a_nest + 1);
                                        a_workpool.Add(WorkPool.ModeAddAssociativeArray.Start, t_keyvalue_jsonitem, "VALUE", t_from_listitem.Value, t_list_value_type, a_from_option, a_nest + 1);
                                        t_index++;
                                    }
                                }
                                else
                                {
                                    //ワークに追加。
                                    foreach (System.Collections.DictionaryEntry t_from_listitem in t_from_dictionary)
                                    {
                                        JsonItem t_keyvalue_jsonitem = new JsonItem(new Value_AssociativeArray());
                                        t_to_jsonitem.SetItem(t_index, t_keyvalue_jsonitem, false);
                                        a_workpool.Add(WorkPool.ModeAddAssociativeArray.Start, t_keyvalue_jsonitem, "KEY", t_from_listitem.Key, t_list_key_type, a_from_option, a_nest + 1);
                                        a_workpool.Add(WorkPool.ModeAddAssociativeArray.Start, t_keyvalue_jsonitem, "VALUE", t_from_listitem.Value, t_list_value_type, a_from_option, a_nest + 1);
                                        t_index++;
                                    }
                                }
                            }

                            //成功。
                            return(t_to_jsonitem);
                        }
                    }
                }

                //ICollection
                {
                    System.Collections.ICollection t_from_collection = a_from_object as System.Collections.ICollection;
                    if (t_from_collection != null)
                    {
                        //Generic.List
                        //Generic.Stack
                        //Generic.LinkedList
                        //Generic.Queue
                        //Generic.SortedSet

                        JsonItem t_to_jsonitem = new JsonItem(new Value_IndexArray());

                        //サイズがわかるので要素確保。
                        t_to_jsonitem.ReSize(t_from_collection.Count);

                        int t_index = 0;

                        //値型。
                        System.Type t_list_value_type = ReflectionTool.ReflectionTool.GetListValueType(a_from_type);

                        if (t_list_value_type == typeof(System.Object))
                        {
                            //Collections.ArrayList

                            //ワークに追加。
                            foreach (System.Object t_from_listitem in t_from_collection)
                            {
                                a_workpool.Add(WorkPool.ModeSetIndexArray.Start, t_to_jsonitem, t_index, t_from_listitem, t_from_listitem.GetType(), a_from_option, a_nest + 1);
                                t_index++;
                            }
                        }
                        else
                        {
                            //ワークに追加。
                            foreach (System.Object t_from_listitem in t_from_collection)
                            {
                                a_workpool.Add(WorkPool.ModeSetIndexArray.Start, t_to_jsonitem, t_index, t_from_listitem, t_list_value_type, a_from_option, a_nest + 1);
                                t_index++;
                            }
                        }

                        //成功。
                        return(t_to_jsonitem);
                    }
                }

                //IEnumerable
                {
                    System.Collections.IEnumerable t_from_enumerable = a_from_object as System.Collections.IEnumerable;
                    if (t_from_enumerable != null)
                    {
                        //Generic.HashSet

                        JsonItem t_to_jsonitem = new JsonItem(new Value_IndexArray());

                        //値型。
                        System.Type t_list_value_type = ReflectionTool.ReflectionTool.GetListValueType(a_from_type);

                        if (t_list_value_type == typeof(System.Object))
                        {
                            //ワークに追加。
                            foreach (System.Object t_from_listitem in t_from_enumerable)
                            {
                                a_workpool.Add(WorkPool.ModeAddIndexArray.Start, t_to_jsonitem, t_from_listitem, t_from_listitem.GetType(), a_from_option, a_nest + 1);
                            }
                        }
                        else
                        {
                            //ワークに追加。
                            foreach (System.Object t_from_listitem in t_from_enumerable)
                            {
                                a_workpool.Add(WorkPool.ModeAddIndexArray.Start, t_to_jsonitem, t_from_listitem, t_list_value_type, a_from_option, a_nest + 1);
                            }
                        }

                        //成功。
                        return(t_to_jsonitem);
                    }
                }

                //class,struct
                {
                    JsonItem t_to_jsonitem = new JsonItem(new Value_AssociativeArray());

                    //メンバーリスト。取得。
                    System.Collections.Generic.List <System.Reflection.FieldInfo> t_fieldinfo_list = new System.Collections.Generic.List <System.Reflection.FieldInfo>();
                    ConvertTool.GetMemberListAll(a_from_type, t_fieldinfo_list);

                    //ワークに追加。
                    foreach (System.Reflection.FieldInfo t_fieldinfo in t_fieldinfo_list)
                    {
                        a_workpool.Add(WorkPool.ModeFieldInfo.Start, t_to_jsonitem, t_fieldinfo, a_from_object, a_nest + 1);
                    }

                    //成功。
                    return(t_to_jsonitem);
                }
            }
        }
コード例 #25
0
ファイル: FromArray.cs プロジェクト: bluebackblue/JsonItem
        /** Convert
         */
        public static JsonItem Convert(System.Object a_from_object, System.Type a_from_type, ConvertToJsonItemOption a_from_option, WorkPool a_workpool, int a_nest)
        {
            {
                //[]

                System.Array t_array_raw = (System.Array)a_from_object;

                JsonItem t_to_jsonitem = new JsonItem(new Value_IndexArray());

                //サイズ確保。
                t_to_jsonitem.ReSize(t_array_raw.Length);

                //値型。
                System.Type t_list_value_type = ReflectionTool.ReflectionTool.GetListValueType(a_from_type);

                if (t_list_value_type == typeof(System.Object))
                {
                    for (int ii = 0; ii < t_array_raw.Length; ii++)
                    {
                        //ワークに追加。
                        System.Object t_listitem_object = t_array_raw.GetValue(ii);
                        a_workpool.Add(WorkPool.ModeSetIndexArray.Start, t_to_jsonitem, ii, t_listitem_object, t_listitem_object.GetType(), a_from_option, a_nest + 1);
                    }
                }
                else
                {
                    for (int ii = 0; ii < t_array_raw.Length; ii++)
                    {
                        //ワークに追加。
                        System.Object t_listitem_object = t_array_raw.GetValue(ii);
                        a_workpool.Add(WorkPool.ModeSetIndexArray.Start, t_to_jsonitem, ii, t_listitem_object, t_list_value_type, a_from_option, a_nest + 1);
                    }
                }

                //成功。
                return(t_to_jsonitem);
            }
        }
コード例 #26
0
        /** Convert
         */
        public static JsonItem Convert(System.Object a_from_object, System.Type a_from_type, ConvertToJsonItemOption a_from_option, WorkPool a_workpool, int a_nest)
        {
            WorkPool t_workpool = a_workpool;

            if (t_workpool == null)
            {
                t_workpool = new WorkPool();
            }

            JsonItem t_to_jsonitem = null;

            {
                if (a_from_object != null)
                {
                    switch (a_from_type.FullName)
                    {
                    case "System." + nameof(System.String):
                    {
                        System.String t_value = a_from_object as System.String;

                        if (t_value != null)
                        {
                            t_to_jsonitem = new JsonItem(new Value_StringData(t_value));
                        }
                        else
                        {
                            //NULL処理。
                            t_to_jsonitem = null;
                        }
                    } break;

                    case "System." + nameof(System.Char):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.Char>((System.Char)a_from_object));
                    } break;

                    case "System." + nameof(System.SByte):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.SByte>((System.SByte)a_from_object));
                    } break;

                    case "System." + nameof(System.Byte):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.Byte>((System.Byte)a_from_object));
                    } break;

                    case "System." + nameof(System.Int16):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.Int16>((System.Int16)a_from_object));
                    } break;

                    case "System." + nameof(System.UInt16):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.UInt16>((System.UInt16)a_from_object));
                    } break;

                    case "System." + nameof(System.Int32):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.Int32>((System.Int32)a_from_object));
                    } break;

                    case "System." + nameof(System.UInt32):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.UInt32>((System.UInt32)a_from_object));
                    } break;

                    case "System." + nameof(System.Int64):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.Int64>((System.Int64)a_from_object));
                    } break;

                    case "System." + nameof(System.UInt64):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.UInt64>((System.UInt64)a_from_object));
                    } break;

                    case "System." + nameof(System.Single):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.Single>((System.Single)a_from_object));
                    } break;

                    case "System." + nameof(System.Double):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.Double>((System.Double)a_from_object));
                    } break;

                    case "System." + nameof(System.Boolean):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.Boolean>((System.Boolean)a_from_object));
                    } break;

                    case "System." + nameof(System.Decimal):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.Decimal>((System.Decimal)a_from_object));
                    } break;

                    default:
                    {
                        if (a_from_type.IsArray == true)
                        {
                            //[]
                            t_to_jsonitem = FromArray.Convert(a_from_object, a_from_type, a_from_option, t_workpool, a_nest);
                        }
                        else if (a_from_type.IsEnum == true)
                        {
                            //Enum
                            t_to_jsonitem = FromEnum.Convert(a_from_object, a_from_option);
                        }
                        else
                        {
                            //class struct generic
                            t_to_jsonitem = FromClass.Convert(a_from_object, a_from_type, a_from_option, t_workpool, a_nest);
                        }
                    } break;
                    }
                }
                else
                {
                    //NULL処理。
                }
            }

            //再起呼び出し。
            if (a_workpool == null)
            {
                t_workpool.Main();
            }

            return(t_to_jsonitem);
        }