public List<ImportResult> ProcessPath(string path, ImportMode importMode = ImportMode.Auto, Series series = null, DownloadClientItem downloadClientItem = null)
        {
            if (_diskProvider.FolderExists(path))
            {
                var directoryInfo = new DirectoryInfo(path);

                if (series == null)
                {
                    return ProcessFolder(directoryInfo, importMode, downloadClientItem);
                }

                return ProcessFolder(directoryInfo, importMode, series, downloadClientItem);
            }

            if (_diskProvider.FileExists(path))
            {
                var fileInfo = new FileInfo(path);

                if (series == null)
                {
                    return ProcessFile(fileInfo, importMode, downloadClientItem);
                }

                return ProcessFile(fileInfo, importMode, series, downloadClientItem);
            }

            _logger.Error("Import failed, path does not exist or is not accessible by Sonarr: {0}", path);
            return new List<ImportResult>();
        }
Beispiel #2
0
        public ImportActivity(
            ImportMode mode,
            SqlConnection connection,
            BatchParams batchParams,
            string targetTable,
            char csvDelimiterChar,
            string numberFormatInfo,
            IEnumerable<CsvColumnInfo> csvMetadata)
        {
            if (connection == null)
                throw new ArgumentNullException("connection");
            if (string.IsNullOrEmpty(targetTable))
                throw new ArgumentException("Target table name cannot be empty", "targetTable");
            if (csvMetadata == null)
                throw new ArgumentNullException("csvMetadata");

            _mode = mode;
            _csvMetadata = csvMetadata;
            _csvDelimiterChar = csvDelimiterChar;
            _numberFormatInfo = numberFormatInfo;

            _loader = DataLoaderBase.CreateLoader(
                mode,
                connection,
                batchParams,
                targetTable,
                _csvMetadata
                .Where(sci => !sci.ExcludeFromMapping && (mode != ImportMode.BulkDelete || sci.DeletionKey))
                .Select(sci => sci.Name));
        }
 /// <summary>
 /// ctor which takes a Device object along with import mode
 /// </summary>
 /// <param name="device"></param>
 /// <param name="importmode"></param>
 public ExportImportDevice(Device device, ImportMode importmode)
 {
     this.Id = device.Id;
     this.ETag = device.ETag;
     this.ImportMode = importmode;
     this.Status = device.Status;
     this.StatusReason = device.StatusReason;
     this.Authentication = device.Authentication;
 }
Beispiel #4
0
 public static DataLoaderBase CreateLoader(ImportMode mode, SqlConnection connection,
     BatchParams batchParams, string targetTable, IEnumerable<string> columns)
 {
     switch (mode)
     {
         case ImportMode.BulkInsert:
             return new BulkDataLoader(connection, batchParams, targetTable, columns, false);
         case ImportMode.BulkInsertWithSkipped:
             return new BulkDataLoader(connection, batchParams, targetTable, columns, true);
         case ImportMode.BulkDelete:
             return new DeleteDataLoader(connection, batchParams, targetTable, columns);
         case ImportMode.Smart:
             return new SmartDataLoader(connection, batchParams, targetTable, columns);
         default:
             throw new InvalidOperationException("Unknown ImportMode - '" + mode.ToString() + "'");
     }
 }
Beispiel #5
0
        static IEnumerable <ExportImportDevice> GenerateExportImportDeviceListForBulkOperations(IEnumerable <Device> devices, ImportMode importMode)
        {
            if (devices == null)
            {
                throw new ArgumentNullException(nameof(devices));
            }

            if (!devices.Any())
            {
                throw new ArgumentException(nameof(devices));
            }

            var exportImportDeviceList = new List <ExportImportDevice>(devices.Count());

            foreach (Device device in devices)
            {
                ValidateDeviceId(device);

                switch (importMode)
                {
                case ImportMode.Create:
                    if (!string.IsNullOrWhiteSpace(device.ETag))
                    {
                        throw new ArgumentException(ApiResources.ETagSetWhileRegisteringDevice);
                    }
                    break;

                case ImportMode.Update:
                    // No preconditions
                    break;

                case ImportMode.UpdateIfMatchETag:
                    if (string.IsNullOrWhiteSpace(device.ETag))
                    {
                        throw new ArgumentException(ApiResources.ETagNotSetWhileUpdatingDevice);
                    }
                    break;

                case ImportMode.Delete:
                    // No preconditions
                    break;

                case ImportMode.DeleteIfMatchETag:
                    if (string.IsNullOrWhiteSpace(device.ETag))
                    {
                        throw new ArgumentException(ApiResources.ETagNotSetWhileDeletingDevice);
                    }
                    break;

                default:
                    throw new ArgumentException(IotHubApiResources.GetString(ApiResources.InvalidImportMode, importMode));
                }

                var exportImportDevice = new ExportImportDevice(device, importMode);

                exportImportDeviceList.Add(exportImportDevice);
            }

            return(exportImportDeviceList);
        }
Beispiel #6
0
 /// <summary>
 /// Returns true if the mode is Compute or ImportOrCompute.
 /// </summary>
 private static bool ShouldCompute(ImportMode mode)
 {
     return(mode == ImportMode.Compute || mode == ImportMode.ImportOrCompute);
 }
Beispiel #7
0
        private void GetDuplicates(ImportProductPrice[] importProductPrices, ValidationContext <ImportProductPrice[]> context, ImportMode importMode)
        {
            var duplicates = importProductPrices.GroupBy(importProductPrice => new { importProductPrice.Sku, importProductPrice.Price.MinQuantity })
                             .SelectMany(group => importMode == ImportMode.CreateOnly ? group.Skip(1) : group.Take(group.Count() - 1))
                             .ToArray();

            context.RootContextData[Duplicates] = duplicates;
        }
        private List<ImportResult> ProcessFolder(DirectoryInfo directoryInfo, ImportMode importMode, Series series, DownloadClientItem downloadClientItem)
        {
            if (_seriesService.SeriesPathExists(directoryInfo.FullName))
            {
                _logger.Warn("Unable to process folder that is mapped to an existing show");
                return new List<ImportResult>();
            }

            var cleanedUpName = GetCleanedUpFolderName(directoryInfo.Name);
            var folderInfo = Parser.Parser.ParseTitle(directoryInfo.Name);

            if (folderInfo != null)
            {
                _logger.Debug("{0} folder quality: {1}", cleanedUpName, folderInfo.Quality);
            }

            var videoFiles = _diskScanService.GetVideoFiles(directoryInfo.FullName);

            if (downloadClientItem == null)
            {
                foreach (var videoFile in videoFiles)
                {
                    if (_diskProvider.IsFileLocked(videoFile))
                    {
                        return new List<ImportResult>
                               {
                                   FileIsLockedResult(videoFile)
                               };
                    }
                }
            }

            var decisions = _importDecisionMaker.GetImportDecisions(videoFiles.ToList(), series, folderInfo, true);
            var importResults = _importApprovedEpisodes.Import(decisions, true, downloadClientItem, importMode);

            if ((downloadClientItem == null || !downloadClientItem.IsReadOnly) &&
                importResults.Any(i => i.Result == ImportResultType.Imported) &&
                ShouldDeleteFolder(directoryInfo, series))
            {
                _logger.Debug("Deleting folder after importing valid files");
                _diskProvider.DeleteFolder(directoryInfo.FullName, true);
            }

            return importResults;
        }
Beispiel #9
0
        private LoadCounters ProcessImportTask( ImportEntity impEntity, ImportMode impMode,
			FileInfo dataFile, string logname, ref int rowcount, ref int skiprowcount, ref int errorcode )
        {
            using( var stream = ReadDataFile( dataFile ) )
            {
                var report = ImportFacade.ImportData( impEntity.GetFormatName(), impMode, stream, dataFile.Name );

                if( Configuration.LogDetails && ( report.HasValidationErrors || report.HasErrors ) )
                {
                    Encoding encoding = Encoding.GetEncoding( Configuration.LogEncoding );
                    using( var log = new StreamWriter( logname, false, encoding ) )
                    {
                        log.WriteLine( "found={0}", report.TotalCount );

                        if( report.HasValidationErrors )
                        {
                            log.WriteLine( "*** Parse and validation errors ***" );
                            foreach( var error in report.ValidationErrors )
                            {
                                log.WriteLine( "source record: " + error.RawRecord );
                                foreach( var detail in error.Details )
                                {
                                    detail.WriteToLog( log );
                                }
                            }
                        }

                        if( report.HasErrors )
                        {
                            foreach( var error in report.Errors )
                                LogException( error, log );
                        }
                    }
                }

                rowcount = impMode == ImportMode.BulkDelete ? report.Counters.Deleted : report.Counters.Added;
                skiprowcount = report.Counters.Skipped;
                int totalrows = rowcount + skiprowcount;
                errorcode = totalrows == report.TotalCount ? 0 : totalrows == 0 ? 2920 : 2910;

                return report.Counters;
            }
        }
    void ImportPosts(Id entryCollectionId, Id pagesCollectionId, Id mediaCollectionId, ImportMode mode, BlogMLBlog blog)
    {

      foreach (BlogMLPost post in blog.Posts)
      {
        LogProgress("Loading post with ID={0}", post.ID);

        try
        {
          AtomEntry entry = new AtomEntry();
          entry.Title = new AtomTitle() { Text = post.Title };
          if (post.HasExcerpt) entry.Summary = new AtomSummary() { Text = post.Excerpt.UncodedText };
          entry.Content = new AtomContent() { Type = "html", Text = post.Content.Text };
          entry.Control = new AppControl();
          entry.Control.Approved = post.Approved;

          //categories
          var ecats = new List<AtomCategory>();
          foreach (BlogMLCategoryReference cat in post.Categories)
          {
            var ec = blog.Categories.Where(c => c.ID == cat.Ref).SingleOrDefault();
            if (ec == null) throw new Exception("Invalid category reference in BlogML file.");
            ecats.Add(new AtomCategory() { Term = ec.Title });
          }
          entry.Categories = ecats;

          //authors
          var eauths = new List<AtomPerson>();
          for (int i = 0; i < post.Authors.Count; i++)
          {
            var user = UserRepository.GetUser(post.Authors[i].Ref);
            if (user == null) throw new Exception("Invalid author reference in BlogML file.");
            eauths.Add(user.ToAtomAuthor());
          }
          entry.Authors = eauths;

          entry.Published = post.DateCreated;
          entry.Updated = post.DateModified;
          
          ////fix links http://localhost:1333 to new address
          //string xmlstr = entry.Xml.ToString();
          //xmlstr = xmlstr.Replace("http://localhost:1333/", appSvc.Base.ToString());
          //entry.Xml = XElement.Parse(xmlstr);

          //TODO: add old link
          //entry.Links =

          //post to blog when normal, otherwise pages collection
          if (post.PostType == BlogML.BlogPostTypes.Normal)
            entry = AtomPubService.CreateEntry(entryCollectionId, entry, post.PostName);
          else if (pagesCollectionId != null)
            entry = AtomPubService.CreateEntry(pagesCollectionId, entry, post.PostName);
          else
          {
            LogProgress("Skipping {0} posts as there is no pages collection selected", post.PostType.ToString());
            continue;
          }
          
          LogProgress("Post added as new entry in collection with ID={0}", entry.Id);

          if (mediaCollectionId != null)
          {
            foreach (BlogMLAttachment attachment in post.Attachments)
            {
              try
              {
                string name = null;
                if (!string.IsNullOrEmpty(attachment.Path)) name = Path.GetFileNameWithoutExtension(attachment.Path);
                if (name == null && !string.IsNullOrEmpty(attachment.Url)) name = attachment.Url.IndexOf('/') > 0 ?
                attachment.Url.Substring(attachment.Url.LastIndexOf('/')) : attachment.Url;
                if (name == null) name = "Attachment";
                Stream stream = null;
                if (attachment.Embedded)
                {
                  LogProgress("Processing embedded attachment '{0}'", name);
                  stream = new MemoryStream(attachment.Data);
                }
                else if (!string.IsNullOrEmpty(attachment.Path) && File.Exists(attachment.Path))
                {
                  LogProgress("Processing local attachment '{0}'", name);
                  //first try to get locally
                  stream = File.OpenRead(attachment.Path);
                }
                else
                {
                  LogProgress("Processing remote attachment '{0}'", name);
                  //next try to download
                  stream = new WebClient().OpenRead(attachment.Url);
                }
                var media = AtomPubService.CreateMedia(mediaCollectionId, stream, name, attachment.MimeType);
                LogProgress("New media created from attachment with Id={0}", media.Id);
                //update entry with new media url
                entry.Content.Text = entry.Content.Text.Replace(attachment.Url, media.Content.Src.ToString());
              }
              catch (Exception ex)
              {
                LogService.Error(ex);
                LogProgress(System.Web.HttpUtility.HtmlEncode(ex.Message));
              }
            }
          }

          foreach (BlogMLComment comment in post.Comments)
          {
            try
            {
              LogProgress("Processing comment for post with ID={0}", comment.ID);
              AtomEntry acmt = new AtomEntry();
              acmt.Control = new AppControl();
              acmt.Title = new AtomTitle() { Text = string.IsNullOrEmpty(comment.Title) ? "Comment" : comment.Title };
              acmt.Content = new AtomContent() { Type = "html", Text = comment.Content.Text };
              acmt.Published = comment.DateCreated;
              acmt.Updated = comment.DateModified;
              acmt.Control.Approved = comment.Approved;
              //TODO: detect if user and set ID
              acmt.Authors = Enumerable.Repeat(new AtomPerson(Atom.AtomNs + "author")
              {
                Email = comment.UserEMail,
                Name = comment.UserName,
                Uri = !string.IsNullOrEmpty(comment.UserUrl) ? new Uri(comment.UserUrl) : null
              }, 1);

              acmt = AnnotateService.Annotate(entry.Id, acmt, comment.ID);

              LogProgress("Comment added as new annotation on entry with ID={0}", acmt.Id);
            }
            catch (Exception ex)
            {
              LogService.Error(ex);
              LogProgress(System.Web.HttpUtility.HtmlEncode(ex.Message));
            }
          }

          foreach (BlogMLTrackback trackback in post.Trackbacks)
          {
            try
            {
              LogProgress("Processing trackback for post with ID={0}", trackback.ID);

              AtomEntry atb = new AtomEntry();
              atb.AnnotationType = "trackback";
              atb.Title = new AtomTitle() { Text = trackback.Title };
              atb.Control = new AppControl();
              atb.Control.Approved = trackback.Approved;
              atb.Published = trackback.DateCreated;
              atb.Updated = trackback.DateModified;
              atb.Content = new AtomContent() { Src = new Uri(trackback.Url), Type = "text/html" };
              atb.Authors = new List<AtomPerson>() { new AtomAuthor() 
                  { 
                      Name = "Trackback",// string.Empty,
                      Uri = new Uri(trackback.Url)
                  } };

              AnnotateService.Annotate(entry.Id, atb, trackback.ID);
              LogProgress("Trackback added as new annotation on entry with ID={0}", atb.Id);
            }
            catch (Exception ex)
            {
              LogService.Error(ex);
              LogProgress(System.Web.HttpUtility.HtmlEncode(ex.Message));
            }
          }
        }
        catch (Exception ex)
        {
          LogService.Error(ex);
          LogProgress(System.Web.HttpUtility.HtmlEncode(ex.Message));
        }
      }
    }
        /// <summary>
        /// 导入数据到关系数据库
        /// </summary>
        /// <typeparam name="T">实体类类型</typeparam>
        /// <param name="mode">导入模式</param>
        /// <param name="isNew">导入模式为更新模式的时候,进行实体类数据新旧比较的自定义方法,第一个参数为源实体,第二个参数为数据库的目标实体,返回源是否比目标新</param>
        /// <returns>导入的数据数量</returns>
        public ImportResult Import <T>(ImportMode mode, Func <T, T, bool> isNew) where T : EntityBase, new()
        {
            Type         entityType      = typeof(T);
            string       importTableName = EntityFieldsCache.Item(entityType).TableName;
            ImportResult result          = new ImportResult();

            result.ImportTable = importTableName;
            result.IsCancel    = true;

            //导出批次管理
            List <ExportBatchInfo> batchList = MemDB.Get <ExportBatchInfo>();
            ExportBatchInfo        currBatch = batchList.FirstOrDefault(p => p.ExportTableName == importTableName);

            if (currBatch == null)
            {
                result.Flag = ImportResultFlag.NoBatchInfo;
                return(result);//没有导入批次信息,不能导入
            }
            //只有比数据库的导入批次数据新,才可以导入
            OQL q = OQL.From(currBatch)
                    .Select()
                    .Where(currBatch.ExportTableName)
                    .END;
            ExportBatchInfo dbBatch = this.CurrDbContext.QueryObject <ExportBatchInfo>(q);

            if (dbBatch == null)
            {
                currBatch.SetDefaultChanges();
                this.CurrDbContext.Add <ExportBatchInfo>(currBatch);
                result.BatchNumber = currBatch.BatchNumber;
            }
            else
            {
                result.BatchNumber = currBatch.BatchNumber;
                if (currBatch.BatchNumber <= dbBatch.BatchNumber)
                {
                    result.Flag = ImportResultFlag.IsOldData;
                    return(result);//没有新数据需要导入
                }
                currBatch.ID = dbBatch.ID;
            }

            //导入数据
            int      count = 0;//
            List <T> list  = this.MemDB.Get <T>();

            if (list.Count > 0)
            {
                ImportEntityEventArgs args = new ImportEntityEventArgs(list, entityType, importTableName, currBatch.BatchNumber);
                if (BeforeImport != null)
                {
                    BeforeImport(this, args);
                    if (args.Cancel)
                    {
                        result.Flag = ImportResultFlag.UserCanceled;
                        return(result);
                    }
                }

                if (mode == ImportMode.Append)
                {
                    list.ForEach(item => {
                        item.SetDefaultChanges();
                    });
                    count = this.CurrDbContext.AddList(list);
                }
                else if (mode == ImportMode.TruncateAndInsert)
                {
                    string sql = "TRUNCATE TABLE [" + importTableName + "]";
                    this.CurrDbContext.CurrentDataBase.ExecuteNonQuery(sql);
                    list.ForEach(item =>
                    {
                        item.SetDefaultChanges();
                    });
                    count = this.CurrDbContext.AddList(list);
                }
                else if (mode == ImportMode.Update)
                {
                    if (isNew == null)
                    {
                        throw new ArgumentNullException("当 ImportMode 为Update 模式的时候,参数 isNew 不能为空。");
                    }
                    foreach (T item in list)
                    {
                        T           dbEntity = (T)item.Clone();
                        EntityQuery eq       = new EntityQuery(this.CurrDbContext.CurrentDataBase);
                        if (eq.FillEntity(dbEntity))
                        {
                            if (isNew(item, dbEntity))
                            {
                                item.SetDefaultChanges();//设置了更改状态,才可以更新到数据库
                                count += eq.Update(item);
                            }
                        }
                    }
                }
                else if (mode == ImportMode.Merge)
                {
                    foreach (T item in list)
                    {
                        T           dbEntity = (T)item.Clone();
                        EntityQuery eq       = new EntityQuery(this.CurrDbContext.CurrentDataBase);
                        if (eq.FillEntity(dbEntity))
                        {
                            int changedCount = dbEntity.MapFrom(item, true);
                            if (changedCount > 0)
                            {
                                count += eq.Update(dbEntity);
                            }
                        }
                        else
                        {
                            //没有Fill成功实体,说明数据库没有此数据,则添加数据到数据库
                            item.SetDefaultChanges();
                            count += eq.Insert(item);
                        }
                    }
                }
                else
                {
                    //自定义的处理方式,请在 BeforeImport 事件自行处理
                }

                if (AfterImport != null)
                {
                    args.Cancel = false;
                    AfterImport(this, args);
                }
            }//end if
            //更新导入批次信息
            currBatch.BatchNumber    = result.BatchNumber;
            currBatch.LastExportDate = DateTime.Now;
            this.CurrDbContext.Update <ExportBatchInfo>(currBatch);

            result.IsCancel    = false;
            result.Flag        = ImportResultFlag.Succeed;
            result.ImportCount = count;
            return(result);
        }
        public void     DrawAssetImportParams(Rect r2, ImportAssetsWindow importAssetsWindow)
        {
            this.updateWindow = importAssetsWindow;
            //string	gameObjectName = parameter.gameObjectName;

            //if (gameObjectName == null)
            //	gameObjectName = parameter.gameObjectName = this.hierarchy.GetGameObjectName(parameter.gameObjectInstanceID);

            float w = r2.width;

            r2.height = Constants.SingleLineHeight;
            //Rect	r2 = GUILayoutUtility.GetRect(22F, Constants.SingleLineHeight);
            bool canRemember = this.localAsset == null &&
                               this.isSupported == true;

            if (Event.current.type == EventType.MouseDown)
            {
                if (canRemember == true)
                {
                    r2.width -= AssetImportParameters.RememberLabelWidth + AssetImportParameters.RememberSpacing + AssetImportParameters.LocationButtonWidth;
                }
                else
                {
                    r2.width -= AssetImportParameters.LocationButtonWidth;
                }

                //if (r2.Contains(Event.current.mousePosition) == true)
                //{
                //	this.hierarchy.PingObject(this.gameObjectInstanceID);
                //	Event.current.Use();
                //}

                if (canRemember == true)
                {
                    r2.width += AssetImportParameters.RememberLabelWidth + AssetImportParameters.RememberSpacing + AssetImportParameters.LocationButtonWidth;
                }
                else
                {
                    r2.width += AssetImportParameters.LocationButtonWidth;
                }
            }

            GUI.Box(r2, string.Empty, GeneralStyles.Toolbar);

            //if (Event.current.type == EventType.Repaint)
            //{
            //	Rect	r3 = r2;
            //	r3.width = 1F;
            //	r3.height = r3.height * 4F + 6F;

            //	//EditorGUI.DrawRect(r3, Color.cyan);
            //}

            r2.width = ImportAssetsWindow.GameObjectIconWidth;
            GUI.DrawTexture(r2, AssetPreview.GetMiniTypeThumbnail(this.type), ScaleMode.ScaleToFit);
            r2.x += r2.width;

            string name = this.name ?? (this.name = this.hierarchy.GetResourceName(this.type, this.instanceID));

            if (name == null)
            {
                GUI.Label(r2, GeneralStyles.StatusWheel);
                r2.x += r2.width;

                r2.width = w - r2.x;
                GUI.Label(r2, this.type.Name);
                importAssetsWindow.Repaint();
            }
            else
            {
                r2.width = w - r2.x;
                GUI.Label(r2, this.type.Name + " : " + this.name);
            }

            r2.x     = r2.width + ImportAssetsWindow.GameObjectIconWidth - AssetImportParameters.RememberLabelWidth - AssetImportParameters.RememberSpacing - AssetImportParameters.LocationButtonWidth;
            r2.width = AssetImportParameters.RememberLabelWidth;
            if (canRemember == true)
            {
                this.remember = GUI.Toggle(r2, this.remember, "Remember", GeneralStyles.ToolbarToggle);
            }

            r2.x    += r2.width + AssetImportParameters.RememberSpacing;
            r2.width = AssetImportParameters.LocationButtonWidth;
            if (GUI.Button(r2, "Locations (" + this.originPath.Count + ")", GeneralStyles.ToolbarButton) == true)
            {
                PopupWindow.Show(r2, new AssetLocationsWindow(this.hierarchy, this.originPath));
                //importAssets2.importingAssetsParams.Remove(this);
            }

            r2.y    += r2.height + 2F;
            r2.x     = 5F;
            r2.width = w - r2.x;

            using (LabelWidthRestorer.Get(120F))
            {
                int pathsCount = this.originPath.Count;
                //if (pathsCount == 1)
                //	EditorGUI.LabelField(r2, "Component Path", this.originPath[0]);
                //else if (pathsCount > 1)
                //{
                //	EditorGUI.LabelField(r2, "Component Path", string.Empty);

                //	r2.xMin += EditorGUIUtility.labelWidth;
                //	if (GUI.Button(r2, "Many (" + pathsCount + ")", GeneralStyles.ToolbarDropDown) == true)
                //	{
                //	}
                //	r2.xMin -= EditorGUIUtility.labelWidth;
                //}
                r2.y += /*r2.height + */ 2F;

                if (this.localAsset != null)
                {
                    EditorGUI.ObjectField(r2, "Asset", this.localAsset, this.type, false);
                }
                else if (this.isSupported == false)
                {
                    r2.height = 24F;
                    r2.xMin  += 5F;
                    r2.xMax  -= 5F;
                    EditorGUI.HelpBox(r2, "Not supported.", MessageType.Warning);
                }
                else
                {
                    bool hasError = this.importMode == ImportMode.None;

                    //EditorGUILayout.BeginHorizontal();
                    {
                        using (LabelWidthRestorer.Get(100F))
                        {
                            if (pathsCount > 0)
                            {
                                EditorGUI.BeginDisabledGroup(this.parametersConfirmed == true);
                                {
                                    //r2.width = 182F/* - EditorGUI.indentLevel * 15F*/;
                                    this.importMode = (ImportMode)EditorGUI.EnumPopup(r2, "Import Mode", this.importMode);
                                    r2.y           += r2.height;
                                }
                                EditorGUI.EndDisabledGroup();
                            }

                            //EditorGUILayout.BeginVertical();
                            {
                                EditorGUI.BeginDisabledGroup(this.parametersConfirmed == true);
                                {
                                    if (this.importMode == ImportMode.Auto)
                                    {
                                        if (this.name == null)
                                        {
                                            this.name = this.hierarchy.GetResourceName(this.type, this.instanceID);
                                        }

                                        if (this.autoPath == null && this.name != null)
                                        {
                                            IObjectImporter importer = RemoteUtility.GetImportAssetTypeSupported(this.type);

                                            if (importer != null)
                                            {
                                                string path     = this.prefabPath;
                                                string filename = string.Join("_", this.name.Split(Path.GetInvalidFileNameChars())) + importer.GetExtension();

                                                if (string.IsNullOrEmpty(this.hierarchy.specificSharedSubFolder) == false)
                                                {
                                                    path = this.hierarchy.specificSharedSubFolder;
                                                }

                                                //if (this.hierarchy.rawCopyAssetsToSubFolder == true)
                                                //	path += "/" + .gameObjectName;
                                                //else if (this.hierarchy.prefixAsset == true)
                                                //	filename = string.Join("_", (parameter.gameObjectName).Split(Path.GetInvalidFileNameChars())) + '_' + filename;

                                                this.autoPath = path + "/" + filename;
                                            }
                                        }

                                        if (/*parameter.gameObjectName != null && */ this.name != null)
                                        {
                                            if (this.autoPath == null)
                                            {
                                                r2.height = 24F;
                                                hasError  = true;
                                                EditorGUI.HelpBox(r2, "Asset type is not supported, will not be imported.", MessageType.Warning);
                                                r2.y += r2.height;
                                            }
                                            else
                                            {
                                                EditorGUI.BeginChangeCheck();
                                                this.autoPath = NGEditorGUILayout.SaveFileField(r2, "Output Path", this.autoPath);
                                                if (EditorGUI.EndChangeCheck() == true)
                                                {
                                                    Uri  pathUri;
                                                    bool isValidUri = Uri.TryCreate(this.autoPath, UriKind.Relative, out pathUri);
                                                    bool v          = isValidUri && pathUri != null /* && pathUri.IsLoopback*/;

                                                    //FileInfo fi = null;
                                                    //try
                                                    //{
                                                    //	fi = new FileInfo(parameter.autoPath);
                                                    //}
                                                    //catch (System.ArgumentException) { }
                                                    //catch (PathTooLongException) { }
                                                    //catch (System.NotSupportedException) { }

                                                    if (v == false)
                                                    {
                                                        //if (ReferenceEquals(fi, null))
                                                        this.autoPathError = "Path is invalid.";
                                                    }
                                                    // file name is not valid
                                                    else
                                                    {
                                                        this.autoPathError = null;
                                                    }
                                                    // file name is valid... May check for existence by calling fi.Exists.
                                                }
                                                r2.y += r2.height;

                                                if (string.IsNullOrEmpty(this.autoPathError) == false)
                                                {
                                                    r2.height = 24F;
                                                    EditorGUI.HelpBox(r2, this.autoPathError, MessageType.Error);
                                                    r2.y += r2.height;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            Utility.content.text = "Waiting for server...";
                                            EditorGUI.LabelField(r2, Utility.content, GeneralStyles.StatusWheel);
                                            r2.y += r2.height;

                                            importAssetsWindow.Repaint();
                                        }
                                    }
                                    else if (this.importMode == ImportMode.UseGUID)
                                    {
                                        EditorGUI.BeginChangeCheck();
                                        Object o = EditorGUI.ObjectField(r2, "Asset", this.guidAsset, this.type, false);
                                        if (EditorGUI.EndChangeCheck() == true)
                                        {
                                            this.guidAsset = o;
                                            this.guid      = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(o));
                                        }
                                        r2.y += r2.height;

                                        EditorGUI.LabelField(r2, "GUID", this.guid ?? "None");
                                        r2.y += r2.height;

                                        if (string.IsNullOrEmpty(this.guid) == true)
                                        {
                                            hasError = true;
                                        }
                                    }
                                    else if (this.importMode == ImportMode.RawCopy)
                                    {
                                        EditorGUI.BeginChangeCheck();
                                        string path = NGEditorGUILayout.SaveFileField(r2, "Output Path", this.outputPath);
                                        if (EditorGUI.EndChangeCheck() == true)
                                        {
                                            if (path.StartsWith(Application.dataPath) == true)
                                            {
                                                this.outputPath = path.Substring(Application.dataPath.Length - "Assets".Length);
                                            }
                                            else if (path.StartsWith("Assets") == true)
                                            {
                                                this.outputPath = path;
                                            }
                                        }
                                        r2.y += r2.height;

                                        if (string.IsNullOrEmpty(path) == false &&
                                            path.StartsWith(Application.dataPath) == false &&
                                            path.StartsWith("Assets") == false)
                                        {
                                            hasError  = true;
                                            r2.height = 24F;
                                            EditorGUI.HelpBox(r2, "Path must be in Assets folder.", MessageType.Warning);
                                            r2.y += r2.height;
                                        }
                                    }
                                }
                                EditorGUI.EndDisabledGroup();

                                r2.y     += 2F;
                                r2.height = Constants.SingleLineHeight;

                                if (this.parametersConfirmed == true)
                                {
                                    if (this.importErrorMessage != null)
                                    {
                                        r2.xMin  += 5F;
                                        r2.height = 32F;
                                        EditorGUI.HelpBox(r2, "Import failed : " + this.importErrorMessage, MessageType.Error);
                                    }
                                    else if (this.copyAsset != null && (this.importMode == ImportMode.RawCopy || this.importMode == ImportMode.Auto))
                                    {
                                        EditorGUI.ObjectField(r2, "Created Asset", this.copyAsset, this.type, false);
                                    }
                                    else if (this.totalBytes > 0)
                                    {
                                        r2.xMin += 5F;

                                        if (this.bytesReceived == this.totalBytes)
                                        {
                                            EditorGUI.ProgressBar(r2, 1F, "Creating asset...");
                                        }
                                        else
                                        {
                                            float  rate = (float)this.bytesReceived / (float)this.totalBytes;
                                            string cacheFileSize;

                                            if (this.totalBytes >= 1024 * 1024)
                                            {
                                                cacheFileSize = ((float)(this.bytesReceived / (1024F * 1024F))).ToString("N1") + " / " + ((float)(this.totalBytes / (1024F * 1024F))).ToString("N1") + " MiB";
                                            }
                                            else if (this.totalBytes >= 1024)
                                            {
                                                cacheFileSize = ((float)(this.bytesReceived / 1024F)).ToString("N1") + " / " + ((float)(this.totalBytes / 1024F)).ToString("N1") + " KiB";
                                            }
                                            else
                                            {
                                                cacheFileSize = this.bytesReceived + " / " + this.totalBytes + " B";
                                            }

                                            EditorGUI.ProgressBar(r2, rate, cacheFileSize + " (" + (rate * 100F).ToString("0.0") + "%)");
                                            importAssetsWindow.Repaint();
                                        }
                                    }
                                }
                                else
                                {
                                    EditorGUI.BeginDisabledGroup(hasError);
                                    {
                                        r2.width = 100F;
                                        r2.x     = w - r2.width - 10F;

                                        if (GUI.Button(r2, "Confirm") == true)
                                        {
                                            this.Confirm();
                                            importAssetsWindow.Repaint();
                                        }
                                    }
                                    EditorGUI.EndDisabledGroup();
                                }
                            }
                        }

                        if (Conf.DebugMode != Conf.DebugState.None && this.importErrorMessage != null && GUI.Button(r2, "Retry Import") == true)
                        {
                            this.ResetImport();
                        }
                    }
                }
            }
        }
Beispiel #13
0
        public static bool OwnerMustBeSet(EntityReference sourceOwnerId, EntityReference ownerInCrm, ImportMode setOwnerMode)
        {
            if (sourceOwnerId != null && Constants.UpdateModes.Contains(setOwnerMode))
            {
                bool ownerIsEqualToCurrentOwner = ownerInCrm != null && sourceOwnerId.Id == ownerInCrm.Id;
                if (!ownerIsEqualToCurrentOwner || (setOwnerMode != ImportMode.UpdateChangedValuesOnly && setOwnerMode != ImportMode.AllChangedValuesOnly))
                {
                    return(true);
                }
            }

            return(false);
        }
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Name != null)
         {
             hashCode = hashCode * 59 + Name.GetHashCode();
         }
         if (Type != null)
         {
             hashCode = hashCode * 59 + Type.GetHashCode();
         }
         if (ImportMode != null)
         {
             hashCode = hashCode * 59 + ImportMode.GetHashCode();
         }
         if (AclHandling != null)
         {
             hashCode = hashCode * 59 + AclHandling.GetHashCode();
         }
         if (PackageRoots != null)
         {
             hashCode = hashCode * 59 + PackageRoots.GetHashCode();
         }
         if (PackageFilters != null)
         {
             hashCode = hashCode * 59 + PackageFilters.GetHashCode();
         }
         if (PropertyFilters != null)
         {
             hashCode = hashCode * 59 + PropertyFilters.GetHashCode();
         }
         if (TempFsFolder != null)
         {
             hashCode = hashCode * 59 + TempFsFolder.GetHashCode();
         }
         if (UseBinaryReferences != null)
         {
             hashCode = hashCode * 59 + UseBinaryReferences.GetHashCode();
         }
         if (AutoSaveThreshold != null)
         {
             hashCode = hashCode * 59 + AutoSaveThreshold.GetHashCode();
         }
         if (CleanupDelay != null)
         {
             hashCode = hashCode * 59 + CleanupDelay.GetHashCode();
         }
         if (FileThreshold != null)
         {
             hashCode = hashCode * 59 + FileThreshold.GetHashCode();
         }
         if (MEGA_BYTES != null)
         {
             hashCode = hashCode * 59 + MEGA_BYTES.GetHashCode();
         }
         if (UseOffHeapMemory != null)
         {
             hashCode = hashCode * 59 + UseOffHeapMemory.GetHashCode();
         }
         if (DigestAlgorithm != null)
         {
             hashCode = hashCode * 59 + DigestAlgorithm.GetHashCode();
         }
         if (MonitoringQueueSize != null)
         {
             hashCode = hashCode * 59 + MonitoringQueueSize.GetHashCode();
         }
         if (PathsMapping != null)
         {
             hashCode = hashCode * 59 + PathsMapping.GetHashCode();
         }
         if (StrictImport != null)
         {
             hashCode = hashCode * 59 + StrictImport.GetHashCode();
         }
         return(hashCode);
     }
 }
        protected List <dynamic> CreateCommandsInOrder(
            ImportMode importMode,
            int id,
            DateTime from,
            DateTime until)
        {
            var importSubaddressCommands = new List <ImportSubaddressFromCrab>();
            List <ImportSubaddressFromCrab>         importSubaddressHistCommands;
            List <ImportSubaddressStatusFromCrab>   importSubaddressStatusCommands;
            List <ImportSubaddressStatusFromCrab>   importSubaddressStatusHistCommands;
            List <ImportSubaddressPositionFromCrab> importSubaddressPositionCommands;
            List <ImportSubaddressPositionFromCrab> importSubaddressPositionHistCommands;
            var importHouseNumberSubaddressCommands = new List <ImportHouseNumberSubaddressFromCrab>();
            List <ImportHouseNumberSubaddressFromCrab> importHouseNumberSubaddressCommandsHist;
            var importSubaddressMailCantonCommands = new List <ImportSubaddressMailCantonFromCrab>();
            List <ImportSubaddressMailCantonFromCrab> importSubaddressMailCantonCommandsHist;

            using (var context = _crabEntitiesFactory())
            {
                var importSubaddressFromCrab = AdresSubadresQueries.GetTblSubadresBySubadresId(id, context);
                if (importSubaddressFromCrab != null)
                {
                    importSubaddressCommands = new List <ImportSubaddressFromCrab> {
                        CrabSubaddressMapper.Map(importSubaddressFromCrab)
                    }
                }
                ;

                importSubaddressHistCommands = CrabSubaddressMapper.Map(AdresSubadresQueries.GetTblSubadresHistBySubadresId(id, context)).ToList();

                importSubaddressStatusCommands     = CrabSubaddressStatusMapper.Map(AdresSubadresQueries.GetTblSubadresstatussesBySubadresId(id, context)).ToList();
                importSubaddressStatusHistCommands = CrabSubaddressStatusMapper.Map(AdresSubadresQueries.GetTblSubadresstatussesHistBySubadresId(id, context)).ToList();

                importSubaddressPositionCommands     = CrabSubaddressPositionMapper.Map(AdresSubadresQueries.GetTblAdrespositiesBySubadresId(id, context)).ToList();
                importSubaddressPositionHistCommands = CrabSubaddressPositionMapper.Map(AdresSubadresQueries.GetTblAdrespositiesHistBySubadresId(id, context)).ToList();

                var allHouseNumbers = importSubaddressHistCommands.Select(x => (int)x.HouseNumberId).ToList();
                if (importSubaddressFromCrab != null)
                {
                    allHouseNumbers.Add((int)importSubaddressCommands.First().HouseNumberId);
                }

                allHouseNumbers = allHouseNumbers.Distinct().ToList();

                foreach (var houseNumber in allHouseNumbers)
                {
                    var tblHuisNummerByHuisnummerId = AdresHuisnummerQueries.GetTblHuisNummerByHuisnummerId(houseNumber, context);
                    if (tblHuisNummerByHuisnummerId != null)
                    {
                        var importHouseNumberSubadresFromCrab = CrabSubaddressHouseNumberMapper.Map(tblHuisNummerByHuisnummerId, id);
                        if (importHouseNumberSubadresFromCrab != null)
                        {
                            importHouseNumberSubaddressCommands.Add(importHouseNumberSubadresFromCrab);
                        }
                    }

                    importSubaddressMailCantonCommands.AddRange(
                        CrabSubaddressMailCantonMapper.GetCommandsFor(AdresHuisnummerQueries.GetTblHuisnummerPostkantonsByHuisnummerId(houseNumber, context), id));
                }

                importHouseNumberSubaddressCommandsHist =
                    CrabSubaddressHouseNumberMapper.Map(AdresHuisnummerQueries.GetTblHuisNummerHistByHuisnummerIds(allHouseNumbers, context), id).ToList();

                importSubaddressMailCantonCommandsHist =
                    CrabSubaddressMailCantonMapper.GetCommandsFor(AdresHuisnummerQueries.GetTblHuisnummerPostKantonHistsByHuisnummerIds(allHouseNumbers, context),
                                                                  id).ToList();
            }

            var allSubaddressCommands = importSubaddressHistCommands.Select(x =>
                                                                            Tuple.Create <dynamic, int, int, string>(x, 2, 0, $"Subadres {x.SubaddressId}"))
                                        .Concat(importSubaddressCommands.Select(x =>
                                                                                Tuple.Create <dynamic, int, int, string>(x, 2, 1, $"Subadres {x.SubaddressId}")))
                                        .Concat(importSubaddressStatusHistCommands.Select(x =>
                                                                                          Tuple.Create <dynamic, int, int, string>(x, 3, 0, $"Subadres {x.SubaddressId}")))
                                        .Concat(importSubaddressStatusCommands.Select(x =>
                                                                                      Tuple.Create <dynamic, int, int, string>(x, 3, 1, $"Subadres {x.SubaddressId}")))
                                        .Concat(importSubaddressPositionHistCommands.Select(x =>
                                                                                            Tuple.Create <dynamic, int, int, string>(x, 3, 2, $"Subadres {x.SubaddressId}")))
                                        .Concat(importSubaddressPositionCommands.Select(x =>
                                                                                        Tuple.Create <dynamic, int, int, string>(x, 3, 3, $"Subadres {x.SubaddressId}")))
                                        .Concat(importHouseNumberSubaddressCommandsHist.Select(x =>
                                                                                               Tuple.Create <dynamic, int, int, string>(x, 0, 0, $"Subadres {x.SubaddressId}")))
                                        .Concat(importHouseNumberSubaddressCommands.Select(x =>
                                                                                           Tuple.Create <dynamic, int, int, string>(x, 0, 1, $"Subadres {x.SubaddressId}")))
                                        .Concat(importSubaddressMailCantonCommandsHist.Select(x =>
                                                                                              Tuple.Create <dynamic, int, int, string>(x, 1, 0, $"Subadres {x.SubaddressId}")))
                                        .Concat(importSubaddressMailCantonCommands.Select(x =>
                                                                                          Tuple.Create <dynamic, int, int, string>(x, 1, 1, $"Subadres {x.SubaddressId}")))
                                        .ToList();

            var addressCommands = allSubaddressCommands
                                  .Where(x => x.Item1.Timestamp > from.ToCrabInstant() && x.Item1.Timestamp <= until.ToCrabInstant());

            if (importMode == ImportMode.Update) //if an update changes the subaddress' house number, make sure the commands for that house number are also sent
            {
                var houseNumbersForUpdate = importSubaddressCommands
                                            .Concat(importSubaddressHistCommands)
                                            .Where(x => x.Timestamp > from.ToCrabInstant() && x.Timestamp <= until.ToCrabInstant())
                                            .Select(x => x.HouseNumberId).ToList();

                if (houseNumbersForUpdate.Any())
                {
                    var houseNumbersBeforeUpdate = importSubaddressCommands
                                                   .Concat(importSubaddressHistCommands)
                                                   .Where(x => x.Timestamp <= from.ToCrabInstant())
                                                   .Select(x => x.HouseNumberId).ToList();

                    var newHouseNumbers = houseNumbersForUpdate.Except(houseNumbersBeforeUpdate);

                    foreach (var newHouseNumber in newHouseNumbers)
                    {
                        addressCommands = addressCommands.Concat(allSubaddressCommands.Except(addressCommands).Where(x =>
                                                                                                                     //(x.Item1 is ImportSubaddressFromCrab importSubaddressFromCrab && importSubaddressFromCrab.HouseNumberId == newHouseNumber) ||
                                                                                                                     (x.Item1 is ImportSubaddressMailCantonFromCrab importSubaddressMailCantonFromCrab && importSubaddressMailCantonFromCrab.HouseNumberId == newHouseNumber) ||
                                                                                                                     (x.Item1 is ImportHouseNumberSubaddressFromCrab importHouseNumberSubaddressFromCrab && importHouseNumberSubaddressFromCrab.HouseNumberId == newHouseNumber)));
                    }
                }
            }

            addressCommands = addressCommands.OrderBy(x => x.Item1.Timestamp)
                              .ThenBy(x => x.Item2)
                              .ThenBy(x => x.Item3);

            var commands = new List <dynamic>();

            ImportHouseNumberSubaddressFromCrab initialImportHouseNumberSubaddressFromCrab = null;

            if (importMode == ImportMode.Init)
            {
                initialImportHouseNumberSubaddressFromCrab = importHouseNumberSubaddressCommands
                                                             .Concat(importHouseNumberSubaddressCommandsHist)
                                                             .OrderBy(x => (Instant)x.Timestamp)
                                                             .First(x => x.HouseNumberId == addressCommands.First <ImportSubaddressFromCrab>().HouseNumberId);

                commands.Add(initialImportHouseNumberSubaddressFromCrab);
            }

            foreach (var adresCommand in addressCommands)
            {
                if (importMode == ImportMode.Update || !adresCommand.Item1.Equals(initialImportHouseNumberSubaddressFromCrab))
                {
                    commands.Add(adresCommand.Item1);
                }
            }

            return(commands);
        }
        /// <summary>
        /// Returns true if OrgApacheSlingDistributionSerializationImplVltVaultDistributionProperties instances are equal
        /// </summary>
        /// <param name="other">Instance of OrgApacheSlingDistributionSerializationImplVltVaultDistributionProperties to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(OrgApacheSlingDistributionSerializationImplVltVaultDistributionProperties other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                     ) &&
                 (
                     Type == other.Type ||
                     Type != null &&
                     Type.Equals(other.Type)
                 ) &&
                 (
                     ImportMode == other.ImportMode ||
                     ImportMode != null &&
                     ImportMode.Equals(other.ImportMode)
                 ) &&
                 (
                     AclHandling == other.AclHandling ||
                     AclHandling != null &&
                     AclHandling.Equals(other.AclHandling)
                 ) &&
                 (
                     PackageRoots == other.PackageRoots ||
                     PackageRoots != null &&
                     PackageRoots.Equals(other.PackageRoots)
                 ) &&
                 (
                     PackageFilters == other.PackageFilters ||
                     PackageFilters != null &&
                     PackageFilters.Equals(other.PackageFilters)
                 ) &&
                 (
                     PropertyFilters == other.PropertyFilters ||
                     PropertyFilters != null &&
                     PropertyFilters.Equals(other.PropertyFilters)
                 ) &&
                 (
                     TempFsFolder == other.TempFsFolder ||
                     TempFsFolder != null &&
                     TempFsFolder.Equals(other.TempFsFolder)
                 ) &&
                 (
                     UseBinaryReferences == other.UseBinaryReferences ||
                     UseBinaryReferences != null &&
                     UseBinaryReferences.Equals(other.UseBinaryReferences)
                 ) &&
                 (
                     AutoSaveThreshold == other.AutoSaveThreshold ||
                     AutoSaveThreshold != null &&
                     AutoSaveThreshold.Equals(other.AutoSaveThreshold)
                 ) &&
                 (
                     CleanupDelay == other.CleanupDelay ||
                     CleanupDelay != null &&
                     CleanupDelay.Equals(other.CleanupDelay)
                 ) &&
                 (
                     FileThreshold == other.FileThreshold ||
                     FileThreshold != null &&
                     FileThreshold.Equals(other.FileThreshold)
                 ) &&
                 (
                     MEGA_BYTES == other.MEGA_BYTES ||
                     MEGA_BYTES != null &&
                     MEGA_BYTES.Equals(other.MEGA_BYTES)
                 ) &&
                 (
                     UseOffHeapMemory == other.UseOffHeapMemory ||
                     UseOffHeapMemory != null &&
                     UseOffHeapMemory.Equals(other.UseOffHeapMemory)
                 ) &&
                 (
                     DigestAlgorithm == other.DigestAlgorithm ||
                     DigestAlgorithm != null &&
                     DigestAlgorithm.Equals(other.DigestAlgorithm)
                 ) &&
                 (
                     MonitoringQueueSize == other.MonitoringQueueSize ||
                     MonitoringQueueSize != null &&
                     MonitoringQueueSize.Equals(other.MonitoringQueueSize)
                 ) &&
                 (
                     PathsMapping == other.PathsMapping ||
                     PathsMapping != null &&
                     PathsMapping.Equals(other.PathsMapping)
                 ) &&
                 (
                     StrictImport == other.StrictImport ||
                     StrictImport != null &&
                     StrictImport.Equals(other.StrictImport)
                 ));
        }
Beispiel #17
0
        public ImporterBase( ImportSettings settings, ImportMode mode )
        {
            if( settings == null )
                throw new ArgumentNullException( "settings" );
            _Connection = new SqlConnection( ConfigurationManager.ConnectionStrings[ settings.ConnectionStringName ].ConnectionString );
            _Connection.Open();
            _Activity = new ImportActivity(
                        mode,
                        _Connection,
                        settings.BatchParams,
                        settings.TargetTable,
                        settings.CsvDelimiterChar,
                        settings.NumberFormatInfo,
                        settings.CsvMetadata );

            _Activity.ValidateRecord += OnValidateRecord;

            _Activity.Complete += ( s, e ) => _CurrentReport.Counters = e.Counters;

            _Activity.DbError += ( s, e ) => _CurrentReport.AddError( e.ErrorInfo );
        }
        /// <summary>
        /// Initialiezs a new instance of the DictionaryWrapper class
        /// </summary>
        /// <param name="wrapped">the wrapped dictionary</param>
        public ExcelDataDictionaryWrapper(IDictionary <string, ExcelDataRecord> wrapped, ImportMode mode)
        {
            if (mode == ImportMode.TextPlusActualTypes)
            {
                throw new ArgumentException("Unsupported for DictionaryWrapper", nameof(mode));
            }

            this.wrapped = wrapped;
        }
Beispiel #19
0
 public StandardImporter(ImportSettings settings, ImportMode mode)
     : base(settings, mode)
 {
 }
Beispiel #20
0
        public static bool StatusMustBeSet(OptionSetValue sourceStatuscode, OptionSetValue statuscodeInCrm, ImportMode setStateMode)
        {
            if (sourceStatuscode != null && Constants.UpdateModes.Contains(setStateMode))
            {
                bool statuscodeIsEqualToCurrentStatuscode = statuscodeInCrm != null && sourceStatuscode.Value == statuscodeInCrm.Value;
                if (!statuscodeIsEqualToCurrentStatuscode || (setStateMode != ImportMode.UpdateChangedValuesOnly && setStateMode != ImportMode.AllChangedValuesOnly))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #21
0
 public static Promise <RunResult> ImportAsync(string gameDataPath, CommandInput input, ImportMode mode)
 {
     return(ImportAsync(gameDataPath, new string[0], input, mode));
 }
Beispiel #22
0
 public void SetBusinessKeyAndImportTypeForRecord(int record, string businessKey, ImportMode importMode)
 {
     this.databaseInterface.ExecuteNonQuery(
         "Update tblRecordLog set CombinedBusinessKey = '" + SafeString(businessKey) + "', " +
         "ImportMode=" + (int)importMode + " " +
         "Where pkRecordLogId = " + record);
 }
Beispiel #23
0
 public void PushImportMode(ImportMode mode)
 {
     this.importModes.AddFirst(mode);
 }
Beispiel #24
0
        public static ImportReport ImportData(string format, ImportMode mode, Stream stream, string filename)
        {
            if (string.IsNullOrEmpty(format))
                throw new ArgumentException("csv data format is not specified", "format");
            if (stream == null)
                throw new ArgumentNullException("stream");
            if (string.IsNullOrEmpty(filename))
                throw new ArgumentException("csv data filename is not specified", "filename");

            var settings = GetSettings(format);

            ImporterBase importer = null;
            switch (format)
            {
                case _prices:
                    if( mode == ImportMode.BulkInsert ||
                       mode == ImportMode.BulkInsertWithSkipped )
                    {
                        importer = new PricesImporter( settings, mode );
                    }
                    break;
                case _priceFactors:
                    if (mode == ImportMode.BulkInsert ||
                        mode == ImportMode.BulkInsertWithSkipped)
                    {
                        importer = new PriceFactorsImporter(settings, mode);
                    }
                    break;
                case _crosses:
                case _crossesBrands:
                case _crossesGroups:
                case _crossesLinks:
                    if( mode == ImportMode.BulkInsert ||
                        mode == ImportMode.BulkInsertWithSkipped ||
                        mode == ImportMode.BulkDelete)
                    {
                        importer = new StandardImporter(settings, mode);
                    }
                    break;
            }

            if (importer == null)
            {
                throw new InvalidOperationException(
                    string.Format("{0} {1} importer not supported", format, mode));
            }

            try
            {
                return importer.ImportData(stream, filename);
            }
            catch (Exception ex)
            {
                return new ImportReport() { LoadResult = -1, Counters = new LoadCounters() { Aborted = -1 } };
                //TODO: Вернуть объект ImportReport с флагом, чтобы не удалять файл с данными и файл отмашки.
            }
            finally
            {
                importer.Dispose();
            }
        }
        private List<ImportResult> ProcessFolder(DirectoryInfo directoryInfo, ImportMode importMode, DownloadClientItem downloadClientItem)
        {
            var cleanedUpName = GetCleanedUpFolderName(directoryInfo.Name);
            var series = _parsingService.GetSeries(cleanedUpName);

            if (series == null)
            {
                _logger.Debug("Unknown Series {0}", cleanedUpName);

                return new List<ImportResult>
                       {
                           UnknownSeriesResult("Unknown Series")
                       };
            }

            return ProcessFolder(directoryInfo, importMode, series, downloadClientItem);
        }
        public override void Execute()
        {
            try
            {
                Dictionary <string, SyncEntity> completedImports = ReadCompletedImports();

                var allFiles = ReadFiles(FilesFilter);
                Program.Console($"Found {allFiles.Length} files to import");
                foreach (var f in allFiles.OrderBy(f => f.Name))
                {
                    if (completedImports.ContainsKey(f.Name))
                    {
                        Program.Console($"Skipping {f.Name}, already imported on {completedImports[f.Name].Imported.ToString("u")}");
                        continue;
                    }

                    var fileNameSplit = f.Name.Split('.');
                    if (fileNameSplit.Length != 4)
                    {
                        throw new InvalidOperationException($"File {f.Name} do not have 4 components: [Order].[Collection].[Operation].json");
                    }
                    string     collectionName = fileNameSplit[1];
                    ImportMode importMode     = Enum.Parse <ImportMode>(fileNameSplit[2], true);

                    Program.Console($"Importing {f.Name} to collection {collectionName}, mode {importMode}");


                    SyncEntity importResult = new SyncEntity();
                    importResult.FileName = f.Name;

                    try
                    {
                        switch (importMode)
                        {
                        case ImportMode.Drop:
                            dropCollection(collectionName);
                            break;

                        case ImportMode.Delete:
                            deleteFromCollection(collectionName, f);
                            break;

                        case ImportMode.Insert:
                        case ImportMode.Upsert:
                        case ImportMode.Merge:
                            var resultCode = Program.Exec(IMPORT_COMMAND, $"{ConnectionString.ToCommandLine()}{AuthenticationDatabaseToCommandLine()} --collection {collectionName} --type json --mode {importMode.ToString().ToLower()} --stopOnError --file {f.Name}");
                            if (resultCode != 0)
                            {
                                throw new InvalidOperationException($"mongoimport result code {resultCode}, interrupting");
                            }
                            break;

                        case ImportMode.Eval:
                            var evalResultCode = Program.Exec(MONGO_COMMAND, $"{Connection} {f.Name}");
                            if (evalResultCode != 0)
                            {
                                throw new InvalidOperationException($"mongo result code {evalResultCode}, interrupting");
                            }
                            break;

                        case ImportMode.CreateIndex:
                            var text = File.ReadAllText(f.FullName);

                            Program.Console("Index params:");
                            Program.Console(text);

                            var command  = string.Format(CREATE_INDEX, collectionName, text);
                            var fileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".js");
                            File.WriteAllText(fileName, command);

                            try
                            {
                                var createIndexResultCode = Program.Exec(MONGO_COMMAND, $"{Connection} {fileName}");
                                switch (createIndexResultCode)
                                {
                                // no error
                                case 0:
                                    break;

                                case 11000:
                                    throw new InvalidOperationException($"CreateIndex failed with error 'duplicate key error', interrupting");

                                default:
                                    // all error codes with explanation
                                    // https://github.com/mongodb/mongo/blob/master/src/mongo/base/error_codes.err
                                    throw new InvalidOperationException($"CreateIndex result code {createIndexResultCode}, interrupting");
                                }
                            }
                            finally
                            {
                                File.Delete(fileName);
                            }
                            break;

                        default: throw new InvalidOperationException($"Import mode {importMode} not implemented yet");
                        }
                        importResult.Success = true;
                    }
                    finally
                    {
                        SyncCollection.InsertOne(importResult);
                    }
                }
                Program.Console($"Import completed successfully");
            }
            catch (Exception ex)
            {
                Program.Console($"Error during import: {ex.Message}");
                Environment.Exit(1);
            }
        }
Beispiel #27
0
        public void Import(string file, ImportMode mode)
        {
            string foundFile = file;
            if(!File.Exists(foundFile))
            {
                foreach (string path in this.importPaths)
                {
                    foundFile = Path.Combine(path, file);
                    if (File.Exists(foundFile))
                        break;
                }

                if (!File.Exists(foundFile))
                    throw new CompileException(string.Format("Unable to find import \"{0}\" in import paths", file));
            }

            string fullPath = Path.GetFullPath(foundFile);
            if (importedFiles.Contains(fullPath))
                return;

            string fileDir = Path.GetDirectoryName(fullPath);
            this.AddImportPath(fileDir);

            PushImportMode(mode);
            this.FileStack.Push(fullPath);

            if (mode == ImportMode.Library)
                this.importedLibraries.Add(file);

            try
            {
                Nodes.ICompileNode root = LanguageUtilities.ParseFile(fullPath);
                this.Compile(root);
            }
            catch(Exception e)
            {
                throw new CompileException("Encountered exception while including " + fullPath, e);
            }

            this.FileStack.Pop();
            PopImportMode();

            this.RemoveImportPath(fileDir);
        }
        public static Hash128 GetSubSceneArtifactHash(Hash128 sceneGUID, Hash128 buildConfigurationGUID, ImportMode importMode)
        {
            var guid = SceneWithBuildConfigurationGUIDs.EnsureExistsFor(sceneGUID, buildConfigurationGUID, out var mustRequestRefresh);

            if (mustRequestRefresh)
            {
                UnityEditor.AssetDatabase.Refresh();
            }

            if (!s_HashToString.TryGetValue(guid, out var guidString))
            {
                guidString = s_HashToString[guid] = guid.ToString();
            }
            return(AssetDatabaseCompatibility.GetArtifactHash(guidString, SubSceneImporterType, importMode));
        }
Beispiel #29
0
        private List <ImportResult> ProcessFolder(IDirectoryInfo directoryInfo, ImportMode importMode, Artist artist, DownloadClientItem downloadClientItem)
        {
            if (_artistService.ArtistPathExists(directoryInfo.FullName))
            {
                _logger.Warn("Unable to process folder that is mapped to an existing artist");
                return(new List <ImportResult>());
            }

            var cleanedUpName = GetCleanedUpFolderName(directoryInfo.Name);
            var folderInfo    = Parser.Parser.ParseAlbumTitle(directoryInfo.Name);
            var trackInfo     = new ParsedTrackInfo {
            };

            if (folderInfo != null)
            {
                _logger.Debug("{0} folder quality: {1}", cleanedUpName, folderInfo.Quality);

                trackInfo = new ParsedTrackInfo
                {
                    AlbumTitle   = folderInfo.AlbumTitle,
                    ArtistTitle  = folderInfo.ArtistName,
                    Quality      = folderInfo.Quality,
                    ReleaseGroup = folderInfo.ReleaseGroup,
                    ReleaseHash  = folderInfo.ReleaseHash,
                };
            }
            else
            {
                trackInfo = null;
            }

            var audioFiles = _diskScanService.FilterFiles(directoryInfo.FullName, _diskScanService.GetAudioFiles(directoryInfo.FullName));

            if (downloadClientItem == null)
            {
                foreach (var audioFile in audioFiles)
                {
                    if (_diskProvider.IsFileLocked(audioFile.FullName))
                    {
                        return(new List <ImportResult>
                        {
                            FileIsLockedResult(audioFile.FullName)
                        });
                    }
                }
            }

            var decisions     = _importDecisionMaker.GetImportDecisions(audioFiles, artist, trackInfo);
            var importResults = _importApprovedTracks.Import(decisions, true, downloadClientItem, importMode);

            if (importMode == ImportMode.Auto)
            {
                importMode = (downloadClientItem == null || downloadClientItem.CanMoveFiles) ? ImportMode.Move : ImportMode.Copy;
            }

            if (importMode == ImportMode.Move &&
                importResults.Any(i => i.Result == ImportResultType.Imported) &&
                ShouldDeleteFolder(directoryInfo, artist))
            {
                _logger.Debug("Deleting folder after importing valid files");
                _diskProvider.DeleteFolder(directoryInfo.FullName, true);
            }

            return(importResults);
        }
        public List<ImportResult> Import(List<ImportDecision> decisions, bool newDownload, DownloadClientItem downloadClientItem = null, ImportMode importMode = ImportMode.Auto)
        {
            var qualifiedImports = decisions.Where(c => c.Approved)
               .GroupBy(c => c.LocalEpisode.Series.Id, (i, s) => s
                   .OrderByDescending(c => c.LocalEpisode.Quality, new QualityModelComparer(s.First().LocalEpisode.Series.Profile))
                   .ThenByDescending(c => c.LocalEpisode.Size))
               .SelectMany(c => c)
               .ToList();

            var importResults = new List<ImportResult>();

            foreach (var importDecision in qualifiedImports.OrderBy(e => e.LocalEpisode.Episodes.Select(episode => episode.EpisodeNumber).MinOrDefault())
                                                           .ThenByDescending(e => e.LocalEpisode.Size))
            {
                var localEpisode = importDecision.LocalEpisode;
                var oldFiles = new List<EpisodeFile>();

                try
                {
                    //check if already imported
                    if (importResults.SelectMany(r => r.ImportDecision.LocalEpisode.Episodes)
                                         .Select(e => e.Id)
                                         .Intersect(localEpisode.Episodes.Select(e => e.Id))
                                         .Any())
                    {
                        importResults.Add(new ImportResult(importDecision, "Episode has already been imported"));
                        continue;
                    }

                    var episodeFile = new EpisodeFile();
                    episodeFile.DateAdded = DateTime.UtcNow;
                    episodeFile.SeriesId = localEpisode.Series.Id;
                    episodeFile.Path = localEpisode.Path.CleanFilePath();
                    episodeFile.Size = _diskProvider.GetFileSize(localEpisode.Path);
                    episodeFile.Quality = localEpisode.Quality;
                    episodeFile.MediaInfo = localEpisode.MediaInfo;
                    episodeFile.SeasonNumber = localEpisode.SeasonNumber;
                    episodeFile.Episodes = localEpisode.Episodes;
                    episodeFile.ReleaseGroup = localEpisode.ParsedEpisodeInfo.ReleaseGroup;

                    bool copyOnly;
                    switch (importMode)
                    {
                        default:
                        case ImportMode.Auto:
                            copyOnly = downloadClientItem != null && downloadClientItem.IsReadOnly;
                            break;
                        case ImportMode.Move:
                            copyOnly = false;
                            break;
                        case ImportMode.Copy:
                            copyOnly = true;
                            break;
                    }

                    if (newDownload)
                    {
                        episodeFile.SceneName = GetSceneName(downloadClientItem, localEpisode);

                        var moveResult = _episodeFileUpgrader.UpgradeEpisodeFile(episodeFile, localEpisode, copyOnly);
                        oldFiles = moveResult.OldFiles;
                    }
                    else
                    {
                        episodeFile.RelativePath = localEpisode.Series.Path.GetRelativePath(episodeFile.Path);
                    }

                    _mediaFileService.Add(episodeFile);
                    importResults.Add(new ImportResult(importDecision));

                    if (newDownload)
                    {
                        _extraService.ImportExtraFiles(localEpisode, episodeFile, copyOnly);
                    }

                    if (downloadClientItem != null)
                    {
                        _eventAggregator.PublishEvent(new EpisodeImportedEvent(localEpisode, episodeFile, newDownload, downloadClientItem.DownloadClient, downloadClientItem.DownloadId, downloadClientItem.IsReadOnly));
                    }
                    else
                    {
                        _eventAggregator.PublishEvent(new EpisodeImportedEvent(localEpisode, episodeFile, newDownload));
                    }

                    if (newDownload)
                    {
                        _eventAggregator.PublishEvent(new EpisodeDownloadedEvent(localEpisode, episodeFile, oldFiles));
                    }
                }
                catch (Exception e)
                {
                    _logger.Warn(e, "Couldn't import episode " + localEpisode);
                    importResults.Add(new ImportResult(importDecision, "Failed to import episode"));
                }
            }

            //Adding all the rejected decisions
            importResults.AddRange(decisions.Where(c => !c.Approved)
                                            .Select(d => new ImportResult(d, d.Rejections.Select(r => r.Reason).ToArray())));

            return importResults;
        }
Beispiel #31
0
 public ImportProductPricesAreNotDuplicatesValidator(ImportMode importMode)
 {
     _importMode = importMode;
     AttachValidators();
 }
 /// <summary>
 /// Gets the API URL to post to
 /// </summary>
 /// <param name="importMode">The impost Mode option</param>
 /// <returns>The API URL as string</returns>
 public static string GetAPIPostURL(ImportMode importMode)
 {
     return(string.Format("{0}?Login={1}&EncryptedPassword={2}&Import={3}", VOLUSION_BASE_API, VOLUSION_USER, VOLUSION_PASSWORD, GetEnumDescription(importMode)));
 }
Beispiel #33
0
        public List <ImportResult> Import(List <ImportDecision <LocalBook> > decisions, bool replaceExisting, DownloadClientItem downloadClientItem = null, ImportMode importMode = ImportMode.Auto)
        {
            var importResults         = new List <ImportResult>();
            var allImportedTrackFiles = new List <BookFile>();
            var allOldTrackFiles      = new List <BookFile>();
            var addedAuthors          = new List <Author>();

            var bookDecisions = decisions.Where(e => e.Item.Book != null && e.Approved)
                                .GroupBy(e => e.Item.Book.ForeignBookId).ToList();

            var iDecision = 1;

            foreach (var bookDecision in bookDecisions)
            {
                _logger.ProgressInfo($"Importing book {iDecision++}/{bookDecisions.Count} {bookDecision.First().Item.Book}");

                var decisionList = bookDecision.ToList();

                var author = EnsureAuthorAdded(decisionList, addedAuthors);

                if (author == null)
                {
                    // failed to add the author, carry on with next book
                    continue;
                }

                var book = EnsureBookAdded(decisionList);

                if (book == null)
                {
                    // failed to add the book, carry on with next one
                    continue;
                }

                var edition = EnsureEditionAdded(decisionList);

                if (edition == null)
                {
                    // failed to add the edition, carry on with next one
                    continue;
                }

                // if (replaceExisting)
                // {
                //     RemoveExistingTrackFiles(author, book);
                // }

                // set the correct release to be monitored before importing the new files
                var newRelease = bookDecision.First().Item.Edition;
                _logger.Debug("Updating release to {0}", newRelease);
                book.Editions = _editionService.SetMonitored(newRelease);

                // Publish book edited event.
                // Deliberatly don't put in the old book since we don't want to trigger an AuthorScan.
                _eventAggregator.PublishEvent(new BookEditedEvent(book, book));
            }

            var qualifiedImports = decisions.Where(c => c.Approved)
                                   .GroupBy(c => c.Item.Author.Id, (i, s) => s
                                            .OrderByDescending(c => c.Item.Quality, new QualityModelComparer(s.First().Item.Author.QualityProfile))
                                            .ThenByDescending(c => c.Item.Size))
                                   .SelectMany(c => c)
                                   .ToList();

            _logger.ProgressInfo($"Importing {qualifiedImports.Count} files");
            _logger.Debug($"Importing {qualifiedImports.Count} files. replaceExisting: {replaceExisting}");

            var filesToAdd          = new List <BookFile>(qualifiedImports.Count);
            var trackImportedEvents = new List <TrackImportedEvent>(qualifiedImports.Count);

            foreach (var importDecision in qualifiedImports.OrderByDescending(e => e.Item.Size))
            {
                var localTrack = importDecision.Item;
                var oldFiles   = new List <BookFile>();

                try
                {
                    //check if already imported
                    if (importResults.Select(r => r.ImportDecision.Item.Book.Id).Contains(localTrack.Book.Id))
                    {
                        importResults.Add(new ImportResult(importDecision, "Book has already been imported"));
                        continue;
                    }

                    localTrack.Book.Author = localTrack.Author;

                    var bookFile = new BookFile
                    {
                        Path         = localTrack.Path.CleanFilePath(),
                        CalibreId    = localTrack.CalibreId,
                        Size         = localTrack.Size,
                        Modified     = localTrack.Modified,
                        DateAdded    = DateTime.UtcNow,
                        ReleaseGroup = localTrack.ReleaseGroup,
                        Quality      = localTrack.Quality,
                        MediaInfo    = localTrack.FileTrackInfo.MediaInfo,
                        EditionId    = localTrack.Edition.Id,
                        Author       = localTrack.Author,
                        Edition      = localTrack.Edition
                    };

                    bool copyOnly;
                    switch (importMode)
                    {
                    default:
                    case ImportMode.Auto:
                        copyOnly = downloadClientItem != null && !downloadClientItem.CanMoveFiles;
                        break;

                    case ImportMode.Move:
                        copyOnly = false;
                        break;

                    case ImportMode.Copy:
                        copyOnly = true;
                        break;
                    }

                    if (!localTrack.ExistingFile)
                    {
                        bookFile.SceneName = GetSceneReleaseName(downloadClientItem);

                        var moveResult = _bookFileUpgrader.UpgradeBookFile(bookFile, localTrack, copyOnly);
                        oldFiles = moveResult.OldFiles;
                    }
                    else
                    {
                        // Delete existing files from the DB mapped to this path
                        var previousFile = _mediaFileService.GetFileWithPath(bookFile.Path);

                        if (previousFile != null)
                        {
                            _mediaFileService.Delete(previousFile, DeleteMediaFileReason.ManualOverride);
                        }

                        _audioTagService.WriteTags(bookFile, false);
                        _eBookTagService.WriteTags(bookFile, false);
                    }

                    filesToAdd.Add(bookFile);
                    importResults.Add(new ImportResult(importDecision));

                    if (!localTrack.ExistingFile)
                    {
                        _extraService.ImportTrack(localTrack, bookFile, copyOnly);
                    }

                    allImportedTrackFiles.Add(bookFile);
                    allOldTrackFiles.AddRange(oldFiles);

                    // create all the import events here, but we can't publish until the trackfiles have been
                    // inserted and ids created
                    trackImportedEvents.Add(new TrackImportedEvent(localTrack, bookFile, oldFiles, !localTrack.ExistingFile, downloadClientItem));
                }
                catch (RootFolderNotFoundException e)
                {
                    _logger.Warn(e, "Couldn't import book " + localTrack);
                    _eventAggregator.PublishEvent(new TrackImportFailedEvent(e, localTrack, !localTrack.ExistingFile, downloadClientItem));

                    importResults.Add(new ImportResult(importDecision, "Failed to import book, Root folder missing."));
                }
                catch (DestinationAlreadyExistsException e)
                {
                    _logger.Warn(e, "Couldn't import book " + localTrack);
                    importResults.Add(new ImportResult(importDecision, "Failed to import book, Destination already exists."));
                }
                catch (UnauthorizedAccessException e)
                {
                    _logger.Warn(e, "Couldn't import book " + localTrack);
                    _eventAggregator.PublishEvent(new TrackImportFailedEvent(e, localTrack, !localTrack.ExistingFile, downloadClientItem));

                    importResults.Add(new ImportResult(importDecision, "Failed to import book, Permissions error"));
                }
                catch (Exception)
                {
                    throw;
                }
            }

            var watch = new System.Diagnostics.Stopwatch();

            watch.Start();
            _mediaFileService.AddMany(filesToAdd);
            _logger.Debug($"Inserted new trackfiles in {watch.ElapsedMilliseconds}ms");

            // now that trackfiles have been inserted and ids generated, publish the import events
            foreach (var trackImportedEvent in trackImportedEvents)
            {
                _eventAggregator.PublishEvent(trackImportedEvent);
            }

            var bookImports = importResults.Where(e => e.ImportDecision.Item.Book != null)
                              .GroupBy(e => e.ImportDecision.Item.Book.Id).ToList();

            foreach (var bookImport in bookImports)
            {
                var book   = bookImport.First().ImportDecision.Item.Book;
                var author = bookImport.First().ImportDecision.Item.Author;

                if (bookImport.Where(e => e.Errors.Count == 0).ToList().Count > 0 && author != null && book != null)
                {
                    _eventAggregator.PublishEvent(new BookImportedEvent(
                                                      author,
                                                      book,
                                                      allImportedTrackFiles.Where(s => s.EditionId == book.Id).ToList(),
                                                      allOldTrackFiles.Where(s => s.EditionId == book.Id).ToList(),
                                                      replaceExisting,
                                                      downloadClientItem));
                }
            }

            //Adding all the rejected decisions
            importResults.AddRange(decisions.Where(c => !c.Approved)
                                   .Select(d => new ImportResult(d, d.Rejections.Select(r => r.Reason).ToArray())));

            // Refresh any authors we added
            if (addedAuthors.Any())
            {
                _commandQueueManager.Push(new BulkRefreshAuthorCommand(addedAuthors.Select(x => x.Id).ToList(), true));
            }

            return(importResults);
        }
Beispiel #34
0
        public List <ImportResult> Import(List <ImportDecision <LocalTrack> > decisions, bool replaceExisting, DownloadClientItem downloadClientItem = null, ImportMode importMode = ImportMode.Auto)
        {
            var qualifiedImports = decisions.Where(c => c.Approved)
                                   .GroupBy(c => c.Item.Artist.Id, (i, s) => s
                                            .OrderByDescending(c => c.Item.Quality, new QualityModelComparer(s.First().Item.Artist.QualityProfile))
                                            .ThenByDescending(c => c.Item.Size))
                                   .SelectMany(c => c)
                                   .ToList();

            _logger.Debug($"Importing {qualifiedImports.Count} files. replaceExisting: {replaceExisting}");

            var importResults         = new List <ImportResult>();
            var allImportedTrackFiles = new List <TrackFile>();
            var allOldTrackFiles      = new List <TrackFile>();

            var albumDecisions = decisions.Where(e => e.Item.Album != null && e.Approved)
                                 .GroupBy(e => e.Item.Album.Id).ToList();

            foreach (var albumDecision in albumDecisions)
            {
                var album      = albumDecision.First().Item.Album;
                var newRelease = albumDecision.First().Item.Release;

                if (replaceExisting)
                {
                    var artist        = albumDecision.First().Item.Artist;
                    var rootFolder    = _diskProvider.GetParentFolder(artist.Path);
                    var previousFiles = _mediaFileService.GetFilesByAlbum(album.Id);

                    _logger.Debug($"Deleting {previousFiles.Count} existing files for {album}");

                    foreach (var previousFile in previousFiles)
                    {
                        var subfolder = rootFolder.GetRelativePath(_diskProvider.GetParentFolder(previousFile.Path));
                        if (_diskProvider.FileExists(previousFile.Path))
                        {
                            _logger.Debug("Removing existing track file: {0}", previousFile);
                            _recycleBinProvider.DeleteFile(previousFile.Path, subfolder);
                        }
                        _mediaFileService.Delete(previousFile, DeleteMediaFileReason.Upgrade);
                    }
                }

                // set the correct release to be monitored before importing the new files
                _logger.Debug("Updating release to {0} [{1} tracks]", newRelease, newRelease.TrackCount);
                album.AlbumReleases = _releaseService.SetMonitored(newRelease);

                // Publish album edited event.
                // Deliberatly don't put in the old album since we don't want to trigger an ArtistScan.
                _eventAggregator.PublishEvent(new AlbumEditedEvent(album, album));
            }

            var filesToAdd          = new List <TrackFile>(qualifiedImports.Count);
            var albumReleasesDict   = new Dictionary <int, List <AlbumRelease> >(albumDecisions.Count);
            var trackImportedEvents = new List <TrackImportedEvent>(qualifiedImports.Count);

            foreach (var importDecision in qualifiedImports.OrderBy(e => e.Item.Tracks.Select(track => track.AbsoluteTrackNumber).MinOrDefault())
                     .ThenByDescending(e => e.Item.Size))
            {
                var localTrack = importDecision.Item;
                var oldFiles   = new List <TrackFile>();

                try
                {
                    //check if already imported
                    if (importResults.SelectMany(r => r.ImportDecision.Item.Tracks)
                        .Select(e => e.Id)
                        .Intersect(localTrack.Tracks.Select(e => e.Id))
                        .Any())
                    {
                        importResults.Add(new ImportResult(importDecision, "Track has already been imported"));
                        continue;
                    }

                    // cache album releases and set artist to speed up firing the TrackImported events
                    // (otherwise they'll be retrieved from the DB for each track)
                    if (!albumReleasesDict.ContainsKey(localTrack.Album.Id))
                    {
                        albumReleasesDict.Add(localTrack.Album.Id, localTrack.Album.AlbumReleases.Value);
                    }
                    if (!localTrack.Album.AlbumReleases.IsLoaded)
                    {
                        localTrack.Album.AlbumReleases = albumReleasesDict[localTrack.Album.Id];
                    }
                    localTrack.Album.Artist = localTrack.Artist;

                    foreach (var track in localTrack.Tracks)
                    {
                        track.Artist       = localTrack.Artist;
                        track.AlbumRelease = localTrack.Release;
                        track.Album        = localTrack.Album;
                    }

                    var trackFile = new TrackFile {
                        Path         = localTrack.Path.CleanFilePath(),
                        Size         = localTrack.Size,
                        Modified     = localTrack.Modified,
                        DateAdded    = DateTime.UtcNow,
                        ReleaseGroup = localTrack.ReleaseGroup,
                        Quality      = localTrack.Quality,
                        MediaInfo    = localTrack.FileTrackInfo.MediaInfo,
                        AlbumId      = localTrack.Album.Id,
                        Artist       = localTrack.Artist,
                        Album        = localTrack.Album,
                        Tracks       = localTrack.Tracks
                    };

                    bool copyOnly;
                    switch (importMode)
                    {
                    default:
                    case ImportMode.Auto:
                        copyOnly = downloadClientItem != null && !downloadClientItem.CanMoveFiles;
                        break;

                    case ImportMode.Move:
                        copyOnly = false;
                        break;

                    case ImportMode.Copy:
                        copyOnly = true;
                        break;
                    }

                    if (!localTrack.ExistingFile)
                    {
                        trackFile.SceneName = GetSceneReleaseName(downloadClientItem, localTrack);

                        var moveResult = _trackFileUpgrader.UpgradeTrackFile(trackFile, localTrack, copyOnly);
                        oldFiles = moveResult.OldFiles;
                    }
                    else
                    {
                        // Delete existing files from the DB mapped to this path
                        var previousFile = _mediaFileService.GetFileWithPath(trackFile.Path);

                        if (previousFile != null)
                        {
                            _mediaFileService.Delete(previousFile, DeleteMediaFileReason.ManualOverride);
                        }

                        _audioTagService.WriteTags(trackFile, false);
                    }

                    filesToAdd.Add(trackFile);
                    importResults.Add(new ImportResult(importDecision));

                    if (!localTrack.ExistingFile)
                    {
                        _extraService.ImportTrack(localTrack, trackFile, copyOnly);
                    }

                    allImportedTrackFiles.Add(trackFile);
                    allOldTrackFiles.AddRange(oldFiles);

                    // create all the import events here, but we can't publish until the trackfiles have been
                    // inserted and ids created
                    trackImportedEvents.Add(new TrackImportedEvent(localTrack, trackFile, oldFiles, !localTrack.ExistingFile, downloadClientItem));
                }
                catch (RootFolderNotFoundException e)
                {
                    _logger.Warn(e, "Couldn't import track " + localTrack);
                    _eventAggregator.PublishEvent(new TrackImportFailedEvent(e, localTrack, !localTrack.ExistingFile, downloadClientItem));

                    importResults.Add(new ImportResult(importDecision, "Failed to import track, Root folder missing."));
                }
                catch (DestinationAlreadyExistsException e)
                {
                    _logger.Warn(e, "Couldn't import track " + localTrack);
                    importResults.Add(new ImportResult(importDecision, "Failed to import track, Destination already exists."));
                }
                catch (UnauthorizedAccessException e)
                {
                    _logger.Warn(e, "Couldn't import track " + localTrack);
                    _eventAggregator.PublishEvent(new TrackImportFailedEvent(e, localTrack, !localTrack.ExistingFile, downloadClientItem));

                    importResults.Add(new ImportResult(importDecision, "Failed to import track, Permissions error"));
                }
                catch (Exception e)
                {
                    _logger.Warn(e, "Couldn't import track " + localTrack);
                    importResults.Add(new ImportResult(importDecision, "Failed to import track"));
                }
            }

            var watch = new System.Diagnostics.Stopwatch();

            watch.Start();
            _mediaFileService.AddMany(filesToAdd);
            _logger.Debug($"Inserted new trackfiles in {watch.ElapsedMilliseconds}ms");
            filesToAdd.ForEach(f => f.Tracks.Value.ForEach(t => t.TrackFileId = f.Id));
            _trackService.SetFileIds(filesToAdd.SelectMany(x => x.Tracks.Value).ToList());
            _logger.Debug($"TrackFileIds updated, total {watch.ElapsedMilliseconds}ms");

            // now that trackfiles have been inserted and ids generated, publish the import events
            foreach (var trackImportedEvent in trackImportedEvents)
            {
                _eventAggregator.PublishEvent(trackImportedEvent);
            }

            var albumImports = importResults.Where(e => e.ImportDecision.Item.Album != null)
                               .GroupBy(e => e.ImportDecision.Item.Album.Id).ToList();

            foreach (var albumImport in albumImports)
            {
                var release = albumImport.First().ImportDecision.Item.Release;
                var album   = albumImport.First().ImportDecision.Item.Album;
                var artist  = albumImport.First().ImportDecision.Item.Artist;

                if (albumImport.Where(e => e.Errors.Count == 0).ToList().Count > 0 && artist != null && album != null)
                {
                    _eventAggregator.PublishEvent(new AlbumImportedEvent(
                                                      artist,
                                                      album,
                                                      release,
                                                      allImportedTrackFiles.Where(s => s.AlbumId == album.Id).ToList(),
                                                      allOldTrackFiles.Where(s => s.AlbumId == album.Id).ToList(), replaceExisting,
                                                      downloadClientItem));
                }
            }

            //Adding all the rejected decisions
            importResults.AddRange(decisions.Where(c => !c.Approved)
                                   .Select(d => new ImportResult(d, d.Rejections.Select(r => r.Reason).ToArray())));

            return(importResults);
        }
Beispiel #35
0
        static IEnumerable <ExportImportDevice> GenerateExportImportDeviceListForTwinBulkOperations(IEnumerable <Twin> twins, ImportMode importMode)
        {
            if (twins == null)
            {
                throw new ArgumentNullException(nameof(twins));
            }

            if (!twins.Any())
            {
                throw new ArgumentException(nameof(twins));
            }

            var exportImportDeviceList = new List <ExportImportDevice>(twins.Count());

            foreach (Twin twin in twins)
            {
                ValidateTwinId(twin);

                switch (importMode)
                {
                case ImportMode.UpdateTwin:
                    // No preconditions
                    break;

                case ImportMode.UpdateTwinIfMatchETag:
                    if (string.IsNullOrWhiteSpace(twin.ETag))
                    {
                        throw new ArgumentException(ApiResources.ETagNotSetWhileUpdatingTwin);
                    }
                    break;

                default:
                    throw new ArgumentException(IotHubApiResources.GetString(ApiResources.InvalidImportMode, importMode));
                }

                var exportImportDevice = new ExportImportDevice();
                exportImportDevice.Id         = twin.DeviceId;
                exportImportDevice.ImportMode = importMode;
                exportImportDevice.TwinETag   = importMode == ImportMode.UpdateTwinIfMatchETag ? twin.ETag : null;
                exportImportDevice.Tags       = twin.Tags;
                exportImportDevice.Properties = new ExportImportDevice.PropertyContainer();
                exportImportDevice.Properties.DesiredProperties = twin.Properties?.Desired;

                exportImportDeviceList.Add(exportImportDevice);
            }

            return(exportImportDeviceList);
        }
 internal static Hash128 CalculateTargetHash(GUID guid, BuildTarget target, ImportMode importMode)
 {
     return(LiveLinkBuildImporter.GetHash(guid.ToString(), target, importMode));
 }
Beispiel #37
0
 private static Hash128 ProduceArtifact(GUID guid, Type importerType, ImportMode mode)
 {
     return(ProduceArtifact(guid, importerType, mode, out _));
 }
        private List <ImportResult> ProcessFolder(IDirectoryInfo directoryInfo, ImportMode importMode, Author author, DownloadClientItem downloadClientItem)
        {
            if (_authorService.AuthorPathExists(directoryInfo.FullName))
            {
                _logger.Warn("Unable to process folder that is mapped to an existing author");
                return(new List <ImportResult>());
            }

            var cleanedUpName = GetCleanedUpFolderName(directoryInfo.Name);
            var folderInfo    = Parser.Parser.ParseBookTitle(directoryInfo.Name);
            var trackInfo     = new ParsedTrackInfo {
            };

            if (folderInfo != null)
            {
                _logger.Debug("{0} folder quality: {1}", cleanedUpName, folderInfo.Quality);

                trackInfo = new ParsedTrackInfo
                {
                    AlbumTitle   = folderInfo.BookTitle,
                    ArtistTitle  = folderInfo.AuthorName,
                    Quality      = folderInfo.Quality,
                    ReleaseGroup = folderInfo.ReleaseGroup,
                    ReleaseHash  = folderInfo.ReleaseHash,
                };
            }
            else
            {
                trackInfo = null;
            }

            var audioFiles = _diskScanService.FilterFiles(directoryInfo.FullName, _diskScanService.GetBookFiles(directoryInfo.FullName));

            if (downloadClientItem == null)
            {
                foreach (var audioFile in audioFiles)
                {
                    if (_diskProvider.IsFileLocked(audioFile.FullName))
                    {
                        return(new List <ImportResult>
                        {
                            FileIsLockedResult(audioFile.FullName)
                        });
                    }
                }
            }

            var idOverrides = new IdentificationOverrides
            {
                Author = author
            };
            var idInfo = new ImportDecisionMakerInfo
            {
                DownloadClientItem = downloadClientItem,
                ParsedTrackInfo    = trackInfo
            };
            var idConfig = new ImportDecisionMakerConfig
            {
                Filter          = FilterFilesType.None,
                NewDownload     = true,
                SingleRelease   = false,
                IncludeExisting = false,
                AddNewAuthors   = false
            };

            var decisions     = _importDecisionMaker.GetImportDecisions(audioFiles, idOverrides, idInfo, idConfig);
            var importResults = _importApprovedTracks.Import(decisions, true, downloadClientItem, importMode);

            if (importMode == ImportMode.Auto)
            {
                importMode = (downloadClientItem == null || downloadClientItem.CanMoveFiles) ? ImportMode.Move : ImportMode.Copy;
            }

            if (importMode == ImportMode.Move &&
                importResults.Any(i => i.Result == ImportResultType.Imported) &&
                ShouldDeleteFolder(directoryInfo, author))
            {
                _logger.Debug("Deleting folder after importing valid files");
                _diskProvider.DeleteFolder(directoryInfo.FullName, true);
            }

            return(importResults);
        }
Beispiel #39
0
        public static Promise <RunResult> ImportAsync(string gameDataPath, string[] entities, CommandInput input, ImportMode mode)
        {
            if (gameDataPath == null)
            {
                throw new ArgumentNullException("gameDataPath");
            }
            if (entities == null)
            {
                throw new ArgumentNullException("entities");
            }
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            if (Enum.IsDefined(typeof(ImportMode), mode) == false)
            {
                throw new ArgumentException("Unknown import mode.", "mode");
            }
            if (File.Exists(gameDataPath) == false)
            {
                throw new IOException(string.Format("GameData file '{0}' doesn't exists.", gameDataPath));
            }

            var runTask = RunInternal
                          (
                RunOptions.FlattenArguments(
                    "DATA", "IMPORT", gameDataPath,
                    "--entities", entities,
                    "--mode", mode,
                    "--input", input.Source,
                    "--inputFormat", input.Format,
                    "--inputFormattingOptions", input.FormattingOptions
                    )
                          );

            input.StickWith(runTask);
            return(runTask);
        }
    public void Import(Id entryCollectionId, Id pagesCollectionId, Id mediaCollectionId, ImportMode mode, BlogMLBlog blog)
    {
      progress = new Progress();
      LogProgress("Import started, mode={0}", mode);
      LogProgress("Blog found with title of '{0}'", blog.Title);
      try
      {
        AppService appSvc = AppServiceRepository.GetService();

        if (mode == ImportMode.New)
        {
          var ws = appSvc.GetWorkspace();
          //clean out old collections
          CleanOutCollection(ws.GetCollection("blog").Id, appSvc);
          CleanOutCollection(ws.GetCollection("pages").Id, appSvc);
          CleanOutCollection(ws.GetCollection("media").Id, appSvc);

          ws.Title = new AtomTitle() { Text = entryCollectionId.Owner };

          //change old id's to new id's
          ChangeCollectionId(appSvc, ws.GetCollection("blog").Id, entryCollectionId);
          ChangeCollectionId(appSvc, ws.GetCollection("pages").Id, pagesCollectionId);
          ChangeCollectionId(appSvc, ws.GetCollection("media").Id, mediaCollectionId);
        }
        else if (mode == ImportMode.Overwrite)
        {
          CleanOutCollection(entryCollectionId, appSvc);
          CleanOutCollection(pagesCollectionId, appSvc);
          CleanOutCollection(mediaCollectionId, appSvc);
        }

        TurnOffTrackbacks(entryCollectionId, appSvc);
        TurnOffTrackbacks(pagesCollectionId, appSvc);
        TurnOffTrackbacks(mediaCollectionId, appSvc);

        var coll = appSvc.GetCollection(entryCollectionId);

        if (mode != ImportMode.Merge)
        {
          coll.Title = new AtomTitle() { Text = blog.Title };
          //this is workspace subtitle, not collection
          appSvc.GetWorkspace().Subtitle = new AtomSubtitle() { Text = blog.SubTitle };
        }

        var users = ImportUsers(blog, appSvc);
        if (users.FirstOrDefault() != null && mode == ImportMode.New)
        {
          //user is likely not authenticated when new, so auth them
          System.Threading.Thread.CurrentPrincipal = new GenericPrincipal(users[0], null);
        }

        ImportCategories(blog, coll);
        AtomPubService.UpdateService(appSvc);
        ImportPosts(entryCollectionId, pagesCollectionId, mediaCollectionId, mode, blog);

        //make sure there is an About and Blogroll pages
        if (mode == ImportMode.New && pagesCollectionId != null)
        {
          var entries = AtomPubService.GetEntries(new EntryCriteria()
          {
            EntryId = pagesCollectionId.AddPath("About"),
            Approved = true
          }, 0, 1);
          if (entries.Count() == 0)
          {
            AtomPubService.CreateEntry(pagesCollectionId, new AtomEntry()
            {
              Title = new AtomTitle() { Text = "About Me" },
              Content = new AtomContent() { Text = "This is a temporary placeholder until I can update this entry." },
            }, "About");
          }
          entries = AtomPubService.GetEntries(new EntryCriteria()
          {
            EntryId = pagesCollectionId.AddPath("Blogroll"),
            Approved = true
          }, 0, 1);
          if (entries.Count() == 0)
          {
            AtomPubService.CreateEntry(pagesCollectionId, new AtomEntry()
            {
              Title = new AtomTitle() { Text = "Blog Roll" },
              Content = new AtomContent() { Type = "html", Text = "<ul><li><a href='http://atomsite.net'>AtomSite.net</a></li></ul>" },
            }, "Blogroll");
          }
        }

        ResetTrackbacks(entryCollectionId, appSvc);
        ResetTrackbacks(pagesCollectionId, appSvc);
        ResetTrackbacks(mediaCollectionId, appSvc);

        LogProgress("Finished!", 100);
      }
      catch (Exception ex)
      {
        LogService.Error(ex);
        LogProgress(System.Web.HttpUtility.HtmlEncode(ex.Message), 100);
      }
    }
Beispiel #41
0
        public List <ImportResult> Import(List <ImportDecision> decisions, bool newDownload, DownloadClientItem downloadClientItem = null, ImportMode importMode = ImportMode.Auto)
        {
            _logger.Debug("Decisions: {0}", decisions.Count);

            var qualifiedImports = decisions.Where(c => c.Approved)
                                   .GroupBy(c => c.LocalMovie.Movie.Id, (i, s) => s
                                            .OrderByDescending(c => c.LocalMovie.Quality, new QualityModelComparer(s.First().LocalMovie.Movie.Profile))
                                            .ThenByDescending(c => c.LocalMovie.Size))
                                   .SelectMany(c => c)
                                   .ToList();

            var importResults = new List <ImportResult>();

            foreach (var importDecision in qualifiedImports.OrderBy(e => e.LocalMovie.Size)
                     .ThenByDescending(e => e.LocalMovie.Size))
            {
                var localMovie = importDecision.LocalMovie;
                var oldFiles   = new List <MovieFile>();

                try
                {
                    //check if already imported
                    if (importResults.Select(r => r.ImportDecision.LocalMovie.Movie)
                        .Select(m => m.Id).Contains(localMovie.Movie.Id))
                    {
                        importResults.Add(new ImportResult(importDecision, "Movie has already been imported"));
                        continue;
                    }

                    var movieFile = new MovieFile();
                    movieFile.DateAdded    = DateTime.UtcNow;
                    movieFile.MovieId      = localMovie.Movie.Id;
                    movieFile.Path         = localMovie.Path.CleanFilePath();
                    movieFile.Size         = _diskProvider.GetFileSize(localMovie.Path);
                    movieFile.Quality      = localMovie.Quality;
                    movieFile.MediaInfo    = localMovie.MediaInfo;
                    movieFile.Movie        = localMovie.Movie;
                    movieFile.ReleaseGroup = localMovie.ParsedMovieInfo.ReleaseGroup;
                    movieFile.Edition      = localMovie.ParsedMovieInfo.Edition;

                    bool copyOnly;
                    switch (importMode)
                    {
                    default:
                    case ImportMode.Auto:
                        copyOnly = downloadClientItem != null && downloadClientItem.IsReadOnly;
                        break;

                    case ImportMode.Move:
                        copyOnly = false;
                        break;

                    case ImportMode.Copy:
                        copyOnly = true;
                        break;
                    }

                    if (newDownload)
                    {
                        movieFile.SceneName = GetSceneName(downloadClientItem, localMovie);

                        var moveResult = _episodeFileUpgrader.UpgradeMovieFile(movieFile, localMovie, copyOnly); //TODO: Check if this works
                        oldFiles = moveResult.OldFiles;
                    }
                    else
                    {
                        movieFile.RelativePath = localMovie.Movie.Path.GetRelativePath(movieFile.Path);
                    }

                    _mediaFileService.Add(movieFile);
                    importResults.Add(new ImportResult(importDecision));

                    if (newDownload)
                    {
                        //_extraService.ImportExtraFiles(localMovie, episodeFile, copyOnly); TODO update for movie
                    }

                    if (downloadClientItem != null)
                    {
                        _eventAggregator.PublishEvent(new MovieImportedEvent(localMovie, movieFile, newDownload, downloadClientItem.DownloadClient, downloadClientItem.DownloadId, downloadClientItem.IsReadOnly));
                    }
                    else
                    {
                        _eventAggregator.PublishEvent(new MovieImportedEvent(localMovie, movieFile, newDownload));
                    }

                    if (newDownload)
                    {
                        _eventAggregator.PublishEvent(new MovieDownloadedEvent(localMovie, movieFile, oldFiles));
                    }
                }
                catch (Exception e)
                {
                    _logger.Warn(e, "Couldn't import movie " + localMovie);
                    importResults.Add(new ImportResult(importDecision, "Failed to import movie"));
                }
            }

            //Adding all the rejected decisions
            importResults.AddRange(decisions.Where(c => !c.Approved)
                                   .Select(d => new ImportResult(d, d.Rejections.Select(r => r.Reason).ToArray())));

            return(importResults);
        }
Beispiel #42
0
        public List <ImportResult> Import(List <ImportDecision> decisions, bool newDownload, DownloadClientItem downloadClientItem = null, ImportMode importMode = ImportMode.Auto)
        {
            _logger.Debug("Decisions: {0}", decisions.Count);

            //I added a null op for the rare case that the quality is null. TODO: find out why that would even happen in the first place.
            var qualifiedImports = decisions.Where(c => c.Approved)
                                   .GroupBy(c => c.LocalMovie.Movie.Id, (i, s) => s
                                            .OrderByDescending(c => c.LocalMovie.Quality ?? new QualityModel {
                Quality = Quality.Unknown
            }, new QualityModelComparer(s.First().LocalMovie.Movie.Profile))
                                            .ThenByDescending(c => c.LocalMovie.Size))
                                   .SelectMany(c => c)
                                   .ToList();

            var importResults = new List <ImportResult>();

            foreach (var importDecision in qualifiedImports.OrderByDescending(e => e.LocalMovie.Size))
            {
                var localMovie = importDecision.LocalMovie;
                var oldFiles   = new List <MovieFile>();

                try
                {
                    //check if already imported
                    if (importResults.Select(r => r.ImportDecision.LocalMovie.Movie)
                        .Select(m => m.Id).Contains(localMovie.Movie.Id))
                    {
                        importResults.Add(new ImportResult(importDecision, "Movie has already been imported"));
                        continue;
                    }

                    var movieFile = new MovieFile();
                    movieFile.DateAdded    = DateTime.UtcNow;
                    movieFile.MovieId      = localMovie.Movie.Id;
                    movieFile.Path         = localMovie.Path.CleanFilePath();
                    movieFile.Size         = _diskProvider.GetFileSize(localMovie.Path);
                    movieFile.Quality      = localMovie.Quality;
                    movieFile.Languages    = localMovie.Languages;
                    movieFile.MediaInfo    = localMovie.MediaInfo;
                    movieFile.Movie        = localMovie.Movie;
                    movieFile.ReleaseGroup = localMovie.ReleaseGroup;
                    movieFile.Edition      = localMovie.Edition;

                    if (downloadClientItem?.DownloadId.IsNotNullOrWhiteSpace() == true)
                    {
                        var grabHistory = _historyService.FindByDownloadId(downloadClientItem.DownloadId)
                                          .OrderByDescending(h => h.Date)
                                          .FirstOrDefault(h => h.EventType == MovieHistoryEventType.Grabbed);

                        if (Enum.TryParse(grabHistory?.Data.GetValueOrDefault("indexerFlags"), true, out IndexerFlags flags))
                        {
                            movieFile.IndexerFlags = flags;
                        }
                    }

                    bool copyOnly;
                    switch (importMode)
                    {
                    default:
                    case ImportMode.Auto:
                        copyOnly = downloadClientItem != null && !downloadClientItem.CanMoveFiles;
                        break;

                    case ImportMode.Move:
                        copyOnly = false;
                        break;

                    case ImportMode.Copy:
                        copyOnly = true;
                        break;
                    }

                    if (newDownload)
                    {
                        movieFile.OriginalFilePath = GetOriginalFilePath(downloadClientItem, localMovie);
                        movieFile.SceneName        = GetSceneName(downloadClientItem, localMovie);
                        var moveResult = _movieFileUpgrader.UpgradeMovieFile(movieFile, localMovie, copyOnly); //TODO: Check if this works
                        oldFiles = moveResult.OldFiles;
                    }
                    else
                    {
                        movieFile.RelativePath = localMovie.Movie.Path.GetRelativePath(movieFile.Path);
                    }

                    movieFile = _mediaFileService.Add(movieFile);
                    importResults.Add(new ImportResult(importDecision));

                    if (newDownload)
                    {
                        _extraService.ImportMovie(localMovie, movieFile, copyOnly);
                    }

                    if (downloadClientItem != null)
                    {
                        _eventAggregator.PublishEvent(new MovieImportedEvent(localMovie, movieFile, newDownload, downloadClientItem, downloadClientItem.DownloadId));
                    }
                    else
                    {
                        _eventAggregator.PublishEvent(new MovieImportedEvent(localMovie, movieFile, newDownload));
                    }

                    if (newDownload)
                    {
                        _eventAggregator.PublishEvent(new MovieDownloadedEvent(localMovie, movieFile, oldFiles, downloadClientItem));
                    }
                }
                catch (RootFolderNotFoundException e)
                {
                    _logger.Warn(e, "Couldn't import movie " + localMovie);
                    _eventAggregator.PublishEvent(new MovieImportFailedEvent(e, localMovie, newDownload, downloadClientItem));

                    importResults.Add(new ImportResult(importDecision, "Failed to import movie, Root folder missing."));
                }
                catch (DestinationAlreadyExistsException e)
                {
                    _logger.Warn(e, "Couldn't import movie " + localMovie);
                    importResults.Add(new ImportResult(importDecision, "Failed to import movie, Destination already exists."));
                }
                catch (Exception e)
                {
                    _logger.Warn(e, "Couldn't import movie " + localMovie);
                    importResults.Add(new ImportResult(importDecision, "Failed to import movie"));
                }
            }

            //Adding all the rejected decisions
            importResults.AddRange(decisions.Where(c => !c.Approved)
                                   .Select(d => new ImportResult(d, d.Rejections.Select(r => r.Reason).ToArray())));

            return(importResults);
        }
        internal static void CalculateTargetDependencies(Entities.Hash128 artifactHash, BuildTarget target, out ResolvedAssetID[] dependencies, ImportMode syncMode)
        {
            List <Entities.Hash128> assets = new List <Entities.Hash128>(LiveLinkBuildImporter.GetDependenciesInternal(artifactHash));
            List <ResolvedAssetID>  resolvedDependencies = new List <ResolvedAssetID>();

            HashSet <Entities.Hash128> visited = new HashSet <Entities.Hash128>();

            for (int i = 0; i < assets.Count; i++)
            {
                if (!visited.Add(assets[i]))
                {
                    continue;
                }

                var resolvedAsset = new ResolvedAssetID
                {
                    GUID       = assets[i],
                    TargetHash = CalculateTargetHash(assets[i], target, syncMode),
                };
                resolvedDependencies.Add(resolvedAsset);

                if (resolvedAsset.TargetHash.IsValid)
                {
                    assets.AddRange(LiveLinkBuildImporter.GetDependenciesInternal(resolvedAsset.TargetHash));
                }
            }

            dependencies = resolvedDependencies.ToArray();
        }
        private List<ImportResult> ProcessFile(FileInfo fileInfo, ImportMode importMode, DownloadClientItem downloadClientItem)
        {
            var series = _parsingService.GetSeries(Path.GetFileNameWithoutExtension(fileInfo.Name));

            if (series == null)
            {
                _logger.Debug("Unknown Series for file: {0}", fileInfo.Name);

                return new List<ImportResult>
                       {
                           UnknownSeriesResult(string.Format("Unknown Series for file: {0}", fileInfo.Name), fileInfo.FullName)
                       };
            }

            return ProcessFile(fileInfo, importMode, series, downloadClientItem);
        }
        public List <ImportResult> Import(List <ImportDecision> decisions, bool newDownload, DownloadClientItem downloadClientItem = null, ImportMode importMode = ImportMode.Auto)
        {
            var qualifiedImports = decisions.Where(c => c.Approved)
                                   .GroupBy(c => c.LocalEpisode.Series.Id, (i, s) => s
                                            .OrderByDescending(c => c.LocalEpisode.Quality, new QualityModelComparer(s.First().LocalEpisode.Series.Profile))
                                            .ThenByDescending(c => c.LocalEpisode.Size))
                                   .SelectMany(c => c)
                                   .ToList();

            var importResults = new List <ImportResult>();

            foreach (var importDecision in qualifiedImports.OrderBy(e => e.LocalEpisode.Episodes.Select(episode => episode.EpisodeNumber).MinOrDefault())
                     .ThenByDescending(e => e.LocalEpisode.Size))
            {
                var localEpisode = importDecision.LocalEpisode;
                var oldFiles     = new List <EpisodeFile>();

                try
                {
                    //check if already imported
                    if (importResults.SelectMany(r => r.ImportDecision.LocalEpisode.Episodes)
                        .Select(e => e.Id)
                        .Intersect(localEpisode.Episodes.Select(e => e.Id))
                        .Any())
                    {
                        importResults.Add(new ImportResult(importDecision, "Episode has already been imported"));
                        continue;
                    }

                    var episodeFile = new EpisodeFile();
                    episodeFile.DateAdded    = DateTime.UtcNow;
                    episodeFile.SeriesId     = localEpisode.Series.Id;
                    episodeFile.Path         = localEpisode.Path.CleanFilePath();
                    episodeFile.Size         = _diskProvider.GetFileSize(localEpisode.Path);
                    episodeFile.Quality      = localEpisode.Quality;
                    episodeFile.MediaInfo    = localEpisode.MediaInfo;
                    episodeFile.SeasonNumber = localEpisode.SeasonNumber;
                    episodeFile.Episodes     = localEpisode.Episodes;
                    episodeFile.ReleaseGroup = localEpisode.ReleaseGroup;

                    bool copyOnly;
                    switch (importMode)
                    {
                    default:
                    case ImportMode.Auto:
                        copyOnly = downloadClientItem != null && !downloadClientItem.CanMoveFiles;
                        break;

                    case ImportMode.Move:
                        copyOnly = false;
                        break;

                    case ImportMode.Copy:
                        copyOnly = true;
                        break;
                    }

                    if (newDownload)
                    {
                        episodeFile.OriginalFilePath = GetOriginalFilePath(downloadClientItem, localEpisode);
                        episodeFile.SceneName        = GetSceneName(downloadClientItem, localEpisode);

                        var moveResult = _episodeFileUpgrader.UpgradeEpisodeFile(episodeFile, localEpisode, copyOnly);
                        oldFiles = moveResult.OldFiles;
                    }
                    else
                    {
                        episodeFile.RelativePath = localEpisode.Series.Path.GetRelativePath(episodeFile.Path);
                    }

                    _mediaFileService.Add(episodeFile);
                    importResults.Add(new ImportResult(importDecision));

                    if (newDownload)
                    {
                        _extraService.ImportEpisode(localEpisode, episodeFile, copyOnly);
                    }

                    _eventAggregator.PublishEvent(new EpisodeImportedEvent(localEpisode, episodeFile, oldFiles, newDownload, downloadClientItem));
                }
                catch (RootFolderNotFoundException e)
                {
                    _logger.Warn(e, "Couldn't import episode " + localEpisode);
                    _eventAggregator.PublishEvent(new EpisodeImportFailedEvent(e, localEpisode, newDownload, downloadClientItem));

                    importResults.Add(new ImportResult(importDecision, "Failed to import episode, Root folder missing."));
                }
                catch (DestinationAlreadyExistsException e)
                {
                    _logger.Warn(e, "Couldn't import episode " + localEpisode);
                    importResults.Add(new ImportResult(importDecision, "Failed to import episode, Destination already exists."));
                }
                catch (Exception e)
                {
                    _logger.Warn(e, "Couldn't import episode " + localEpisode);
                    importResults.Add(new ImportResult(importDecision, "Failed to import episode"));
                }
            }

            //Adding all the rejected decisions
            importResults.AddRange(decisions.Where(c => !c.Approved)
                                   .Select(d => new ImportResult(d, d.Rejections.Select(r => r.Reason).ToArray())));

            return(importResults);
        }
        private List<ImportResult> ProcessFile(FileInfo fileInfo, ImportMode importMode, Series series, DownloadClientItem downloadClientItem)
        {
            if (Path.GetFileNameWithoutExtension(fileInfo.Name).StartsWith("._"))
            {
                _logger.Debug("[{0}] starts with '._', skipping", fileInfo.FullName);

                return new List<ImportResult>
                       {
                           new ImportResult(new ImportDecision(new LocalEpisode { Path = fileInfo.FullName }, new Rejection("Invalid video file, filename starts with '._'")), "Invalid video file, filename starts with '._'")
                       };
            }

            if (downloadClientItem == null)
            {
                if (_diskProvider.IsFileLocked(fileInfo.FullName))
                {
                    return new List<ImportResult>
                           {
                               FileIsLockedResult(fileInfo.FullName)
                           };
                }
            }

            var decisions = _importDecisionMaker.GetImportDecisions(new List<string>() { fileInfo.FullName }, series, null, true);

            return _importApprovedEpisodes.Import(decisions, true, downloadClientItem, importMode);
        }
Beispiel #47
0
 public PricesImporter(ImportSettings settings, ImportMode mode)
     : base(settings, mode)
 {
     _priceCleaner = new PricesCleaner(settings);
 }
Beispiel #48
0
        /// <summary>
        /// Создает новую секцию по названию таблицы, режиму импорта, используя введенный список столбцов
        /// </summary>
        /// <param name="tableName">Название таблицы</param>
        /// <param name="mode">Режим</param>
        /// <param name="list">Список столбцов</param>
        public ImportSection(string tableName, ImportMode mode, List <ImportColumn> list)
        {
            Section = new DataTable(tableName);

            // Вносим в секцию столько столбцов, сколько задействовано при импорте
            for (int j = 0; j <= list.Count; j++)
            {
                Section.Columns.Add(new DataColumn(j.ToString()));
            }
            var currentColumn = 0;
            var i             = 1;
            // Если создаем и изменяем, увеличиваем количество строк в два раза
            var countOfRows = mode != ImportMode.CreateChange ? list[0].Values.Length : list[0].Values.Length * 2;

            // Пилим и вносим самую первую строку
            DataRow row = Section.NewRow();

            row[0] = tableName + ":FORMAT";
            Section.Rows.Add(row);
            // Вносим в секцию все строки, заполняем самый первый столбец согласно режиму
            for (var j = 0; j < countOfRows; j++)
            {
                switch (mode)
                {
                case ImportMode.Create:
                    // Создаем новую строку по образцу, заполняем первый элемент, пихаем в секцию. И так будет с каждым...
                    row    = Section.NewRow();
                    row[0] = tableName + ":CREATE";
                    Section.Rows.Add(row);
                    break;

                case ImportMode.Change:
                    row    = Section.NewRow();
                    row[0] = tableName + ":CHANGE";
                    Section.Rows.Add(row);
                    break;

                case ImportMode.CreateChange:
                    var newRow1 = Section.NewRow();
                    newRow1[0] = tableName + ":CREATE";
                    var newRow2 = Section.NewRow();
                    newRow2[0] = tableName + ":CHANGE";
                    Section.Rows.Add(newRow1);
                    Section.Rows.Add(newRow2);
                    j++;
                    break;

                case ImportMode.Delete:
                    row    = Section.NewRow();
                    row[0] = tableName + ":DELETE";
                    Section.Rows.Add(row);
                    break;
                }
            }
            currentColumn++;
            foreach (ImportColumn col in list)
            {
                // Пилим все остальное
                i = 0;
                // Заполняем первую стркоу названиями столбцов
                Section.Rows[i++][currentColumn] = col.Name;
                // Если значение по умолчанию заполнено, заполняем ими столбец
                if (!(col.DefaultValue is null))
                {
                    for (i = 1; i <= countOfRows; i++)
                    {
                        Section.Rows[i][currentColumn] = col.DefaultValue;
                    }
                }