Ejemplo n.º 1
0
 private static void ProcessCellIdOrCellIdListField <T>(string type, ICell cell, IFieldDescriptor fd, string field_name, bool optional, JToken field_content, Func <JToken, IFieldDescriptor, T> process_content_action)
 {
     if (fd.Type == Consts.c_TYPE_CellId || fd.Type == Consts.c_TYPE_OptionalCellId)
     {
         try
         {
             cell.SetField(field_name, process_content_action(field_content, fd));
         }
         catch (Exception e)
         {
             if (!optional)
             {
                 throw;
             }
             else
             {
                 Log.WriteLine(LogLevel.Warning, e.Message);
             }
         }
     }
     else if (fd.Type == Consts.c_TYPE_CellIdList)
     {
         //cell id list
         if (field_content is JArray)
         {
             foreach (var sub_content in field_content)
             {
                 try
                 {
                     cell.AppendToField(field_name, process_content_action(sub_content, fd));
                 }
                 catch (Exception e)
                 {
                     Log.WriteLine(LogLevel.Warning, e.Message);
                 }
             }
         }
         else
         {
             try
             {
                 cell.AppendToField(field_name, process_content_action(field_content, fd));
             }
             catch (Exception e)
             {
                 Log.WriteLine(LogLevel.Warning, e.Message);
             }
         }
     }
     else
     {
         //not supported
         throw new ImporterException("{0}.{1} has type {2}, expecting CellId or List<CellId>", type, field_name, fd.Type.ToString());
     }
 }
Ejemplo n.º 2
0
        private static void ImportReverseEdges(IGrouping <string, ReverseEdgeFieldDescriptor> rfd_group)
        {
            ushort      src_type_code = Global.StorageSchema.GetCellType(rfd_group.Key);
            List <long> cell_ids      = Global.LocalStorage
                                        .Where(cell => cell.CellType == src_type_code)
                                        .Select(cell => cell.CellId).ToList();
            object save_cell_lock = new object();

            Parallel.ForEach(cell_ids,
#if DEBUG
                             new ParallelOptions {
                MaxDegreeOfParallelism = 1
            },
#endif

                             cellid =>
            {
                var cell = Global.LocalStorage.LoadGenericCell(cellid);
                foreach (var rfd in rfd_group)
                {
                    foreach (var target_id in cell.EnumerateField <long>(rfd.SourceFieldName))
                    {
                        begin:
                        try
                        {
                            ICell remote_cell           = Global.LocalStorage.UseGenericCell(target_id, Trinity.TSL.Lib.CellAccessOptions.ReturnNullOnCellNotFound);
                            bool save_otherwise_dispose = false;
                            if (remote_cell == null)
                            {
                                save_otherwise_dispose = true;
                                remote_cell            = Global.LocalStorage.NewGenericCell(rfd.TargetCellType);
                                remote_cell.CellId     = target_id;
                            }

                            var fd = remote_cell.GetFieldDescriptors().First(_ => _.Name == rfd.TargetFieldName);
                            if (fd.IsOfType <long>() || fd.IsOfType <string>())
                            {
                                remote_cell.AppendToField(rfd.TargetFieldName, cell.CellId);
                            }
                            else if (fd.IsOfType <int>())
                            {
                                remote_cell.AppendToField(rfd.TargetFieldName, (int)cell.CellId);
                            }
                            else
                            {
                                throw new Exception("Unsupported reverse edge import type: " + fd.TypeName);
                            }

                            if (save_otherwise_dispose)
                            {
                                lock (save_cell_lock)
                                {
                                    if (Global.LocalStorage.Contains(target_id))
                                    {
                                        goto begin;
                                    }

                                    Global.LocalStorage.SaveGenericCell(remote_cell);
                                }
                            }
                            else
                            {
                                (remote_cell as ICellAccessor).Dispose();
                            }
                        }
                        catch (Exception e)
                        {
                            Log.WriteLine(LogLevel.Warning, e.Message);
                        }
                    }
                }
            });
        }
Ejemplo n.º 3
0
 protected override void ProcessRecord()
 {
     From.AppendToField("OutEdge", To.CellId);
     Global.LocalStorage.SaveGenericCell(From);
     base.ProcessRecord();
 }
Ejemplo n.º 4
0
        public static void cell_append(IntPtr cell, string field, string content)
        {
            ICell c = (ICell)GCHandle.FromIntPtr(cell).Target;

            c.AppendToField <string>(field, content);
        }